MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: mw.loader.using(['jquery'], function () { $('h2').each(function () { // ONLY targets h2 (Subheading 1) var $heading = $(this); var $content = $heading.nextUntil('h2'); // Stops at the next h2 if ($content.length) { var $toggle = $('<span class="toggle-link" style="cursor: pointer; color: blue; margin-left: 10px;">[+]</span>'); $heading.appen...")
 
Tag: Replaced
 
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. */
mw.loader.using(['jquery'], function () {
    $('h2').each(function () {  // ONLY targets h2 (Subheading 1)
        var $heading = $(this);
        var $content = $heading.nextUntil('h2');  // Stops at the next h2
        if ($content.length) {
            var $toggle = $('<span class="toggle-link" style="cursor: pointer; color: blue; margin-left: 10px;">[+]</span>');
            $heading.append($toggle);
            $content.wrapAll('<div class="collapsible-content" style="display: none;"></div>');
            $toggle.on('click', function () {
                var $container = $toggle.parent().next('.collapsible-content');
                var isVisible = $container.is(':visible');
                $container.toggle(!isVisible);
                $toggle.text(isVisible ? '[+]' : '[-]');
            });
        }
    });
});

Navigation menu