MediaWiki:Common.js: Difference between revisions

From Descendants of Darkness Wiki

No edit summary
Blanked the page
Tag: Blanking
 
(13 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;
    var currentPage = window.location.href;
    sessionStorage.setItem(currentPage, scrollPosition);
  }
  function restoreSidebarScrollPosition() {
    var currentPage = window.location.href;
    var scrollPosition = sessionStorage.getItem(currentPage);
    if (scrollPosition !== null) {
      document.getElementById(sidebarId).scrollTop = parseInt(scrollPosition);
    }
  }
  // Create a MutationObserver to detect changes in the sidebar
  var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
      if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
        saveSidebarScrollPosition();
      }
    });
  });
  // Configure the observer to watch for class attribute changes in the sidebar
  var observerConfig = {
    attributes: true,
    attributeFilter: ['class'],
    subtree: true
  };
  // Start observing the sidebar element
  var sidebarElement = document.getElementById(sidebarId);
  if (sidebarElement) {
    observer.observe(sidebarElement, observerConfig);
  }
  // Restore scroll position when the page is loaded
  window.addEventListener('load', restoreSidebarScrollPosition);
})();

Latest revision as of 12:30, 4 September 2024