MediaWiki: Common.js: Difference between revisions
From Psalms: Layer by Layer
mNo edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
function toggleVisibility(containerId, className) { | function toggleVisibility(containerId, className) { | ||
console.log("Toggling visibility for " + className + " in " + containerId); | |||
var container = document.getElementById(containerId); | var container = document.getElementById(containerId); | ||
if (container) { | if (container) { | ||
Line 22: | Line 22: | ||
// Attach event listeners to all toggle links | // Attach event listeners to all toggle links | ||
var toggleLinks = document.querySelectorAll("[data-container-id][data-class]"); | var toggleLinks = document.querySelectorAll("[data-container-id][data-class]"); | ||
console.log("Found " + toggleLinks.length + " links."); | |||
for (var i = 0; i < toggleLinks.length; i++) { | for (var i = 0; i < toggleLinks.length; i++) { | ||
(function (toggleLink) { | (function (toggleLink) { |
Revision as of 16:54, 15 January 2025
/* Any JavaScript here will be loaded for all users on every page load. */ function toggleVisibility(containerId, className) { console.log("Toggling visibility for " + className + " in " + containerId); var container = document.getElementById(containerId); if (container) { var elements = container.querySelectorAll("g." + className); for (var i = 0; i < elements.length; i++) { var element = elements[i]; if (element.style.display === "none") { element.style.display = ""; // Show element } else { element.style.display = "none"; // Hide element } } } else { console.warn("Container with ID \"" + containerId + "\" not found."); } } function attachToggleListeners() { // Attach event listeners to all toggle links var toggleLinks = document.querySelectorAll("[data-container-id][data-class]"); console.log("Found " + toggleLinks.length + " links."); for (var i = 0; i < toggleLinks.length; i++) { (function (toggleLink) { toggleLink.addEventListener("click", function (event) { event.preventDefault(); // Prevent default link behavior var containerId = toggleLink.getAttribute("data-container-id"); var className = toggleLink.getAttribute("data-class"); toggleVisibility(containerId, className); }); })(toggleLinks[i]); } } (function () { if (document.readyState === "complete" || document.readyState === "interactive") { // console.log("ReadyState is complete."); // if the document has already been loaded attachToggleListeners(); } else { console.log("ReadyState is " + document.readyState); document.addEventListener("DOMContentLoaded", function () { // if the document has already been loaded attachToggleListeners(); }); } })(); // console.log("Common.js is loaded.");