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(),
|
2019-08-05 23:01:29 +00:00
|
|
|
util = mobile.util,
|
2019-02-07 16:34:18 +00:00
|
|
|
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
|
2019-08-05 23:01:29 +00:00
|
|
|
* @param {Function} options.onOpen executed when the menu opens
|
|
|
|
* @param {Function} options.onClose executed when the menu closes
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function MainMenu( options ) {
|
|
|
|
this.activator = options.activator;
|
2019-08-05 23:01:29 +00:00
|
|
|
View.call( this,
|
|
|
|
util.extend( {
|
|
|
|
onOpen: function () {},
|
|
|
|
onClose: function () {}
|
|
|
|
}, 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();
|
2018-09-13 15:33:20 +00:00
|
|
|
// Stop propagation, otherwise the Skin will close the open menus on page center
|
|
|
|
// click
|
2017-07-12 15:12:40 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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}
|
2019-08-05 23:01:29 +00:00
|
|
|
* @private
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
isOpen: function () {
|
2019-08-05 23:01:29 +00:00
|
|
|
return this.$el.hasClass( 'menu--open' );
|
2017-07-12 15:12:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close all open navigation drawers
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2019-08-05 23:01:29 +00:00
|
|
|
* @private
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
closeNavigationDrawers: function () {
|
2019-08-05 23:01:29 +00:00
|
|
|
this.$el.removeClass( 'menu--open' );
|
|
|
|
this.options.onClose();
|
2017-07-12 15:12:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle open navigation drawer
|
2018-08-20 23:40:40 +00:00
|
|
|
* @memberof MainMenu
|
|
|
|
* @instance
|
2019-08-05 23:01:29 +00:00
|
|
|
* @private
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-08-05 23:01:29 +00:00
|
|
|
openNavigationDrawer: function () {
|
2017-07-12 15:12:40 +00:00
|
|
|
// close any existing ones first.
|
|
|
|
this.closeNavigationDrawers();
|
2019-08-05 23:01:29 +00:00
|
|
|
this.$el.addClass( 'menu--open' );
|
|
|
|
this.options.onOpen();
|
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 ) );
|