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 () {
|
2019-09-27 18:53:01 +00:00
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2019-07-02 21:10:10 +00:00
|
|
|
var M = mw.mobileFrontend,
|
2019-07-17 18:14:23 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-10-04 15:03:19 +00:00
|
|
|
skin = mobile.Skin.getSingleton(),
|
|
|
|
mainMenu = require( './menu.js' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-10-04 15:03:19 +00:00
|
|
|
/**
|
|
|
|
* Close navigation if skin is tapped
|
|
|
|
* @param {JQuery.Event} ev
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function onSkinClick( ev ) {
|
|
|
|
var $target = $( ev.target );
|
2017-09-07 17:27:30 +00:00
|
|
|
|
2019-10-04 15:03:19 +00:00
|
|
|
// Make sure the menu is open and we are not clicking on the menu button
|
|
|
|
if (
|
|
|
|
mainMenu &&
|
|
|
|
mainMenu.isOpen() &&
|
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
|
|
|
!$target.hasClass( 'main-menu-button' )
|
|
|
|
) {
|
|
|
|
mainMenu.closeNavigationDrawers();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
skin.on( 'click', onSkinClick.bind( skin ) );
|
2017-09-07 17:27:30 +00:00
|
|
|
|
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).
|
|
|
|
|
2019-07-31 23:28:27 +00:00
|
|
|
var redirectedFrom, $msg, title;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
if ( wgRedirectedFrom === null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
redirectedFrom = mw.Title.newFromText( wgRedirectedFrom );
|
|
|
|
|
|
|
|
if ( redirectedFrom ) {
|
|
|
|
// mw.Title.getPrefixedText includes the human-readable namespace prefix.
|
2019-07-31 23:28:27 +00:00
|
|
|
title = redirectedFrom.getPrefixedText();
|
|
|
|
$msg = $( '<div>' ).html(
|
|
|
|
mw.message( 'mobile-frontend-redirected-from', title ).parse()
|
|
|
|
);
|
|
|
|
$msg.find( 'a' ).attr( 'href', mw.util.getUrl( title, { redirect: 'no' } ) );
|
|
|
|
mw.notify( $msg );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}( mw.config.get( 'wgRedirectedFrom' ) ) );
|
|
|
|
/* eslint-enable no-console */
|
2019-07-02 21:10:10 +00:00
|
|
|
};
|