MediaWiki:Common.js
From Midgard Tales 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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// Add Expand/Collapse button
$(document).ready(function() {
// Target the sidebar portlets
$('#mw-navigation .mw-portlet').each(function() {
var $portlet = $(this);
var $label = $portlet.find('a.nav-link.disabled'); // The section label
var $body = $portlet.find('.mw-portlet-body'); // The collapsible content
// Add a toggle button to the label if it doesn't already exist
if (!$label.find('.collapsible-arrow').length) {
$label.append('<span class="collapsible-arrow">▼</span>');
}
// Collapse/expand on click
$label.on('click', function(e) {
e.preventDefault(); // Prevent the link from navigating
$body.toggle();
$label.find('.collapsible-arrow').text(function(_, text) {
return text === '▼' ? '▶' : '▼';
});
});
});
});