resourceloader: Expose fetch promise in addScript()
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 4 Sep 2015 03:04:01 +0000 (04:04 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 7 Sep 2015 23:47:42 +0000 (00:47 +0100)
Prerequisite for T68598 so that callers can handle errors.

Change-Id: I214159001e04c4b51453e47299b8e5d5033c258a

resources/src/mediawiki/mediawiki.js

index 49c350a..b36dbea 100644 (file)
                         *
                         * @private
                         * @param {string} src URL to script, will be used as the src attribute in the script tag
-                        * @param {Function} [callback] Callback which will be run when the script is done
+                        * @return {jQuery.Promise}
                         */
-                       function addScript( src, callback ) {
-                               $.ajax( {
+                       function addScript( src ) {
+                               return $.ajax( {
                                        url: src,
                                        dataType: 'script',
                                        // Force jQuery behaviour to be for crossDomain. Otherwise jQuery would use
                                        // text, so we'd need to $.globalEval, which then messes up line numbers.
                                        crossDomain: true,
                                        cache: true
-                               } ).always( callback );
+                               } );
                        }
 
                        /**
                                                                return;
                                                        }
 
-                                                       addScript( arr[ i ], function () {
+                                                       addScript( arr[ i ] ).always( function () {
                                                                nestedAddScript( arr, callback, i + 1 );
                                                        } );
                                                };