MediaWiki:Gadget-CollapseTemplatesUsed.js
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.
// Collapse "Templates used on this page" at the bottom of Edit pages by default
mw.loader.using('jquery.makeCollapsible').then(function () {
mw.hook('wikipage.content').add(function ($content) {
var $ul = $content.find('.templatesUsed > ul.mw-editfooter-list.mw-collapsible');
if (!$ul.length) return;
// If not initialized yet, mark collapsed before init
if (!$ul.hasClass('mw-made-collapsible')) {
$ul.addClass('mw-collapsed').makeCollapsible();
} else {
// Already initialized: use the object API
var obj = $ul.data('mw-collapsible');
if (obj && typeof obj.collapse === 'function') {
obj.collapse(); // reliable way post-init
} else {
// Fallback for older skins/builds
$ul.addClass('mw-collapsed');
}
}
// Sync the header button state
$content.find('.templatesUsed .mw-editfooter-toggler')
.attr('aria-expanded', 'false');
});
});