Store navigation scroll position in session storage.
This commit is contained in:
parent
a96b2cb1d8
commit
4f79f11a4a
20
docs/static/script.js
vendored
20
docs/static/script.js
vendored
@ -28,7 +28,18 @@ function Init (menuName)
|
||||
let menuItem = document.getElementById ('nav-' + menuName);
|
||||
if (menuItem !== null) {
|
||||
menuItem.classList.add ('selected');
|
||||
menuItem.scrollIntoView ({ block : 'center' });
|
||||
let scrollSetFromStorage = false;
|
||||
if (window.sessionStorage) {
|
||||
let scrollPos = window.sessionStorage.getItem ('navScrollPos');
|
||||
if (scrollPos) {
|
||||
let navDiv = document.getElementById ('navigation');
|
||||
navDiv.scrollTop = parseInt (scrollPos, 10);
|
||||
scrollSetFromStorage = true;
|
||||
}
|
||||
}
|
||||
if (!scrollSetFromStorage) {
|
||||
menuItem.scrollIntoView ({ block : 'center' });
|
||||
}
|
||||
}
|
||||
hljs.highlightAll ();
|
||||
}
|
||||
@ -52,3 +63,10 @@ window.addEventListener ('load', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener ('beforeunload', (ev) => {
|
||||
if (window.sessionStorage) {
|
||||
let navDiv = document.getElementById ('navigation');
|
||||
window.sessionStorage.setItem ('navScrollPos', navDiv.scrollTop.toString ());
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user