MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* | /* | ||
* GladiusRO Wiki | * GladiusRO Wiki | ||
* Move the article Table of Contents | * Move the article Table of Contents to the bottom | ||
* of the existing left sidebar, below Tools. | |||
*/ | */ | ||
mw.loader.using(['mediawiki.util']).then(function () { | mw.loader.using(['mediawiki.util']).then(function () { | ||
function | function moveTOCToBottomOfSidebar() { | ||
var toc = document.querySelector('#toc'); | var toc = document.querySelector('#toc'); | ||
/* | /* | ||
* Stop if | * Stop if: | ||
* | * 1. This page has no table of contents. | ||
* 2. The table of contents was already moved. | |||
*/ | */ | ||
if (!toc || document.querySelector('#gladius-sidebar-toc')) { | if (!toc || document.querySelector('#gladius-sidebar-toc')) { | ||
| Line 18: | Line 20: | ||
/* | /* | ||
* Find the existing left sidebar. | * Find the existing MediaWiki left sidebar. | ||
*/ | */ | ||
var sidebar = | var sidebar = | ||
| Line 30: | Line 32: | ||
/* | /* | ||
* Create the | * Create the sidebar TOC container. | ||
*/ | */ | ||
var tocContainer = document.createElement('div'); | var tocContainer = document.createElement('div'); | ||
| Line 40: | Line 42: | ||
/* | /* | ||
* Move the original article TOC into the container. | * Move the original article TOC into the new container. | ||
*/ | */ | ||
tocContainer.appendChild(toc); | tocContainer.appendChild(toc); | ||
/* | /* | ||
* | * Put Contents at the very bottom of the sidebar. | ||
* This keeps the logo, navigation and Tools above it. | |||
*/ | */ | ||
sidebar.appendChild(tocContainer); | |||
document.body.classList.add('gladius-toc-enabled'); | document.body.classList.add('gladius-toc-enabled'); | ||
| Line 101: | Line 56: | ||
/* | /* | ||
* | * Wait briefly so the skin can finish loading | ||
* the logo, navigation and Tools sections first. | |||
*/ | */ | ||
function initialiseGladiusTOC() { | function initialiseGladiusTOC() { | ||
window.setTimeout( | window.setTimeout(moveTOCToBottomOfSidebar, 150); | ||
} | } | ||
/* | |||
* Run when the page loads. | |||
*/ | |||
initialiseGladiusTOC(); | initialiseGladiusTOC(); | ||
/* | /* | ||
* Run | * Run again if MediaWiki dynamically refreshes | ||
* the article content. | |||
*/ | */ | ||
mw.hook('wikipage.content'). | mw.hook('wikipage.content').*dd(function () { | ||
initialis*GladiusTOC(); | |||
}); | }); | ||
}); | }); | ||
Revision as of 02:37, 2 August 2026
/*
* GladiusRO Wiki
* Move the article Table of Contents to the bottom
* of the existing left sidebar, below Tools.
*/
mw.loader.using(['mediawiki.util']).then(function () {
function moveTOCToBottomOfSidebar() {
var toc = document.querySelector('#toc');
/*
* Stop if:
* 1. This page has no table of contents.
* 2. The table of contents was already moved.
*/
if (!toc || document.querySelector('#gladius-sidebar-toc')) {
return;
}
/*
* Find the existing MediaWiki left sidebar.
*/
var sidebar =
document.querySelector('#mw-panel') ||
document.querySelector('#mw-navigation') ||
document.querySelector('.sidebar');
if (!sidebar) {
return;
}
/*
* Create the sidebar TOC container.
*/
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 original article TOC into the new container.
*/
tocContainer.appendChild(toc);
/*
* Put Contents at the very bottom of the sidebar.
* This keeps the logo, navigation and Tools above it.
*/
sidebar.appendChild(tocContainer);
document.body.classList.add('gladius-toc-enabled');
}
/*
* Wait briefly so the skin can finish loading
* the logo, navigation and Tools sections first.
*/
function initialiseGladiusTOC() {
window.setTimeout(moveTOCToBottomOfSidebar, 150);
}
/*
* Run when the page loads.
*/
initialiseGladiusTOC();
/*
* Run again if MediaWiki dynamically refreshes
* the article content.
*/
mw.hook('wikipage.content').*dd(function () {
initialis*GladiusTOC();
});
});