mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
enabled remote scripts in browsers
This commit is contained in:
47
lib/coffee-script.js
Normal file → Executable file
47
lib/coffee-script.js
Normal file → Executable file
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Lexer, compile, helpers, lexer, parser, path, processScripts;
|
||||
var Lexer, compile, grind, grindRemote, helpers, lexer, parser, path, processScripts;
|
||||
if (typeof process !== "undefined" && process !== null) {
|
||||
path = require('path');
|
||||
Lexer = require('./lexer').Lexer;
|
||||
@@ -59,22 +59,45 @@
|
||||
return "";
|
||||
}
|
||||
};
|
||||
if ((typeof document !== "undefined" && document !== null) && document.getElementsByTagName) {
|
||||
if ((typeof document === "undefined" || document === null) ? undefined : document.getElementsByTagName) {
|
||||
grind = function(coffee) {
|
||||
return setTimeout(exports.compile(coffee, {
|
||||
noWrap: true
|
||||
}));
|
||||
};
|
||||
grindRemote = function(url) {
|
||||
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() {
|
||||
if (xhr.readyState === 4) {
|
||||
return grind(xhr.responseText);
|
||||
}
|
||||
};
|
||||
return xhr.send(null);
|
||||
};
|
||||
processScripts = function() {
|
||||
var _a, _b, _c, _d, tag;
|
||||
_a = []; _c = document.getElementsByTagName('script');
|
||||
for (_b = 0, _d = _c.length; _b < _d; _b++) {
|
||||
tag = _c[_b];
|
||||
if (tag.type === 'text/coffeescript') {
|
||||
_a.push(eval(exports.compile(tag.innerHTML)));
|
||||
var _a, _b, _c, script;
|
||||
_b = document.getElementsByTagName('script');
|
||||
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
||||
script = _b[_a];
|
||||
if (script.type === 'text/coffeescript') {
|
||||
if (script.src) {
|
||||
grindRemote(script.src);
|
||||
} else {
|
||||
grind(script.innerHTML);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _a;
|
||||
return null;
|
||||
};
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('load', processScripts, false);
|
||||
} else if (window.attachEvent) {
|
||||
window.attachEvent('onload', processScripts);
|
||||
addEventListener('DOMContentLoaded', processScripts, false);
|
||||
} else {
|
||||
attachEvent('onload', processScripts);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user