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. */
// Make sidebar sections collapsible
$(document).ready(function() {
$(document).ready(function() {
     $('#mw-panel div.portal h3').each(function() {
    // Target the sidebar portlets
         var $heading = $(this);
     $('#mw-navigation .mw-portlet').each(function() {
         var $content = $heading.next('div.body');
         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
         // Add a toggle button to the label
         $heading.append('<span class="collapsible-arrow">▼</span>');
         $label.append('<span class="collapsible-arrow">▼</span>');


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


         // Collapse all sections by default (optional)
         // Collapse all sections by default (optional)
         $content.hide();
         $body.hide();
         $heading.find('.collapsible-arrow').text('▶');
         $label.find('.collapsible-arrow').text('▶');
     });
     });
});
});

Revision as of 07:04, 31 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */
$(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 === '▼' ? '▶' : '▼';
            });
        });

        // Collapse all sections by default (optional)
        $body.hide();
        $label.find('.collapsible-arrow').text('▶');
    });
});