Skip to content
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

Merged
merged 4 commits into from
Dec 4, 2023
Merged

scrolly #308

merged 4 commits into from
Dec 4, 2023

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Dec 4, 2023

closes #305

@Fil Fil requested review from mbostock and cinxmo December 4, 2023 11:13
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);
Copy link
Member

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.

Copy link
Contributor Author

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?

Suggested change
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));

Copy link
Member

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.

@Fil Fil merged commit 5874262 into main Dec 4, 2023
1 check passed
@Fil Fil deleted the fil/scrolly branch December 4, 2023 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retain sidebar scroll offset when navigating
2 participants