2 * Material is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI
5 * Copyright 2015 Lutty Yang <lutty@wcan.in>
7 * Have a bug? Please create an issue here on GitHub!
8 * https://github.com/LuttyYang/luci-theme-material/issues
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>
16 * https://github.com/muicss/mui
18 * Licensed to the public under the Apache License 2.0
21 $(".main > .loading").fadeOut();
24 * trim text, Remove spaces, wrap
28 function trimText(text) {
29 return text.replace(/[ \t\n\r]+/g, " ");
33 var lastNode = undefined;
34 var mainNodeName = undefined;
39 if (node[0] == "admin"){
40 luciLocation = [node[1], node[2]];
45 for(var i in luciLocation){
46 nodeUrl += luciLocation[i];
47 if (i != luciLocation.length - 1){
54 * get the current node by Burl (primary)
55 * @returns {boolean} success?
57 function getCurrentNodeByUrl() {
59 if (!$('body').hasClass('logged-in')) {
60 luciLocation = ["Main", "Login"];
64 $(".main > .main-left > .nav > .slide > .menu").each(function () {
66 ulNode.next().find("a").each(function () {
68 var href = that.attr("href");
70 if (href.indexOf(nodeUrl) != -1) {
72 ulNode.next(".slide-menu").stop(true, true);
73 lastNode = that.parent();
74 lastNode.addClass("active");
86 $(".main > .main-left > .nav > .slide > .menu").click(function () {
87 var ul = $(this).next(".slide-menu");
89 if (!ul.is(":visible")) {
90 menu.addClass("active");
91 ul.addClass("active");
92 ul.stop(true).slideDown("fast");
94 ul.stop(true).slideUp("fast", function () {
95 menu.removeClass("active");
96 ul.removeClass("active");
103 * hook menu click and add the hash
105 $(".main > .main-left > .nav > .slide > .slide-menu > li > a").click(function () {
106 if (lastNode != undefined) lastNode.removeClass("active");
107 $(this).parent().addClass("active");
108 $(".main > .loading").fadeIn("fast");
115 $(".main > .main-left > .nav > .slide > .slide-menu > li").click(function () {
116 if (lastNode != undefined) lastNode.removeClass("active");
117 $(this).addClass("active");
118 $(".main > .loading").fadeIn("fast");
119 window.location = $($(this).find("a")[0]).attr("href");
124 * get current node and open it
126 if (getCurrentNodeByUrl()) {
127 mainNodeName = "node-" + luciLocation[0] + "-" + luciLocation[1];
128 mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g, "_").toLowerCase();
129 $("body").addClass(mainNodeName);
131 $(".cbi-button-up").val("");
132 $(".cbi-button-down").val("");
136 * hook other "A Label" and add hash to it.
138 $("#maincontent > .container").find("a").each(function () {
140 var onclick = that.attr("onclick");
141 if (onclick == undefined || onclick == "") {
142 that.click(function () {
143 var href = that.attr("href");
144 if (href.indexOf("#") == -1) {
145 $(".main > .loading").fadeIn("fast");
155 var showSide = false;
156 $(".showSide").click(function () {
158 $(".darkMask").stop(true).fadeOut("fast");
159 $(".main-left").stop(true).animate({
162 $(".main-right").css("overflow-y", "visible");
165 $(".darkMask").stop(true).fadeIn("fast");
166 $(".main-left").stop(true).animate({
169 $(".main-right").css("overflow-y", "hidden");
175 $(".darkMask").click(function () {
178 $(".darkMask").stop(true).fadeOut("fast");
179 $(".main-left").stop(true).animate({
182 $(".main-right").css("overflow-y", "visible");
186 $(window).resize(function () {
187 if ($(window).width() > 921) {
188 $(".main-left").css("width", "");
189 $(".darkMask").stop(true);
190 $(".darkMask").css("display", "none");
196 * fix legend position
198 $("legend").each(function () {
200 that.after("<span class='panel-title'>" + that.text() + "</span>");
203 $(".cbi-section-table-titles, .cbi-section-table-descr, .cbi-section-descr").each(function () {
205 if (that.text().trim() == ""){
206 that.css("display", "none");
211 $(".main-right").focus();
212 $(".main-right").blur();
213 $("input").attr("size", "0");
215 if (mainNodeName != undefined) {
216 console.log(mainNodeName);
217 switch (mainNodeName) {
218 case "node-status-system_log":
219 case "node-status-kernel_log":
220 $("#syslog").focus(function () {
222 $(".main-right").focus();
223 $(".main-right").blur();
226 case "node-status-firewall":
227 var button = $(".node-status-firewall > .main fieldset li > a");
228 button.addClass("cbi-button cbi-button-reset a-to-btn");
230 case "node-system-reboot":
231 var button = $(".node-system-reboot > .main > .main-right p > a");
232 button.addClass("cbi-button cbi-input-reset a-to-btn");