Sidebar: fold each module's pages

A chevron beside each module folds or unfolds its pages. The current
module is always open; the others keep the state you left them in; a
folded module shows its pages' counts added up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:27:22 -07:00
co-authored by Claude Opus 5.5
parent 9ca09c1ffa
commit 2a605ac265
4 changed files with 59 additions and 6 deletions
+33
View File
@@ -137,4 +137,37 @@
});
document.addEventListener("DOMContentLoaded", syncProvider);
// Sidebar: each module's pages fold under a toggle. The module you're in
// is always open; the others stay as you last left them (closed at
// first). A folded module shows the sum of its pages' counts.
(function () {
var KEY = "supermarket.nav";
var state = {};
try { state = JSON.parse(localStorage.getItem(KEY)) || {}; } catch (e) {}
function set(sub, btn, open) {
sub.hidden = !open;
btn.setAttribute("aria-expanded", open ? "true" : "false");
btn.closest(".nav-row").classList.toggle("collapsed", !open);
}
document.querySelectorAll(".subnav[data-subnav]").forEach(function (sub) {
var btn = document.querySelector('.nav-toggle[aria-controls="' + sub.id + '"]');
if (!btn) return;
btn.hidden = false;
var sum = 0;
sub.querySelectorAll(".count-badge").forEach(function (b) { sum += parseInt(b.textContent, 10) || 0; });
var total = btn.closest(".nav-row").querySelector(".nav-sum");
if (total && sum > 0) {
total.textContent = sum;
total.title = sum + " waiting";
total.hidden = false;
}
set(sub, btn, sub.hasAttribute("data-current") || state[sub.dataset.subnav] === true);
btn.addEventListener("click", function () {
var open = sub.hidden;
set(sub, btn, open);
state[sub.dataset.subnav] = open;
try { localStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
});
});
})();
})();