MediaWiki:Mobile.js: Difference between revisions

From ICE List Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the mobile site */
(function () {
( function () {
if (mw.config.get('skin') !== 'minerva') return;
if ( mw.config.get( 'skin' ) !== 'minerva' ) {
 
return;
var injected = false;
}


function addLinks() {
function buildList(container) {
var menu = document.querySelector( '.menu' );
if (injected) return;
if ( !menu ) {
injected = true;
return;
}


var ul = document.createElement( 'ul' );
var ul = document.createElement('ul');
ul.className = 'mobile-custom-links';
ul.className = 'ic-mobile-menu-links';


var links = [
var links = [
{ title: 'Home', href: mw.util.getUrl( 'Main Page' ) },
{ text: 'Home', page: 'Main Page' },
{ title: 'All Agents', href: mw.util.getUrl( 'Category:Agent' ) },
{ text: 'All Agents', page: 'Category:Agent' },
{ title: 'All Incidents', href: mw.util.getUrl( 'Category:Incidents' ) },
{ text: 'All Incidents', page: 'Category:Incidents' },
{ title: 'All Vehicles', href: mw.util.getUrl( 'Category:Vehicles' ) },
{ text: 'All Vehicles', page: 'Category:Vehicles' },
{ title: 'Submit an Incident', href: mw.util.getUrl( 'ICE List:Submit incident' ) },
{ text: 'Submit an Incident', page: 'ICE List:Submit incident' },
{ title: 'Submit an Agent', href: mw.util.getUrl( 'ICE List:Submit Agent' ) },
{ text: 'Submit an Agent', page: 'ICE List:Submit Agent' },
{ title: 'About ICE List', href: mw.util.getUrl( 'ICE List Wiki:About' ) },
{ text: 'About ICE List', page: 'ICE List Wiki:About' },
{ title: 'Join as a Volunteer', href: mw.util.getUrl( 'ICE List Wiki:Volunteer' ) },
{ text: 'Join as a Volunteer', page: 'ICE List Wiki:Volunteer' },
{ title: 'Donate to ICE List', href: mw.util.getUrl( 'ICE List Wiki:Donate' ) }
{ text: 'Donate to ICE List', page: 'ICE List Wiki:Donate' }
];
];


links.forEach( function ( link ) {
links.forEach(function (l) {
var li = document.createElement( 'li' );
var li = document.createElement('li');
var a = document.createElement( 'a' );
var a = document.createElement('a');
a.textContent = link.title;
a.textContent = l.text;
a.href = link.href;
a.href = mw.util.getUrl(l.page);
li.appendChild( a );
li.appendChild(a);
ul.appendChild( li );
ul.appendChild(li);
} );
});
 
container.appendChild(ul);
}
 
function findMenuContainer() {
// Minerva menu panel containers vary by version/config
return (
document.querySelector('#mw-mf-page-left .menu') ||
document.querySelector('#mw-mf-page-left') ||
document.querySelector('.navigation-drawer__content') ||
document.querySelector('.menu') ||
null
);
}
 
function tryInject() {
var c = findMenuContainer();
if (!c) return false;


menu.appendChild( ul );
// Prefer an existing list inside the menu if present
var listHost = c.querySelector('ul') ? c : c;
buildList(listHost);
return true;
}
}


mw.hook( 'mobileFrontend.menuReady' ).add( addLinks );
// Try immediately
}() );
if (tryInject()) return;
 
// Otherwise observe DOM until the menu exists
var obs = new MutationObserver(function () {
tryInject();
if (injected) obs.disconnect();
});


alert('Mobile.js loaded');
obs.observe(document.documentElement, { childList: true, subtree: true });
})();

Revision as of 21:57, 16 December 2025

(function () {
	if (mw.config.get('skin') !== 'minerva') return;

	var injected = false;

	function buildList(container) {
		if (injected) return;
		injected = true;

		var ul = document.createElement('ul');
		ul.className = 'ic-mobile-menu-links';

		var links = [
			{ text: 'Home', page: 'Main Page' },
			{ text: 'All Agents', page: 'Category:Agent' },
			{ text: 'All Incidents', page: 'Category:Incidents' },
			{ text: 'All Vehicles', page: 'Category:Vehicles' },
			{ text: 'Submit an Incident', page: 'ICE List:Submit incident' },
			{ text: 'Submit an Agent', page: 'ICE List:Submit Agent' },
			{ text: 'About ICE List', page: 'ICE List Wiki:About' },
			{ text: 'Join as a Volunteer', page: 'ICE List Wiki:Volunteer' },
			{ text: 'Donate to ICE List', page: 'ICE List Wiki:Donate' }
		];

		links.forEach(function (l) {
			var li = document.createElement('li');
			var a = document.createElement('a');
			a.textContent = l.text;
			a.href = mw.util.getUrl(l.page);
			li.appendChild(a);
			ul.appendChild(li);
		});

		container.appendChild(ul);
	}

	function findMenuContainer() {
		// Minerva menu panel containers vary by version/config
		return (
			document.querySelector('#mw-mf-page-left .menu') ||
			document.querySelector('#mw-mf-page-left') ||
			document.querySelector('.navigation-drawer__content') ||
			document.querySelector('.menu') ||
			null
		);
	}

	function tryInject() {
		var c = findMenuContainer();
		if (!c) return false;

		// Prefer an existing list inside the menu if present
		var listHost = c.querySelector('ul') ? c : c;
		buildList(listHost);
		return true;
	}

	// Try immediately
	if (tryInject()) return;

	// Otherwise observe DOM until the menu exists
	var obs = new MutationObserver(function () {
		tryInject();
		if (injected) obs.disconnect();
	});

	obs.observe(document.documentElement, { childList: true, subtree: true });
})();