2010-09-04 06:39:01 -04:00
|
|
|
(function() {
|
2011-04-30 13:33:28 -04:00
|
|
|
var CoffeeScript, runScripts;
|
2010-09-22 01:05:00 +09:00
|
|
|
CoffeeScript = require('./coffee-script');
|
2010-10-12 17:10:39 +09:00
|
|
|
CoffeeScript.require = require;
|
2010-09-22 01:05:00 +09: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-21 21:12:59 -05:00
|
|
|
if (options == null) {
|
|
|
|
options = {};
|
|
|
|
}
|
2010-10-26 19:13:55 +09:00
|
|
|
options.bare = true;
|
2010-10-12 17:10:39 +09:00
|
|
|
return Function(CoffeeScript.compile(code, options))();
|
2010-09-21 22:31:59 -04:00
|
|
|
};
|
2011-04-30 13:33:28 -04:00
|
|
|
if (typeof window === "undefined" || window === null) {
|
|
|
|
return;
|
2010-09-22 01:05:00 +09:00
|
|
|
}
|
2011-04-30 13:48:54 -04:00
|
|
|
CoffeeScript.load = function(url, callback) {
|
2010-09-22 01:05:00 +09:00
|
|
|
var xhr;
|
2011-04-30 13:33:28 -04:00
|
|
|
xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
|
2010-09-22 01:05:00 +09:00
|
|
|
xhr.open('GET', url, true);
|
|
|
|
if ('overrideMimeType' in xhr) {
|
|
|
|
xhr.overrideMimeType('text/plain');
|
|
|
|
}
|
|
|
|
xhr.onreadystatechange = function() {
|
2010-11-08 23:07:51 -05:00
|
|
|
if (xhr.readyState === 4) {
|
2011-04-30 13:48:54 -04:00
|
|
|
if (xhr.status === 200) {
|
|
|
|
CoffeeScript.run(xhr.responseText);
|
|
|
|
} else {
|
|
|
|
throw new Error("Could not load " + url);
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
return callback();
|
|
|
|
}
|
2010-11-08 23:07:51 -05:00
|
|
|
}
|
2010-09-04 06:39:01 -04:00
|
|
|
};
|
2010-09-22 01:05:00 +09:00
|
|
|
return xhr.send(null);
|
|
|
|
};
|
2010-10-12 17:10:39 +09:00
|
|
|
runScripts = function() {
|
2011-04-30 13:48:54 -04:00
|
|
|
var coffees, execute, index, length, s, scripts;
|
|
|
|
scripts = document.getElementsByTagName('script');
|
|
|
|
coffees = (function() {
|
|
|
|
var _i, _len, _results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
|
|
|
s = scripts[_i];
|
|
|
|
if (s.type === 'text/coffeescript') {
|
|
|
|
_results.push(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
})();
|
|
|
|
index = 0;
|
|
|
|
length = coffees.length;
|
|
|
|
(execute = function() {
|
|
|
|
var script;
|
|
|
|
script = coffees[index++];
|
|
|
|
if ((script != null ? script.type : void 0) === 'text/coffeescript') {
|
2011-04-30 13:33:28 -04:00
|
|
|
if (script.src) {
|
2011-04-30 13:48:54 -04:00
|
|
|
return CoffeeScript.load(script.src, execute);
|
2011-04-30 13:33:28 -04:00
|
|
|
} else {
|
|
|
|
CoffeeScript.run(script.innerHTML);
|
2011-04-30 13:48:54 -04:00
|
|
|
return execute();
|
2011-04-30 13:33:28 -04:00
|
|
|
}
|
2011-04-11 13:38:38 -06:00
|
|
|
}
|
2011-04-30 13:48:54 -04:00
|
|
|
})();
|
2010-09-22 01:05:00 +09:00
|
|
|
return null;
|
|
|
|
};
|
2011-04-30 13:33:28 -04:00
|
|
|
if (window.addEventListener) {
|
|
|
|
addEventListener('DOMContentLoaded', runScripts, false);
|
|
|
|
} else {
|
|
|
|
attachEvent('onload', runScripts);
|
2010-09-04 06:39:01 -04:00
|
|
|
}
|
2010-09-21 16:53:58 +09:00
|
|
|
}).call(this);
|