MediaWiki:Common.js

From Realm Of Thrones
Revision as of 03:22, 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 () {
    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");
            event.stopPropagation();
        });
    }


    toc.addEventListener("click", function (event) {
        event.stopPropagation();
    });


    floatingToc.addEventListener("click", function (event) {
        if (floatingToc.classList.contains("collapsed") && event.target.id === "floating-toc-show-button") {
            floatingToc.classList.remove("collapsed");
        }
    });


    var showButton = document.createElement("div");
    showButton.id = "floating-toc-show-button";
    showButton.innerText = "Contents ▼";
    floatingToc.appendChild(showButton);
});