|
|
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */
| |
| (function () {
| |
| function makeCollapsible(ul) {
| |
| if (!ul || ul.dataset.smwCollapsibleDone) return;
| |
| ul.dataset.smwCollapsibleDone = "1";
| |
|
| |
|
| // Wrap the UL so CSS can target it cleanly
| |
| var wrapper = document.createElement("div");
| |
| wrapper.className = "smw-collapsible";
| |
| ul.parentNode.insertBefore(wrapper, ul);
| |
| wrapper.appendChild(ul);
| |
|
| |
| // Create a toggle button
| |
| var btn = document.createElement("button");
| |
| btn.type = "button";
| |
| btn.className = "smw-collapsible-toggle";
| |
| btn.setAttribute("aria-expanded", "false");
| |
| btn.textContent = "Show list";
| |
|
| |
| wrapper.insertBefore(btn, ul);
| |
|
| |
| btn.addEventListener("click", function () {
| |
| var open = wrapper.classList.toggle("is-open");
| |
| btn.setAttribute("aria-expanded", open ? "true" : "false");
| |
| btn.textContent = open ? "Hide list" : "Show list";
| |
| });
| |
| }
| |
|
| |
| function init($content) {
| |
| // Adjust this selector if you only want *some* SMW lists collapsible.
| |
| var root = $content && $content[0] ? $content[0] : document;
| |
| root.querySelectorAll("ul.smw-format.ul-format").forEach(makeCollapsible);
| |
| }
| |
|
| |
| // MediaWiki-friendly hook (runs on normal page loads + AJAX content)
| |
| if (window.mw && mw.hook) {
| |
| mw.hook("wikipage.content").add(init);
| |
| } else {
| |
| // Fallback
| |
| document.addEventListener("DOMContentLoaded", function () { init(); });
| |
| }
| |
| })();
| |