Skip to content

Commit

Permalink
AG-13054 - Sync up scroll positioning code
Browse files Browse the repository at this point in the history
  • Loading branch information
taktran committed Nov 26, 2024
1 parent 6be46dc commit 86da719
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions packages/ag-charts-website/src/pages/[framework]/[pageName].astro
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,7 @@ const descriptionWithSeoTagline = `${description} ${seoTagline}`;
</Layout>

<script>
/**
* Retain scroll position between page changes
*
* Use session storage to store the scroll position and get it on page load
*/
const SCROLL_POSITION_LOCALSTORAGE_KEY = 'docs-scroll-position';
// NOTE: Need page nav to be on page on page load (ie, not generated on client side)
const NAV_SCROLL_CONTAINER_SELECTOR = '#docs-nav-scroll';
import { initNavScrollPositionSync } from '@ag-website-shared/utils/navScrollPosition';

window.addEventListener('load', () => {
const nav = document.querySelector(NAV_SCROLL_CONTAINER_SELECTOR);
const top = sessionStorage.getItem(SCROLL_POSITION_LOCALSTORAGE_KEY);

if (nav && top !== null) {
nav.scrollTop = parseInt(top, 10);
}

window.addEventListener('beforeunload', () => {
if (!nav) {
return;
}

sessionStorage.setItem(SCROLL_POSITION_LOCALSTORAGE_KEY, nav.scrollTop);
});
});
initNavScrollPositionSync();
</script>

0 comments on commit 86da719

Please sign in to comment.