mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/preInit.js
jdlrobson 72df451bd3 Embrace packageFiles
Help with readability by using module.exports and require rather than the MobileFrontend
provided mw.mobileFrontend module manager (and avoid adopting webpack at this time)

Replace usages of mw.mobileFrontend.require with local require and module.exports
(compatible with RL or Node implementation)

Changes:
* Notifications modules are merged into skins.minerva.scripts and initialised
via a client side check.
* new file overlayManager for exporting an overlayManager singleton
rather than being hidden inside resources/skins.minerva.scripts/init.js
* All M.define/M.requires swapped out for require where possible
The `define` method is now forbidden in the repo.

Bug: T212944
Change-Id: I44790dd3fc6fe42bb502d79c39c4081c223bf2b1
2019-07-16 18:04:10 +00:00

57 lines
1.4 KiB
JavaScript

// 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
*/
module.exports = function () {
var M = mw.mobileFrontend,
skin = M.require( 'mobile.init/skin' ),
mainMenu = require( './menu.js' ),
toast = M.require( 'mobile.startup' ).toast;
/**
* Close navigation if skin is tapped
* @param {JQuery.Event} ev
* @private
*/
function onSkinClick( ev ) {
var $target = $( ev.target );
// 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 ) );
( 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 */
};