MediaWiki:Gadget-enhancedTableHandling.js

From Angelina Jordan Wiki
Revision as of 11:59, 11 August 2025 by Most2dot0 (talk | contribs) (Replaced code with ChatGPT generated one for Gadgets)

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(['mediawiki.util'], function () {
    jQuery(function ($) {
        // Escape characters for jQuery ID selector
        function escapeSelector(id) {
            return id.replace(/([ #;?%&,.+*~':"!^$[\]()=>|\/@])/g, '\\$1');
        }

        function forceExpandCollapsible() {
            var hash = window.location.hash;
            if (!hash) return;

            var rawId = decodeURIComponent(hash.slice(1)); // drop leading '#' then decode
            var targetId = escapeSelector(rawId);
            var $target = $('#' + targetId);

            if (!$target.length) return;

            // adjust this selector if your collapsible rows are placed differently
            var $collapsible = $target.closest('tr').next('tr.mw-collapsible');

            if ($collapsible.length && $collapsible.hasClass('mw-collapsed')) {
                $collapsible.removeClass('mw-collapsed');
                $collapsible.css('display', 'table-row');
            }
        }

        // initial load (from other page or direct link)
        forceExpandCollapsible();

        // handle in-page navigation
        $(window).on('hashchange', forceExpandCollapsible);
    });
});