1 <script type=
"text/javascript">
3 function get_children(node) {
6 for (var k in node.children) {
7 if (!node.children.hasOwnProperty(k))
10 if (!node.children[k].satisfied)
13 if (!node.children[k].hasOwnProperty('title'))
16 children.push(Object.assign(node.children[k], { name: k }));
19 return children.sort(function(a, b) {
20 return ((a.order ||
1000) - (b.order ||
1000));
24 function render_tabmenu(tree, url, level) {
25 var container = document.querySelector('#tabmenu'),
26 ul = E('ul', { 'class': 'tabs' }),
27 children = get_children(tree),
30 for (var i =
0; i < children.length; i++) {
31 var isActive = (L.env.dispatchpath[
3 + (level ||
0)] == children[i].name),
32 activeClass = isActive ? ' active' : '',
33 className = 'tabmenu-item-%s %s'.format(children[i].name, activeClass);
35 ul.appendChild(E('li', { 'class': className }, [
36 E('a', { 'href': L.url(url, children[i].name) }, [ _(children[i].title) ] )]));
39 activeNode = children[i];
42 if (ul.children.length ==
0)
45 container.appendChild(ul);
46 container.style.display = '';
49 render_tabmenu(activeNode, url + '/' + activeNode.name, (level ||
0) +
1);
54 function render_mainmenu(tree, url, level) {
55 var ul = level ? E('ul', { 'class': 'dropdown-menu' }) : document.querySelector('#topmenu'),
56 children = get_children(tree);
58 if (children.length ==
0 || level
> 1)
61 for (var i =
0; i < children.length; i++) {
62 var submenu = render_mainmenu(children[i], url + '/' + children[i].name, (level ||
0) +
1),
63 subclass = (!level && submenu.firstElementChild) ? 'dropdown' : null,
64 linkclass = (!level && submenu.firstElementChild) ? 'menu' : null,
65 linkurl = submenu.firstElementChild ? '#' : L.url(url, children[i].name);
67 var li = E('li', { 'class': subclass }, [
68 E('a', { 'class': linkclass, 'href': linkurl }, [ _(children[i].title) ]),
75 ul.style.display = '';
80 function render_modemenu(tree) {
81 var ul = document.querySelector('#modemenu'),
82 children = get_children(tree);
84 for (var i =
0; i < children.length; i++) {
85 var isActive = (L.env.requestpath.length ? children[i].name == L.env.requestpath[
0] : i ==
0);
87 ul.appendChild(E('li', { 'class': isActive ? 'active' : null }, [
88 E('a', { 'href': L.url(children[i].name) }, [ _(children[i].title) ]),
90 E('span', { 'class': 'divider' }, [ '|' ])
94 render_mainmenu(children[i], children[i].name);
97 if (ul.children.length
> 1)
98 ul.style.display = '';
101 document.addEventListener('luci-loaded', function(ev) {
102 var tree = <%= luci.http.write_json(luci.dispatcher.menu_json() or {}) %
>,
106 render_modemenu(tree);
108 if (L.env.dispatchpath.length
>=
3) {
109 for (var i =
0; i <
3 && node; i++) {
110 node = node.children[L.env.dispatchpath[i]];
111 url = url + (url ? '/' : '') + L.env.dispatchpath[i];
115 render_tabmenu(node, url);