MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
document.addEventListener("DOMContentLoaded", function () { | 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(); | |||
event.stopPropagation(); | |||
}); | }); | ||
} | |||
toc.addEventListener("click", function (event) { | |||
event.stopPropagation(); | |||
}); | |||
} | floatingToc.addEventListener("click", function (event) { | ||
if (floatingToc.classList.contains("collapsed") && event.target === floatingToc) { | |||
floatingToc.classList.remove("collapsed"); | |||
} | |||
}); | |||
}); | }); |
Revision as of 03:15, 25 March 2025
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 === floatingToc) {
floatingToc.classList.remove("collapsed");
}
});
});