aboutsummaryrefslogtreecommitdiff
path: root/point/libs/text
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-08-10 17:28:37 +0200
committerPacien TRAN-GIRARD2014-08-10 17:28:37 +0200
commite7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 (patch)
tree189988e3e272b806262d1df6b87f1da089ef4af8 /point/libs/text
parenta32e898c8d7ad3774f5654e88bb24d5c26482137 (diff)
downloadwhatsthepoint-e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2.tar.gz
First versionHEADmaster
Diffstat (limited to 'point/libs/text')
-rw-r--r--point/libs/text/text.js389
1 files changed, 389 insertions, 0 deletions
diff --git a/point/libs/text/text.js b/point/libs/text/text.js
new file mode 100644
index 0000000..2748bed
--- /dev/null
+++ b/point/libs/text/text.js
@@ -0,0 +1,389 @@
1/**
2 * @license RequireJS text 2.0.12 Copyright (c) 2010-2014, 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, XMLHttpRequest, ActiveXObject,
8 define, window, process, Packages,
9 java, location, Components, FileUtils */
10
11define(['module'], function (module) {
12 'use strict';
13
14 var text, fs, Cc, Ci, xpcIsWindows,
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.12',
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
68 if (xhr) {
69 progIds = [progId]; // so faster next time
70 break;
71 }
72 }
73 }
74
75 return xhr;
76 },
77
78 /**
79 * Parses a resource name into its component parts. Resource names
80 * look like: module/name.ext!strip, where the !strip part is
81 * optional.
82 * @param {String} name the resource name
83 * @returns {Object} with properties "moduleName", "ext" and "strip"
84 * where strip is a boolean.
85 */
86 parseName: function (name) {
87 var modName, ext, temp,
88 strip = false,
89 index = name.indexOf("."),
90 isRelative = name.indexOf('./') === 0 ||
91 name.indexOf('../') === 0;
92
93 if (index !== -1 && (!isRelative || index > 1)) {
94 modName = name.substring(0, index);
95 ext = name.substring(index + 1, name.length);
96 } else {
97 modName = name;
98 }
99
100 temp = ext || modName;
101 index = temp.indexOf("!");
102 if (index !== -1) {
103 //Pull off the strip arg.
104 strip = temp.substring(index + 1) === "strip";
105 temp = temp.substring(0, index);
106 if (ext) {
107 ext = temp;
108 } else {
109 modName = temp;
110 }
111 }
112
113 return {
114 moduleName: modName,
115 ext: ext,
116 strip: strip
117 };
118 },
119
120 xdRegExp: /^((\w+)\:)?\/\/([^\/\\]+)/,
121
122 /**
123 * Is an URL on another domain. Only works for browser use, returns
124 * false in non-browser environments. Only used to know if an
125 * optimized .js version of a text resource should be loaded
126 * instead.
127 * @param {String} url
128 * @returns Boolean
129 */
130 useXhr: function (url, protocol, hostname, port) {
131 var uProtocol, uHostName, uPort,
132 match = text.xdRegExp.exec(url);
133 if (!match) {
134 return true;
135 }
136 uProtocol = match[2];
137 uHostName = match[3];
138
139 uHostName = uHostName.split(':');
140 uPort = uHostName[1];
141 uHostName = uHostName[0];
142
143 return (!uProtocol || uProtocol === protocol) &&
144 (!uHostName || uHostName.toLowerCase() === hostname.toLowerCase()) &&
145 ((!uPort && !uHostName) || uPort === port);
146 },
147
148 finishLoad: function (name, strip, content, onLoad) {
149 content = strip ? text.strip(content) : content;
150 if (masterConfig.isBuild) {
151 buildMap[name] = content;
152 }
153 onLoad(content);
154 },
155
156 load: function (name, req, onLoad, config) {
157 //Name has format: some.module.filext!strip
158 //The strip part is optional.
159 //if strip is present, then that means only get the string contents
160 //inside a body tag in an HTML string. For XML/SVG content it means
161 //removing the <?xml ...?> declarations so the content can be inserted
162 //into the current doc without problems.
163
164 // Do not bother with the work if a build and text will
165 // not be inlined.
166 if (config && config.isBuild && !config.inlineText) {
167 onLoad();
168 return;
169 }
170
171 masterConfig.isBuild = config && config.isBuild;
172
173 var parsed = text.parseName(name),
174 nonStripName = parsed.moduleName +
175 (parsed.ext ? '.' + parsed.ext : ''),
176 url = req.toUrl(nonStripName),
177 useXhr = (masterConfig.useXhr) ||
178 text.useXhr;
179
180 // Do not load if it is an empty: url
181 if (url.indexOf('empty:') === 0) {
182 onLoad();
183 return;
184 }
185
186 //Load the text. Use XHR if possible and in a browser.
187 if (!hasLocation || useXhr(url, defaultProtocol, defaultHostName, defaultPort)) {
188 text.get(url, function (content) {
189 text.finishLoad(name, parsed.strip, content, onLoad);
190 }, function (err) {
191 if (onLoad.error) {
192 onLoad.error(err);
193 }
194 });
195 } else {
196 //Need to fetch the resource across domains. Assume
197 //the resource has been optimized into a JS module. Fetch
198 //by the module name + extension, but do not include the
199 //!strip part to avoid file system issues.
200 req([nonStripName], function (content) {
201 text.finishLoad(parsed.moduleName + '.' + parsed.ext,
202 parsed.strip, content, onLoad);
203 });
204 }
205 },
206
207 write: function (pluginName, moduleName, write, config) {
208 if (buildMap.hasOwnProperty(moduleName)) {
209 var content = text.jsEscape(buildMap[moduleName]);
210 write.asModule(pluginName + "!" + moduleName,
211 "define(function () { return '" +
212 content +
213 "';});\n");
214 }
215 },
216
217 writeFile: function (pluginName, moduleName, req, write, config) {
218 var parsed = text.parseName(moduleName),
219 extPart = parsed.ext ? '.' + parsed.ext : '',
220 nonStripName = parsed.moduleName + extPart,
221 //Use a '.js' file name so that it indicates it is a