| 9 |
lars |
1 |
(function(){
|
|
|
2 |
var window = this
|
|
|
3 |
|
|
|
4 |
// logging Shim from HTML5 Boilerplate
|
|
|
5 |
window.log = function() {
|
|
|
6 |
log.history = log.history || []; // store logs to an array for reference
|
|
|
7 |
log.history.push(arguments);
|
|
|
8 |
if (this.console) {
|
|
|
9 |
arguments.callee = arguments.callee.caller;
|
|
|
10 |
var newarr = [].slice.call(arguments);
|
|
|
11 |
(typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
|
|
|
12 |
}
|
|
|
13 |
};
|
|
|
14 |
// make it safe to use console.log always
|
|
|
15 |
(function(b) { function c() { } for (var d = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","), a; a = d.pop(); ) { b[a] = b[a] || c } })((function() {try { console.log(); return window.console; } catch (err) {return window.console = {};}})());
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
// curl.js text! plugin
|
|
|
20 |
define('text', function () {
|
|
|
21 |
var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
|
|
22 |
// collection of modules that have been written to the built file
|
|
|
23 |
built = {};
|
|
|
24 |
|
|
|
25 |
function xhr () {
|
|
|
26 |
if (typeof XMLHttpRequest !== "undefined") {
|
|
|
27 |
// rewrite the getXhr method to always return the native implementation
|
|
|
28 |
xhr = function () { return new XMLHttpRequest(); };
|
|
|
29 |
}
|
|
|
30 |
else {
|
|
|
31 |
// keep trying progIds until we find the correct one, then rewrite the getXhr method
|
|
|
32 |
// to always return that one.
|
|
|
33 |
var noXhr = xhr = function () {
|
|
|
34 |
throw new Error("getXhr(): XMLHttpRequest not available");
|
|
|
35 |
};
|
|
|
36 |
while (progIds.length > 0 && xhr === noXhr) (function (id) {
|
|
|
37 |
try {
|
|
|
38 |
new ActiveXObject(id);
|
|
|
39 |
xhr = function () { return new ActiveXObject(id); };
|
|
|
40 |
}
|
|
|
41 |
catch (ex) {}
|
|
|
42 |
}(progIds.shift()));
|
|
|
43 |
}
|
|
|
44 |
return xhr();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
function fetchText (url, callback, errback) {
|
|
|
48 |
var x = xhr();
|
|
|
49 |
x.open('GET', url, true);
|
|
|
50 |
x.onreadystatechange = function (e) {
|
|
|
51 |
if (x.readyState === 4) {
|
|
|
52 |
if (x.status < 400) {
|
|
|
53 |
callback(x.responseText);
|
|
|
54 |
}
|
|
|
55 |
else {
|
|
|
56 |
errback(new Error('fetchText() failed. status: ' + x.statusText));
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
};
|
|
|
60 |
x.send(null);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
function nameWithExt (name, defaultExt) {
|
|
|
64 |
return name.lastIndexOf('.') <= name.lastIndexOf('/') ?
|
|
|
65 |
name + '.' + defaultExt : name;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
function error (ex) {
|
|
|
69 |
if (console) {
|
|
|
70 |
console.error ? console.error(ex) : console.log(ex.message);
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
function jsEncode (text) {
|
|
|
74 |
// TODO: hoist the map and regex to the enclosing scope for better performance
|
|
|
75 |
var map = { 34: '\\"', 13: '\\r', 12: '\\f', 10: '\\n', 9: '\\t', 8: '\\b' };
|
|
|
76 |
return text.replace(/(["\n\f\t\r\b])/g, function (c) {
|
|
|
77 |
return map[c.charCodeAt(0)];
|
|
|
78 |
});
|
|
|
79 |
}
|
|
|
80 |
return {
|
|
|
81 |
|
|
|
82 |
load: function (resourceName, req, callback, config) {
|
|
|
83 |
// remove suffixes (future)
|
|
|
84 |
// hook up callbacks
|
|
|
85 |
var cb = callback.resolve || callback,
|
|
|
86 |
eb = callback.reject || error;
|
|
|
87 |
// get the text
|
|
|
88 |
fetchText(req['toUrl'](resourceName), cb, eb);
|
|
|
89 |
},
|
|
|
90 |
|
|
|
91 |
build: function (writer, fetcher, config) {
|
|
|
92 |
// writer is a function used to output to the built file
|
|
|
93 |
// fetcher is a function used to fetch a text file
|
|
|
94 |
// config is the global config
|
|
|
95 |
// returns a function that the build tool can use to tell this
|
|
|
96 |
// plugin to write-out a resource
|
|
|
97 |
return function write (pluginId, resource, resolver) {
|
|
|
98 |
var url, absId, text, output;
|
|
|
99 |
url = resolver['toUrl'](nameWithExt(resource, 'html'));
|
|
|
100 |
absId = resolver['toAbsMid'](resource);
|
|
|
101 |
if (!(absId in built)) {
|
|
|
102 |
built[absId] = true;
|
|
|
103 |
// fetch text
|
|
|
104 |
text = jsEncode(fetcher(url));
|
|
|
105 |
// write out a define
|
|
|
106 |
output = 'define("' + pluginId + '!' + absId + '", function () {\n' +
|
|
|
107 |
'\treturn "' + text + '";\n' +
|
|
|
108 |
'});\n';
|
|
|
109 |
writer(output)
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
})
|
|
|
115 |
}).call(typeof window !== 'undefined'? window : this)
|