temporary fix for the toc links (also better logic for scrollArray)

This commit is contained in:
Spax
2025-11-02 16:43:37 -07:00
parent 596a3e672b
commit ee627f32d0
2 changed files with 7 additions and 4 deletions

View File

@@ -8,8 +8,8 @@ function initTocOnClick() {
coll.classList.toggle("active");
const content = coll.nextElementSibling;
if (content) {
event.preventDefault(); // don't jump
if (content.style.maxHeight) {
event.preventDefault(); // don't jump if closing
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
@@ -122,8 +122,10 @@ function saveScroll() {
const pos = window.scrollY;
const scrollArray = JSON.parse(sessionStorage.getItem("scrollPos") ?? "[]");
scrollArray.unshift(pos);
sessionStorage.setItem("scrollPos", JSON.stringify(scrollArray));
if (scrollArray[0] !== Math.round(pos)) {
scrollArray.unshift(Math.round(pos));
sessionStorage.setItem("scrollPos", JSON.stringify(scrollArray));
}
});
}
}