MediaWiki:Common.js

From Fate/Starry Night Wiki
Revision as of 13:35, 10 February 2026 by Admin (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: TOC - floating: mw.hook('wikipage.content').add(function () { const toc = document.getElementById('toc'); if (!toc) return; const tocTop = toc.getBoundingClientRect().top + window.scrollY; function onScroll() { if (window.scrollY > tocTop) { toc.classList.add('toc-floating'); } else { toc.classList.remove('toc-floating'); } } // Desktop only listener...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

/*
  TOC - floating
 */
mw.hook('wikipage.content').add(function () {
  const toc = document.getElementById('toc');
  if (!toc) return;

  const tocTop = toc.getBoundingClientRect().top + window.scrollY;

  function onScroll() {
    if (window.scrollY > tocTop) {
      toc.classList.add('toc-floating');
    } else {
      toc.classList.remove('toc-floating');
    }
  }
  // Desktop only listener
  if (window.innerWidth < 1200) return;
  window.addEventListener('scroll', onScroll);
});
// Prevent overlap with footer
const footer = document.querySelector('#footer');
const footerTop = footer.getBoundingClientRect().top + window.scrollY;
if (window.scrollY + toc.offsetHeight + 100 > footerTop) {
  toc.style.opacity = '0';
} else {
  toc.style.opacity = '1';
}