mediawiki-skins-MinervaNeue/resources/skins.minerva.options/categories.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

61 lines
1.6 KiB
JavaScript

module.exports = function () {
var
M = mw.mobileFrontend,
mobile = M.require( 'mobile.startup' ),
loader = mobile.rlModuleLoader,
features = mw.config.get( 'wgMinervaFeatures', {} ),
overlayManager = require( 'skins.minerva.scripts' ).overlayManager,
eventBus = mobile.eventBusSingleton,
isAnon = mw.user.isAnon();
// check the categories feature has been turned on
if ( !features.categories ) {
return;
}
// categories overlay
overlayManager.add( /^\/categories$/, function () {
return loader.loadModule( 'mobile.categories.overlays', true ).then( function ( loadingOverlay ) {
var categoryOverlay = M.require( 'mobile.categories.overlays/categoryOverlay' );
eventBus.on( 'category-added', function () {
window.location.hash = '#/categories';
} );
loadingOverlay.hide();
return categoryOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: mobile.currentPage().title,
eventBus: eventBus
} );
} );
} );
// add categories overlay
overlayManager.add( /^\/categories\/add$/, function () {
return loader.loadModule( 'mobile.categories.overlays' ).then( function ( loadingOverlay ) {
var CategoryAddOverlay = M.require( 'mobile.categories.overlays/CategoryAddOverlay' );
loadingOverlay.hide();
return new CategoryAddOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: mobile.currentPage().title,
eventBus: eventBus
} );
} );
} );
/**
* Enable the categories button
* @ignore
*/
function initButton() {
// eslint-disable-next-line no-jquery/no-global-selector
$( '.category-button' ).removeClass( 'hidden' );
}
$( initButton );
};