MediaWiki:Common.js: Difference between revisions

From Realm Of Thrones
Jump to navigation Jump to search
SitX (talk | contribs)
No edit summary
SitX (talk | contribs)
No edit summary
Line 1: Line 1:
document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", function () {
     setTimeout(function () {  
     setTimeout(function () {
         var toc = document.querySelector("#mw-content-text #toc");  
         var toc = document.querySelector("#mw-content-text #toc");  
         if (!toc) return;  
         if (!toc) return;  
Line 7: Line 7:
         floatingToc.id = "floating-toc";
         floatingToc.id = "floating-toc";


         toc.parentNode.removeChild(toc);  
         toc.parentNode.removeChild(toc);
         floatingToc.appendChild(toc);
         floatingToc.appendChild(toc);
         document.body.appendChild(floatingToc);
         document.body.appendChild(floatingToc);


         floatingToc.addEventListener("click", function () {
         var hideButton = floatingToc.querySelector(".toctogglelabel");
            floatingToc.classList.toggle("collapsed");
        });


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

Revision as of 03:00, 25 March 2025

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");
            });
        }
    }, 500);
});