MediaWiki:Common.js

From Realm Of Thrones
Revision as of 03:04, 25 March 2025 by SitX (talk | contribs)
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.
document.addEventListener("DOMContentLoaded", function () {
    setTimeout(function () {
        var toc = document.querySelector("#mw-content-text #toc");
        if (!toc) return;

        var floatingToc = document.createElement("div");
        floatingToc.id = "floating-toc";
        toc.parentNode.removeChild(toc);
        floatingToc.appendChild(toc);
        document.body.appendChild(floatingToc);

        var hideButton = floatingToc.querySelector(".toctogglelabel");

        if (hideButton) {
            hideButton.addEventListener("click", function (event) {
                event.preventDefault();
                floatingToc.classList.toggle("collapsed");
            });
        }

        floatingToc.addEventListener("click", function (event) {
            if (floatingToc.classList.contains("collapsed")) {
                floatingToc.classList.remove("collapsed");
                event.stopPropagation(); 
            }
        });
    }, 500);
});