MediaWiki:Common.css: Difference between revisions

From SZ
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* CSS placed here will be applied to all skins */
# Replace the JAVASCRIPT_CODE section with this updated version:


/* Collapsible sidebar functionality for all pages */
 
/* Collapsible Sidebar Functionality */
$(document).ready(function() {
$(document).ready(function() {
     // Function to make sidebar sections collapsible
     function initCollapsibleSidebar() {
    function makeSidebarCollapsible() {
        // Define which sections should be collapsible
         // Target the sidebar navigation
        var collapsibleSections = [
            'Documentation',
            'Tools & Utilities',
            'Community',
            'Administrative',
            'External Resources'
        ];
 
        // Define which sections start collapsed
        var startCollapsed = ['Administrative', 'External Resources'];
 
         // Process each portal in the sidebar
         $('#mw-panel .portal').each(function() {
         $('#mw-panel .portal').each(function() {
             var $portal = $(this);
             var $portal = $(this);
             var $header = $portal.find('h3');
             var $header = $portal.find('h3');
             var $body = $portal.find('.body');
             var $body = $portal.find('.body');
            var headerText = $header.text().trim();


             // Skip certain sections that shouldn't be collapsible
             // Skip non-collapsible sections
             var portalId = $portal.attr('id');
             var portalId = $portal.attr('id');
             if (portalId === 'p-search' || portalId === 'p-tb' || portalId === 'p-lang') {
             if (portalId === 'p-search' || portalId === 'p-tb' || portalId === 'p-lang') {
Line 17: Line 30:
             }
             }


             // Add toggle functionality only to specific sections
             // Only make specified sections collapsible
             var collapsibleSections = ['Documentation', 'Tools & Utilities', 'Community', 'Administrative', 'External Resources'];
             if (collapsibleSections.includes(headerText)) {
            var headerText = $header.text().trim();
                // Remove any existing toggle buttons
                $header.find('.sidebar-toggle').remove();
 
                // Create toggle button with custom text
                var isCollapsed = startCollapsed.includes(headerText);
                var toggleText = isCollapsed ? 'Show' : 'Hide';  // Changed from [+]/[-]
                var $toggleBtn = $('<span class="sidebar-toggle">' + toggleText + '</span>');


            if (collapsibleSections.includes(headerText)) {
                 // Add toggle button to header
                 // Add toggle button to header
                var $toggleBtn = $('<span class="sidebar-toggle">[−]</span>');
                 $header.append(' ').append($toggleBtn);
                 $header.append(' ').append($toggleBtn);
                // Set initial state
                if (isCollapsed) {
                    $body.hide();
                    $portal.addClass('sidebar-collapsed');
                }


                 // Add click handler
                 // Add click handler
                 $toggleBtn.click(function(e) {
                 $toggleBtn.off('click').on('click', function(e) {
                     e.preventDefault();
                     e.preventDefault();
                     e.stopPropagation();
                     e.stopPropagation();


                     if ($body.is(':visible')) {
                     if ($body.is(':visible')) {
                         $body.slideUp(200);
                         $body.slideUp(300);
                         $toggleBtn.text('[+]');
                         $toggleBtn.text('Show');  // Changed from [+]
                         $portal.addClass('collapsed');
                        $portal.addClass('sidebar-collapsed');
 
                         // Save state to localStorage
                        localStorage.setItem('sidebar-' + headerText, 'collapsed');
                     } else {
                     } else {
                         $body.slideDown(200);
                         $body.slideDown(300);
                         $toggleBtn.text('[−]');
                         $toggleBtn.text('Hide'); // Changed from [-]
                         $portal.removeClass('collapsed');
                         $portal.removeClass('sidebar-collapsed');
 
                        // Save state to localStorage
                        localStorage.setItem('sidebar-' + headerText, 'expanded');
                     }
                     }
                 });
                 });


                 // Start collapsed for some sections
                 // Restore saved state from localStorage
                 if (['Administrative', 'External Resources'].includes(headerText)) {
                 var savedState = localStorage.getItem('sidebar-' + headerText);
                if (savedState === 'collapsed' && $body.is(':visible')) {
                     $body.hide();
                     $body.hide();
                     $toggleBtn.text('[+]');
                     $toggleBtn.text('Show');
                     $portal.addClass('collapsed');
                     $portal.addClass('sidebar-collapsed');
                } else if (savedState === 'expanded' && !$body.is(':visible')) {
                    $body.show();
                    $toggleBtn.text('Hide');
                    $portal.removeClass('sidebar-collapsed');
                 }
                 }
             }
             }
Line 52: Line 86:
     }
     }


     // Run the function
     // Initialize on page load
     makeSidebarCollapsible();
     initCollapsibleSidebar();


     // Also run after any AJAX content loads
     // Re-initialize after AJAX loads (if needed)
     $(document).ajaxComplete(function() {
     $(document).ajaxComplete(function() {
         makeSidebarCollapsible();
         setTimeout(initCollapsibleSidebar, 100);
     });
     });
});
/* CSS for sidebar toggle buttons */
mw.loader.using('mediawiki.util', function() {
    mw.util.addCSS(`
        .sidebar-toggle {
            cursor: pointer;
            font-weight: bold;
            color: #0645ad;
            margin-left: 5px;
            font-size: 12px;
            user-select: none;
        }
        .sidebar-toggle:hover {
            text-decoration: underline;
            color: #0b0080;
        }
        #mw-panel .portal.collapsed .body {
            display: none;
        }
        #mw-panel .portal h3 {
            cursor: default;
        }
        /* Style improvements for collapsible sections */
        #mw-panel .portal {
            margin-bottom: 0.5em;
        }
        #mw-panel .portal .body ul {
            margin: 0;
            padding: 0;
        }
        #mw-panel .portal .body li {
            margin: 0.2em 0;
        }
    `);
});
});

Revision as of 14:37, 20 August 2025

# Replace the JAVASCRIPT_CODE section with this updated version:


/* Collapsible Sidebar Functionality */
$(document).ready(function() {
    function initCollapsibleSidebar() {
        // Define which sections should be collapsible
        var collapsibleSections = [
            'Documentation', 
            'Tools & Utilities', 
            'Community', 
            'Administrative', 
            'External Resources'
        ];

        // Define which sections start collapsed
        var startCollapsed = ['Administrative', 'External Resources'];

        // Process each portal in the sidebar
        $('#mw-panel .portal').each(function() {
            var $portal = $(this);
            var $header = $portal.find('h3');
            var $body = $portal.find('.body');
            var headerText = $header.text().trim();

            // Skip non-collapsible sections
            var portalId = $portal.attr('id');
            if (portalId === 'p-search' || portalId === 'p-tb' || portalId === 'p-lang') {
                return;
            }

            // Only make specified sections collapsible
            if (collapsibleSections.includes(headerText)) {
                // Remove any existing toggle buttons
                $header.find('.sidebar-toggle').remove();

                // Create toggle button with custom text
                var isCollapsed = startCollapsed.includes(headerText);
                var toggleText = isCollapsed ? 'Show' : 'Hide';  // Changed from [+]/[-]
                var $toggleBtn = $('<span class="sidebar-toggle">' + toggleText + '</span>');

                // Add toggle button to header
                $header.append(' ').append($toggleBtn);

                // Set initial state
                if (isCollapsed) {
                    $body.hide();
                    $portal.addClass('sidebar-collapsed');
                }

                // Add click handler
                $toggleBtn.off('click').on('click', function(e) {
                    e.preventDefault();
                    e.stopPropagation();

                    if ($body.is(':visible')) {
                        $body.slideUp(300);
                        $toggleBtn.text('Show');  // Changed from [+]
                        $portal.addClass('sidebar-collapsed');

                        // Save state to localStorage
                        localStorage.setItem('sidebar-' + headerText, 'collapsed');
                    } else {
                        $body.slideDown(300);
                        $toggleBtn.text('Hide');  // Changed from [-]
                        $portal.removeClass('sidebar-collapsed');

                        // Save state to localStorage
                        localStorage.setItem('sidebar-' + headerText, 'expanded');
                    }
                });

                // Restore saved state from localStorage
                var savedState = localStorage.getItem('sidebar-' + headerText);
                if (savedState === 'collapsed' && $body.is(':visible')) {
                    $body.hide();
                    $toggleBtn.text('Show');
                    $portal.addClass('sidebar-collapsed');
                } else if (savedState === 'expanded' && !$body.is(':visible')) {
                    $body.show();
                    $toggleBtn.text('Hide');
                    $portal.removeClass('sidebar-collapsed');
                }
            }
        });
    }

    // Initialize on page load
    initCollapsibleSidebar();

    // Re-initialize after AJAX loads (if needed)
    $(document).ajaxComplete(function() {
        setTimeout(initCollapsibleSidebar, 100);
    });
});