MediaWiki:Common.js

From Warmachine University Archive
Revision as of 22:55, 15 March 2026 by Admin (talk | contribs) (Inject archived sidebar into Vector panel)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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: [
				{ 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;
	}

	mw.loader.using( 'mediawiki.util' ).then( function () {
		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 );
		} );
	} );
}() );