mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-05 09:54:06 +08:00
🎉 Sync 2026-03-17 01:46:54
This commit is contained in:
1 parent
1d5bc5d4fe
commit
70383e4d88
102 files changed
+4904
-7994
No files matched your search
@@ -2,83 +2,124 @@
|
||||
'require baseclass';
|
||||
'require ui';
|
||||
|
||||
// 兼容新旧版本 LuCI
|
||||
var LuciCompat = {
|
||||
isNewVersion: function() {
|
||||
return L.env.luci_version && parseFloat(L.env.luci_version.split('.')[0]) >= 23;
|
||||
}
|
||||
};
|
||||
|
||||
return baseclass.extend({
|
||||
__init__: function () {
|
||||
__init__: function() {
|
||||
ui.menu.load().then(L.bind(this.render, this));
|
||||
},
|
||||
|
||||
render: function (tree) {
|
||||
render: function(tree) {
|
||||
var node = tree,
|
||||
url = '',
|
||||
children = ui.menu.getChildren(tree);
|
||||
url = '';
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var isActive = (L.env.requestpath.length ? children[i].name == L.env.requestpath[0] : i == 0);
|
||||
this.renderModeMenu(node);
|
||||
|
||||
if (isActive)
|
||||
this.renderMainMenu(children[i], children[i].name);
|
||||
}
|
||||
|
||||
if (L.env.dispatchpath.length >= 3) {
|
||||
// 兼容新旧版本的 dispatchpath
|
||||
var dispatchpath = L.env.dispatchpath || [];
|
||||
if (dispatchpath.length >= 3) {
|
||||
for (var i = 0; i < 3 && node; i++) {
|
||||
node = node.children[L.env.dispatchpath[i]];
|
||||
url = url + (url ? '/' : '') + L.env.dispatchpath[i];
|
||||
node = node.children[dispatchpath[i]];
|
||||
url = url + (url ? '/' : '') + dispatchpath[i];
|
||||
}
|
||||
|
||||
if (node)
|
||||
this.renderTabMenu(node, url);
|
||||
}
|
||||
|
||||
document.querySelector('a.showSide')
|
||||
.addEventListener('click', ui.createHandlerFn(this, 'handleSidebarToggle'));
|
||||
document.querySelector('.darkMask')
|
||||
.addEventListener('click', ui.createHandlerFn(this, 'handleSidebarToggle'));
|
||||
var showSideBtn = document.querySelector('.showSide');
|
||||
var darkMask = document.querySelector('.darkMask');
|
||||
|
||||
if (showSideBtn)
|
||||
showSideBtn.addEventListener('click', ui.createHandlerFn(this, 'handleSidebarToggle'));
|
||||
|
||||
if (darkMask)
|
||||
darkMask.addEventListener('click', ui.createHandlerFn(this, 'handleSidebarToggle'));
|
||||
|
||||
var loadingEl = document.querySelector(".main > .loading");
|
||||
if (loadingEl) {
|
||||
loadingEl.style.opacity = '0';
|
||||
loadingEl.style.visibility = 'hidden';
|
||||
}
|
||||
|
||||
if (window.innerWidth <= 992) {
|
||||
var mainLeft = document.querySelector('.main-left');
|
||||
if (mainLeft)
|
||||
mainLeft.style.width = '0';
|
||||
}
|
||||
|
||||
var mainRight = document.querySelector('.main-right');
|
||||
if (mainRight)
|
||||
mainRight.style.overflow = 'auto';
|
||||
|
||||
window.addEventListener('resize', this.handleSidebarToggle, true);
|
||||
},
|
||||
|
||||
handleMenuExpand: function (ev) {
|
||||
handleMenuExpand: function(ev) {
|
||||
var a = ev.target, slide = a.parentNode, slide_menu = a.nextElementSibling;
|
||||
var collapse = false;
|
||||
|
||||
document.querySelectorAll('.main .main-left .nav > li >ul.active').forEach(function (ul) {
|
||||
$(ul).stop(true).slideUp("fast", function () {
|
||||
// 兼容无 jQuery 环境
|
||||
if (typeof $ !== 'undefined' && $.fn && $.fn.slideUp) {
|
||||
$(ul).stop(true).slideUp("fast", function () {
|
||||
ul.classList.remove('active');
|
||||
if (ul.previousElementSibling)
|
||||
ul.previousElementSibling.classList.remove('active');
|
||||
});
|
||||
} else {
|
||||
ul.style.display = 'none';
|
||||
ul.classList.remove('active');
|
||||
ul.previousElementSibling.classList.remove('active');
|
||||
});
|
||||
if (ul.previousElementSibling)
|
||||
ul.previousElementSibling.classList.remove('active');
|
||||
}
|
||||
|
||||
if (!collapse && ul === slide_menu) {
|
||||
collapse = true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!slide_menu)
|
||||
return;
|
||||
|
||||
|
||||
if (!collapse) {
|
||||
$(slide).find(".slide-menu").slideDown("fast",function(){
|
||||
if (typeof $ !== 'undefined' && $.fn && $.fn.slideDown) {
|
||||
$(slide).find(".slide-menu").slideDown("fast", function(){
|
||||
slide_menu.classList.add('active');
|
||||
a.classList.add('active');
|
||||
});
|
||||
} else {
|
||||
var slideMenus = slide.querySelectorAll('.slide-menu');
|
||||
slideMenus.forEach(function(menu) {
|
||||
menu.style.display = 'block';
|
||||
});
|
||||
slide_menu.classList.add('active');
|
||||
a.classList.add('active');
|
||||
});
|
||||
}
|
||||
a.blur();
|
||||
}
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
},
|
||||
|
||||
renderMainMenu: function (tree, url, level) {
|
||||
renderMainMenu: function(tree, url, level) {
|
||||
var l = (level || 0) + 1,
|
||||
ul = E('ul', { 'class': level ? 'slide-menu' : 'nav' }),
|
||||
children = ui.menu.getChildren(tree);
|
||||
ul = E('ul', { 'class': level ? 'slide-menu' : 'nav' }),
|
||||
children = ui.menu.getChildren(tree);
|
||||
|
||||
if (children.length == 0 || l > 2)
|
||||
return E([]);
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var isActive = ((L.env.dispatchpath[l] == children[i].name) && (L.env.dispatchpath[l - 1] == tree.name)),
|
||||
submenu = this.renderMainMenu(children[i], url + '/' + children[i].name, l),
|
||||
hasChildren = submenu.children.length,
|
||||
slideClass = hasChildren ? 'slide' : null,
|
||||
menuClass = hasChildren ? 'menu' : 'food';
|
||||
menuClass = hasChildren ? 'menu' : null;
|
||||
if (isActive) {
|
||||
ul.classList.add('active');
|
||||
slideClass += " active";
|
||||
@@ -97,14 +138,46 @@ return baseclass.extend({
|
||||
}
|
||||
|
||||
if (l == 1) {
|
||||
document.querySelector('#mainmenu').appendChild(ul);
|
||||
document.querySelector('#mainmenu').style.display = '';
|
||||
var container = document.querySelector('#mainmenu');
|
||||
|
||||
container.appendChild(ul);
|
||||
container.style.display = '';
|
||||
}
|
||||
|
||||
return ul;
|
||||
},
|
||||
|
||||
renderTabMenu: function (tree, url, level) {
|
||||
renderModeMenu: function(tree) {
|
||||
var ul = document.querySelector('#modemenu');
|
||||
if (!ul) return;
|
||||
|
||||
var children = ui.menu.getChildren(tree);
|
||||
|
||||
// 兼容新旧版本的 requestpath
|
||||
var requestpath = L.env.requestpath || [];
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var isActive = (requestpath.length ? children[i].name == requestpath[0] : i == 0);
|
||||
|
||||
ul.appendChild(E('li', {}, [
|
||||
E('a', {
|
||||
'href': L.url(children[i].name),
|
||||
'class': isActive ? 'active' : null
|
||||
}, [ _(children[i].title) ])
|
||||
]));
|
||||
|
||||
if (isActive)
|
||||
this.renderMainMenu(children[i], children[i].name);
|
||||
|
||||
if (i > 0 && i < children.length)
|
||||
ul.appendChild(E('li', {'class': 'divider'}, [E('span')]))
|
||||
}
|
||||
|
||||
if (children.length > 1 && ul.parentElement)
|
||||
ul.parentElement.style.display = '';
|
||||
},
|
||||
|
||||
renderTabMenu: function(tree, url, level) {
|
||||
var container = document.querySelector('#tabmenu'),
|
||||
l = (level || 0) + 1,
|
||||
ul = E('ul', { 'class': 'tabs' }),
|
||||
@@ -136,23 +209,38 @@ return baseclass.extend({
|
||||
return ul;
|
||||
},
|
||||
|
||||
handleSidebarToggle: function (ev) {
|
||||
var showside = document.querySelector('a.showSide'),
|
||||
sidebar = document.querySelector('#mainmenu'),
|
||||
darkmask = document.querySelector('.darkMask'),
|
||||
scrollbar = document.querySelector('.main-right');
|
||||
handleSidebarToggle: function(ev) {
|
||||
var width = window.innerWidth,
|
||||
darkMask = document.querySelector('.darkMask'),
|
||||
mainRight = document.querySelector('.main-right'),
|
||||
mainLeft = document.querySelector('.main-left'),
|
||||
open = mainLeft.style.width == '';
|
||||
|
||||
if (showside.classList.contains('active')) {
|
||||
showside.classList.remove('active');
|
||||
sidebar.classList.remove('active');
|
||||
scrollbar.classList.remove('active');
|
||||
darkmask.classList.remove('active');
|
||||
if (width > 992 || ev.type == 'resize')
|
||||
open = true;
|
||||
|
||||
darkMask.style.visibility = open ? '' : 'visible';
|
||||
darkMask.style.opacity = open ? '': 1;
|
||||
|
||||
if (width <= 992)
|
||||
mainLeft.style.width = open ? '0' : '';
|
||||
else
|
||||
mainLeft.style.width = ''
|
||||
|
||||
// 初始化设置,css后置设置导致刷新会闪现。
|
||||
mainLeft.style.transition = 'visibility 2000ms, width 200ms';
|
||||
mainLeft.style.visibility = open ? '' : 'visible';
|
||||
|
||||
mainRight.style['overflow-y'] = open ? 'auto' : 'visible';
|
||||
|
||||
var header = document.querySelector("header");
|
||||
if (header) {
|
||||
if (typeof $ !== 'undefined' && $.fn && $.fn.css) {
|
||||
$("header").css("box-shadow", open ? "0 2px 4px rgb(0 0 0 / 8%)" : "17rem 2px 4px rgb(0 0 0 / 8%)");
|
||||
} else {
|
||||
header.style.boxShadow = open ? "0 2px 4px rgb(0 0 0 / 8%)" : "17rem 2px 4px rgb(0 0 0 / 8%)";
|
||||
}
|
||||
}
|
||||
else {
|
||||
showside.classList.add('active');
|
||||
sidebar.classList.add('active');
|
||||
scrollbar.classList.add('active');
|
||||
darkmask.classList.add('active');
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user