mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
rebuild for PR #3012
This commit is contained in:
parent
92208fec44
commit
3aa646e425
1 changed files with 39 additions and 23 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue