MediaWiki:Common.js

Revision as of 14:04, 28 November 2025 by MikeParker (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

// COLLAPSIBLE HEADER - improved (arrow left + CSS rotate)
$(document).ready(function () {
    $(".collapsible-header").each(function () {
        var header = $(this);
        var content = header.next(".collapsible-content");

        // Skip if there is no associated collapsible-content block
        if (content.length === 0) return;

        // Check if the section should start open (template may add class "open")
        var startsOpen = header.hasClass("open");

        // Hide content only if it should start closed
        if (!startsOpen) {
            content.hide();
        } else {
            // ensure the header has the open class in case it's needed
            header.addClass("open");
        }

        // Always use the same arrow character and rotate with CSS
        // Prepend so the arrow appears before the header text
        header.prepend('<span class="collapse-toggle" aria-hidden="true">▼</span>');

        // Make header clickable
        header.css("cursor", "pointer");

        // Collapse / Expand behavior
        header.on("click", function () {
            content.slideToggle(200);
            header.toggleClass("open");
        });
    });
});