MediaWiki:Gadget-enhancedTableHandling.js
From Angelina Jordan Wiki
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([], function () {
jQuery(function ($) {
console.log('gadget loaded'); // debug output
// Expand collapsibles if they are target of a jump to its anchor id
function escapeSelector(id) {
return id.replace(/([ #;?%&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1');
}
function forceExpandCollapsible() {
var hash = decodeURIComponent(window.location.hash); // Decode the URL-encoded hash
if (hash) {
var targetId = escapeSelector(hash.substring(1)); // Remove '#' and escape the ID
var target = $('#' + targetId);
if (target.length) {
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');
}
}
}
}
// Execute immediately to catch the case when coming from another page
forceExpandCollapsible();
// Also handle hash changes (e.g., clicking on an in-page link)
$(window).on('hashchange', function() {
forceExpandCollapsible();
});
});
});