2017-07-12 15:12:40 +00:00
|
|
|
// FIXME: make this an object with a constructor to facilitate testing
|
|
|
|
// (see https://bugzilla.wikimedia.org/show_bug.cgi?id=44264)
|
|
|
|
/**
|
|
|
|
* mobileFrontend namespace
|
|
|
|
* @class mw.mobileFrontend
|
|
|
|
* @singleton
|
|
|
|
*/
|
2019-07-02 21:10:10 +00:00
|
|
|
module.exports = function () {
|
|
|
|
var M = mw.mobileFrontend,
|
2019-07-17 18:14:23 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
|
|
|
skin = mobile.Skin.getSingleton(),
|
2019-07-02 21:10:10 +00:00
|
|
|
mainMenu = require( './menu.js' ),
|
2019-07-17 18:14:23 +00:00
|
|
|
toast = mobile.toast;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2017-09-07 17:27:30 +00:00
|
|
|
/**
|
|
|
|
* Close navigation if skin is tapped
|
2018-07-03 14:50:09 +00:00
|
|
|
* @param {JQuery.Event} ev
|
2017-09-07 17:27:30 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function onSkinClick( ev ) {
|
2019-02-15 19:04:11 +00:00
|
|
|
var $target = $( ev.target );
|
2017-09-07 17:27:30 +00:00
|
|
|
|
|
|
|
// Make sure the menu is open and we are not clicking on the menu button
|
|
|
|
if (
|
|
|
|
mainMenu &&
|
|
|
|
mainMenu.isOpen() &&
|
|
|
|
!$target.hasClass( 'main-menu-button' )
|
|
|
|
) {
|
|
|
|
mainMenu.closeNavigationDrawers();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skin.on( 'click', onSkinClick.bind( skin ) );
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
( function ( wgRedirectedFrom ) {
|
|
|
|
// If the user has been redirected, then show them a toast message (see
|
|
|
|
// https://phabricator.wikimedia.org/T146596).
|
|
|
|
|
|
|
|
var redirectedFrom;
|
|
|
|
|
|
|
|
if ( wgRedirectedFrom === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
redirectedFrom = mw.Title.newFromText( wgRedirectedFrom );
|
|
|
|
|
|
|
|
if ( redirectedFrom ) {
|
|
|
|
|
|
|
|
// mw.Title.getPrefixedText includes the human-readable namespace prefix.
|
|
|
|
toast.show( mw.msg(
|
|
|
|
'mobile-frontend-redirected-from',
|
|
|
|
redirectedFrom.getPrefixedText()
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
}( mw.config.get( 'wgRedirectedFrom' ) ) );
|
|
|
|
/* eslint-enable no-console */
|
2019-07-02 21:10:10 +00:00
|
|
|
};
|