|
|
| (21 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| (function () {
| |
| var sidebarId = 'mw-navigation';
| |
|
| |
|
| // Save the sidebar scroll position to session storage
| |
| function saveSidebarScrollPosition() {
| |
| var scrollPosition = document.getElementById(sidebarId).scrollTop;
| |
| sessionStorage.setItem('sidebarScrollPosition', scrollPosition);
| |
| }
| |
|
| |
| // Restore the sidebar scroll position from session storage
| |
| function restoreSidebarScrollPosition() {
| |
| var scrollPosition = sessionStorage.getItem('sidebarScrollPosition');
| |
| if (scrollPosition !== null) {
| |
| document.getElementById(sidebarId).scrollTop = parseInt(scrollPosition);
| |
| }
| |
| }
| |
|
| |
| // Save the sidebar scroll position before navigating away
| |
| window.addEventListener('beforeunload', saveSidebarScrollPosition);
| |
|
| |
| // Restore the sidebar scroll position on page load
| |
| window.addEventListener('DOMContentLoaded', restoreSidebarScrollPosition);
| |
|
| |
| // Save the sidebar scroll position when clicking on sidebar links
| |
| document.querySelectorAll('#' + sidebarId + ' a').forEach(function (link) {
| |
| link.addEventListener('click', function (event) {
| |
| saveSidebarScrollPosition();
| |
| });
| |
| });
| |
| })();
| |