MediaWiki: Common.js: Difference between revisions

From Psalms: Layer by Layer
Jump to: navigation, search
No edit summary
mNo edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


//console.log("Hello world!");
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.");

Revision as of 12:40, 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.");