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