|
|
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);
| |
| }); | | }); |