theme: add initial commit for rosy theme
[project/luci.git] / themes / luci-theme-rosy / htdocs / luci-static / rosy / js / script.js
1 /**
2 * Rosy is a theme for LuCI. It is based on luci-theme-bootstrap
3 *
4 * luci-theme-rosy
5 * Copyright 2018 Rosy Song <rosysong@rosinson.com>
6 * Copyright 2018 Yan Lan Shen <yanlan.shen@rosinson.com>
7 *
8 * Have a bug? Please create an issue here on GitHub!
9 * https://github.com/rosywrt/luci-theme-rosy/issues
10 *
11 * luci-theme-bootstrap:
12 * Copyright 2008 Steven Barth <steven@midlink.org>
13 * Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
14 * Copyright 2012 David Menting <david@nut-bolt.nl>
15 *
16 * Licensed to the public under the Apache License 2.0
17 */
18
19 (function ($) {
20 $(".main > .loading").fadeOut();
21
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
31
32 var lastNode = undefined;
33 var mainNodeName = undefined;
34
35 var nodeUrl = "";
36 (function(node){
37 if (node[0] == "admin"){
38 luciLocation = [node[1], node[2]];
39 }else{
40 luciLocation = node;
41 }
42
43 for(var i in luciLocation){
44 nodeUrl += luciLocation[i];
45 if (i != luciLocation.length - 1){
46 nodeUrl += "/";
47 }
48 }
49 })(luciLocation);
50
51 /**
52 * get the current node by Burl (primary)
53 * @returns {boolean} success?
54 */
55 function getCurrentNodeByUrl() {
56 var ret = false;
57 if (!$('body').hasClass('logged-in')) {
58 luciLocation = ["Main", "Login"];
59 return true;
60 }
61
62 $(".main > .main-left .nav > .slide > .menu").each(function () {
63 var ulNode = $(this);
64 ulNode.next().find("a").each(function () {
65 var that = $(this);
66 var href = that.attr("href");
67
68 if (href.indexOf(nodeUrl) != -1) {
69 ulNode.click();
70 ulNode.next(".slide-menu").stop(true, true);
71 lastNode = that.parent();
72 lastNode.addClass("active");
73 ret = true;
74 return true;
75 }
76 });
77 });
78 return ret;
79 }
80
81 /**
82 * menu click
83 */
84 $(".main > .main-left .nav > .slide > .menu").click(function () {
85 var ul = $(this).next(".slide-menu");
86 var menu = $(this);
87 if (!ul.is(":visible")) {
88 menu.addClass("active");
89 ul.addClass("active");
90 ul.stop(true).slideDown("fast");
91 } else {
92 ul.stop(true).slideUp("fast", function () {
93 menu.removeClass("active");
94 ul.removeClass("active");
95 });
96 }
97 return false;
98 });
99
100
101 /**
102 * hook menu click and add the hash
103 */
104 $(".main > .main-left .nav > .slide > .slide-menu > li > a").click(function () {
105 if (lastNode != undefined) lastNode.removeClass("active");
106 $(this).parent().addClass("active");
107 $(".main > .loading").fadeIn("fast");
108 return true;
109 });
110
111 /**
112 * fix menu click
113 */
114 $(".main > .main-left .nav > .slide > .slide-menu > li").click(function () {
115 if (lastNode != undefined) lastNode.removeClass("active");
116 $(this).addClass("active");
117 $(".main > .loading").fadeIn("fast");
118 window.location = $($(this).find("a")[0]).attr("href");
119 return false;
120 });
121
122 /**
123 * get current node and open it
124 */
125 if (getCurrentNodeByUrl()) {
126 mainNodeName = "node-" + luciLocation[0] + "-" + luciLocation[1];
127 mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g, "_").toLowerCase();
128 $("body").addClass(mainNodeName);
129 }
130 $(".cbi-button-up").val("");
131 $(".cbi-button-down").val("");
132
133
134 /**
135 * hook other "A Label" and add hash to it.
136 */
137 $("#maincontent > .container").find("a").each(function () {
138 var that = $(this);
139 var onclick = that.attr("onclick");
140 if (onclick == undefined || onclick == "") {
141 that.click(function () {
142 var href = that.attr("href");
143 if (href.indexOf("#") == -1) {
144 $(".main > .loading").fadeIn("fast");
145 return true;
146 }
147 });
148 }
149 });
150
151 /**
152 * Sidebar expand
153 */
154 var showSide = false;
155 $(".showSide").click(function () {
156 if (showSide) {
157 $(".main-left").stop(true).animate({
158 right: '100%'
159 }, "fast");
160 $(".main-right").css("overflow-y", "auto");
161 showSide = false;
162 } else {
163 $(".main-left").stop(true).animate({
164 right: '0'
165 }, "fast");
166 $(".main-right").css("overflow-y", "hidden");
167 showSide = true;
168 }
169 });
170
171
172 $(".logged-in .main-left").click(function () {
173 if (showSide) {
174 showSide = false;
175
176 $(this).stop(true).fadeOut("fast");
177 $(".main-left").stop(true).animate({
178 right: '100%'
179 }, "fast");
180 $(".main-right").css("overflow-y", "auto");
181 }
182 });
183
184 $(".logged-in .main-left > *").click(function () {
185 event.stopPropagation();
186 if ((navigator.userAgent.indexOf('MSIE') >= 0)&& (navigator.userAgent.indexOf('Opera') < 0)){
187 event.cancelBubble = true;
188 }else{
189 event.stopPropagation();
190 }
191 });
192
193 $(window).resize(function () {
194 if ($(window).width() > 921) {
195 $(".main-left").css("width", "");
196 $(".darkMask").stop(true);
197 $(".darkMask").css("display", "none");
198 showSide = false;
199 }
200 if( $(window).width() > 992 ){
201 $('.logged-in .main-right').width( $(window).width() - $('.logged-in .main-left').width() - 50 );
202 }
203 });
204
205 /**
206 * fix legend position
207 */
208 $("legend").each(function () {
209 var that = $(this);
210 that.after("<span class='panel-title'>" + that.text() + "</span>");
211 });
212
213 $(".cbi-section-table-titles, .cbi-section-table-descr, .cbi-section-descr").each(function () {
214 var that = $(this);
215 if (that.text().trim() == ""){
216 that.css("display", "none");
217 }
218 });
219
220
221 $(".main-right").focus();
222 $(".main-right").blur();
223 $("input").attr("size", "0");
224
225 if (mainNodeName != undefined) {
226 console.log(mainNodeName);
227 switch (mainNodeName) {
228 case "node-status-system_log":
229 case "node-status-kernel_log":
230 $("#syslog").focus(function () {
231 $("#syslog").blur();
232 $(".main-right").focus();
233 $(".main-right").blur();
234 });
235 break;
236 case "node-status-firewall":
237 var button = $(".node-status-firewall > .main fieldset li > a");
238 button.addClass("cbi-button cbi-button-reset a-to-btn");
239 break;
240 case "node-system-reboot":
241 var button = $(".node-system-reboot > .main > .main-right p > a");
242 button.addClass("cbi-button cbi-input-reset a-to-btn");
243 break;
244 }
245 }
246
247 $('<div class="iconpwd"></div>').appendTo($('.node-main-login form .cbi-value input[type="password"]').parent()[0]);
248
249 $('<div class="iconuser"></div>').appendTo($('.node-main-login form .cbi-value input[type="text"]').parent()[0]);
250
251 $('<div class="iconeye"></div>').appendTo($('.node-main-login form .cbi-value input[type="password"]').parent()[0]);
252
253 var num = true;
254 $('.cbi-value-field .iconeye').click(function(){
255 if(num){
256 $('.node-main-login form .cbi-value-last input[type="password"]').prop('type', 'text');
257 $('.node-main-login form .cbi-value-field .iconeye').removeClass('opeye').addClass('cleye');
258 num = false;
259 }else {
260 $('.node-main-login form .cbi-value-last input[type="text"]').prop('type', 'password');
261 $('.node-main-login form .cbi-value-field .iconeye').removeClass('cleye').addClass('opeye');
262 num = true
263 }
264
265 })
266
267 if( $(window).width() > 992 ){
268 $('.logged-in .main-right').width( $(window).width() - $('.logged-in .main-left').width() - 50 );
269 }
270
271
272 })(jQuery);