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-10-20 15:51:11 -04:00
|
|
|
(options != null) ? options.bare = true : undefined;
|
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-01 20:52:23 -04:00
|
|
|
return xhr.readyState === 4 ? CoffeeScript.run(xhr.responseText, options) : undefined;
|
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-10-19 09:51:52 -04:00
|
|
|
var _i, _j, _len, _ref, script;
|
2010-10-06 23:24:32 -04:00
|
|
|
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;
|
2010-10-20 13:29:06 -04:00
|
|
|
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);
|
2010-10-20 13:29:06 -04:00
|
|
|
}) : undefined;
|
2010-09-21 22:31:59 -04:00
|
|
|
})();
|
2010-10-19 09:51:52 -04:00
|
|
|
script = _j;
|
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);
|