MediaWiki:Common.js: Difference between revisions
From Midgard Tales Wiki
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// | // Function to collapse all sections | ||
$('#mw-navigation .mw-portlet'). | function collapseAll() { | ||
$('#mw-navigation .mw-portlet .mw-portlet-body').hide(); | |||
$('#mw-navigation .mw-portlet .collapsible-arrow').text('▶'); | |||
} | |||
// Add a | // Function to expand all sections | ||
function expandAll() { | |||
$('#mw-navigation .mw-portlet .mw-portlet-body').show(); | |||
$('#mw-navigation .mw-portlet .collapsible-arrow').text('▼'); | |||
} | |||
// Add a "Close All" button | |||
var $closeAllButton = $('<button>', { | |||
text: 'Close All', | |||
id: 'close-all-button', | |||
click: function() { | |||
collapseAll(); | |||
$(this).text('Open All').off('click').on('click', function() { | |||
expandAll(); | |||
$(this).text('Close All').off('click').on('click', function() { | |||
collapseAll(); | |||
$(this).text('Open All'); | |||
}); | |||
}); | |||
} | |||
}); | |||
// Add the button to the sidebar | |||
$('#mw-navigation').prepend($closeAllButton); | |||
// Add collapsible arrows to section labels | |||
$('#mw-navigation .mw-portlet a.nav-link.disabled').each(function() { | |||
var $label = $(this); | |||
var $body = $label.next('.mw-portlet-body'); | |||
// Add a collapsible arrow if it doesn't already exist | |||
if (!$label.find('.collapsible-arrow').length) { | if (!$label.find('.collapsible-arrow').length) { | ||
$label.append('<span class="collapsible-arrow">▼</span>'); | $label.append('<span class="collapsible-arrow">▼</span>'); | ||
| Line 15: | Line 44: | ||
// Collapse/expand on click | // Collapse/expand on click | ||
$label.on('click', function(e) { | $label.on('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
$body.toggle(); | $body.toggle(); | ||
$label.find('.collapsible-arrow').text(function(_, text) { | $label.find('.collapsible-arrow').text(function(_, text) { | ||
Revision as of 07:14, 31 January 2025
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
// Function to collapse all sections
function collapseAll() {
$('#mw-navigation .mw-portlet .mw-portlet-body').hide();
$('#mw-navigation .mw-portlet .collapsible-arrow').text('▶');
}
// Function to expand all sections
function expandAll() {
$('#mw-navigation .mw-portlet .mw-portlet-body').show();
$('#mw-navigation .mw-portlet .collapsible-arrow').text('▼');
}
// Add a "Close All" button
var $closeAllButton = $('<button>', {
text: 'Close All',
id: 'close-all-button',
click: function() {
collapseAll();
$(this).text('Open All').off('click').on('click', function() {
expandAll();
$(this).text('Close All').off('click').on('click', function() {
collapseAll();
$(this).text('Open All');
});
});
}
});
// Add the button to the sidebar
$('#mw-navigation').prepend($closeAllButton);
// Add collapsible arrows to section labels
$('#mw-navigation .mw-portlet a.nav-link.disabled').each(function() {
var $label = $(this);
var $body = $label.next('.mw-portlet-body');
// Add a collapsible arrow 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();
$body.toggle();
$label.find('.collapsible-arrow').text(function(_, text) {
return text === '▼' ? '▶' : '▼';
});
});
});
});