reverted @kitgoncharov's commits that broke the browser runner.

This commit is contained in:
Jeremy Ashkenas
2011-04-30 13:33:28 -04:00
parent f1ad2e1fae
commit 0dfe2429bc
3 changed files with 43 additions and 93 deletions

View File

@@ -1,6 +1,5 @@
(function() {
var CoffeeScript, create, document, runScripts;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var CoffeeScript, runScripts;
CoffeeScript = require('./coffee-script');
CoffeeScript.require = require;
CoffeeScript.eval = function(code, options) {
@@ -13,67 +12,41 @@
options.bare = true;
return Function(CoffeeScript.compile(code, options))();
};
document = typeof this.document !== 'undefined' ? document : null;
create = function() {
throw new Error('`XMLHttpRequest` is not supported.');
};
if (typeof this.ActiveXObject !== 'undefined') {
create = __bind(function() {
return new this.ActiveXObject('Microsoft.XMLHTTP');
}, this);
} else if (typeof this.XMLHttpRequest !== 'undefined') {
create = __bind(function() {
return new this.XMLHttpRequest;
}, this);
if (typeof window === "undefined" || window === null) {
return;
}
CoffeeScript.load = function(url, options, callback) {
CoffeeScript.load = function(url, options) {
var xhr;
xhr = create();
xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
xhr.open('GET', url, true);
if ('overrideMimeType' in xhr) {
xhr.overrideMimeType('text/plain');
}
xhr.onreadystatechange = function() {
var error, result;
if (xhr.readyState === 4) {
error = result = null;
if (xhr.status === 200) {
try {
result = CoffeeScript.run(xhr.responseText);
} catch (error) {
error = exception;
}
} else {
error = new Error("An error occurred while loading the script `" + url + "`.");
}
return typeof callback === "function" ? callback(error, result) : void 0;
return CoffeeScript.run(xhr.responseText, options);
}
};
return xhr.send(null);
};
runScripts = function() {
var execute, index, length, scripts;
scripts = document.getElementsByTagName('script');
index = 0;
length = scripts.length;
(execute = function(error) {
var script;
if (error) {
throw error;
var script, _i, _len, _ref;
_ref = document.getElementsByTagName('script');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
script = _ref[_i];
if (script.type === 'text/coffeescript') {
if (script.src) {
CoffeeScript.load(script.src);
} else {
CoffeeScript.run(script.innerHTML);
}
}
script = scripts[index++];
if (script.type === 'text/coffeescript' && script.src) {
return CoffeeScript.load(script.src, null, execute);
} else {
CoffeeScript.run(script.innerHTML);
return execute();
}
})();
}
return null;
};
if (typeof this.addEventListener !== 'undefined') {
this.addEventListener('DOMContentLoaded', runScripts, false);
} else if (typeof this.attachEvent !== 'undefined') {
this.attachEvent('onload', runScripts);
if (window.addEventListener) {
addEventListener('DOMContentLoaded', runScripts, false);
} else {
attachEvent('onload', runScripts);
}
}).call(this);