luci-theme-rosy: Change the scroll bar style, compatible with each browser
[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 if ($('.nav').length > 0 && $(window).width() > 992) {
85 var oScroll = new MyScrollBar({
86 selId: 'navBox',
87 time: 100,
88 bgColor: 'transprent',
89 barColor: '#839dd67a',
90 enterColor: '#839dd6cc',
91 enterShow: false
92 });
93 }
94
95 $(".main > .main-left .nav > .slide > .menu").click(function () {
96 var ul = $(this).next(".slide-menu");
97 var menu = $(this);
98 if (!ul.is(":visible")) {
99 menu.addClass("active");
100 ul.addClass("active");
101 ul.stop(true).slideDown("fast");
102 } else {
103 ul.stop(true).slideUp("fast", function () {
104 menu.removeClass("active");
105 ul.removeClass("active");
106 });
107 }
108 if ($('.nav').length > 0 && $(window).width() > 992) {
109 oScroll.setSize(200);
110 }
111 setInterval(function(){
112 if($('.nav').height() < $('.navbar-container').height()){
113 $('.nav').css('transform', 'translate(0px, 0px)');
114 }
115 }, 300);
116 return false;
117 });
118
119
120 /**
121 * hook menu click and add the hash
122 */
123 $(".main > .main-left .nav > .slide > .slide-menu > li > a").click(function () {
124 if (lastNode != undefined) lastNode.removeClass("active");
125 $(this).parent().addClass("active");
126 $(".main > .loading").fadeIn("fast");
127 return true;
128 });
129
130 /**
131 * fix menu click
132 */
133 $(".main > .main-left .nav > .slide > .slide-menu > li").click(function () {
134 if (lastNode != undefined) lastNode.removeClass("active");
135 $(this).addClass("active");
136 $(".main > .loading").fadeIn("fast");
137 window.location = $($(this).find("a")[0]).attr("href");
138 return false;
139 });
140
141 /**
142 * get current node and open it
143 */
144 if (getCurrentNodeByUrl()) {
145 mainNodeName = "node-" + luciLocation[0] + "-" + luciLocation[1];
146 mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g, "_").toLowerCase();
147 $("body").addClass(mainNodeName);
148 }
149 $(".cbi-button-up").val("");
150 $(".cbi-button-down").val("");
151
152
153 /**
154 * hook other "A Label" and add hash to it.
155 */
156 $("#maincontent > .container").find("a").each(function () {
157 var that = $(this);
158 var onclick = that.attr("onclick");
159 if (onclick == undefined || onclick == "") {
160 that.click(function () {
161 var href = that.attr("href");
162 if (href.indexOf("#") == -1) {
163 $(".main > .loading").fadeIn("fast");
164 return true;
165 }
166 });
167 }
168 });
169
170 /**
171 * Sidebar expand
172 */
173 var showSide = false;
174 $(".showSide").click(function () {
175 if (showSide) {
176 $(".main-left").stop(true).animate({
177 right: '100%'
178 }, "fast");
179 $(".main-right").css("overflow-y", "auto");
180 showSide = false;
181 } else {
182 $(".main-left").stop(true).animate({
183 right: '0'
184 }, "fast");
185 $(".main-right").css("overflow-y", "hidden");
186 showSide = true;
187 }
188 });
189
190
191 $(".logged-in .main-left").click(function () {
192 if (showSide) {
193 showSide = false;
194
195 $(this).stop(true).fadeOut("fast");
196 $(".main-left").stop(true).animate({
197 right: '100%'
198 }, "fast");
199 $(".main-right").css("overflow-y", "auto");
200 }
201 });
202
203 $(".logged-in .main-left > *").click(function () {
204 event.stopPropagation();
205 if ((navigator.userAgent.indexOf('MSIE') >= 0)&& (navigator.userAgent.indexOf('Opera') < 0)){
206 event.cancelBubble = true;
207 }else{
208 event.stopPropagation();
209 }
210 });
211
212 $(window).resize(function () {
213 if ($(window).width() > 921) {
214 $(".main-left").css("width", "");
215 $(".darkMask").stop(true);
216 $(".darkMask").css("display", "none");
217 showSide = false;
218 }
219 if( $(window).width() > 992 ){
220 $('.logged-in .main-right').width( $(window).width() - $('.logged-in .main-left').width() - 50 );
221 }
222 });
223
224 /**
225 * fix legend position
226 */
227 $("legend").each(function () {
228 var that = $(this);
229 that.after("<span class='panel-title'>" + that.text() + "</span>");
230 });
231
232 $(".cbi-section-table-titles, .cbi-section-table-descr, .cbi-section-descr").each(function () {
233 var that = $(this);
234 if (that.text().trim() == ""){
235 that.css("display", "none");
236 }
237 });
238
239
240 $(".main-right").focus();
241 $(".main-right").blur();
242 $("input").attr("size", "0");
243
244 if (mainNodeName != undefined) {
245 console.log(mainNodeName);
246 switch (mainNodeName) {
247 case "node-status-system_log":
248 case "node-status-kernel_log":
249 $("#syslog").focus(function () {
250 $("#syslog").blur();
251 $(".main-right").focus();
252 $(".main-right").blur();
253 });
254 break;
255 case "node-status-firewall":
256 var button = $(".node-status-firewall > .main fieldset li > a");
257 button.addClass("cbi-button cbi-button-reset a-to-btn");
258 break;
259 case "node-system-reboot":
260 var button = $(".node-system-reboot > .main > .main-right p > a");
261 button.addClass("cbi-button cbi-input-reset a-to-btn");
262 break;
263 }
264 }
265
266 $('<div class="iconpwd"></div>').appendTo($('.node-main-login form .cbi-value input[type="password"]').parent()[0]);
267
268 $('<div class="iconuser"></div>').appendTo($('.node-main-login form .cbi-value input[type="text"]').parent()[0]);
269
270 $('<div class="iconeye"></div>').appendTo($('.node-main-login form .cbi-value input[type="password"]').parent()[0]);
271
272 var num = true;
273 $('.cbi-value-field .iconeye').click(function(){
274 if(num){
275 $('.node-main-login form .cbi-value-last input[type="password"]').prop('type', 'text');
276 $('.node-main-login form .cbi-value-field .iconeye').removeClass('opeye').addClass('cleye');
277 num = false;
278 }else {
279 $('.node-main-login form .cbi-value-last input[type="text"]').prop('type', 'password');
280 $('.node-main-login form .cbi-value-field .iconeye').removeClass('cleye').addClass('opeye');
281 num = true
282 }
283
284 })
285
286 $('body.logged-in').css('min-height', $(window).height());
287
288 $(function(){
289 if( $(window).width() > 992 ){
290 $('.logged-in .main-right').outerWidth( $(window).width() - $('.logged-in .main-left').width() - 50 );
291 }
292
293 $('.cbi-section .table').each(function(){
294 var thisTr = $(this).children('.tr').get(0);
295 var td = $(thisTr).children('.td').get(0);
296 var th = $(thisTr).children('.th').get(0)
297 var a = window.getComputedStyle(thisTr, ':before').getPropertyValue('content');
298 console.log(td, th);
299
300 if( th && a != 'none' ){
301 $(th).css('border-top-left-radius', '0');
302 }else if( td && a != 'none' ){
303 $(td).css('border-top-left-radius', '0');
304 }
305 });
306 });
307
308 $('.lang_enNetwork #cbi-samba-sambashare .table').wrap('<div class="table-container"></div>');
309
310 })(jQuery);