1 |
|
2 | (function() {
|
3 | var CoffeeScript, runScripts;
|
4 |
|
5 | CoffeeScript = require('./coffee-script');
|
6 |
|
7 | CoffeeScript.require = require;
|
8 |
|
9 | CoffeeScript["eval"] = function(code, options) {
|
10 | var _ref;
|
11 | if (options == null) {
|
12 | options = {};
|
13 | }
|
14 | if ((_ref = options.bare) == null) {
|
15 | options.bare = true;
|
16 | }
|
17 | return eval(CoffeeScript.compile(code, options));
|
18 | };
|
19 |
|
20 | CoffeeScript.run = function(code, options) {
|
21 | if (options == null) {
|
22 | options = {};
|
23 | }
|
24 | options.bare = true;
|
25 | return Function(CoffeeScript.compile(code, options))();
|
26 | };
|
27 |
|
28 | if (typeof window === "undefined" || window === null) {
|
29 | return;
|
30 | }
|
31 |
|
32 | CoffeeScript.load = function(url, callback) {
|
33 | var xhr;
|
34 | xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
|
35 | xhr.open('GET', url, true);
|
36 | if ('overrideMimeType' in xhr) {
|
37 | xhr.overrideMimeType('text/plain');
|
38 | }
|
39 | xhr.onreadystatechange = function() {
|
40 | var _ref;
|
41 | if (xhr.readyState === 4) {
|
42 | if ((_ref = xhr.status) === 0 || _ref === 200) {
|
43 | CoffeeScript.run(xhr.responseText);
|
44 | } else {
|
45 | throw new Error("Could not load " + url);
|
46 | }
|
47 | if (callback) {
|
48 | return callback();
|
49 | }
|
50 | }
|
51 | };
|
52 | return xhr.send(null);
|
53 | };
|
54 |
|
55 | runScripts = function() {
|
56 | var coffees, execute, index, length, s, scripts;
|
57 | scripts = document.getElementsByTagName('script');
|
58 | coffees = (function() {
|
59 | var _i, _len, _results;
|
60 | _results = [];
|
61 | for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
62 | s = scripts[_i];
|
63 | if (s.type === 'text/coffeescript') {
|
64 | _results.push(s);
|
65 | }
|
66 | }
|
67 | return _results;
|
68 | })();
|
69 | index = 0;
|
70 | length = coffees.length;
|
71 | (execute = function() {
|
72 | var script;
|
73 | script = coffees[index++];
|
74 | if ((script != null ? script.type : void 0) === 'text/coffeescript') {
|
75 | if (script.src) {
|
76 | return CoffeeScript.load(script.src, execute);
|
77 | } else {
|
78 | CoffeeScript.run(script.innerHTML);
|
79 | return execute();
|
80 | }
|
81 | }
|
82 | })();
|
83 | return null;
|
84 | };
|
85 |
|
86 | if (window.addEventListener) {
|
87 | addEventListener('DOMContentLoaded', runScripts, false);
|
88 | } else {
|
89 | attachEvent('onload', runScripts);
|
90 | }
|
91 |
|
92 | }).call(this);
|