2010-09-04 10:39:01 +00:00
|
|
|
(function() {
|
2010-10-12 08:10:39 +00:00
|
|
|
var CoffeeScript, runScripts;
|
2010-09-21 16:05:00 +00:00
|
|
|
CoffeeScript = require('./coffee-script');
|
2010-10-12 08:10:39 +00:00
|
|
|
CoffeeScript.require = require;
|
2010-09-21 16:05:00 +00:00
|
|
|
CoffeeScript.eval = function(code, options) {
|
|
|
|
return eval(CoffeeScript.compile(code, options));
|
|
|
|
};
|
2010-09-22 02:31:59 +00:00
|
|
|
CoffeeScript.run = function(code, options) {
|
2010-11-02 03:11:25 +00:00
|
|
|
options == null && (options = {});
|
2010-10-26 10:13:55 +00:00
|
|
|
options.bare = true;
|
2010-10-12 08:10:39 +00:00
|
|
|
return Function(CoffeeScript.compile(code, options))();
|
2010-09-22 02:31:59 +00:00
|
|
|
};
|
2010-09-21 16:05:00 +00:00
|
|
|
if (!(typeof window !== "undefined" && window !== null)) {
|
2010-10-07 02:24:52 +00:00
|
|
|
return;
|
2010-09-21 16:05:00 +00:00
|
|
|
}
|
|
|
|
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-10-28 02:50:20 +00:00
|
|
|
return xhr.readyState === 4 ? CoffeeScript.run(xhr.responseText, options) : void 0;
|
2010-09-04 10:39:01 +00:00
|
|
|
};
|
2010-09-21 16:05:00 +00:00
|
|
|
return xhr.send(null);
|
|
|
|
};
|
2010-10-12 08:10:39 +00:00
|
|
|
runScripts = function() {
|
2010-11-02 03:58:03 +00:00
|
|
|
var script, _i, _len, _ref;
|
2010-10-22 01:51:06 +00:00
|
|
|
_ref = document.getElementsByTagName('script');
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2010-10-13 11:29:22 +00:00
|
|
|
script = _ref[_i];
|
|
|
|
if (script.type === 'text/coffeescript') {
|
|
|
|
if (script.src) {
|
|
|
|
CoffeeScript.load(script.src);
|
|
|
|
} else {
|
|
|
|
CoffeeScript.run(script.innerHTML);
|
|
|
|
}
|
|
|
|
}
|
2010-09-04 10:39:01 +00:00
|
|
|
}
|
2010-09-21 16:05:00 +00:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
if (window.addEventListener) {
|
2010-10-12 08:10:39 +00:00
|
|
|
addEventListener('DOMContentLoaded', runScripts, false);
|
2010-09-21 16:05:00 +00:00
|
|
|
} else {
|
2010-10-12 08:10:39 +00:00
|
|
|
attachEvent('onload', runScripts);
|
2010-09-04 10:39:01 +00:00
|
|
|
}
|
2010-09-21 07:53:58 +00:00
|
|
|
}).call(this);
|