mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/menu.js
jdlrobson 7f68c3d3ad MainMenu is a controller not a View and server rendered (take 2)
There should be no caching implications for this change, as the main menu
has been server side rendered on all wikis since 10th October.

As Stephen pointed out somewhere, this is a bit of a micro-optimisation
Let's simplify this code by always rendering it in the HTML. MainMenu.js
as a result becomes a controller that just decides when to show it.

The geolocation check for Nearby is removed given the fact that all
grade A browsers for mediawiki have Geolocation support.

ev.preventDefault in onSkinClick is dropped since the link to the '#'
(the default behaviour) is wanted

Additional changes
* Browser support suggests "animations" class is redundant now
* `open` event no longer filed - not being used anywhere
* Transparent shield is now managed by the MainMenu controller not
the skin (which was confusing)
* Test geolocation using a simple feature tests
rather than abstracting it away inside Browser
* The main menu button is always hidden under either a translucent shield
and/or the main menu itself when it has been opened
so so it's not possible to ever click it while the menu is open
 - the click handler is thus simplified
removing a check for the class of the button

Bug: T234650
Change-Id: If101eebbdbda1519af922745917237648722820e
2019-10-29 16:37:04 -07:00

48 lines
1.1 KiB
JavaScript

var MainMenu = require( './menu/MainMenu.js' ),
mainMenu = createMainMenu();
/**
* N.B. that the activator - the UI element that the user must click in order to open the main
* menu - is always `.header .main-menu-button`.
*
* @return {MainMenu}
*
* @ignore
*/
function createMainMenu() {
return new MainMenu( '.header .main-menu-button' );
}
/**
* Wire up the main menu
*/
function init() {
/**
* Close navigation if skin is tapped
* @private
*/
function onSkinClick() {
mainMenu.closeNavigationDrawers();
}
// eslint-disable-next-line no-jquery/no-global-selector
$( '.mw-mf-page-center__mask' ).on( 'click', onSkinClick );
// See I09c27a084100b223662f84de6cbe01bebe1fe774
// will trigger every time the Echo notification is opened or closed.
// This controls the drawer like behaviour of notifications
// on tablet in mobile mode.
mw.hook( 'echo.mobile' ).add( function ( isOpen ) {
if ( isOpen ) {
mainMenu.openNavigationDrawer( 'secondary' );
} else {
mainMenu.closeNavigationDrawers();
}
} );
}
module.exports = {
mainMenu: mainMenu,
init: init
};