@catlab/requirejs-plugins 0.0.0-stage → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.mdown +148 -0
- package/lib/Markdown.Converter.js +1353 -0
- package/lib/require.js +2019 -0
- package/lib/text.js +332 -0
- package/package.json +18 -4
- package/src/async.js +44 -0
- package/src/depend.js +27 -0
- package/src/font.js +45 -0
- package/src/goog.js +38 -0
- package/src/image.js +53 -0
- package/src/json.js +66 -0
- package/src/mdown.js +59 -0
- package/src/noext.js +28 -0
- package/src/propertyParser.js +43 -0
- package/README.md +0 -3
package/lib/text.js
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license RequireJS text 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
|
3
|
+
* Available via the MIT or new BSD license.
|
|
4
|
+
* see: http://github.com/requirejs/text for details
|
|
5
|
+
*/
|
|
6
|
+
/*jslint regexp: true */
|
|
7
|
+
/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
|
|
8
|
+
define: false, window: false, process: false, Packages: false,
|
|
9
|
+
java: false, location: false */
|
|
10
|
+
|
|
11
|
+
define(['module'], function (module) {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var text, fs,
|
|
15
|
+
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
|
|
16
|
+
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
|
|
17
|
+
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
|
|
18
|
+
hasLocation = typeof location !== 'undefined' && location.href,
|
|
19
|
+
defaultProtocol = hasLocation && location.protocol && location.protocol.replace(/\:/, ''),
|
|
20
|
+
defaultHostName = hasLocation && location.hostname,
|
|
21
|
+
defaultPort = hasLocation && (location.port || undefined),
|
|
22
|
+
buildMap = [],
|
|
23
|
+
masterConfig = (module.config && module.config()) || {};
|
|
24
|
+
|
|
25
|
+
text = {
|
|
26
|
+
version: '2.0.5',
|
|
27
|
+
|
|
28
|
+
strip: function (content) {
|
|
29
|
+
//Strips <?xml ...?> declarations so that external SVG and XML
|
|
30
|
+
//documents can be added to a document without worry. Also, if the string
|
|
31
|
+
//is an HTML document, only the part inside the body tag is returned.
|
|
32
|
+
if (content) {
|
|
33
|
+
content = content.replace(xmlRegExp, "");
|
|
34
|
+
var matches = content.match(bodyRegExp);
|
|
35
|
+
if (matches) {
|
|
36
|
+
content = matches[1];
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
content = "";
|
|
40
|
+
}
|
|
41
|
+
return content;
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
jsEscape: function (content) {
|
|
45
|
+
return content.replace(/(['\\])/g, '\\$1')
|
|
46
|
+
.replace(/[\f]/g, "\\f")
|
|
47
|
+
.replace(/[\b]/g, "\\b")
|
|
48
|
+
.replace(/[\n]/g, "\\n")
|
|
49
|
+
.replace(/[\t]/g, "\\t")
|
|
50
|
+
.replace(/[\r]/g, "\\r")
|
|
51
|
+
.replace(/[\u2028]/g, "\\u2028")
|
|
52
|
+
.replace(/[\u2029]/g, "\\u2029");
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
createXhr: masterConfig.createXhr || function () {
|
|
56
|
+
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
|
57
|
+
var xhr, i, progId;
|
|
58
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
59
|
+
return new XMLHttpRequest();
|
|
60
|
+
} else if (typeof ActiveXObject !== "undefined") {
|
|
61
|
+
for (i = 0; i < 3; i += 1) {
|
|
62
|
+
progId = progIds[i];
|
|
63
|
+
try {
|
|
64
|
+
xhr = new ActiveXObject(progId);
|
|
65
|
+
} catch (e) {}
|
|
66
|
+
|
|
67
|
+
if (xhr) {
|
|
68
|
+
progIds = [progId]; // so faster next time
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return xhr;
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Parses a resource name into its component parts. Resource names
|
|
79
|
+
* look like: module/name.ext!strip, where the !strip part is
|
|
80
|
+
* optional.
|
|
81
|
+
* @param {String} name the resource name
|
|
82
|
+
* @returns {Object} with properties "moduleName", "ext" and "strip"
|
|
83
|
+
* where strip is a boolean.
|
|
84
|
+
*/
|
|
85
|
+
parseName: function (name) {
|
|
86
|
+
var modName, ext, temp,
|
|
87
|
+
strip = false,
|
|
88
|
+
index = name.indexOf("."),
|
|
89
|
+
isRelative = name.indexOf('./') === 0 ||
|
|
90
|
+
name.indexOf('../') === 0;
|
|
91
|
+
|
|
92
|
+
if (index !== -1 && (!isRelative || index > 1)) {
|
|
93
|
+
modName = name.substring(0, index);
|
|
94
|
+
ext = name.substring(index + 1, name.length);
|
|
95
|
+
} else {
|
|
96
|
+
modName = name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
temp = ext || modName;
|
|
100
|
+
index = temp.indexOf("!");
|
|
101
|
+
if (index !== -1) {
|
|
102
|
+
//Pull off the strip arg.
|
|
103
|
+
strip = temp.substring(index + 1) === "strip";
|
|
104
|
+
temp = temp.substring(0, index);
|
|
105
|
+
if (ext) {
|
|
106
|
+
ext = temp;
|
|
107
|
+
} else {
|
|
108
|
+
modName = temp;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
moduleName: modName,
|
|
114
|
+
ext: ext,
|
|
115
|
+
strip: strip
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/,
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Is an URL on another domain. Only works for browser use, returns
|
|
123
|
+
* false in non-browser environments. Only used to know if an
|
|
124
|
+
* optimized .js version of a text resource should be loaded
|
|
125
|
+
* instead.
|
|
126
|
+
* @param {String} url
|
|
127
|
+
* @returns Boolean
|
|
128
|
+
*/
|
|
129
|
+
useXhr: function (url, protocol, hostname, port) {
|
|
130
|
+
var uProtocol, uHostName, uPort,
|
|
131
|
+
match = text.xdRegExp.exec(url);
|
|
132
|
+
if (!match) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
uProtocol = match[2];
|
|
136
|
+
uHostName = match[3];
|
|
137
|
+
|
|
138
|
+
uHostName = uHostName.split(':');
|
|
139
|
+
uPort = uHostName[1];
|
|
140
|
+
uHostName = uHostName[0];
|
|
141
|
+
|
|
142
|
+
return (!uProtocol || uProtocol === protocol) &&
|
|
143
|
+
(!uHostName || uHostName.toLowerCase() === hostname.toLowerCase()) &&
|
|
144
|
+
((!uPort && !uHostName) || uPort === port);
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
finishLoad: function (name, strip, content, onLoad) {
|
|
148
|
+
content = strip ? text.strip(content) : content;
|
|
149
|
+
if (masterConfig.isBuild) {
|
|
150
|
+
buildMap[name] = content;
|
|
151
|
+
}
|
|
152
|
+
onLoad(content);
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
load: function (name, req, onLoad, config) {
|
|
156
|
+
//Name has format: some.module.filext!strip
|
|
157
|
+
//The strip part is optional.
|
|
158
|
+
//if strip is present, then that means only get the string contents
|
|
159
|
+
//inside a body tag in an HTML string. For XML/SVG content it means
|
|
160
|
+
//removing the <?xml ...?> declarations so the content can be inserted
|
|
161
|
+
//into the current doc without problems.
|
|
162
|
+
|
|
163
|
+
// Do not bother with the work if a build and text will
|
|
164
|
+
// not be inlined.
|
|
165
|
+
if (config.isBuild && !config.inlineText) {
|
|
166
|
+
onLoad();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
masterConfig.isBuild = config.isBuild;
|
|
171
|
+
|
|
172
|
+
var parsed = text.parseName(name),
|
|
173
|
+
nonStripName = parsed.moduleName +
|
|
174
|
+
(parsed.ext ? '.' + parsed.ext : ''),
|
|
175
|
+
url = req.toUrl(nonStripName),
|
|
176
|
+
useXhr = (masterConfig.useXhr) ||
|
|
177
|
+
text.useXhr;
|
|
178
|
+
|
|
179
|
+
//Load the text. Use XHR if possible and in a browser.
|
|
180
|
+
if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
|
|
181
|
+
text.get(url, function (content) {
|
|
182
|
+
text.finishLoad(name, parsed.strip, content, onLoad);
|
|
183
|
+
}, function (err) {
|
|
184
|
+
if (onLoad.error) {
|
|
185
|
+
onLoad.error(err);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
//Need to fetch the resource across domains. Assume
|
|
190
|
+
//the resource has been optimized into a JS module. Fetch
|
|
191
|
+
//by the module name + extension, but do not include the
|
|
192
|
+
//!strip part to avoid file system issues.
|
|
193
|
+
req([nonStripName], function (content) {
|
|
194
|
+
text.finishLoad(parsed.moduleName + '.' + parsed.ext,
|
|
195
|
+
parsed.strip, content, onLoad);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
write: function (pluginName, moduleName, write, config) {
|
|
201
|
+
if (buildMap.hasOwnProperty(moduleName)) {
|
|
202
|
+
var content = text.jsEscape(buildMap[moduleName]);
|
|
203
|
+
write.asModule(pluginName + "!" + moduleName,
|
|
204
|
+
"define(function () { return '" +
|
|
205
|
+
content +
|
|
206
|
+
"';});\n");
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
writeFile: function (pluginName, moduleName, req, write, config) {
|
|
211
|
+
var parsed = text.parseName(moduleName),
|
|
212
|
+
extPart = parsed.ext ? '.' + parsed.ext : '',
|
|
213
|
+
nonStripName = parsed.moduleName + extPart,
|
|
214
|
+
//Use a '.js' file name so that it indicates it is a
|
|
215
|
+
//script that can be loaded across domains.
|
|
216
|
+
fileName = req.toUrl(parsed.moduleName + extPart) + '.js';
|
|
217
|
+
|
|
218
|
+
//Leverage own load() method to load plugin value, but only
|
|
219
|
+
//write out values that do not have the strip argument,
|
|
220
|
+
//to avoid any potential issues with ! in file names.
|
|
221
|
+
text.load(nonStripName, req, function (value) {
|
|
222
|
+
//Use own write() method to construct full module value.
|
|
223
|
+
//But need to create shell that translates writeFile's
|
|
224
|
+
//write() to the right interface.
|
|
225
|
+
var textWrite = function (contents) {
|
|
226
|
+
return write(fileName, contents);
|
|
227
|
+
};
|
|
228
|
+
textWrite.asModule = function (moduleName, contents) {
|
|
229
|
+
return write.asModule(moduleName, fileName, contents);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
text.write(pluginName, nonStripName, textWrite, config);
|
|
233
|
+
}, config);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
if (masterConfig.env === 'node' || (!masterConfig.env &&
|
|
238
|
+
typeof process !== "undefined" &&
|
|
239
|
+
process.versions &&
|
|
240
|
+
!!process.versions.node)) {
|
|
241
|
+
//Using special require.nodeRequire, something added by r.js.
|
|
242
|
+
fs = require.nodeRequire('fs');
|
|
243
|
+
|
|
244
|
+
text.get = function (url, callback) {
|
|
245
|
+
var file = fs.readFileSync(url, 'utf8');
|
|
246
|
+
//Remove BOM (Byte Mark Order) from utf8 files if it is there.
|
|
247
|
+
if (file.indexOf('\uFEFF') === 0) {
|
|
248
|
+
file = file.substring(1);
|
|
249
|
+
}
|
|
250
|
+
callback(file);
|
|
251
|
+
};
|
|
252
|
+
} else if (masterConfig.env === 'xhr' || (!masterConfig.env &&
|
|
253
|
+
text.createXhr())) {
|
|
254
|
+
text.get = function (url, callback, errback, headers) {
|
|
255
|
+
var xhr = text.createXhr(), header;
|
|
256
|
+
xhr.open('GET', url, true);
|
|
257
|
+
|
|
258
|
+
//Allow plugins direct access to xhr headers
|
|
259
|
+
if (headers) {
|
|
260
|
+
for (header in headers) {
|
|
261
|
+
if (headers.hasOwnProperty(header)) {
|
|
262
|
+
xhr.setRequestHeader(header.toLowerCase(), headers[header]);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//Allow overrides specified in config
|
|
268
|
+
if (masterConfig.onXhr) {
|
|
269
|
+
masterConfig.onXhr(xhr, url);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
xhr.onreadystatechange = function (evt) {
|
|
273
|
+
var status, err;
|
|
274
|
+
//Do not explicitly handle errors, those should be
|
|
275
|
+
//visible via console output in the browser.
|
|
276
|
+
if (xhr.readyState === 4) {
|
|
277
|
+
status = xhr.status;
|
|
278
|
+
if (status > 399 && status < 600) {
|
|
279
|
+
//An http 4xx or 5xx error. Signal an error.
|
|
280
|
+
err = new Error(url + ' HTTP status: ' + status);
|
|
281
|
+
err.xhr = xhr;
|
|
282
|
+
errback(err);
|
|
283
|
+
} else {
|
|
284
|
+
callback(xhr.responseText);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
xhr.send(null);
|
|
289
|
+
};
|
|
290
|
+
} else if (masterConfig.env === 'rhino' || (!masterConfig.env &&
|
|
291
|
+
typeof Packages !== 'undefined' && typeof java !== 'undefined')) {
|
|
292
|
+
//Why Java, why is this so awkward?
|
|
293
|
+
text.get = function (url, callback) {
|
|
294
|
+
var stringBuffer, line,
|
|
295
|
+
encoding = "utf-8",
|
|
296
|
+
file = new java.io.File(url),
|
|
297
|
+
lineSeparator = java.lang.System.getProperty("line.separator"),
|
|
298
|
+
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
|
299
|
+
content = '';
|
|
300
|
+
try {
|
|
301
|
+
stringBuffer = new java.lang.StringBuffer();
|
|
302
|
+
line = input.readLine();
|
|
303
|
+
|
|
304
|
+
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
|
305
|
+
// http://www.unicode.org/faq/utf_bom.html
|
|
306
|
+
|
|
307
|
+
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
|
308
|
+
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
|
309
|
+
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
|
310
|
+
// Eat the BOM, since we've already found the encoding on this file,
|
|
311
|
+
// and we plan to concatenating this buffer with others; the BOM should
|
|
312
|
+
// only appear at the top of a file.
|
|
313
|
+
line = line.substring(1);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
stringBuffer.append(line);
|
|
317
|
+
|
|
318
|
+
while ((line = input.readLine()) !== null) {
|
|
319
|
+
stringBuffer.append(lineSeparator);
|
|
320
|
+
stringBuffer.append(line);
|
|
321
|
+
}
|
|
322
|
+
//Make sure we return a JavaScript string and not a Java string.
|
|
323
|
+
content = String(stringBuffer.toString()); //String
|
|
324
|
+
} finally {
|
|
325
|
+
input.close();
|
|
326
|
+
}
|
|
327
|
+
callback(content);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return text;
|
|
332
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catlab/requirejs-plugins",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Unmodified copy of millermedeiros/requirejs-plugins v1.0.3 (commit ac9de4bfae70b0630754a9faf93c42db362cb9a2), which is not on the npm registry. RequireJS plugins: async, depend, font, goog, image, json, mdown, noext, text.",
|
|
5
|
+
"main": "src/json.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Miller Medeiros (http://blog.millermedeiros.com)",
|
|
12
|
+
"homepage": "https://github.com/millermedeiros/requirejs-plugins",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/millermedeiros/requirejs-plugins.git"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/async.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* RequireJS plugin for async dependency load like JSONP and Google Maps
|
|
3
|
+
* Author: Miller Medeiros
|
|
4
|
+
* Version: 0.1.2 (2014/02/24)
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
define(function(){
|
|
8
|
+
|
|
9
|
+
var DEFAULT_PARAM_NAME = 'callback',
|
|
10
|
+
_uid = 0;
|
|
11
|
+
|
|
12
|
+
function injectScript(src){
|
|
13
|
+
var s, t;
|
|
14
|
+
s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = src;
|
|
15
|
+
t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(s,t);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function formatUrl(name, id){
|
|
19
|
+
var paramRegex = /!(.+)/,
|
|
20
|
+
url = name.replace(paramRegex, ''),
|
|
21
|
+
param = (paramRegex.test(name))? name.replace(/.+!/, '') : DEFAULT_PARAM_NAME;
|
|
22
|
+
url += (url.indexOf('?') < 0)? '?' : '&';
|
|
23
|
+
return url + param +'='+ id;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function uid() {
|
|
27
|
+
_uid += 1;
|
|
28
|
+
return '__async_req_'+ _uid +'__';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return{
|
|
32
|
+
load : function(name, req, onLoad, config){
|
|
33
|
+
if(config.isBuild){
|
|
34
|
+
onLoad(null); //avoid errors on the optimizer
|
|
35
|
+
}else{
|
|
36
|
+
var id = uid();
|
|
37
|
+
//create a global variable that stores onLoad so callback
|
|
38
|
+
//function can define new module after async load
|
|
39
|
+
window[id] = onLoad;
|
|
40
|
+
injectScript(formatUrl(req.toUrl(name), id));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
package/src/depend.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* Plugin to load JS files that have dependencies but aren't wrapped into
|
|
3
|
+
* `define` calls.
|
|
4
|
+
* Author: Miller Medeiros
|
|
5
|
+
* Version: 0.1.0 (2011/12/13)
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
*/
|
|
8
|
+
define(function () {
|
|
9
|
+
|
|
10
|
+
var rParts = /^(.*)\[([^\]]*)\]$/;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
|
|
14
|
+
//example: depend!bar[jquery,lib/foo]
|
|
15
|
+
load : function(name, req, onLoad, config){
|
|
16
|
+
var parts = rParts.exec(name);
|
|
17
|
+
|
|
18
|
+
req(parts[2].split(','), function(){
|
|
19
|
+
req([parts[1]], function(mod){
|
|
20
|
+
onLoad(mod);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
});
|
package/src/font.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* RequireJS plugin for loading web fonts using the WebFont Loader
|
|
3
|
+
* Author: Miller Medeiros
|
|
4
|
+
* Version: 0.2.0 (2011/12/06)
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
define(['propertyParser'], function (propertyParser) {
|
|
8
|
+
|
|
9
|
+
var rParts = /^([^,]+),([^\|]+)\|?/;
|
|
10
|
+
|
|
11
|
+
function parseName(name) {
|
|
12
|
+
var data = {},
|
|
13
|
+
vendors = name.split('|'),
|
|
14
|
+
n = vendors.length,
|
|
15
|
+
match;
|
|
16
|
+
|
|
17
|
+
while (n--) {
|
|
18
|
+
match = rParts.exec(vendors[n]);
|
|
19
|
+
data[ match[1] ] = propertyParser.parseProperties(match[2]);
|
|
20
|
+
}
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// API
|
|
25
|
+
return {
|
|
26
|
+
|
|
27
|
+
//example: font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]
|
|
28
|
+
load : function(name, req, onLoad, config){
|
|
29
|
+
if (config.isBuild) {
|
|
30
|
+
onLoad(null); //avoid errors on the optimizer
|
|
31
|
+
} else {
|
|
32
|
+
var data = parseName(name);
|
|
33
|
+
data.active = onLoad;
|
|
34
|
+
data.inactive = function(){
|
|
35
|
+
onLoad(false);
|
|
36
|
+
};
|
|
37
|
+
req([(document.location.protocol === 'https:'? 'https' : 'http') +'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'], function(){
|
|
38
|
+
WebFont.load(data);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
});
|
package/src/goog.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* RequireJS plugin for loading Google Ajax API modules thru `google.load`
|
|
3
|
+
* Author: Miller Medeiros
|
|
4
|
+
* Version: 0.2.0 (2011/12/06)
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
define(['async', 'propertyParser'], function (async, propertyParser) {
|
|
8
|
+
|
|
9
|
+
var rParts = /^([^,]+)(?:,([^,]+))?(?:,(.+))?/;
|
|
10
|
+
|
|
11
|
+
function parseName(name){
|
|
12
|
+
var match = rParts.exec(name),
|
|
13
|
+
data = {
|
|
14
|
+
moduleName : match[1],
|
|
15
|
+
version : match[2] || '1'
|
|
16
|
+
};
|
|
17
|
+
data.settings = propertyParser.parseProperties(match[3]);
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
load : function(name, req, onLoad, config){
|
|
23
|
+
if (config.isBuild) {
|
|
24
|
+
onLoad(null); //avoid errors on the optimizer
|
|
25
|
+
} else {
|
|
26
|
+
var data = parseName(name),
|
|
27
|
+
settings = data.settings;
|
|
28
|
+
|
|
29
|
+
settings.callback = onLoad;
|
|
30
|
+
|
|
31
|
+
req(['async!'+ (document.location.protocol === 'https:'? 'https' : 'http') +'://www.google.com/jsapi'], function(){
|
|
32
|
+
google.load(data.moduleName, data.version, settings);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
});
|
package/src/image.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* RequireJS Image Plugin
|
|
3
|
+
* Author: Miller Medeiros
|
|
4
|
+
* Version: 0.2.2 (2013/02/08)
|
|
5
|
+
* Released under the MIT license
|
|
6
|
+
*/
|
|
7
|
+
define(function(){
|
|
8
|
+
|
|
9
|
+
var CACHE_BUST_QUERY_PARAM = 'bust',
|
|
10
|
+
CACHE_BUST_FLAG = '!bust',
|
|
11
|
+
RELATIVE_FLAG = '!rel';
|
|
12
|
+
|
|
13
|
+
function noop(){}
|
|
14
|
+
|
|
15
|
+
function cacheBust(url){
|
|
16
|
+
url = url.replace(CACHE_BUST_FLAG, '');
|
|
17
|
+
url += (url.indexOf('?') < 0)? '?' : '&';
|
|
18
|
+
return url + CACHE_BUST_QUERY_PARAM +'='+ Math.round(2147483647 * Math.random());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
load : function(name, req, onLoad, config){
|
|
23
|
+
var img;
|
|
24
|
+
if(config.isBuild){
|
|
25
|
+
onLoad(null); //avoid errors on the optimizer since it can't inline image files
|
|
26
|
+
}else{
|
|
27
|
+
img = new Image();
|
|
28
|
+
img.onerror = function (err) {
|
|
29
|
+
onLoad.error(err);
|
|
30
|
+
};
|
|
31
|
+
img.onload = function(evt){
|
|
32
|
+
onLoad(img);
|
|
33
|
+
try {
|
|
34
|
+
delete img.onload; //release memory - suggested by John Hann
|
|
35
|
+
} catch(err) {
|
|
36
|
+
img.onload = noop; // IE7 :(
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
if (name.indexOf(RELATIVE_FLAG) !== -1) {
|
|
40
|
+
//load image relative to module path / baseUrl
|
|
41
|
+
img.src = req.toUrl( name.replace(RELATIVE_FLAG, '') );
|
|
42
|
+
} else {
|
|
43
|
+
img.src = name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
normalize : function (name, normalize) {
|
|
48
|
+
//used normalize to avoid caching references to a "cache busted" request
|
|
49
|
+
return (name.indexOf(CACHE_BUST_FLAG) === -1)? name : cacheBust(name);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
});
|
package/src/json.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** @license
|
|
2
|
+
* RequireJS plugin for loading JSON files
|
|
3
|
+
* - depends on Text plugin and it was HEAVILY "inspired" by it as well.
|
|
4
|
+
* Author: Miller Medeiros
|
|
5
|
+
* Version: 0.4.0 (2014/04/10)
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
*/
|
|
8
|
+
define(['text'], function(text){
|
|
9
|
+
|
|
10
|
+
var CACHE_BUST_QUERY_PARAM = 'bust',
|
|
11
|
+
CACHE_BUST_FLAG = '!bust',
|
|
12
|
+
jsonParse = (typeof JSON !== 'undefined' && typeof JSON.parse === 'function')? JSON.parse : function(val){
|
|
13
|
+
return eval('('+ val +')'); //quick and dirty
|
|
14
|
+
},
|
|
15
|
+
buildMap = {};
|
|
16
|
+
|
|
17
|
+
function cacheBust(url){
|
|
18
|
+
url = url.replace(CACHE_BUST_FLAG, '');
|
|
19
|
+
url += (url.indexOf('?') < 0)? '?' : '&';
|
|
20
|
+
return url + CACHE_BUST_QUERY_PARAM +'='+ Math.round(2147483647 * Math.random());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//API
|
|
24
|
+
return {
|
|
25
|
+
|
|
26
|
+
load : function(name, req, onLoad, config) {
|
|
27
|
+
if (( config.isBuild && (config.inlineJSON === false || name.indexOf(CACHE_BUST_QUERY_PARAM +'=') !== -1)) || (req.toUrl(name).indexOf('empty:') === 0)) {
|
|
28
|
+
//avoid inlining cache busted JSON or if inlineJSON:false
|
|
29
|
+
//and don't inline files marked as empty!
|
|
30
|
+
onLoad(null);
|
|
31
|
+
} else {
|
|
32
|
+
text.get(req.toUrl(name), function(data){
|
|
33
|
+
if (config.isBuild) {
|
|
34
|
+
buildMap[name] = data;
|
|
35
|
+
onLoad(data);
|
|
36
|
+
} else {
|
|
37
|
+
onLoad(jsonParse(data));
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
onLoad.error, {
|
|
41
|
+
accept: 'application/json'
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
normalize : function (name, normalize) {
|
|
48
|
+
// used normalize to avoid caching references to a "cache busted" request
|
|
49
|
+
if (name.indexOf(CACHE_BUST_FLAG) !== -1) {
|
|
50
|
+
name = cacheBust(name);
|
|
51
|
+
}
|
|
52
|
+
// resolve any relative paths
|
|
53
|
+
return normalize(name);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
//write method based on RequireJS official text plugin by James Burke
|
|
57
|
+
//https://github.com/jrburke/requirejs/blob/master/text.js
|
|
58
|
+
write : function(pluginName, moduleName, write){
|
|
59
|
+
if(moduleName in buildMap){
|
|
60
|
+
var content = buildMap[moduleName];
|
|
61
|
+
write('define("'+ pluginName +'!'+ moduleName +'", function(){ return '+ content +';});\n');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
};
|
|
66
|
+
});
|