diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index 73aa0ed801..fd4bf2301b 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -244,6 +244,8 @@ ve.init.mw.Target.onModulesReady = function () { } // Dereference the callbacks this.pluginCallbacks = []; + // Add the platform promise to the list + promises.push( ve.init.platform.getInitializedPromise() ); // Create a master promise tracking all the promises we got, and wait for it // to be resolved $.when.apply( $, promises ).done( this.modulesReady.resolve ).fail( this.modulesReady.reject ); diff --git a/modules/ve/init/ve.init.Platform.js b/modules/ve/init/ve.init.Platform.js index f788e29c36..cbf4fdffd8 100644 --- a/modules/ve/init/ve.init.Platform.js +++ b/modules/ve/init/ve.init.Platform.js @@ -127,3 +127,29 @@ ve.init.Platform.prototype.getUserLanguages = function () { ve.init.Platform.prototype.getMediaSources = function () { throw new Error( 've.init.Platform.getMediaSources must be overridden in subclass' ); }; + +/** + * Initialize the platform. The default implementation is to do nothing and return a resolved + * promise. Subclasses should override this if they have asynchronous initialization work to do. + * + * External callers should not call this. Instead, call #getInitializedPromise. + * + * @private + * @returns {jQuery.Promise} Promise that will be resolved once initialization is done + */ +ve.init.Platform.prototype.initialize = function () { + return $.Deferred().resolve().promise(); +}; + +/** + * Get a promise to track when the platform has initialized. The platform won't be ready for use + * until this promise is resolved. + * + * @returns {jQuery.Promise} Promise that will be resolved once the platform is ready + */ +ve.init.Platform.prototype.getInitializedPromise = function () { + if ( !this.initialized ) { + this.initialized = this.initialize(); + } + return this.initialized; +};