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 | * Move Contents below the Tools section. | ||
*/ | */ | ||
(function ( | (function () { | ||
'use strict'; | 'use strict'; | ||
function | var attempts = 0; | ||
var maximumAttempts = 30; | |||
function moveGladiusTOC() { | |||
var toc = document.getElementById('toc'); | var toc = document.getElementById('toc'); | ||
var tools = document.getElementById('p-tb'); | var tools = document.getElementById('p-tb'); | ||
var existingContainer = | |||
document.getElementById('gladius-sidebar-toc'); | |||
/* | /* | ||
* Stop | * Stop if Contents was already moved. | ||
*/ | */ | ||
if ( | if (existingContainer) { | ||
return; | return true; | ||
} | } | ||
if ( | /* | ||
return; | * Wait until both the article TOC | ||
* and the Tools sidebar panel exist. | |||
*/ | |||
if (!toc || !tools || !tools.parentNode) { | |||
return false; | |||
} | } | ||
/* | /* | ||
* Create a new | * Create a new container. | ||
*/ | */ | ||
var tocContainer = document.createElement('div'); | var tocContainer = document.createElement('div'); | ||
| Line 33: | Line 39: | ||
tocContainer.className = 'portal 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 original TOC out of the article. | ||
*/ | */ | ||
tocContainer.appendChild(toc); | tocContainer.appendChild(toc); | ||
/* | /* | ||
* Insert Contents immediately | * Insert Contents immediately after Tools. | ||
*/ | */ | ||
if ( | tools.insertAdjacentElement( | ||
'afterend', | |||
tocContainer | |||
); | |||
return true; | |||
} | |||
function retryMoveGladiusTOC() { | |||
attempts++; | |||
if (moveGladiusTOC()) { | |||
return; | |||
} | |||
if (attempts < maximumAttempts) { | |||
window.setTimeout( | |||
retryMoveGladiusTOC, | |||
200 | |||
); | ); | ||
} | } | ||
| Line 52: | Line 76: | ||
/* | /* | ||
* | * Start after the complete page has loaded. | ||
*/ | */ | ||
if (document.readyState === 'loading') { | |||
document.addEventListener( | |||
}); | 'DOMContentLoaded', | ||
retryMoveGladiusTOC | |||
); | |||
} else { | |||
retryMoveGladiusTOC(); | |||
} | |||
/* | /* | ||
* | * Try once more after all images and skin | ||
* components have loaded. | |||
*/ | */ | ||
window.addEventListener( | |||
'load', | |||
retryMoveGladiusTOC | |||
); | |||
}( | }()); | ||
Revision as of 02:46, 2 August 2026
/*
* GladiusRO Wiki
* Move Contents below the Tools section.
*/
(function () {
'use strict';
var attempts = 0;
var maximumAttempts = 30;
function moveGladiusTOC() {
var toc = document.getElementById('toc');
var tools = document.getElementById('p-tb');
var existingContainer =
document.getElementById('gladius-sidebar-toc');
/*
* Stop if Contents was already moved.
*/
if (existingContainer) {
return true;
}
/*
* Wait until both the article TOC
* and the Tools sidebar panel exist.
*/
if (!toc || !tools || !tools.parentNode) {
return false;
}
/*
* Create a new container.
*/
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 original TOC out of the article.
*/
tocContainer.appendChild(toc);
/*
* Insert Contents immediately after Tools.
*/
tools.insertAdjacentElement(
'afterend',
tocContainer
);
return true;
}
function retryMoveGladiusTOC() {
attempts++;
if (moveGladiusTOC()) {
return;
}
if (attempts < maximumAttempts) {
window.setTimeout(
retryMoveGladiusTOC,
200
);
}
}
/*
* Start after the complete page has loaded.
*/
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
retryMoveGladiusTOC
);
} else {
retryMoveGladiusTOC();
}
/*
* Try once more after all images and skin
* components have loaded.
*/
window.addEventListener(
'load',
retryMoveGladiusTOC
);
}());