Add support for errBack to require.linearExecution
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Sep 2016 16:31:01 +0000 (18:31 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 28 Sep 2016 16:31:54 +0000 (18:31 +0200)
wcfsetup/install/files/js/require.linearExecution.js

index 4729d6725dff68deaa081dc5383e780115935433..9f2e40a090e5c0d579c85778c1a9b7fce83f1ba1 100644 (file)
@@ -3,7 +3,7 @@
        var queue = [];
        var counter = 0;
        
-       window.require = function(dependencies, callback) {
+       window.require = function(dependencies, callback, errBack) {
                if (!Array.isArray(dependencies)) {
                        return orgRequire.apply(window, arguments);
                }
                var i = counter++;
                queue.push(i);
                
-               orgRequire(dependencies, function() {
-                       var args = arguments;
-                       
-                       queue[queue.indexOf(i)] = function() { callback.apply(window, args); };
-                       
-                       executeCallbacks();
-               });
+               if (errBack) {
+                       orgRequire(dependencies, function() {
+                               var args = arguments;
+                               
+                               queue[queue.indexOf(i)] = function() { callback.apply(window, args); };
+                               
+                               executeCallbacks();
+                       }, function() {
+                               var args = arguments;
+                               
+                               queue[queue.indexOf(i)] = function() { errBack.apply(window, args); };
+                               
+                               executeCallbacks();
+                       });
+               }
+               else {
+                       orgRequire(dependencies, function() {
+                               var args = arguments;
+                               
+                               queue[queue.indexOf(i)] = function() { callback.apply(window, args); };
+                               
+                               executeCallbacks();
+                       });
+               }
        };
        window.require.config = orgRequire.config;