-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scrolly #308
scrolly #308
Conversation
restore on load closes #305
src/render.ts
Outdated
@@ -138,6 +138,9 @@ function renderSidebar(title = "Home", pages: (Page | Section)[], path: string): | |||
case "false": if (!details.classList.contains("observablehq-section-active")) details.open = false; break; | |||
} | |||
} | |||
window.onbeforeunload = () => sessionStorage.setItem("observablehq-sidebar-scrolly", document.querySelector("#observablehq-sidebar").scrollTop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use addEventListener
here (and no window.
) so that the user can use window.onbeforeunload
without interfering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I get the "no window." part of your comment? Is the code below ok?
window.onbeforeunload = () => sessionStorage.setItem("observablehq-sidebar-scrolly", document.querySelector("#observablehq-sidebar").scrollTop); | |
window.addEventListener("beforeunload", () => sessionStorage.setItem("observablehq-sidebar-scrolly", document.querySelector("#observablehq-sidebar").scrollTop)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of window.addEventListener
write addEventListener
since window
is already the global scope.
closes #305