MediaWiki:Minerva.js: Difference between revisions
Appearance
Created page with "→* * Custom mobile navigation for the hamburger menu. * * MinervaNeue does not support custom MediaWiki:Sidebar groups in the * mobile main menu — only the hardcoded Home/Random entries are used. * This is a known upstream limitation (https://phabricator.wikimedia.org/T65459). * This script mirrors the custom sidebar sections into the mobile drawer. * * Keep in sync with MediaWiki:Sidebar.: ( function () { var sections = [ { heading:..." |
No edit summary |
||
| Line 39: | Line 39: | ||
} | } | ||
var sitelinks = menu.querySelector( 'ul.hlist' ); | var sitelinks = menu.querySelector( 'ul.hlist' ); | ||
sections.forEach( function ( section ) { | var firstGroup = menu.querySelector( '#p-navigation' ); | ||
sections.forEach( function ( section ) { | |||
var ul = document.createElement( 'ul' ); | |||
ul.className = 'toggle-list__list'; | |||
section.links.forEach( function ( link ) { | |||
var li = document.createElement( 'li' ); | |||
li.className = 'toggle-list-item'; | |||
var a = document.createElement( 'a' ); | |||
a.className = 'toggle-list-item__anchor'; | |||
a.href = link.href; | |||
var span = document.createElement( 'span' ); | |||
span.className = 'toggle-list-item__label'; | |||
span.textContent = link.label; | |||
a.appendChild( span ); | |||
li.appendChild( a ); | |||
ul.appendChild( li ); | |||
} ); | |||
if ( firstGroup && firstGroup.nextSibling ) { | |||
// Insert right after the navigation group (Home/Random), | |||
// before whatever comes next (Login, Configuration, etc.) | |||
firstGroup.nextSibling.parentNode.insertBefore( ul, firstGroup.nextSibling ); | |||
// Update reference so next section inserts after the one we just added | |||
firstGroup = ul; | |||
} else { | |||
menu.appendChild( ul ); | |||
} | |||
} ); | |||
}() ); | }() ); | ||
Latest revision as of 01:49, 28 March 2026
/**
* Custom mobile navigation for the hamburger menu.
*
* MinervaNeue does not support custom MediaWiki:Sidebar groups in the
* mobile main menu — only the hardcoded Home/Random entries are used.
* This is a known upstream limitation (https://phabricator.wikimedia.org/T65459).
* This script mirrors the custom sidebar sections into the mobile drawer.
*
* Keep in sync with MediaWiki:Sidebar.
*/
( function () {
var sections = [
{
heading: 'Explore',
links: [
{ label: 'Skate Anatomy', href: '/wiki/Category:Skate_Anatomy' },
{ label: 'Gear', href: '/wiki/Category:Gear' },
{ label: 'Styles', href: '/wiki/Category:Styles' },
{ label: 'Resources', href: '/wiki/Category:Resources' },
{ label: 'Regions', href: '/wiki/Category:Regions' },
{ label: 'Rinks', href: '/wiki/Category:Rinks' },
{ label: 'Skate History', href: '/wiki/Category:Skate_History' },
{ label: 'Events', href: '/wiki/Category:Events' },
{ label: 'Techniques', href: '/wiki/Category:Techniques' },
{ label: 'Troubleshooting', href: '/wiki/Category:Troubleshooting' }
]
},
{
heading: 'Contribute',
links: [
{ label: 'Contributing', href: '/wiki/Rollerskating_Wiki:Contributing' },
{ label: 'Guidelines', href: '/wiki/Rollerskating_Wiki:Contributing_Guidelines' }
]
}
];
var menu = document.getElementById( 'mw-mf-page-left' );
if ( !menu ) {
return;
}
var sitelinks = menu.querySelector( 'ul.hlist' );
var firstGroup = menu.querySelector( '#p-navigation' );
sections.forEach( function ( section ) {
var ul = document.createElement( 'ul' );
ul.className = 'toggle-list__list';
section.links.forEach( function ( link ) {
var li = document.createElement( 'li' );
li.className = 'toggle-list-item';
var a = document.createElement( 'a' );
a.className = 'toggle-list-item__anchor';
a.href = link.href;
var span = document.createElement( 'span' );
span.className = 'toggle-list-item__label';
span.textContent = link.label;
a.appendChild( span );
li.appendChild( a );
ul.appendChild( li );
} );
if ( firstGroup && firstGroup.nextSibling ) {
// Insert right after the navigation group (Home/Random),
// before whatever comes next (Login, Configuration, etc.)
firstGroup.nextSibling.parentNode.insertBefore( ul, firstGroup.nextSibling );
// Update reference so next section inserts after the one we just added
firstGroup = ul;
} else {
menu.appendChild( ul );
}
} );
}() );