From 0795d1801cb9a7dbdd929d52e50046a7a7e0efdd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 26 Jun 2015 14:58:26 +0200 Subject: [PATCH] Fixed build config and moved inline script into require.linearExecution.js --- wcfsetup/install/files/js/require.build.js | 5 +-- .../files/js/require.linearExecution.js | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 wcfsetup/install/files/js/require.linearExecution.js diff --git a/wcfsetup/install/files/js/require.build.js b/wcfsetup/install/files/js/require.build.js index 54f1619695..12255c132a 100644 --- a/wcfsetup/install/files/js/require.build.js +++ b/wcfsetup/install/files/js/require.build.js @@ -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 index 0000000000..375e8353ea --- /dev/null +++ b/wcfsetup/install/files/js/require.linearExecution.js @@ -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); -- 2.20.1