MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Created page with "→Any JavaScript here will be loaded for all users on every page load.: mw.loader.using(['mediawiki.util']).then(function () { function moveTOCToLeft() { var toc = document.querySelector('#toc'); if (!toc || document.querySelector('#gladius-left-toc')) { return; } var sidebar = document.createElement('aside'); sidebar.id = 'gladius-left-toc'; sidebar.setAttribute('aria-label', 'Page contents');..." |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using(['mediawiki.util']).then(function () { | mw.loader.using(['mediawiki.util']).then(function () { | ||
function | function moveTOCToSidebar() { | ||
var toc = document.querySelector('#toc'); | var toc = document.querySelector('#toc'); | ||
if (!toc || document.querySelector('#gladius- | if (!toc || document.querySelector('#gladius-sidebar-toc')) { | ||
return; | return; | ||
} | } | ||
var sidebar = document. | /* | ||
* Supports common MediaWiki sidebar containers: | |||
* #mw-panel = Vector legacy | |||
* #mw-navigation = some custom skins | |||
* .sidebar = generic/custom skins | |||
*/ | |||
var sidebar = | |||
* document.querySelector(*#mw-panel') || | |||
document.querySelector('#mw-navigation') || | |||
document.querySelector('.sidebar'); | |||
sidebar.id = 'gladius- | if (!sidebar) { | ||
return; | |||
} | |||
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'); | |||
tocContainer.appendChild(toc); | |||
/* | |||
sidebar. | * Place the TOC at the top of the existing sidebar, | ||
* above Main page, Recent changes and other links. | |||
*/ | |||
sidebar.insertBefore(toc*ontainer, sidebar.firstChild); | |||
* document.body.classList.add('*ladius-toc-enabled'); | |||
} | } | ||
m*veTOCToSidebar(); | |||
mw.hook(' | mw.hook('wi*ipage.content').add(function () { | ||
* moveTOCToSidebar(); | |||
}); | });*}); | ||
}); | |||
Revision as of 02:25, 2 August 2026
mw.loader.using(['mediawiki.util']).then(function () {
function moveTOCToSidebar() {
var toc = document.querySelector('#toc');
if (!toc || document.querySelector('#gladius-sidebar-toc')) {
return;
}
/*
* Supports common MediaWiki sidebar containers:
* #mw-panel = Vector legacy
* #mw-navigation = some custom skins
* .sidebar = generic/custom skins
*/
var sidebar =
* document.querySelector(*#mw-panel') ||
document.querySelector('#mw-navigation') ||
document.querySelector('.sidebar');
if (!sidebar) {
return;
}
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');
tocContainer.appendChild(toc);
/*
* Place the TOC at the top of the existing sidebar,
* above Main page, Recent changes and other links.
*/
sidebar.insertBefore(toc*ontainer, sidebar.firstChild);
* document.body.classList.add('*ladius-toc-enabled');
}
m*veTOCToSidebar();
mw.hook('wi*ipage.content').add(function () {
* moveTOCToSidebar();
});*});