From 3aa646e425e88a77dd791d36f7ea96007e1e81fc Mon Sep 17 00:00:00 2001 From: Cotton Hou Date: Fri, 28 Jun 2013 09:40:22 +0800 Subject: [PATCH] rebuild for PR #3012 --- lib/coffee-script/browser.js | 62 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js index e5411d8c..070bee03 100644 --- a/lib/coffee-script/browser.js +++ b/lib/coffee-script/browser.js @@ -45,11 +45,14 @@ }; } - CoffeeScript.load = function(url, callback, options) { + CoffeeScript.load = function(url, callback, options, hold) { var xhr; if (options == null) { options = {}; } + if (hold == null) { + hold = false; + } options.sourceFiles = [url]; xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new window.XMLHttpRequest(); xhr.open('GET', url, true); @@ -57,15 +60,18 @@ xhr.overrideMimeType('text/plain'); } xhr.onreadystatechange = function() { - var _ref; + var param, _ref; if (xhr.readyState === 4) { if ((_ref = xhr.status) === 0 || _ref === 200) { - CoffeeScript.run(xhr.responseText, options); + param = [xhr.responseText, options]; + if (!hold) { + CoffeeScript.run.apply(CoffeeScript, param); + } } else { throw new Error("Could not load " + url); } if (callback) { - return callback(); + return callback(param); } } }; @@ -73,7 +79,7 @@ }; runScripts = function() { - var coffees, coffeetypes, execute, index, length, s, scripts; + var coffees, coffeetypes, execute, i, index, s, script, scripts, _fn, _i, _len; scripts = window.document.getElementsByTagName('script'); coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']; coffees = (function() { @@ -88,25 +94,35 @@ return _results; })(); index = 0; - length = coffees.length; - (execute = function() { - var mediatype, options, script; - script = coffees[index++]; - mediatype = script != null ? script.type : void 0; - if (__indexOf.call(coffeetypes, mediatype) >= 0) { - options = { - literate: mediatype === 'text/literate-coffeescript' - }; - if (script.src) { - return CoffeeScript.load(script.src, execute, options); - } else { - options.sourceFiles = ['embedded']; - CoffeeScript.run(script.innerHTML, options); - return execute(); - } + execute = function() { + var param; + param = coffees[index]; + if (param instanceof Array) { + CoffeeScript.run.apply(CoffeeScript, param); + index++; + return execute(); } - })(); - return null; + }; + _fn = function(script, i) { + var options; + options = { + literate: script.type === coffeetypes[1] + }; + if (script.src) { + return CoffeeScript.load(script.src, function(param) { + coffees[i] = param; + return execute(); + }, options, true); + } else { + options.sourceFiles = ['embedded']; + return coffees[i] = [script.innerHTML, options]; + } + }; + for (i = _i = 0, _len = coffees.length; _i < _len; i = ++_i) { + script = coffees[i]; + _fn(script, i); + } + return execute(); }; if (window.addEventListener) {