MediaWiki:Common.js

From SZ
Revision as of 20:22, 25 August 2025 by Test2 (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
mw.loader.using('jquery', function () {
    $(function () {
        // Select top-level sidebar items with submenus
        $('.vector-menu-portal .vector-menu-content-list > li').each(function () {
            var $item = $(this);
            var $subMenu = $item.children('ul');

            if ($subMenu.length) {
                $item.addClass('collapsible-header');
                $subMenu.hide(); // Hide by default

                // Click to toggle submenu
                $item.on('click', function (e) {
                    // Prevent links in submenu from triggering collapse
                    if (e.target.tagName !== 'A') {
                        e.preventDefault();
                        $item.toggleClass('open');
                        $subMenu.slideToggle(200);
                    }
                });
            }
        });
    });
});