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