Jump to content

MediaWiki:Minerva.js

From Rollerskating Wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
 * 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 );
          }
      } );
}() );