Array

MediaWiki:Common.js: Difference between revisions

No edit summary
m (Reverted edit by SpencerMarsh (talk) to last revision by MikeParker)
Tags: Blanking Rollback
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
// COLLAPSIBLE HEADERS
$(document).ready(function () {
    $(".collapsible-wrapper").each(function () {
        var wrapper = $(this);
        var titleContent = wrapper.find(".collapsible-title-content");
        var bodyContent = wrapper.find(".collapsible-body-content");
        if (titleContent.length === 0 || bodyContent.length === 0) return;
        var startsOpen = wrapper.data("state") === "open";
        var titleHTML = titleContent.html();
        var bodyHTML = bodyContent.html();
        var header = $('<div class="collapsible-header"></div>');
        var content = $('<div class="collapsible-content"></div>');
        if (startsOpen) header.addClass("open");
        var arrow = startsOpen ? "▲" : "▼";
        header.append(titleHTML);
        header.append('<span class="collapse-toggle" aria-hidden="true">' + arrow + '</span>');
        content.html(bodyHTML);
        if (!startsOpen) content.hide();
        wrapper.replaceWith(header.add(content));
       
        // Inicializar elementos mw-collapsible dentro del contenido
        content.find('.mw-collapsible').each(function() {
            if (typeof mw !== 'undefined' && mw.hook) {
                mw.hook('wikipage.content').fire($(this));
            }
        });
       
        header.on("click", function () {
            content.slideToggle(150);
            header.toggleClass("open");
            var icon = header.hasClass("open") ? "▲" : "▼";
            header.find(".collapse-toggle").text(icon);
        });
    });


    // COLLAPSIBLE NOTES SECTION
    // Find the Notes div generated by the template
    var notesHeader = $('.notes-collapsible-header');
   
    if (notesHeader.length === 0) return;
   
    // The references container is after the header
    var notesContent = notesHeader.next('.notes-collapsible-content');
   
    if (notesContent.length === 0) return;
   
    // Initial state: collapsed
    notesContent.hide();
    var isOpen = false;
   
    // Update the icon based on the state
    function updateIcon() {
        var icon = isOpen ? "▲" : "▼";
        notesHeader.find('.notes-collapse-toggle').text(icon);
    }
   
    updateIcon();
   
    // Handle clicks on the header
    notesHeader.on('click', function(e) {
        // Do nothing if clicking on the "BACK TO TOP" link
        if ($(e.target).closest('a[href="#top"]').length > 0) {
            return; // Allow the link to work normally
        }
       
        // Prevent the link from activating if clicking elsewhere
        e.preventDefault();
       
        // Toggle the content
        notesContent.slideToggle(150);
        isOpen = !isOpen;
        updateIcon();
    });
});

Latest revision as of 04:49, 6 January 2026