MediaWiki:Common.js

From Warmachine University Archive
Revision as of 23:08, 15 March 2026 by Admin (talk | contribs) (Inject requested left sidebar menu into Vector panel)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function () {
	var sections = [
		{
			id: 'wmu-navigation',
			label: 'Navigation',
			links: [
				{ href: '/index.php/Main_Page', label: 'Home Page' },
				{ href: '/index.php?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: [
				{ href: '/index.php?title=Useful_External_Links', label: 'Get the Rules Free' },
				{ href: '/index.php?title=LPG_-_Theme_Forces', label: 'Theme Forces' },
				{ href: '/index.php?title=Steamroller', label: 'Steamroller' },
				{ href: '/index.php?title=Infernal_Rulings', label: 'Rule Clarifications' }
			]
		},
		{
			id: 'wmu-training',
			label: 'Training',
			links: [
				{ href: '/index.php?title=Crash_Course_(101)', label: 'Basic Training' },
				{ href: '/index.php?title=Learning_to_Play_the_Game_(LPG)', label: 'Intermediate Training' },
				{ href: '/index.php?title=Learn_Objectives,_Tactics,_%26_Strategy_(LOTS)', label: 'Advanced Training' },
				{ href: '/index.php?title=Glossary', label: 'Glossary' }
			]
		},
		{
			id: 'wmu-warmachine',
			label: 'Warmachine',
			links: [
				{ href: '/index.php?title=Cryx', label: 'Cryx' },
				{ href: '/index.php?title=Cygnar', label: 'Cygnar' },
				{ href: '/index.php?title=Khador', label: 'Khador' },
				{ href: '/index.php?title=Protectorate_of_Menoth', label: 'Protectorate' },
				{ href: '/index.php?title=Retribution_of_Scyrah', label: 'Retribution' },
				{ href: '/index.php?title=Mercenaries', label: 'Mercenaries' }
			]
		},
		{
			id: 'wmu-hordes',
			label: 'Hordes',
			links: [
				{ href: '/index.php?title=Circle_Orboros', label: 'Circle' },
				{ href: '/index.php?title=Legion_of_Everblight', label: 'Legion' },
				{ href: '/index.php?title=Skorne', label: 'Skorne' },
				{ href: '/index.php?title=Trollbloods', label: 'Trollbloods' },
				{ href: '/index.php?title=Minions', label: 'Minions' }
			]
		},
		{
			id: 'wmu-mini-factions',
			label: 'Mini-Factions',
			links: [
				{ href: '/index.php?title=Convergence_of_Cyriss', label: 'Convergence' },
				{ href: '/index.php?title=Crucible_Guard', label: 'Crucible Guard' },
				{ href: '/index.php?title=Grymkin', label: 'Grymkin' },
				{ href: '/index.php?title=Infernals', label: 'Infernals' },
				{ href: '/index.php?title=Orgoth', label: 'Orgoth' }
			]
		},
		{
			id: 'wmu-other-games',
			label: 'Other PP Games',
			links: [
				{ href: '/index.php?title=Other_PP_Games', label: 'Neo-Mechanika' },
				{ href: '/index.php?title=Other_PP_Games', label: 'Riot Quest' },
				{ href: '/index.php?title=Other_PP_Games', label: '...more' }
			]
		},
		{
			id: 'wmu-vaults',
			label: 'The Vaults',
			links: [
				{ href: '/index.php?title=FAQ', label: 'FAQ' },
				{ href: '/index.php?title=League_Models', label: 'League Models' },
				{ href: '/index.php?title=New_Releases', label: 'New Releases' },
				{ href: '/index.php?title=Attack_Sequence', label: 'Attack Sequence' },
				{ href: '/index.php?title=Template:Index_Vaults', label: '...more' }
			]
		},
		{
			id: 'wmu-other',
			label: 'Other',
			links: [
				{ href: 'https://www.loswarmachine.com/', label: 'Other LOS sites', external: true },
				{ href: '/index.php?title=Useful_External_Links', label: 'Other useful websites' },
				{ href: '/index.php/Special:Random', label: 'Random page' },
				{ href: '/index.php/Special:RecentChanges', label: 'Recent changes' },
				{ href: '/index.php?title=War_Table', label: 'War Table' }
			]
		}
	];

	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;
			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 injectIntoPanel() {
		var panel = document.getElementById( 'mw-panel' );
		var tools = document.getElementById( 'p-tb' );
		if ( !panel || document.getElementById( 'wmu-navigation' ) ) {
			return;
		}

		sections.forEach( function ( section ) {
			panel.insertBefore( makePortlet( section ), tools || null );
		} );
	}

	function init() {
		if ( document.readyState === 'loading' ) {
			document.addEventListener( 'DOMContentLoaded', injectIntoPanel, { once: true } );
		} else {
			injectIntoPanel();
		}
	}

	init();
}() );