2019-09-05 21:55:55 +00:00
|
|
|
( function () {
|
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-09-05 21:55:55 +00:00
|
|
|
* @param {string} options.activator selector for element that when clicked can open or
|
|
|
|
* close the menu
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function MainMenu( options ) {
|
2019-09-05 21:55:55 +00:00
|
|
|
// Remove `mw-mf-viewport__nav-placeholder` to signal the menu has been loaded
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#mw-mf-page-left' ).removeClass( 'mw-mf-viewport__nav-placeholder' );
|
2017-07-12 15:12:40 +00:00
|
|
|
this.activator = options.activator;
|
|
|
|
|
2019-09-05 21:55:55 +00:00
|
|
|
this.registerClickEvents();
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-09-05 21:55:55 +00:00
|
|
|
MainMenu.prototype = {
|
2017-07-12 15:12:40 +00:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
2019-09-05 21:55:55 +00:00
|
|
|
self.openNavigationDrawer();
|
2017-07-12 15:12:40 +00:00
|
|
|
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' );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-09-05 21:55:55 +00:00
|
|
|
};
|
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
|
|
|
|
2019-09-05 21:55:55 +00:00
|
|
|
}() );
|