2018-11-16 15:16:25 +00:00
|
|
|
( function ( M ) {
|
2019-02-07 16:34:18 +00:00
|
|
|
var
|
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend = mobile.mfExtend,
|
2019-02-07 16:34:18 +00:00
|
|
|
browser = mobile.Browser.getSingleton(),
|
|
|
|
View = mobile.View;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Representation of the main menu
|
|
|
|
*
|
|
|
|
* @class MainMenu
|
|
|
|
* @extends View
|
2018-07-10 22:47:31 +00:00
|
|
|
* @param {Object} options Configuration options
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function MainMenu( options ) {
|
|
|
|
this.activator = options.activator;
|
2019-08-07 23:43:43 +00:00
|
|
|
View.call( this, options );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 17:04:26 +00:00
|
|
|
mfExtend( MainMenu, View, {
|
2017-07-12 15:12:40 +00:00
|
|
|
isTemplateMode: true,
|
2019-04-25 02:34:01 +00:00
|
|
|
template: mw.template.get( 'skins.minerva.scripts', 'menu.mustache' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
templatePartials: {
|
2019-04-25 02:34:01 +00:00
|
|
|
menuGroup: mw.template.get( 'skins.minerva.scripts', 'menuGroup.mustache' )
|
2017-07-12 15:12:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-07-03 14:50:09 +00:00
|
|
|
* @cfg {object} defaults Default options hash.
|
2018-09-13 15:33:20 +00:00
|
|
|
* @cfg {string} defaults.activator selector for element that when clicked can open or
|
|
|
|
* close the menu
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
defaults: {
|
|
|
|
activator: undefined
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the nearby menu entry if the browser doesn't support geo location
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
postRender: function () {
|
|
|
|
if ( !browser.supportsGeoLocation() ) {
|
|
|
|
this.$el.find( '.nearby' ).parent().remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.registerClickEvents();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers events for opening and closing the main menu
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
registerClickEvents: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
// Listen to the main menu button clicks
|
|
|
|
$( this.activator )
|
|
|
|
.off( 'click' )
|
|
|
|
.on( 'click', function ( ev ) {
|
|
|
|
if ( self.isOpen() ) {
|
|
|
|
self.closeNavigationDrawers();
|
|
|
|
} else {
|
|
|
|
self.openNavigationDrawer();
|
|
|
|
}
|
|
|
|
ev.preventDefault();
|
2019-08-26 18:23:42 +00:00
|
|
|
// DO NOT USE stopPropagation or you'll break click tracking in WikimediaEvents
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the navigation drawer is open
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isOpen: function () {
|
2019-08-07 23:43:43 +00:00
|
|
|
// FIXME: We should be moving away from applying classes to the body
|
2019-09-17 13:20:57 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
2019-08-07 23:43:43 +00:00
|
|
|
return $( document.body ).hasClass( 'navigation-enabled' );
|
2017-07-12 15:12:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close all open navigation drawers
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
closeNavigationDrawers: function () {
|
2019-08-07 23:43:43 +00:00
|
|
|
// FIXME: We should be moving away from applying classes to the body
|
|
|
|
$( document.body ).removeClass( 'navigation-enabled' )
|
|
|
|
.removeClass( 'secondary-navigation-enabled' )
|
|
|
|
.removeClass( 'primary-navigation-enabled' );
|
2017-07-12 15:12:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle open navigation drawer
|
2019-08-07 23:43:43 +00:00
|
|
|
* @param {string} [drawerType] A name that identifies the navigation drawer that
|
|
|
|
* should be toggled open. Defaults to 'primary'.
|
|
|
|
* @fires MainMenu#open
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-08-07 23:43:43 +00:00
|
|
|
openNavigationDrawer: function ( drawerType ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
// close any existing ones first.
|
|
|
|
this.closeNavigationDrawers();
|
2019-08-07 23:43:43 +00:00
|
|
|
drawerType = drawerType || 'primary';
|
|
|
|
// FIXME: We should be moving away from applying classes to the body
|
2019-09-17 13:20:57 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
|
|
|
$( document.body )
|
|
|
|
.toggleClass( 'navigation-enabled' )
|
2019-08-07 23:43:43 +00:00
|
|
|
.toggleClass( drawerType + '-navigation-enabled' );
|
|
|
|
|
|
|
|
this.emit( 'open' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2019-07-02 21:10:10 +00:00
|
|
|
module.exports = MainMenu;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-11-16 15:16:25 +00:00
|
|
|
}( mw.mobileFrontend ) );
|