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. */
$(document).ready(function() {
$(document).ready(function() {
    console.log('Collapsible script loaded'); // Confirm the script is running
     // Function to collapse all sections
     // Function to collapse all sections
     function collapseAll() {
     function collapseAll() {
        console.log('Collapsing all sections'); // Debug message
         $('#mw-navigation .mw-portlet .mw-portlet-body').hide();
         $('#mw-navigation .mw-portlet .mw-portlet-body').hide();
         $('#mw-navigation .mw-portlet .collapsible-arrow').text('');
         $('#mw-navigation .mw-portlet .collapsible-text').text('Expand');
     }
     }


     // Function to expand all sections
     // Function to expand all sections
     function expandAll() {
     function expandAll() {
        console.log('Expanding all sections'); // Debug message
         $('#mw-navigation .mw-portlet .mw-portlet-body').show();
         $('#mw-navigation .mw-portlet .mw-portlet-body').show();
         $('#mw-navigation .mw-portlet .collapsible-arrow').text('');
         $('#mw-navigation .mw-portlet .collapsible-text').text('Collapse');
     }
     }


Line 18: Line 22:
         id: 'close-all-button',
         id: 'close-all-button',
         click: function() {
         click: function() {
            console.log('Close All button clicked'); // Debug message
             collapseAll();
             collapseAll();
             $(this).text('Open All').off('click').on('click', function() {
             $(this).text('Open All').off('click').on('click', function() {
                console.log('Open All button clicked'); // Debug message
                 expandAll();
                 expandAll();
                 $(this).text('Close All').off('click').on('click', function() {
                 $(this).text('Close All').off('click').on('click', function() {
Line 32: Line 38:
     $('#mw-navigation .mw-wiki-navigation-logo').after($closeAllButton);
     $('#mw-navigation .mw-wiki-navigation-logo').after($closeAllButton);


     // Add collapsible arrows to section labels
     // Add collapsible text to section labels
     $('#mw-navigation .mw-portlet a.nav-link.disabled').each(function() {
     $('#mw-navigation .mw-portlet a.nav-link.disabled').each(function() {
         var $label = $(this);
         var $label = $(this);
         var $body = $label.next('.mw-portlet-body');
         var $body = $label.next('.mw-portlet-body');


         // Add a collapsible arrow if it doesn't already exist
         // Add collapsible text if it doesn't already exist
         if (!$label.find('.collapsible-arrow').length) {
         if (!$label.find('.collapsible-text').length) {
             $label.append('<span class="collapsible-arrow"></span>');
             $label.append('<span class="collapsible-text">Collapse</span>');
         }
         }


         // Collapse/expand on click
         // Collapse/expand on click
         $label.on('click', function(e) {
         $label.on('click', function(e) {
            console.log('Section label clicked:', $label.text()); // Debug message
             e.preventDefault();
             e.preventDefault();
             $body.toggle();
             $body.toggle();
             $label.find('.collapsible-arrow').text(function(_, text) {
             $label.find('.collapsible-text').text(function(_, text) {
                 return text === '' ? '' : '';
                 return text === 'Collapse' ? 'Expand' : 'Collapse';
             });
             });
         });
         });
     });
     });
});
});

Revision as of 07:19, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
    console.log('Collapsible script loaded'); // Confirm the script is running

    // Function to collapse all sections
    function collapseAll() {
        console.log('Collapsing all sections'); // Debug message
        $('#mw-navigation .mw-portlet .mw-portlet-body').hide();
        $('#mw-navigation .mw-portlet .collapsible-text').text('Expand');
    }

    // Function to expand all sections
    function expandAll() {
        console.log('Expanding all sections'); // Debug message
        $('#mw-navigation .mw-portlet .mw-portlet-body').show();
        $('#mw-navigation .mw-portlet .collapsible-text').text('Collapse');
    }

    // Add a "Close All" button
    var $closeAllButton = $('<button>', {
        text: 'Close All',
        id: 'close-all-button',
        click: function() {
            console.log('Close All button clicked'); // Debug message
            collapseAll();
            $(this).text('Open All').off('click').on('click', function() {
                console.log('Open All button clicked'); // Debug message
                expandAll();
                $(this).text('Close All').off('click').on('click', function() {
                    collapseAll();
                    $(this).text('Open All');
                });
            });
        }
    });

    // Insert the button below the logo
    $('#mw-navigation .mw-wiki-navigation-logo').after($closeAllButton);

    // Add collapsible text to section labels
    $('#mw-navigation .mw-portlet a.nav-link.disabled').each(function() {
        var $label = $(this);
        var $body = $label.next('.mw-portlet-body');

        // Add collapsible text if it doesn't already exist
        if (!$label.find('.collapsible-text').length) {
            $label.append('<span class="collapsible-text">Collapse</span>');
        }

        // Collapse/expand on click
        $label.on('click', function(e) {
            console.log('Section label clicked:', $label.text()); // Debug message
            e.preventDefault();
            $body.toggle();
            $label.find('.collapsible-text').text(function(_, text) {
                return text === 'Collapse' ? 'Expand' : 'Collapse';
            });
        });
    });
});