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 */
/* CSS placed here will be applied to all skins */
/* CSS placed here will be applied to all skins */


mw.loader.using('jquery.makeCollapsible').then(function () {
/* Collapsible sidebar functionality for all pages */
     // Turn sidebar collapsibles into an accordion
$(document).ready(function() {
     $('#mw-panel .mw-collapsible').on('beforeExpand.mw-collapsible', function () {
     // Function to make sidebar sections collapsible
         // Collapse siblings when one expands
     function makeSidebarCollapsible() {
         $(this).siblings('.mw-collapsible').each(function () {
         // Target the sidebar navigation
             if (!$(this).hasClass('mw-collapsed')) {
         $('#mw-panel .portal').each(function() {
                $(this).find('.mw-collapsible-toggle').click();
             var $portal = $(this);
            var $header = $portal.find('h3');
            var $body = $portal.find('.body');
 
            // Skip certain sections that shouldn't be collapsible
            var portalId = $portal.attr('id');
            if (portalId === 'p-search' || portalId === 'p-tb' || portalId === 'p-lang') {
                return;
             }
             }
        });
    });
});


/* Style collapsible sidebar sections like dropdowns */
            // Add toggle functionality only to specific sections
.mw-collapsible-toggle {
            var collapsibleSections = ['Documentation', 'Tools & Utilities', 'Community', 'Administrative', 'External Resources'];
    float: right;
            var headerText = $header.text().trim();
    font-weight: bold;
    cursor: pointer;
}


.mw-collapsible.mw-collapsed > .mw-collapsible-toggle::after {
            if (collapsibleSections.includes(headerText)) {
    content: " "; /* arrow when collapsed */
                // Add toggle button to header
}
                var $toggleBtn = $('<span class="sidebar-toggle">[−]</span>');
                $header.append(' ').append($toggleBtn);


.mw-collapsible:not(.mw-collapsed) > .mw-collapsible-toggle::after {
                // Add click handler
    content: " ▲"; /* arrow when expanded */
                $toggleBtn.click(function(e) {
}
                    e.preventDefault();
                    e.stopPropagation();


                    if ($body.is(':visible')) {
                        $body.slideUp(200);
                        $toggleBtn.text('[+]');
                        $portal.addClass('collapsed');
                    } else {
                        $body.slideDown(200);
                        $toggleBtn.text('[−]');
                        $portal.removeClass('collapsed');
                    }
                });


/* Collapsible Sidebar Styles */
                // Start collapsed for some sections
.sidebar-toggle {
                if (['Administrative', 'External Resources'].includes(headerText)) {
    cursor: pointer;
                    $body.hide();
    font-weight: bold;
                    $toggleBtn.text('[+]');
    color: #0645ad;
                    $portal.addClass('collapsed');
    margin-left: 8px;
                }
    font-size: 11px;
            }
    user-select: none;
        });
     text-decoration: none;
     }
    display: inline-block;
    min-width: 20px;
    text-align: center;
}


.sidebar-toggle:hover {
     // Run the function
     text-decoration: underline;
     makeSidebarCollapsible();
     color: #0b0080;
    background-color: #f8f9fa;
    border-radius: 2px;
}


/* Collapsed state styling */
    // Also run after any AJAX content loads
#mw-panel .portal.sidebar-collapsed .body {
    $(document).ajaxComplete(function() {
     display: none !important;
        makeSidebarCollapsible();
}
     });
});


/* Improve sidebar section spacing */
/* CSS for sidebar toggle buttons */
#mw-panel .portal {
mw.loader.using('mediawiki.util', function() {
     margin-bottom: 0.7em;
     mw.util.addCSS(`
    border-bottom: 1px solid #eaecf0;
        .sidebar-toggle {
    padding-bottom: 0.3em;
            cursor: pointer;
}
            font-weight: bold;
            color: #0645ad;
            margin-left: 5px;
            font-size: 12px;
            user-select: none;
        }


#mw-panel .portal:last-child {
        .sidebar-toggle:hover {
    border-bottom: none;
            text-decoration: underline;
}
            color: #0b0080;
        }


/* Header styling for collapsible sections */
        #mw-panel .portal.collapsed .body {
#mw-panel .portal h3 {
            display: none;
    cursor: default;
        }
    position: relative;
    font-weight: bold;
    color: #333;
}


/* Body content styling */
        #mw-panel .portal h3 {
#mw-panel .portal .body {
            cursor: default;
    transition: all 0.3s ease;
        }
}


#mw-panel .portal .body ul {
        /* Style improvements for collapsible sections */
    margin: 0.3em 0 0 0;
        #mw-panel .portal {
    padding: 0;
            margin-bottom: 0.5em;
    list-style: none;
        }
}


#mw-panel .portal .body li {
        #mw-panel .portal .body ul {
    margin: 0.2em 0;
            margin: 0;
    padding: 0.1em 0;
            padding: 0;
    line-height: 1.3;
        }
}


#mw-panel .portal .body li a {
        #mw-panel .portal .body li {
    color: #0645ad;
            margin: 0.2em 0;
    text-decoration: none;
        }
    display: block;
     `);
    padding: 2px 0;
});
}
 
#mw-panel .portal .body li a:hover {
    text-decoration: underline;
    background-color: #f8f9fa;
    border-radius: 2px;
    padding: 2px 4px;
    margin: 0 -4px;
}
 
/* Visual indicator for collapsible sections */
#mw-panel .portal h3:has(.sidebar-toggle) {
     background: linear-gradient(to right, #f8f9fa 0%, transparent 100%);
    padding: 2px 4px;
    margin: 0 -4px;
    border-radius: 3px;
}
 
/* Responsive adjustments */
@media (max-width: 768px) {
    .sidebar-toggle {
        font-size: 14px;
        margin-left: 10px;
    }
}

Revision as of 14:22, 20 August 2025

/* CSS placed here will be applied to all skins */

/* Collapsible sidebar functionality for all pages */
$(document).ready(function() {
    // Function to make sidebar sections collapsible
    function makeSidebarCollapsible() {
        // Target the sidebar navigation
        $('#mw-panel .portal').each(function() {
            var $portal = $(this);
            var $header = $portal.find('h3');
            var $body = $portal.find('.body');

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

            // Add toggle functionality only to specific sections
            var collapsibleSections = ['Documentation', 'Tools & Utilities', 'Community', 'Administrative', 'External Resources'];
            var headerText = $header.text().trim();

            if (collapsibleSections.includes(headerText)) {
                // Add toggle button to header
                var $toggleBtn = $('<span class="sidebar-toggle">[−]</span>');
                $header.append(' ').append($toggleBtn);

                // Add click handler
                $toggleBtn.click(function(e) {
                    e.preventDefault();
                    e.stopPropagation();

                    if ($body.is(':visible')) {
                        $body.slideUp(200);
                        $toggleBtn.text('[+]');
                        $portal.addClass('collapsed');
                    } else {
                        $body.slideDown(200);
                        $toggleBtn.text('[−]');
                        $portal.removeClass('collapsed');
                    }
                });

                // Start collapsed for some sections
                if (['Administrative', 'External Resources'].includes(headerText)) {
                    $body.hide();
                    $toggleBtn.text('[+]');
                    $portal.addClass('collapsed');
                }
            }
        });
    }

    // Run the function
    makeSidebarCollapsible();

    // Also run after any AJAX content loads
    $(document).ajaxComplete(function() {
        makeSidebarCollapsible();
    });
});

/* 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;
        }
    `);
});