mediawiki-skins-MinervaNeue/resources/skins.minerva.options/categories.js
jdlrobson df60088bf5 Clicking the category overlays is synchronous
This also means we can now get rid of the rlModuleLoader module
and make all OverlayManager routes synchronous form now on.

Depends-On: Iacea45ea5ac7332d61a33041bbd25ea4830e1375
Bug: T214641
Change-Id: I73cb622bbda44f4cfe51d08189419e15003b9d91
2020-02-04 16:53:16 +08:00

71 lines
1.8 KiB
JavaScript

module.exports = function () {
var
// eslint-disable-next-line no-restricted-properties
M = mw.mobileFrontend,
mobile = M.require( 'mobile.startup' ),
headers = mobile.headers,
icons = mobile.icons,
Overlay = mobile.Overlay,
features = mw.config.get( 'wgMinervaFeatures', {} ),
OverlayManager = mobile.OverlayManager,
overlayManager = OverlayManager.getSingleton(),
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 mobile.categoryOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: mobile.currentPage().title,
eventBus: eventBus
} );
} );
overlayManager.add( /^\/categories\/add$/, function () {
// A transitional overlay that loads instantly that will be replaced with a
// CategoryAddOverlay as soon as it is available.
var spinnerOverlay = Overlay.make(
{
headers: [
headers.header( '', [
icons.spinner()
], icons.back() )
],
heading: ''
}, icons.spinner()
);
// Load the additional code and replace the temporary overlay with the new overlay.
mw.loader.using( 'mobile.categories.overlays' ).then( function () {
var CategoryAddOverlay = M.require( 'mobile.categories.overlays' ).CategoryAddOverlay;
overlayManager.replaceCurrent(
new CategoryAddOverlay( {
api: new mw.Api(),
isAnon: isAnon,
title: mobile.currentPage().title
} )
);
} );
return spinnerOverlay;
} );
/**
* Enable the categories button
* @ignore
*/
function initButton() {
// eslint-disable-next-line no-jquery/no-global-selector
$( '.category-button' ).removeClass( 'hidden' );
}
$( initButton );
};