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 below the Tools section. | ||
*/ | */ | ||
(function ($, mw) { | |||
'use strict'; | |||
function | function moveTOCBelowTools() { | ||
var toc = document. | var toc = document.getElementById('toc'); | ||
var tools = document.getElementById('p-tb'); | |||
/* | /* | ||
* Stop | * Stop when: | ||
* | * - The page does not have a TOC. | ||
* | * - The Tools section cannot be found. | ||
* - The TOC was already moved. | |||
*/ | */ | ||
if (!toc || | if (!toc || !tools) { | ||
return; | return; | ||
} | } | ||
if (document.getElementById('gladius-sidebar-toc')) { | |||
return; | return; | ||
} | } | ||
/* | /* | ||
* Create | * Create a new sidebar section for Contents. | ||
*/ | */ | ||
var tocContainer = document.createElement('div'); | var tocContainer = document.createElement('div'); | ||
tocContainer.id = 'gladius-sidebar-toc'; | tocContainer.id = 'gladius-sidebar-toc'; | ||
tocContainer.className = 'mw-portlet | tocContainer.className = 'portal mw-portlet'; | ||
tocContainer.setAttribute('role', 'navigation'); | tocContainer.setAttribute('role', 'navigation'); | ||
tocContainer.setAttribute('aria-label', 'Page contents'); | tocContainer.setAttribute('aria-label', 'Page contents'); | ||
/* | /* | ||
* Move the | * Move the existing article TOC into the new container. | ||
*/ | */ | ||
tocContainer.appendChild(toc); | tocContainer.appendChild(toc); | ||
/* | /* | ||
* | * Insert Contents immediately below the Tools section. | ||
*/ | */ | ||
if (tools.parentNode) { | |||
tools.parentNode.insertBefore( | |||
tocContainer, | |||
tools.nextSibling | |||
); | |||
} | |||
} | } | ||
/* | /* | ||
* Wait | * Wait until the MediaWiki page is ready. | ||
*/ | */ | ||
function | $(function () { | ||
moveTOCBelowTools(); | |||
} | }); | ||
/* | /* | ||
* | * Also support dynamically loaded article content. | ||
*/ | */ | ||
mw.hook('wikipage.content').*dd(function () { | |||
window.se*Timeout(moveTOCBelowTools, 50); | |||
* }); | |||
}(jQuery, mediaWiki)); | |||
Revision as of 02:41, 2 August 2026
/*
* GladiusRO Wiki
* Move the article Table of Contents below the Tools section.
*/
(function ($, mw) {
'use strict';
function moveTOCBelowTools() {
var toc = document.getElementById('toc');
var tools = document.getElementById('p-tb');
/*
* Stop when:
* - The page does not have a TOC.
* - The Tools section cannot be found.
* - The TOC was already moved.
*/
if (!toc || !tools) {
return;
}
if (document.getElementById('gladius-sidebar-toc')) {
return;
}
/*
* Create a new sidebar section for Contents.
*/
var tocContainer = document.createElement('div');
tocContainer.id = 'gladius-sidebar-toc';
tocContainer.className = 'portal mw-portlet';
tocContainer.setAttribute('role', 'navigation');
tocContainer.setAttribute('aria-label', 'Page contents');
/*
* Move the existing article TOC into the new container.
*/
tocContainer.appendChild(toc);
/*
* Insert Contents immediately below the Tools section.
*/
if (tools.parentNode) {
tools.parentNode.insertBefore(
tocContainer,
tools.nextSibling
);
}
}
/*
* Wait until the MediaWiki page is ready.
*/
$(function () {
moveTOCBelowTools();
});
/*
* Also support dynamically loaded article content.
*/
mw.hook('wikipage.content').*dd(function () {
window.se*Timeout(moveTOCBelowTools, 50);
* });
}(jQuery, mediaWiki));