Fixed build config and moved inline script into require.linearExecution.js
authorAlexander Ebert <ebert@woltlab.com>
Fri, 26 Jun 2015 12:58:26 +0000 (14:58 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 26 Jun 2015 12:58:26 +0000 (14:58 +0200)
wcfsetup/install/files/js/require.build.js
wcfsetup/install/files/js/require.linearExecution.js [new file with mode: 0644]

index 54f1619695ed568aacaac45536212793136c86f0..12255c132a02591e5153edf7c6bb79f4436b0e18 100644 (file)
@@ -13,7 +13,8 @@
        },
        include: [
                "requireLib",
-               "require.config"
+               "require.config",
+               "require.linearExecution"
        ],
        excludeShallow: [
                'WoltLab/_Meta'
@@ -49,7 +50,7 @@
                                }
                        }
                        
-                       return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'"; }).join(', ') + '], function() { });';
+                       return 'define([' + global.allModules.map(function (item) { return "'" + item.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\.js$/, '') + "'"; }).join(', ') + '], function() { });';
                }
                
                return contents;
diff --git a/wcfsetup/install/files/js/require.linearExecution.js b/wcfsetup/install/files/js/require.linearExecution.js
new file mode 100644 (file)
index 0000000..375e835
--- /dev/null
@@ -0,0 +1,32 @@
+(function(window) {
+       var orgRequire = window.require;
+       var queue = [];
+       var counter = 0;
+       
+       window.require = function(dependencies, callback) {
+               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();
+               });
+       };
+       
+       function executeCallbacks() {
+               while (queue.length) {
+                       if (typeof queue[0] !== 'function') {
+                               break;
+                       }
+                       
+                       queue.shift()();
+               }
+       };
+})(window);