MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Wait for DOM before injecting archived sidebar) |
(Render archive navigation on both left and right) |
||
| Line 149: | Line 149: | ||
nav.appendChild( content ); | nav.appendChild( content ); | ||
return nav; | return nav; | ||
} | |||
function buildPanel( panelId, beforeNode ) { | |||
var panel = document.createElement( 'div' ); | |||
panel.id = panelId; | |||
sections.forEach( function ( section ) { | |||
panel.appendChild( makePortlet( section ) ); | |||
} ); | |||
beforeNode.parentNode.insertBefore( panel, beforeNode ); | |||
return panel; | |||
} | } | ||
| Line 154: | Line 164: | ||
var panel = document.getElementById( 'mw-panel' ); | var panel = document.getElementById( 'mw-panel' ); | ||
var tools = document.getElementById( 'p-tb' ); | var tools = document.getElementById( 'p-tb' ); | ||
if ( !panel || document.getElementById( 'wmu-navigation' ) ) { | var content = document.getElementById( 'content' ); | ||
if ( !panel || !content || document.getElementById( 'wmu-navigation' ) ) { | |||
return; | return; | ||
} | } | ||
| Line 161: | Line 172: | ||
panel.insertBefore( makePortlet( section ), tools || null ); | panel.insertBefore( makePortlet( section ), tools || null ); | ||
} ); | } ); | ||
if ( !document.getElementById( 'wmu-left-panel' ) ) { | |||
buildPanel( 'wmu-left-panel', content ); | |||
} | |||
} | } | ||
Revision as of 23:01, 15 March 2026
( function () {
var sections = [
{
id: 'wmu-navigation',
label: 'Navigation',
links: [
{ title: 'Main Page', label: 'Home Page' },
{ title: 'Find your local community', label: 'Find a local club' },
{ href: 'https://www.patreon.com/user?u=35827616&fan_landing=true', label: 'Patreon', external: true }
]
},
{
id: 'wmu-core-rules',
label: 'Core Rules',
links: [
{ title: 'Useful External Links', label: 'Get the Rules Free' },
{ title: 'LPG - Theme Forces', label: 'Theme Forces' },
{ title: 'Steamroller', label: 'Steamroller' },
{ title: 'Infernal Rulings', label: 'Rule Clarifications' }
]
},
{
id: 'wmu-training',
label: 'Training',
links: [
{ title: 'Crash Course (101)', label: 'Basic Training' },
{ title: 'Learning to Play the Game (LPG)', label: 'Intermediate Training' },
{ title: 'Learn Objectives, Tactics, & Strategy (LOTS)', label: 'Advanced Training' },
{ title: 'Glossary', label: 'Glossary' }
]
},
{
id: 'wmu-warmachine',
label: 'Warmachine',
links: [
{ title: 'Cryx', label: 'Cryx' },
{ title: 'Cygnar', label: 'Cygnar' },
{ title: 'Khador', label: 'Khador' },
{ title: 'Protectorate of Menoth', label: 'Protectorate' },
{ title: 'Retribution of Scyrah', label: 'Retribution' },
{ title: 'Mercenaries', label: 'Mercenaries' }
]
},
{
id: 'wmu-hordes',
label: 'Hordes',
links: [
{ title: 'Circle Orboros', label: 'Circle' },
{ title: 'Legion of Everblight', label: 'Legion' },
{ title: 'Skorne', label: 'Skorne' },
{ title: 'Trollbloods', label: 'Trollbloods' },
{ title: 'Minions', label: 'Minions' }
]
},
{
id: 'wmu-mini-factions',
label: 'Mini-Factions',
links: [
{ title: 'Convergence of Cyriss', label: 'Convergence' },
{ title: 'Crucible Guard', label: 'Crucible Guard' },
{ title: 'Grymkin', label: 'Grymkin' },
{ title: 'Infernals', label: 'Infernals' },
{ title: 'Orgoth', label: 'Orgoth' }
]
},
{
id: 'wmu-other-pp-games',
label: 'Other PP Games',
links: [
{ title: 'Other PP Games', label: 'Neo-Mechanika' },
{ title: 'Other PP Games', label: 'Riot Quest' },
{ title: 'Other PP Games', label: '...more' }
]
},
{
id: 'wmu-vaults',
label: 'The Vaults',
links: [
{ title: 'FAQ', label: 'FAQ' },
{ title: 'League Models', label: 'League Models' },
{ title: 'New Releases', label: 'New Releases' },
{ title: 'Attack Sequence', label: 'Attack Sequence' },
{ title: 'Template:Index Vaults', label: '...more' }
]
},
{
id: 'wmu-other',
label: 'Other',
links: [
{ href: 'https://www.loswarmachine.com/', label: 'Other LOS sites', external: true },
{ title: 'Useful External Links', label: 'Other useful websites' },
{ title: 'Special:Random', label: 'Random page', special: true },
{ title: 'Special:RecentChanges', label: 'Recent changes', special: true },
{ title: 'War Table', label: 'War Table' }
]
}
];
function titleToHref( title, special ) {
var normalized = title.replace(/ /g, '_');
if ( special ) {
return '/index.php/' + encodeURI( normalized );
}
return '/index.php?title=' + encodeURIComponent( normalized );
}
function makePortlet( section ) {
var nav = document.createElement( 'nav' );
nav.id = section.id;
nav.className = 'vector-menu mw-portlet vector-menu-portal portal';
nav.setAttribute( 'role', 'navigation' );
nav.setAttribute( 'aria-labelledby', section.id + '-label' );
var heading = document.createElement( 'h3' );
heading.id = section.id + '-label';
heading.className = 'vector-menu-heading';
var headingLabel = document.createElement( 'span' );
headingLabel.className = 'vector-menu-heading-label';
headingLabel.textContent = section.label;
heading.appendChild( headingLabel );
var content = document.createElement( 'div' );
content.className = 'vector-menu-content';
var list = document.createElement( 'ul' );
list.className = 'vector-menu-content-list';
section.links.forEach( function ( link, index ) {
var item = document.createElement( 'li' );
item.id = section.id + '-' + index;
item.className = 'mw-list-item';
var anchor = document.createElement( 'a' );
anchor.href = link.href || titleToHref( link.title, link.special );
if ( link.external ) {
anchor.rel = 'nofollow';
}
var span = document.createElement( 'span' );
span.textContent = link.label;
anchor.appendChild( span );
item.appendChild( anchor );
list.appendChild( item );
} );
content.appendChild( list );
nav.appendChild( heading );
nav.appendChild( content );
return nav;
}
function buildPanel( panelId, beforeNode ) {
var panel = document.createElement( 'div' );
panel.id = panelId;
sections.forEach( function ( section ) {
panel.appendChild( makePortlet( section ) );
} );
beforeNode.parentNode.insertBefore( panel, beforeNode );
return panel;
}
function injectSidebar() {
var panel = document.getElementById( 'mw-panel' );
var tools = document.getElementById( 'p-tb' );
var content = document.getElementById( 'content' );
if ( !panel || !content || document.getElementById( 'wmu-navigation' ) ) {
return;
}
sections.forEach( function ( section ) {
panel.insertBefore( makePortlet( section ), tools || null );
} );
if ( !document.getElementById( 'wmu-left-panel' ) ) {
buildPanel( 'wmu-left-panel', content );
}
}
mw.loader.using( 'mediawiki.util' ).then( function () {
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', injectSidebar, { once: true } );
return;
}
injectSidebar();
} );
}() );