MediaWiki:Mobile.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
(function () { | |||
( function () { | if (mw.config.get('skin') !== 'minerva') return; | ||
if ( mw.config.get( 'skin' ) !== 'minerva' ) | |||
var injected = false; | |||
function | function buildList(container) { | ||
if (injected) return; | |||
if ( | injected = true; | ||
var ul = document.createElement( 'ul' ); | var ul = document.createElement('ul'); | ||
ul.className = 'mobile- | ul.className = 'ic-mobile-menu-links'; | ||
var 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 ( | 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 = | a.textContent = l.text; | ||
a.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. | // 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 }); | |||
})(); | |||