summaryrefslogtreecommitdiffhomepage
path: root/themes/luci-theme-bootstrap/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-04-15 22:46:25 +0200
committerJo-Philipp Wich <jo@mein.io>2020-04-16 13:30:35 +0200
commit1ac8df2614336b34109375e62f201cf6bac46734 (patch)
tree0f1352c5f4f827e38fb654d701b69dbfebdcfa15 /themes/luci-theme-bootstrap/luasrc
parent48269ade6163c34f348632bf225e2c6649b0a9c1 (diff)
luci-theme-bootstrap: rework menu rendering
Utilize the LuCI.ui.menu class to load, traverse and cache the menu tree in the local session store. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'themes/luci-theme-bootstrap/luasrc')
-rw-r--r--themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/footer.htm1
-rw-r--r--themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm10
-rw-r--r--themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/json-menu.htm134
3 files changed, 2 insertions, 143 deletions
diff --git a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/footer.htm b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/footer.htm
index ec6895f06d..d0c395bf31 100644
--- a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/footer.htm
+++ b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/footer.htm
@@ -12,6 +12,7 @@
<ul class="breadcrumb pull-right" id="modemenu" style="display:none"></ul>
</footer>
</div>
+ <script type="text/javascript">L.require('menu-bootstrap')</script>
</body>
</html>
diff --git a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm
index 39415154aa..89aa338152 100644
--- a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm
+++ b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/header.htm
@@ -35,9 +35,6 @@
<% end -%>
<script src="<%=url('admin/translations', luci.i18n.context.lang)%><%# ?v=PKG_VERSION %>"></script>
<script src="<%=resource%>/cbi.js"></script>
- <script src="<%=resource%>/xhr.js"></script>
-
- <% include("themes/bootstrap/json-menu") %>
</head>
<body class="lang_<%=luci.i18n.context.lang%> <% if node then %><%= striptags( node.title ) %><%- end %>" data-page="<%= pcdata(table.concat(disp.context.requestpath, "-")) %>">
@@ -46,12 +43,7 @@
<div class="container">
<a class="brand" href="#"><%=boardinfo.hostname or "?"%></a>
<ul class="nav" id="topmenu" style="display:none"></ul>
- <div id="indicators" class="pull-right">
- <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
- <span class="label success" id="xhr_poll_status_on"><%:Auto Refresh%> <%:on%></span>
- <span class="label" id="xhr_poll_status_off" style="display:none"><%:Auto Refresh%> <%:off%></span>
- </span>
- </div>
+ <div id="indicators" class="pull-right"></div>
</div>
</div>
</header>
diff --git a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/json-menu.htm b/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/json-menu.htm
deleted file mode 100644
index ea11cf2263..0000000000
--- a/themes/luci-theme-bootstrap/luasrc/view/themes/bootstrap/json-menu.htm
+++ /dev/null
@@ -1,134 +0,0 @@
-<script type="text/javascript">
- (function() {
- function get_children(node) {
- var children = [];
-
- for (var k in node.children) {
- if (!node.children.hasOwnProperty(k))
- continue;
-
- if (!node.children[k].satisfied)
- continue;
-
- if (!node.children[k].hasOwnProperty('title'))
- continue;
-
- children.push(Object.assign(node.children[k], { name: k }));
- }
-
- return children.sort(function(a, b) {
- return ((a.order || 1000) - (b.order || 1000));
- });
- }
-
- function render_tabmenu(tree, url, level) {
- var container = document.querySelector('#tabmenu'),
- ul = E('ul', { 'class': 'tabs' }),
- children = get_children(tree),
- activeNode = null;
-
- for (var i = 0; i < children.length; i++) {
- var isActive = (L.env.dispatchpath[3 + (level || 0)] == children[i].name),
- activeClass = isActive ? ' active' : '',
- className = 'tabmenu-item-%s %s'.format(children[i].name, activeClass);
-
- ul.appendChild(E('li', { 'class': className }, [
- E('a', { 'href': L.url(url, children[i].name) }, [ _(children[i].title) ] )]));
-
- if (isActive)
- activeNode = children[i];
- }
-
- if (ul.children.length == 0)
- return E([]);
-
- container.appendChild(ul);
- container.style.display = '';
-
- if (activeNode)
- render_tabmenu(activeNode, url + '/' + activeNode.name, (level || 0) + 1);
-
- return ul;
- }
-
- function render_mainmenu(tree, url, level) {
- var ul = level ? E('ul', { 'class': 'dropdown-menu' }) : document.querySelector('#topmenu'),
- children = get_children(tree);
-
- if (children.length == 0 || level > 1)
- return E([]);
-
- for (var i = 0; i < children.length; i++) {
- var submenu = render_mainmenu(children[i], url + '/' + children[i].name, (level || 0) + 1),
- subclass = (!level && submenu.firstElementChild) ? 'dropdown' : null,
- linkclass = (!level && submenu.firstElementChild) ? 'menu' : null,
- linkurl = submenu.firstElementChild ? '#' : L.url(url, children[i].name);
-
- var li = E('li', { 'class': subclass }, [
- E('a', { 'class': linkclass, 'href': linkurl }, [ _(children[i].title) ]),
- submenu
- ]);
-
- ul.appendChild(li);
- }
-
- ul.style.display = '';
-
- return ul;
- }
-
- function render_modemenu(tree) {
- var ul = document.querySelector('#modemenu'),
- children = get_children(tree);
-
- for (var i = 0; i < children.length; i++) {
- var isActive = (L.env.requestpath.length ? children[i].name == L.env.requestpath[0] : i == 0);
-
- ul.appendChild(E('li', { 'class': isActive ? 'active' : null }, [
- E('a', { 'href': L.url(children[i].name) }, [ _(children[i].title) ]),
- ' ',
- E('span', { 'class': 'divider' }, [ '|' ])
- ]));
-
- if (isActive)
- render_mainmenu(children[i], children[i].name);
- }
-
- if (ul.children.length > 1)
- ul.style.display = '';
- }
-
- function adjust_body_margin(ev) {
- var body = document.querySelector('body'),
- head = document.querySelector('header');
-
- body.style.marginTop = head.offsetHeight + 'px';
- }
-
- document.addEventListener('luci-loaded', function(ev) {
- var tree = <%= luci.http.write_json(luci.dispatcher.menu_json() or {}) %>,
- node = tree,
- url = '';
-
- render_modemenu(tree);
-
- if (L.env.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];
- }
-
- if (node)
- render_tabmenu(node, url);
- }
-
- document.addEventListener('poll-start', adjust_body_margin);
- document.addEventListener('poll-stop', adjust_body_margin);
- document.addEventListener('uci-new-changes', adjust_body_margin);
- document.addEventListener('uci-clear-changes', adjust_body_margin);
- window.addEventListener('resize', adjust_body_margin);
-
- adjust_body_margin(ev);
- });
- })();
-</script>