MediaWiki:Common.js: Difference between revisions

From Midgard Tales Wiki

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
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. */
// Add Expand/Collapse All button
$(document).ready(function() {
$(document).ready(function() {
     // Target the sidebar portlets
     // Create the button
     $('#mw-navigation .mw-portlet').each(function() {
     var $toggleButton = $('<button>', {
        var $portlet = $(this);
        text: 'Collapse All',
        var $label = $portlet.find('a.nav-link.disabled'); // The section label
        class: 'toggle-all-button',
        var $body = $portlet.find('.mw-portlet-body'); // The collapsible content
        click: function() {
            var $button = $(this);
            var isCollapsed = $button.text() === 'Expand All';


        // Add a toggle button to the label
            // Toggle all sections
        $label.append('<span class="collapsible-arrow"></span>');
            $('#mw-navigation .mw-portlet .mw-portlet-body').toggle(!isCollapsed);
            $('#mw-navigation .mw-portlet .collapsible-arrow').text(isCollapsed ? '' : '▶');


        // Collapse/expand on click
             // Update button text
        $label.on('click', function(e) {
             $button.text(isCollapsed ? 'Collapse All' : 'Expand All');
             e.preventDefault(); // Prevent the link from navigating
        }
             $body.toggle();
    });
            $label.find('.collapsible-arrow').text(function(_, text) {
                return text === '▼' ? '' : '';
            });
        });


        // Collapse all sections by default (optional)
    // Add the button to the sidebar
        $body.hide();
    $('#mw-navigation').prepend($toggleButton);
        $label.find('.collapsible-arrow').text('▶');
    });
});
});

Revision as of 07:07, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Add Expand/Collapse All button
$(document).ready(function() {
    // Create the button
    var $toggleButton = $('<button>', {
        text: 'Collapse All',
        class: 'toggle-all-button',
        click: function() {
            var $button = $(this);
            var isCollapsed = $button.text() === 'Expand All';

            // Toggle all sections
            $('#mw-navigation .mw-portlet .mw-portlet-body').toggle(!isCollapsed);
            $('#mw-navigation .mw-portlet .collapsible-arrow').text(isCollapsed ? '▼' : '▶');

            // Update button text
            $button.text(isCollapsed ? 'Collapse All' : 'Expand All');
        }
    });

    // Add the button to the sidebar
    $('#mw-navigation').prepend($toggleButton);
});