Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 2: Line 2:


$(document).ready(function() {
$(document).ready(function() {
     // Wait for collapsible elements to be initialized by MediaWiki
     var $sections = $('.accordion-section');
    mw.hook('wikipage.content').add(function() {
        var $sections = $('.accordion-section');


        // Initialize: disable links in collapsed sections
    // Initialize: disable links in all headers by default (since all start collapsed)
        $sections.each(function() {
    $sections.find('.accordion-header a').css('pointer-events', 'none');
            if ($(this).hasClass('mw-collapsed')) {
                $(this).find('.mw-headline a').css('pointer-events', 'none');
            }
        });


        // Handle clicks on headers
    // Handle header clicks
        $sections.on('click', '.mw-headline', function(e) {
    $('.accordion-header').on('click', function(e) {
            var $section = $(this).closest('.accordion-section');
        var $section = $(this).closest('.accordion-section');
            var isCollapsed = $section.hasClass('mw-collapsed');
        var $content = $section.find('.accordion-content');
        var isHidden = $content.is(':hidden');


            if (isCollapsed) {
        if (isHidden) {
                // Collapse all other sections
            // Collapse all other sections
                $sections.not($section).addClass('mw-collapsed');
            $sections.not($section).find('.accordion-content').slideUp(200);
                // Expand this section
            $sections.not($section).removeClass('expanded');
                $section.removeClass('mw-collapsed');
             $sections.not($section).find('.accordion-header a').css('pointer-events', 'none');
                // Enable links in this section
                $section.find('.mw-headline a').css('pointer-events', 'auto');
                // Disable links in all other sections
                $sections.not($section).find('.mw-headline a').css('pointer-events', 'none');
             } else {
                // Collapse this section
                $section.addClass('mw-collapsed');
                // Disable links in this section
                $section.find('.mw-headline a').css('pointer-events', 'none');
            }


             // Prevent link click from propagating if collapsed
             // Expand this section
            if (e.target.tagName === 'A' && $section.hasClass('mw-collapsed')) {
            $content.slideDown(200);
                e.preventDefault();
            $section.addClass('expanded');
            }
            $section.find('.accordion-header a').css('pointer-events', 'auto');
         });
        } else {
            // Collapse this section
            $content.slideUp(200);
            $section.removeClass('expanded');
            $section.find('.accordion-header a').css('pointer-events', 'none');
        }
 
        // Prevent link click if content is hidden
        if (e.target.tagName === 'A' && $content.is(':hidden')) {
            e.preventDefault();
         }
     });
     });
});
});

Revision as of 07:49, 29 March 2025

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
    var $sections = $('.accordion-section');

    // Initialize: disable links in all headers by default (since all start collapsed)
    $sections.find('.accordion-header a').css('pointer-events', 'none');

    // Handle header clicks
    $('.accordion-header').on('click', function(e) {
        var $section = $(this).closest('.accordion-section');
        var $content = $section.find('.accordion-content');
        var isHidden = $content.is(':hidden');

        if (isHidden) {
            // Collapse all other sections
            $sections.not($section).find('.accordion-content').slideUp(200);
            $sections.not($section).removeClass('expanded');
            $sections.not($section).find('.accordion-header a').css('pointer-events', 'none');

            // Expand this section
            $content.slideDown(200);
            $section.addClass('expanded');
            $section.find('.accordion-header a').css('pointer-events', 'auto');
        } else {
            // Collapse this section
            $content.slideUp(200);
            $section.removeClass('expanded');
            $section.find('.accordion-header a').css('pointer-events', 'none');
        }

        // Prevent link click if content is hidden
        if (e.target.tagName === 'A' && $content.is(':hidden')) {
            e.preventDefault();
        }
    });
});