mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
(function() {
|
|
var CoffeeScript, runScripts;
|
|
CoffeeScript = require('./coffee-script');
|
|
CoffeeScript.require = require;
|
|
CoffeeScript.eval = function(code, options) {
|
|
return eval(CoffeeScript.compile(code, options));
|
|
};
|
|
CoffeeScript.run = function(code, options) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
options.bare = true;
|
|
return Function(CoffeeScript.compile(code, options))();
|
|
};
|
|
if (typeof window == "undefined" || window === null) {
|
|
return;
|
|
}
|
|
CoffeeScript.load = function(url, options) {
|
|
var xhr;
|
|
xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
|
|
xhr.open('GET', url, true);
|
|
if ('overrideMimeType' in xhr) {
|
|
xhr.overrideMimeType('text/plain');
|
|
}
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState === 4) {
|
|
return CoffeeScript.run(xhr.responseText, options);
|
|
}
|
|
};
|
|
return xhr.send(null);
|
|
};
|
|
runScripts = function() {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
if (window.addEventListener) {
|
|
addEventListener('DOMContentLoaded', runScripts, false);
|
|
} else {
|
|
attachEvent('onload', runScripts);
|
|
}
|
|
}).call(this);
|