MediaWiki:Common.js: Difference between revisions
From Descendants of Darkness Wiki
|
|
| (20 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| (function () {
| |
| var sidebarId = 'mw-navigation';
| |
|
| |
|
| function saveSidebarScrollPosition() {
| |
| var scrollPosition = document.getElementById(sidebarId).scrollTop;
| |
| sessionStorage.setItem('sidebarScrollPosition', scrollPosition);
| |
| }
| |
|
| |
| function restoreSidebarScrollPosition() {
| |
| var scrollPosition = sessionStorage.getItem('sidebarScrollPosition');
| |
| if (scrollPosition !== null) {
| |
| document.getElementById(sidebarId).scrollTop = parseInt(scrollPosition);
| |
| }
| |
| }
| |
|
| |
| window.addEventListener('beforeunload', saveSidebarScrollPosition);
| |
| window.addEventListener('load', restoreSidebarScrollPosition);
| |
|
| |
| document.getElementById(sidebarId).addEventListener('click', function (event) {
| |
| if (event.target.tagName === 'A') {
| |
| saveSidebarScrollPosition();
| |
| }
| |
| });
| |
| })();
| |
Latest revision as of 12:30, 4 September 2024