UNPKG

caffeine

Version:

Unfancy JavaScript powered by CoffeeScript Caffeine

93 lines (83 loc) 2.31 kB
// Generated by Caffeine 0.2.7 (function() { var Caffeine, runScripts; Caffeine = require('./caffeine'); Caffeine.require = require; Caffeine["eval"] = function(code, options) { var _ref; if (options == null) { options = {}; } if ((_ref = options.bare) == null) { options.bare = true; } return eval(Caffeine.compile(code, options)); }; Caffeine.run = function(code, options) { if (options == null) { options = {}; } options.bare = true; return Function(Caffeine.compile(code, options))(); }; if (typeof window === "undefined" || window === null) { return; } Caffeine.load = function(url, callback) { var xhr; xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(); xhr.open('GET', url, true); if ('overrideMimeType' in xhr) { xhr.overrideMimeType('text/plain'); } xhr.onreadystatechange = function() { var _ref; if (xhr.readyState === 4) { if ((_ref = xhr.status) === 0 || _ref === 200) { Caffeine.run(xhr.responseText); } else { throw new Error("Could not load " + url); } if (callback) { return callback(); } } }; return xhr.send(null); }; runScripts = function() { 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') { if (script.src) { return Caffeine.load(script.src, execute); } else { Caffeine.run(script.innerHTML); return execute(); } } })(); return null; }; if (window.addEventListener) { addEventListener('DOMContentLoaded', runScripts, false); } else { attachEvent('onload', runScripts); } }).call(this);