mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-09-24 18:58:29 +00:00
Make Deferreds promise compatible
This patch updates the various usages of $.Deferred for loading overlays in routes to be ES6 Promise compatible Bug: T188937 Change-Id: I3fc24bf3471a99e7671d1191bdd46cb741286ee1
This commit is contained in:
parent
65f2e5ef51
commit
56a10c40e0
|
@ -6,40 +6,34 @@
|
|||
|
||||
// categories overlay
|
||||
overlayManager.add( /^\/categories$/, function () {
|
||||
var result = $.Deferred();
|
||||
|
||||
loader.loadModule( 'mobile.categories.overlays', true ).done( function ( loadingOverlay ) {
|
||||
return loader.loadModule( 'mobile.categories.overlays', true ).then( function ( loadingOverlay ) {
|
||||
var CategoryOverlay = M.require( 'mobile.categories.overlays/CategoryOverlay' );
|
||||
M.on( 'category-added', function () {
|
||||
window.location.hash = '#/categories';
|
||||
} );
|
||||
|
||||
loadingOverlay.hide();
|
||||
result.resolve( new CategoryOverlay( {
|
||||
return new CategoryOverlay( {
|
||||
api: new mw.Api(),
|
||||
isAnon: user.isAnon(),
|
||||
title: M.getCurrentPage().title
|
||||
} ) );
|
||||
} );
|
||||
} );
|
||||
return result;
|
||||
} );
|
||||
|
||||
// add categories overlay
|
||||
overlayManager.add( /^\/categories\/add$/, function () {
|
||||
var result = $.Deferred();
|
||||
|
||||
loader.loadModule( 'mobile.categories.overlays' ).done( function ( loadingOverlay ) {
|
||||
return loader.loadModule( 'mobile.categories.overlays' ).then( function ( loadingOverlay ) {
|
||||
var CategoryAddOverlay = M.require( 'mobile.categories.overlays/CategoryAddOverlay' );
|
||||
|
||||
loadingOverlay.hide();
|
||||
result.resolve( new CategoryAddOverlay( {
|
||||
return new CategoryAddOverlay( {
|
||||
api: new mw.Api(),
|
||||
categories: mw.config.get( 'wgCategories' ),
|
||||
isAnon: user.isAnon(),
|
||||
title: M.getCurrentPage().title
|
||||
} ) );
|
||||
} );
|
||||
} );
|
||||
return result;
|
||||
} );
|
||||
|
||||
/**
|
||||
|
|
|
@ -171,7 +171,6 @@
|
|||
overlayManager.add( /^\/editor\/(\d+|all)$/, function ( sectionId ) {
|
||||
var
|
||||
$content = $( '#mw-content-text' ),
|
||||
result = $.Deferred(),
|
||||
preferredEditor = getPreferredEditor(),
|
||||
editorOptions = {
|
||||
overlayManager: overlayManager,
|
||||
|
@ -201,7 +200,7 @@
|
|||
function logInit( editor ) {
|
||||
// If MobileFrontend is not available this will not be possible so
|
||||
// check first.
|
||||
mw.loader.using( 'mobile.loggingSchemas.edit' ).done( function () {
|
||||
mw.loader.using( 'mobile.loggingSchemas.edit' ).then( function () {
|
||||
mw.track( 'mf.schemaEdit', {
|
||||
action: 'init',
|
||||
type: 'section',
|
||||
|
@ -217,13 +216,14 @@
|
|||
* @private
|
||||
* @ignore
|
||||
* @method
|
||||
* @returns {JQuery.Promise}
|
||||
*/
|
||||
function loadSourceEditor() {
|
||||
logInit( 'wikitext' );
|
||||
|
||||
loader.loadModule( 'mobile.editor.overlay' ).done( function () {
|
||||
return loader.loadModule( 'mobile.editor.overlay' ).then( function () {
|
||||
var EditorOverlay = M.require( 'mobile.editor.overlay/EditorOverlay' );
|
||||
result.resolve( new EditorOverlay( editorOptions ) );
|
||||
return new EditorOverlay( editorOptions );
|
||||
} );
|
||||
}
|
||||
|
||||
|
@ -254,15 +254,13 @@
|
|||
editorOverride !== 'SourceEditor'
|
||||
) {
|
||||
logInit( 'visualeditor' );
|
||||
loader.loadModule( 'mobile.editor.ve' ).done( function () {
|
||||
return loader.loadModule( 'mobile.editor.ve' ).then( function () {
|
||||
var VisualEditorOverlay = M.require( 'mobile.editor.ve/VisualEditorOverlay' );
|
||||
result.resolve( new VisualEditorOverlay( editorOptions ) );
|
||||
} ).fail( loadSourceEditor );
|
||||
return new VisualEditorOverlay( editorOptions );
|
||||
}, loadSourceEditor );
|
||||
} else {
|
||||
loadSourceEditor();
|
||||
return loadSourceEditor();
|
||||
}
|
||||
|
||||
return result;
|
||||
} );
|
||||
updateEditPageButton( true );
|
||||
// reveal edit links on user pages
|
||||
|
|
|
@ -61,13 +61,13 @@
|
|||
* @memberof NotificationBadge
|
||||
* @instance
|
||||
* @param {string} moduleName Name of a module to fetch
|
||||
* @return {JQuery.Deferred}
|
||||
* @return {JQuery.Promise}
|
||||
*/
|
||||
_loadModuleScript: function ( moduleName ) {
|
||||
var self = this;
|
||||
|
||||
this.$el.html( this.options.loadingIconHtml );
|
||||
return mw.loader.using( moduleName ).done( function () {
|
||||
return mw.loader.using( moduleName ).then( function () {
|
||||
// trigger a re-render once one to remove loading icon
|
||||
self.render();
|
||||
} );
|
||||
|
@ -105,7 +105,7 @@
|
|||
|
||||
this.$el.on( 'click', $.proxy( this.onClickBadge, this ) );
|
||||
this.options.overlayManager.add( /^\/notifications$/, function () {
|
||||
return self._loadNotificationOverlay().done( function ( overlay ) {
|
||||
return self._loadNotificationOverlay().then( function ( overlay ) {
|
||||
mainMenu.openNavigationDrawer( 'secondary' );
|
||||
overlay.on( 'hide', function () {
|
||||
mainMenu.closeNavigationDrawers();
|
||||
|
@ -115,6 +115,7 @@
|
|||
$( '#mw-mf-page-center' ).one( 'click.secondary', function () {
|
||||
self.options.router.back();
|
||||
} );
|
||||
return overlay;
|
||||
} );
|
||||
} );
|
||||
},
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
}
|
||||
|
||||
// Load the notification filter overlay
|
||||
mw.loader.using( 'mobile.notifications.filter.overlay' ).done( function () {
|
||||
mw.loader.using( 'mobile.notifications.filter.overlay' ).then( function () {
|
||||
var $crossWikiUnreadFilter = $( '.mw-echo-ui-crossWikiUnreadFilterWidget' ),
|
||||
$notifReadState = $( '.mw-echo-ui-notificationsInboxWidget-main-toolbar-readState' ),
|
||||
NotificationsFilterOverlay = M.require( 'mobile.notifications.filter.overlay/NotificationsFilterOverlay' );
|
||||
|
|
|
@ -124,6 +124,12 @@
|
|||
window.print();
|
||||
hideSpinner();
|
||||
}
|
||||
|
||||
function doPrintBeforeTimeout() {
|
||||
if ( self.timeout ) {
|
||||
doPrint();
|
||||
}
|
||||
}
|
||||
// The click handler may be invoked multiple times so if a pending print is occurring
|
||||
// do nothing.
|
||||
if ( !this.timeout ) {
|
||||
|
@ -134,11 +140,7 @@
|
|||
// If all image downloads are taking longer to load then the MAX_PRINT_TIMEOUT
|
||||
// abort the spinner and print regardless.
|
||||
this.timeout = setTimeout( doPrint, MAX_PRINT_TIMEOUT );
|
||||
this.skin.loadImagesList().always( function () {
|
||||
if ( self.timeout ) {
|
||||
doPrint();
|
||||
}
|
||||
} );
|
||||
this.skin.loadImagesList().then( doPrintBeforeTimeout, doPrintBeforeTimeout );
|
||||
}
|
||||
},
|
||||
events: {
|
||||
|
|
|
@ -130,25 +130,23 @@
|
|||
// Routes
|
||||
overlayManager.add( /^\/media\/(.+)$/, loadImageOverlay );
|
||||
overlayManager.add( /^\/languages$/, function () {
|
||||
var result = $.Deferred(),
|
||||
lang = mw.config.get( 'wgUserLanguage' );
|
||||
var lang = mw.config.get( 'wgUserLanguage' );
|
||||
|
||||
loader.loadModule( 'mobile.languages.structured', true ).done( function ( loadingOverlay ) {
|
||||
return loader.loadModule( 'mobile.languages.structured', true ).then( function ( loadingOverlay ) {
|
||||
var PageGateway = M.require( 'mobile.startup/PageGateway' ),
|
||||
gateway = new PageGateway( new mw.Api() ),
|
||||
LanguageOverlay = M.require( 'mobile.languages.structured/LanguageOverlay' );
|
||||
|
||||
gateway.getPageLanguages( mw.config.get( 'wgPageName' ), lang ).done( function ( data ) {
|
||||
return gateway.getPageLanguages( mw.config.get( 'wgPageName' ), lang ).then( function ( data ) {
|
||||
loadingOverlay.hide();
|
||||
result.resolve( new LanguageOverlay( {
|
||||
return new LanguageOverlay( {
|
||||
currentLanguage: mw.config.get( 'wgContentLanguage' ),
|
||||
languages: data.languages,
|
||||
variants: data.variants,
|
||||
deviceLanguage: getDeviceLanguage()
|
||||
} ) );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
return result;
|
||||
} );
|
||||
|
||||
// Setup
|
||||
|
|
|
@ -36,16 +36,15 @@
|
|||
}
|
||||
|
||||
overlayManager.add( /^\/talk\/?(.*)$/, function ( id ) {
|
||||
var result = $.Deferred(),
|
||||
talkOptions = {
|
||||
api: new mw.Api(),
|
||||
title: title,
|
||||
// T184273 using `getCurrentPage` because 'wgPageName' contains underscores instead of spaces.
|
||||
currentPageTitle: M.getCurrentPage().title,
|
||||
licenseMsg: skin.getLicenseMsg()
|
||||
};
|
||||
var talkOptions = {
|
||||
api: new mw.Api(),
|
||||
title: title,
|
||||
// T184273 using `getCurrentPage` because 'wgPageName' contains underscores instead of spaces.
|
||||
currentPageTitle: M.getCurrentPage().title,
|
||||
licenseMsg: skin.getLicenseMsg()
|
||||
};
|
||||
|
||||
loader.loadModule( 'mobile.talk.overlays' ).done( function () {
|
||||
return loader.loadModule( 'mobile.talk.overlays' ).then( function () {
|
||||
var Overlay;
|
||||
if ( id === 'new' ) {
|
||||
Overlay = M.require( 'mobile.talk.overlays/TalkSectionAddOverlay' );
|
||||
|
@ -55,9 +54,8 @@
|
|||
} else {
|
||||
Overlay = M.require( 'mobile.talk.overlays/TalkOverlay' );
|
||||
}
|
||||
result.resolve( new Overlay( talkOptions ) );
|
||||
return new Overlay( talkOptions );
|
||||
} );
|
||||
return result;
|
||||
} );
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue