MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* | |||
* GladiusRO Wiki | |||
* Move the article Table of Contents into the existing left sidebar. | |||
*/ | |||
mw.loader.using(['mediawiki.util']).then(function () { | mw.loader.using(['mediawiki.util']).then(function () { | ||
function moveTOCToSidebar() { | function moveTOCToSidebar() { | ||
var toc = document.querySelector('#toc'); | var toc = document.querySelector('#toc'); | ||
/* | |||
* Stop if: | |||
* 1. The current page has no table of contents. | |||
* 2. The TOC has already been moved. | |||
*/ | |||
if (!toc || document.querySelector('#gladius-sidebar-toc')) { | if (!toc || document.querySelector('#gladius-sidebar-toc')) { | ||
return; | return; | ||
| Line 8: | Line 19: | ||
/* | /* | ||
* | * Find the wiki's existing left sidebar. | ||
* | * The first selector is normally used by Vector. | ||
* | * The other selectors provide support for custom skins. | ||
*/ | */ | ||
var sidebar = | var sidebar = | ||
document.querySelector('#mw-panel') || | |||
document.querySelector('#mw-navigation') || | document.querySelector('#mw-navigation') || | ||
document.querySelector('.sidebar'); | document.querySelector('.sidebar'); | ||
| Line 22: | Line 32: | ||
} | } | ||
/* | |||
* Create a container for the TOC. | |||
*/ | |||
var tocContainer = document.createElement('div'); | var tocContainer = document.createElement('div'); | ||
| Line 29: | Line 42: | ||
tocContainer.setAttribute('aria-label', 'Page contents'); | tocContainer.setAttribute('aria-label', 'Page contents'); | ||
/* | |||
* Move the existing TOC into the new container. | |||
*/ | |||
tocContainer.appendChild(toc); | tocContainer.appendChild(toc); | ||
/* | /* | ||
* | * Insert Contents at the top of the sidebar, | ||
* | * before Main page, Recent changes and other links. | ||
*/ | */ | ||
sidebar.insertBefore( | sidebar.insertBefore(tocContainer, sidebar.firstChild); | ||
document.body.classList.add('gladius-toc-enabled'); | |||
} | } | ||
/* | |||
* Run when the page first loads. | |||
*/ | |||
moveTOCToSidebar(); | |||
mw.hook(' | /* | ||
* | * Run again when MediaWiki dynamically updates page content. | ||
}); | */ | ||
mw.hook('wikipage.conten*').add(function () { | |||
moveT*CToSidebar(); | |||
}); | |||
}); | |||
Revision as of 02:29, 2 August 2026
/*
* GladiusRO Wiki
* Move the article Table of Contents into the existing left sidebar.
*/
mw.loader.using(['mediawiki.util']).then(function () {
function moveTOCToSidebar() {
var toc = document.querySelector('#toc');
/*
* Stop if:
* 1. The current page has no table of contents.
* 2. The TOC has already been moved.
*/
if (!toc || document.querySelector('#gladius-sidebar-toc')) {
return;
}
/*
* Find the wiki's existing left sidebar.
* The first selector is normally used by Vector.
* The other selectors provide support for custom skins.
*/
var sidebar =
document.querySelector('#mw-panel') ||
document.querySelector('#mw-navigation') ||
document.querySelector('.sidebar');
if (!sidebar) {
return;
}
/*
* Create a container for the TOC.
*/
var tocContainer = document.createElement('div');
tocContainer.id = 'gladius-sidebar-toc';
tocContainer.className = 'mw-portlet portal';
tocContainer.setAttribute('role', 'navigation');
tocContainer.setAttribute('aria-label', 'Page contents');
/*
* Move the existing TOC into the new container.
*/
tocContainer.appendChild(toc);
/*
* Insert Contents at the top of the sidebar,
* before Main page, Recent changes and other links.
*/
sidebar.insertBefore(tocContainer, sidebar.firstChild);
document.body.classList.add('gladius-toc-enabled');
}
/*
* Run when the page first loads.
*/
moveTOCToSidebar();
/*
* Run again when MediaWiki dynamically updates page content.
*/
mw.hook('wikipage.conten*').add(function () {
moveT*CToSidebar();
});
});