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


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


             // Update button text
        // Collapse/expand on click
             $button.text(isCollapsed ? 'Collapse All' : 'Expand All');
        $label.on('click', function(e) {
         }
             e.preventDefault(); // Prevent the link from navigating
            $body.toggle();
             $label.find('.collapsible-arrow').text(function(_, text) {
                return text === '▼' ? '' : '';
            });
         });
 
        // Remove this line to keep sections expanded by default
        // $body.hide();
        // $label.find('.collapsible-arrow').text('▶');
     });
     });
    // Add the button to the sidebar
    $('#mw-navigation').prepend($toggleButton);
});
});

Revision as of 07:08, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */
// Add Expand/Collapse button
$(document).ready(function() {
    // Target the sidebar portlets
    $('#mw-navigation .mw-portlet').each(function() {
        var $portlet = $(this);
        var $label = $portlet.find('a.nav-link.disabled'); // The section label
        var $body = $portlet.find('.mw-portlet-body'); // The collapsible content

        // Add a toggle button to the label
        $label.append('<span class="collapsible-arrow">▼</span>');

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

        // Remove this line to keep sections expanded by default
        // $body.hide();
        // $label.find('.collapsible-arrow').text('▶');
    });
});