PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/system/pyrocms/assets/js/admin/functions.js

https://github.com/mul14/pyrocms
JavaScript | 223 lines | 177 code | 23 blank | 23 comment | 20 complexity | 455860e06f495e219baccfa706c59841 MD5 | raw file
  1. /**
  2. * Pyro object
  3. *
  4. * The Pyro object is the foundation of all PyroUI enhancements
  5. */
  6. var pyro = {};
  7. jQuery(function($) {
  8. /**
  9. * This initializes all JS goodness
  10. */
  11. pyro.init = function() {
  12. $( "#datepicker" ).datepicker();
  13. $("#main-nav li ul").hide();
  14. $("#main-nav li a.current").parent().find("ul").toggle();
  15. $("#main-nav li a.current:not(.no-submenu)").addClass("bottom-border");
  16. $("#main-nav li a.top-link").click(function () {
  17. if($(this).hasClass("no-submenu"))
  18. {
  19. return false;
  20. }
  21. $(this).parent().siblings().find("ul").slideUp("normal");
  22. $(this).parent().siblings().find("a").removeClass("bottom-border");
  23. $(this).next().slideToggle("normal");
  24. $(this).toggleClass("bottom-border");
  25. return false;
  26. });
  27. $("#main-nav li a.no-submenu").click(function () {
  28. window.location.href = $(this).attr("href");
  29. return false;
  30. });
  31. // Add the close link to all boxes with the closable class
  32. $(".closable").append('<a href="#" class="close">close</a>');
  33. // Close the notifications when the close link is clicked
  34. $("a.close").live('click', function () {
  35. $(this).fadeTo(200, 0); // This is a hack so that the close link fades out in IE
  36. $(this).parent().fadeTo(200, 0);
  37. $(this).parent().slideUp(400);
  38. return false;
  39. });
  40. // Fade in the notifications
  41. $(".notification").fadeIn("slow");
  42. // Check all checkboxes in table
  43. $(".check-all").live('click', function () {
  44. $(this).parents("table").find("tbody input[type='checkbox']").each(function () {
  45. if($(".check-all").is(":checked") && !$(this).is(':checked'))
  46. {
  47. $(this).click();
  48. }
  49. else if(!$(".check-all").is(":checked") && $(this).is(':checked'))
  50. {
  51. $(this).click();
  52. }
  53. });
  54. // Update uniform if enabled
  55. $.uniform && $.uniform.update();
  56. });
  57. // Confirmation
  58. $("a.confirm").live('click', function(e){
  59. var href = $(this).attr("href");
  60. removemsg = $(this).attr("title");
  61. if (removemsg != 'undefined')
  62. {
  63. if(removemsg.length <= 0)
  64. {
  65. msg = DIALOG_MESSAGE;
  66. }
  67. else
  68. {
  69. msg = removemsg;
  70. }
  71. }
  72. else
  73. {
  74. msg = DIALOG_MESSAGE;
  75. }
  76. if(!confirm(msg))
  77. {
  78. e.preventDefault();
  79. }
  80. else
  81. {
  82. //submits it whether uniform likes it or not
  83. window.location.href = href;
  84. }
  85. });
  86. //make page buttons work (fixes a uniform bug in FF)
  87. $('a.button, a.minibutton').live('click', function() {
  88. var href = $(this).attr("href");
  89. if($(this).hasClass('confirm') === false && $(this).hasClass('colorbox') === false)
  90. {
  91. window.location.href = href;
  92. }
  93. });
  94. //use a confirm dialog on "delete many" buttons
  95. $(':button.button').live('click', function(e) {
  96. if($(this).val() == 'delete')
  97. {
  98. removemsg = $(this).attr("title");
  99. if (removemsg != 'undefined')
  100. {
  101. if(removemsg.length <= 0)
  102. {
  103. msg = DIALOG_MESSAGE;
  104. }
  105. else
  106. {
  107. msg = removemsg;
  108. }
  109. }
  110. else
  111. {
  112. msg = DIALOG_MESSAGE;
  113. }
  114. if(!confirm(msg))
  115. {
  116. e.preventDefault();
  117. }
  118. }
  119. });
  120. // Table zerbra striping
  121. $("tbody tr:nth-child(even)").livequery(function () {
  122. $(this).addClass("alt");
  123. });
  124. $('.tabs').livequery(function () {
  125. $(this).tabs();
  126. });
  127. $('#tabs').livequery(function () {
  128. $(this).tabs({
  129. // This allows for the Back button to work.
  130. select: function(event, ui) {
  131. parent.location.hash = ui.tab.hash;
  132. },
  133. load: function(event, ui) {
  134. confirm_links();
  135. confirm_buttons();
  136. }
  137. });
  138. });
  139. $("select, textarea, input[type=text], input[type=file], input[type=submit], a.button, a.minibutton, button").livequery(function () {
  140. // Update uniform if enabled
  141. $.uniform && $(this).uniform();
  142. });
  143. var current_module = $('#page-header h1 a').text();
  144. // Fancybox modal window
  145. $('a[rel=modal], a.modal').livequery(function() {
  146. $(this).colorbox({
  147. width: "60%",
  148. onComplete: function() {
  149. $.uniform.update();
  150. },
  151. current: current_module + " {current} / {total}"
  152. });
  153. });
  154. $('a[rel="modal-large"], a.modal-large').livequery(function() {
  155. $(this).colorbox({
  156. width: "90%",
  157. height: "95%",
  158. iframe: true,
  159. scrolling: false,
  160. current: current_module + " {current} / {total}"
  161. });
  162. });
  163. // End Fancybox modal window
  164. }
  165. $(document).ready(function() {
  166. pyro.init();
  167. });
  168. });
  169. //functions for codemirror
  170. function html_editor(id, width)
  171. {
  172. CodeMirror.fromTextArea(id, {
  173. height: "30em",
  174. width: width,
  175. parserfile: ["parsejavascript.js","parsexml.js", "parsecss.js", "parsehtmlmixed.js"],
  176. stylesheet: [APPPATH_URI + "assets/css/codemirror/xmlcolors.css", APPPATH_URI + "assets/css/codemirror/csscolors.css"],
  177. path: APPPATH_URI + "assets/js/codemirror/",
  178. tabMode: 'spaces'
  179. });
  180. }
  181. function css_editor(id, width)
  182. {
  183. CodeMirror.fromTextArea(id, {
  184. height: "30em",
  185. width: width,
  186. parserfile: "parsecss.js",
  187. stylesheet: APPPATH_URI + "assets/css/codemirror/csscolors.css",
  188. path: APPPATH_URI + "assets/js/codemirror/"
  189. });
  190. }
  191. function js_editor(id, width)
  192. {
  193. CodeMirror.fromTextArea(id, {
  194. height: "30em",
  195. width: width,
  196. parserfile: ["tokenizejavascript.js", "parsejavascript.js"],
  197. stylesheet: APPPATH_URI + "assets/css/codemirror/jscolors.css",
  198. path: APPPATH_URI + "assets/js/codemirror/"
  199. });
  200. }