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)
mNo edit summary
Line 1: Line 1:
document.addEventListener("DOMContentLoaded", function () {
$(function () {
     var toc = document.querySelector("#mw-content-text #toc");
     var toc = document.getElementById('toc');
     if (!toc) return;
    var tools = document.getElementById('p-tb');
     var admin = document.getElementById('p-managewiki-sidebar-header');


     var floatingToc = document.createElement("div");
     if (toc && tools) {
    floatingToc.id = "floating-toc";
        var tocClone = toc.cloneNode(true);
    toc.parentNode.removeChild(toc);
        tocClone.id = 'toc-sidebar';
    floatingToc.appendChild(toc);
        tocClone.style.display = 'block';
    document.body.appendChild(floatingToc);


 
        if (admin && $(admin).is(':visible')) {
    var hideButton = floatingToc.querySelector(".toctogglelabel");
             admin.parentNode.insertBefore(tocClone, admin.nextSibling);
 
        } else {
    if (hideButton) {
             tools.parentNode.insertBefore(tocClone, tools.nextSibling);
        hideButton.addEventListener("click", function (event) {
         }
             event.preventDefault();
             floatingToc.classList.toggle("collapsed");
            event.stopPropagation();
         });
     }
     }


 
     $('#toc').hide();
     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);
});
});

Revision as of 17:58, 12 April 2025

$(function () {
    var toc = document.getElementById('toc');
    var tools = document.getElementById('p-tb');
    var admin = document.getElementById('p-managewiki-sidebar-header');

    if (toc && tools) {
        var tocClone = toc.cloneNode(true);
        tocClone.id = 'toc-sidebar';
        tocClone.style.display = 'block';

        if (admin && $(admin).is(':visible')) {
            admin.parentNode.insertBefore(tocClone, admin.nextSibling);
        } else {
            tools.parentNode.insertBefore(tocClone, tools.nextSibling);
        }
    }

    $('#toc').hide();
});