1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/lib/browser.js

47 lines
1.5 KiB
JavaScript
Raw Normal View History

(function() {
var CoffeeScript, runScripts;
CoffeeScript = require('./coffee-script');
CoffeeScript.require = require;
CoffeeScript.eval = function(code, options) {
return eval(CoffeeScript.compile(code, options));
};
2010-09-21 22:31:59 -04:00
CoffeeScript.run = function(code, options) {
(options != null) ? options.bare = true : undefined;
return Function(CoffeeScript.compile(code, options))();
2010-09-21 22:31:59 -04:00
};
if (!(typeof window !== "undefined" && window !== null)) {
2010-10-06 22:24:52 -04:00
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() {
return xhr.readyState === 4 ? CoffeeScript.run(xhr.responseText, options) : undefined;
};
return xhr.send(null);
};
runScripts = function() {
var _i, _j, _len, _ref, script;
for (_i = 0, _len = (_ref = document.getElementsByTagName('script')).length; _i < _len; _i++) {
2010-09-21 22:31:59 -04:00
(function() {
var script = _ref[_i];
2010-10-19 10:53:38 -04:00
_j = script;
return script.type === 'text/coffeescript' ? script.src ? CoffeeScript.load(script.src) : setTimeout(function() {
2010-10-19 10:53:38 -04:00
return CoffeeScript.run(script.innerHTML);
}) : undefined;
2010-09-21 22:31:59 -04:00
})();
script = _j;
}
return null;
};
if (window.addEventListener) {
addEventListener('DOMContentLoaded', runScripts, false);
} else {
attachEvent('onload', runScripts);
}
}).call(this);