1
0

script.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * Material is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI
  3. *
  4. * luci-theme-material
  5. * Copyright 2015 Lutty Yang <lutty@wcan.in>
  6. *
  7. * Have a bug? Please create an issue here on GitHub!
  8. * https://github.com/LuttyYang/luci-theme-material/issues
  9. *
  10. * luci-theme-bootstrap:
  11. * Copyright 2008 Steven Barth <steven@midlink.org>
  12. * Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  13. * Copyright 2012 David Menting <david@nut-bolt.nl>
  14. *
  15. * MUI:
  16. * https://github.com/muicss/mui
  17. *
  18. * Licensed to the public under the Apache License 2.0
  19. */
  20. (function ($) {
  21. $(".main > .loading").fadeOut();
  22. /**
  23. * trim text, Remove spaces, wrap
  24. * @param text
  25. * @returns {string}
  26. */
  27. function trimText(text) {
  28. return text.replace(/[ \t\n\r]+/g, " ");
  29. }
  30. var lastNode = undefined;
  31. var mainNodeName = undefined;
  32. var nodeUrl = "";
  33. (function(node){
  34. if (node[0] == "admin"){
  35. luciLocation = [node[1], node[2]];
  36. }else{
  37. luciLocation = node;
  38. }
  39. for(var i in luciLocation){
  40. nodeUrl += luciLocation[i];
  41. if (i != luciLocation.length - 1){
  42. nodeUrl += "/";
  43. }
  44. }
  45. })(luciLocation);
  46. /**
  47. * get the current node by Burl (primary)
  48. * @returns {boolean} success?
  49. */
  50. function getCurrentNodeByUrl() {
  51. var ret = false;
  52. if (!$('body').hasClass('logged-in')) {
  53. luciLocation = ["Main", "Login"];
  54. return true;
  55. }
  56. $(".main > .main-left > .nav > .slide > .menu").each(function () {
  57. var ulNode = $(this);
  58. ulNode.next().find("a").each(function () {
  59. var that = $(this);
  60. var href = that.attr("href");
  61. if (href.indexOf(nodeUrl) != -1) {
  62. ulNode.click();
  63. ulNode.next(".slide-menu").stop(true, true);
  64. lastNode = that.parent();
  65. lastNode.addClass("active");
  66. ret = true;
  67. return true;
  68. }
  69. });
  70. });
  71. return ret;
  72. }
  73. /**
  74. * menu click
  75. */
  76. $(".main > .main-left > .nav > .slide > .menu").click(function () {
  77. var ul = $(this).next(".slide-menu");
  78. var menu = $(this);
  79. if (!ul.is(":visible")) {
  80. menu.addClass("active");
  81. ul.addClass("active");
  82. ul.stop(true).slideDown("fast");
  83. } else {
  84. ul.stop(true).slideUp("fast", function () {
  85. menu.removeClass("active");
  86. ul.removeClass("active");
  87. });
  88. }
  89. return false;
  90. });
  91. /**
  92. * hook menu click and add the hash
  93. */
  94. $(".main > .main-left > .nav > .slide > .slide-menu > li > a").click(function () {
  95. if (lastNode != undefined) lastNode.removeClass("active");
  96. $(this).parent().addClass("active");
  97. $(".main > .loading").fadeIn("fast");
  98. return true;
  99. });
  100. /**
  101. * fix menu click
  102. */
  103. $(".main > .main-left > .nav > .slide > .slide-menu > li").click(function () {
  104. if (lastNode != undefined) lastNode.removeClass("active");
  105. $(this).addClass("active");
  106. $(".main > .loading").fadeIn("fast");
  107. window.location = $($(this).find("a")[0]).attr("href");
  108. return false;
  109. });
  110. /**
  111. * get current node and open it
  112. */
  113. if (getCurrentNodeByUrl()) {
  114. mainNodeName = "node-" + luciLocation[0] + "-" + luciLocation[1];
  115. mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g, "_").toLowerCase();
  116. $("body").addClass(mainNodeName);
  117. }
  118. $(".cbi-button-up").val("");
  119. $(".cbi-button-down").val("");
  120. /**
  121. * hook other "A Label" and add hash to it.
  122. */
  123. $("#maincontent > .container").find("a").each(function () {
  124. var that = $(this);
  125. var onclick = that.attr("onclick");
  126. if (onclick == undefined || onclick == "") {
  127. that.click(function () {
  128. var href = that.attr("href");
  129. if (href.indexOf("#") == -1) {
  130. $(".main > .loading").fadeIn("fast");
  131. return true;
  132. }
  133. });
  134. }
  135. });
  136. /**
  137. * Sidebar expand
  138. */
  139. var showSide = false;
  140. $(".showSide").click(function () {
  141. if (showSide) {
  142. $(".darkMask").stop(true).fadeOut("fast");
  143. $(".main-left").stop(true).animate({
  144. width: "0"
  145. }, "fast");
  146. $(".main-right").css("overflow-y", "auto");
  147. showSide = false;
  148. } else {
  149. $(".darkMask").stop(true).fadeIn("fast");
  150. $(".main-left").stop(true).animate({
  151. width: "15rem"
  152. }, "fast");
  153. $(".main-right").css("overflow-y", "hidden");
  154. showSide = true;
  155. }
  156. });
  157. $(".darkMask").click(function () {
  158. if (showSide) {
  159. showSide = false;
  160. $(".darkMask").stop(true).fadeOut("fast");
  161. $(".main-left").stop(true).animate({
  162. width: "0"
  163. }, "fast");
  164. $(".main-right").css("overflow-y", "auto");
  165. }
  166. });
  167. $(window).resize(function () {
  168. if ($(window).width() > 921) {
  169. $(".main-left").css("width", "");
  170. $(".darkMask").stop(true);
  171. $(".darkMask").css("display", "none");
  172. showSide = false;
  173. }
  174. });
  175. /**
  176. * fix legend position
  177. */
  178. $("legend").each(function () {
  179. var that = $(this);
  180. that.after("<span class='panel-title'>" + that.text() + "</span>");
  181. });
  182. $(".cbi-section-table-titles, .cbi-section-table-descr, .cbi-section-descr").each(function () {
  183. var that = $(this);
  184. if (that.text().trim() == ""){
  185. that.css("display", "none");
  186. }
  187. });
  188. $(".main-right").focus();
  189. $(".main-right").blur();
  190. $("input").attr("size", "0");
  191. if (mainNodeName != undefined) {
  192. console.log(mainNodeName);
  193. switch (mainNodeName) {
  194. case "node-status-system_log":
  195. case "node-status-kernel_log":
  196. $("#syslog").focus(function () {
  197. $("#syslog").blur();
  198. $(".main-right").focus();
  199. $(".main-right").blur();
  200. });
  201. break;
  202. case "node-status-firewall":
  203. var button = $(".node-status-firewall > .main fieldset li > a");
  204. button.addClass("cbi-button cbi-button-reset a-to-btn");
  205. break;
  206. case "node-system-reboot":
  207. var button = $(".node-system-reboot > .main > .main-right p > a");
  208. button.addClass("cbi-button cbi-input-reset a-to-btn");
  209. break;
  210. }
  211. }
  212. })(jQuery);