2022-02-22 04:40:14 +00:00
|
|
|
/**
|
|
|
|
* This module is used to implement persistent navbar expansion.
|
|
|
|
*/
|
2021-12-13 20:36:21 +00:00
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
// The variable to store the expansion information.
|
2021-12-13 20:36:21 +00:00
|
|
|
let expanded = {};
|
2022-02-22 04:40:14 +00:00
|
|
|
|
|
|
|
// Load expansion information from sessionStorage.
|
|
|
|
for (const e of (sessionStorage.getItem("expanded") || "").split(",")) {
|
|
|
|
if (e !== "") {
|
2021-12-13 20:36:21 +00:00
|
|
|
expanded[e] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
/**
|
|
|
|
* Save expansion information to sessionStorage.
|
|
|
|
*/
|
2021-12-13 20:36:21 +00:00
|
|
|
function saveExpanded() {
|
2022-02-22 04:40:14 +00:00
|
|
|
sessionStorage.setItem(
|
|
|
|
"expanded",
|
|
|
|
Object.getOwnPropertyNames(expanded)
|
|
|
|
.filter((e) => expanded[e])
|
|
|
|
.join(",")
|
|
|
|
);
|
2021-12-13 20:36:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
// save expansion information when user change the expansion.
|
|
|
|
for (const elem of document.getElementsByClassName("nav_sect")) {
|
|
|
|
const id = elem.getAttribute("data-path");
|
2021-12-13 20:36:21 +00:00
|
|
|
if (!id) continue;
|
|
|
|
if (expanded[id]) {
|
|
|
|
elem.open = true;
|
|
|
|
}
|
2022-02-22 04:40:14 +00:00
|
|
|
elem.addEventListener("toggle", () => {
|
2021-12-13 20:36:21 +00:00
|
|
|
expanded[id] = elem.open;
|
|
|
|
saveExpanded();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-22 04:40:14 +00:00
|
|
|
// Scroll to center.
|
|
|
|
for (const currentFileLink of document.getElementsByClassName("visible")) {
|
|
|
|
currentFileLink.scrollIntoView({ block: "center" });
|
|
|
|
}
|