Enable sliding categories and extract TODOs

This commit is contained in:
Zack Rauen
2023-09-30 00:13:37 -04:00
parent e7a3f6d17e
commit 5391521c08
11 changed files with 48 additions and 126 deletions

View File

@@ -1,30 +1,3 @@
// function anchorToId(anchor: HTMLAnchorElement) {
// return anchor.href.replace("./", "");
// }
//
// const stored = localStorage.getItem("expanded") ?? "[]";
// let parsed: string[];
// try {
// parsed = JSON.parse(stored) as string[];
// }
// catch (e) {
// parsed = [];
// }
// const state = new Set(parsed);
// const submenus = Array.from(document.querySelectorAll("#menu .submenu-item"));
// for (const sub of submenus) {
// try {
// if (state.has(anchorToId(sub.children[0] as HTMLAnchorElement))) sub.classList.add("expanded");
// }
// catch (e) {
// // TODO: create logger
// console.warn("Could not restore expanded state"); // eslint-disable-line no-console
// console.error(e); // eslint-disable-line no-console
// }
// }
// TODO: Swap this system to use type-book for full-link category
// In case a linked article lead to a new tree
const activeLink = document.querySelector("#menu a.active");
if (activeLink) {
@@ -45,15 +18,10 @@ export default function setupExpanders() {
if ((e.target as Element).closest(".submenu-item,.item") !== ex) return;
e.preventDefault();
e.stopPropagation();
// ex.parentElement.parentElement.classList.toggle("expanded");
ex.classList.toggle("expanded");
// const id = anchorToId(ex.closest("a")!);
// if (state.has(id)) state.delete(id);
// else state.add(id);
// // TODO: be able to remove all submenus of currently collapsed
// localStorage.setItem("expanded", JSON.stringify([...state]));
const ul = ex.querySelector("ul")!;
ul.style.height = `${ul.scrollHeight}px`;
setTimeout(() => ex.classList.toggle("expanded"), 1);
setTimeout(() => ul.style.height = ``, 200);
});
}
}