script.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. var luciLocation;
  35. if (node[0] == "admin"){
  36. luciLocation = [node[1], node[2]];
  37. }else{
  38. luciLocation = node;
  39. }
  40. for(var i in luciLocation){
  41. nodeUrl += luciLocation[i];
  42. if (i != luciLocation.length - 1){
  43. nodeUrl += "/";
  44. }
  45. }
  46. })(luciLocation);
  47. /**
  48. * get the current node by Burl (primary)
  49. * @returns {boolean} success?
  50. */
  51. function getCurrentNodeByUrl() {
  52. var ret = false;
  53. if (!$('body').hasClass('logged-in')) {
  54. luciLocation = ["Main", "Login"];
  55. return true;
  56. }
  57. $(".main > .main-left > .nav > .slide > .menu").each(function () {
  58. var ulNode = $(this);
  59. ulNode.next().find("a").each(function () {
  60. var that = $(this);
  61. var href = that.attr("href");
  62. if (href.indexOf(nodeUrl) != -1) {
  63. ulNode.click();
  64. ulNode.next(".slide-menu").stop(true, true);
  65. lastNode = that.parent();
  66. lastNode.addClass("active");
  67. ret = true;
  68. return true;
  69. }
  70. });
  71. });
  72. return ret;
  73. }
  74. /**
  75. * menu click
  76. */
  77. $(".main > .main-left > .nav > .slide > .menu").click(function () {
  78. var ul = $(this).next(".slide-menu");
  79. var menu = $(this);
  80. if (!ul.is(":visible")) {
  81. menu.addClass("active");
  82. ul.addClass("active");
  83. ul.stop(true).slideDown("fast");
  84. } else {
  85. ul.stop(true).slideUp("fast", function () {
  86. menu.removeClass("active");
  87. ul.removeClass("active");
  88. });
  89. }
  90. return false;
  91. });
  92. /**
  93. * hook menu click and add the hash
  94. */
  95. $(".main > .main-left > .nav > .slide > .slide-menu > li > a").click(function () {
  96. if (lastNode != undefined) lastNode.removeClass("active");
  97. $(this).parent().addClass("active");
  98. $(".main > .loading").fadeIn("fast");
  99. return true;
  100. });
  101. /**
  102. * fix menu click
  103. */
  104. $(".main > .main-left > .nav > .slide > .slide-menu > li").click(function () {
  105. if (lastNode != undefined) lastNode.removeClass("active");
  106. $(this).addClass("active");
  107. $(".main > .loading").fadeIn("fast");
  108. window.location = $($(this).find("a")[0]).attr("href");
  109. return false;
  110. });
  111. /**
  112. * get current node and open it
  113. */
  114. if (getCurrentNodeByUrl()) {
  115. mainNodeName = "node-" + luciLocation[0] + "-" + luciLocation[1];
  116. mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g, "_").toLowerCase();
  117. $("body").addClass(mainNodeName);
  118. }
  119. $(".cbi-button-up").val("");
  120. $(".cbi-button-down").val("");
  121. /**
  122. * hook other "A Label" and add hash to it.
  123. */
  124. $("#maincontent > .container").find("a").each(function () {
  125. var that = $(this);
  126. var onclick = that.attr("onclick");
  127. if (onclick == undefined || onclick == "") {
  128. that.click(function () {
  129. var href = that.attr("href");
  130. if (href.indexOf("#") == -1) {
  131. $(".main > .loading").fadeIn("fast");
  132. return true;
  133. }
  134. });
  135. }
  136. });
  137. /**
  138. * Sidebar expand
  139. */
  140. var showSide = false;
  141. $(".showSide").click(function () {
  142. if (showSide) {
  143. $(".darkMask").stop(true).fadeOut("fast");
  144. $(".main-left").stop(true).animate({
  145. width: "0"
  146. }, "fast");
  147. $(".main-right").css("overflow-y", "visible");
  148. showSide = false;
  149. } else {
  150. $(".darkMask").stop(true).fadeIn("fast");
  151. $(".main-left").stop(true).animate({
  152. width: "15rem"
  153. }, "fast");
  154. $(".main-right").css("overflow-y", "hidden");
  155. showSide = true;
  156. }
  157. });
  158. $(".darkMask").click(function () {
  159. if (showSide) {
  160. showSide = false;
  161. $(".darkMask").stop(true).fadeOut("fast");
  162. $(".main-left").stop(true).animate({
  163. width: "0"
  164. }, "fast");
  165. $(".main-right").css("overflow-y", "visible");
  166. }
  167. });
  168. $(window).resize(function () {
  169. if ($(window).width() > 921) {
  170. $(".main-left").css("width", "");
  171. $(".darkMask").stop(true);
  172. $(".darkMask").css("display", "none");
  173. showSide = false;
  174. }
  175. });
  176. /**
  177. * fix legend position
  178. */
  179. $("legend").each(function () {
  180. var that = $(this);
  181. that.after("<span class='panel-title'>" + that.text() + "</span>");
  182. });
  183. $(".cbi-section-table-titles, .cbi-section-table-descr, .cbi-section-descr").each(function () {
  184. var that = $(this);
  185. if (that.text().trim() == ""){
  186. that.css("display", "none");
  187. }
  188. });
  189. $(".main-right").focus();
  190. $(".main-right").blur();
  191. $("input").attr("size", "0");
  192. if (mainNodeName != undefined) {
  193. console.log(mainNodeName);
  194. switch (mainNodeName) {
  195. case "node-status-system_log":
  196. case "node-status-kernel_log":
  197. $("#syslog").focus(function () {
  198. $("#syslog").blur();
  199. $(".main-right").focus();
  200. $(".main-right").blur();
  201. });
  202. break;
  203. case "node-status-firewall":
  204. var button = $(".node-status-firewall > .main fieldset li > a");
  205. button.addClass("cbi-button cbi-button-reset a-to-btn");
  206. break;
  207. case "node-system-reboot":
  208. var button = $(".node-system-reboot > .main > .main-right p > a");
  209. button.addClass("cbi-button cbi-input-reset a-to-btn");
  210. break;
  211. }
  212. }
  213. })(jQuery);