From fc119e3d60753da2b076fd1ae4731993745222e5 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 12 Dec 2013 11:57:23 -0800 Subject: [PATCH] Allow ve.init.Platforms to asynchronously initialize themselves We'll need this for the standalone platform to load jquery.i18n messages Change-Id: Iacb9fcb2d5750711187f7d72d53d8c7d54c6f30b --- modules/ve-mw/init/ve.init.mw.Target.js | 2 ++ modules/ve/init/ve.init.Platform.js | 26 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) 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; +};