mediawiki-skins-MinervaNeue/resources/skins.minerva.options/categories.js
Stephen Niedzielski c561fbc794 Hygiene: update categoryOverlay to use factory API
- Revise M.require( 'mobile.categories.overlays/CategoryOverlay' ) to
  'mobile.categories.overlays/categoryOverlay' (lowercase c).

- The category overlay is a factory function not a class. Replace new
  operator with function invocation. This only looked strange and didn't
  break anything since the new operator uses the returned value if
  specified, not `this`, which was the result of the factory function
  and the OverlayManager understands both Overlays and functions that
  return Overlays.

Bug: T208915
Change-Id: Ife098ee5ed1a8a164a4e31013a490076658f4147
2019-02-11 22:49:59 +00:00

60 lines
1.6 KiB
JavaScript

( function ( M ) {
var
mobile = M.require( 'mobile.startup' ),
loader = mobile.rlModuleLoader,
features = mw.config.get( 'wgMinervaFeatures', {} ),
overlayManager = M.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: M.getCurrentPage().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: M.getCurrentPage().title,
eventBus: eventBus
} );
} );
} );
/**
* Enable the categories button
* @ignore
*/
function initButton() {
// eslint-disable-next-line jquery/no-global-selector
$( '.category-button' ).removeClass( 'hidden' );
}
$( initButton );
}( mw.mobileFrontend ) );