-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext.js
50 lines (43 loc) · 1.04 KB
/
text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
define([ './has' ], function (has) {
var _getText;
if (has('host-browser')) {
_getText = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
callback(xhr.responseText);
};
xhr.open('GET', url, true);
xhr.send(null);
};
}
else if (has('host-node')) {
var fs = require.nodeRequire('fs');
_getText = function (url, callback) {
fs.readFile(url, { encoding: 'utf8' }, function (error, data) {
if (error) {
throw error;
}
callback(data);
});
};
}
else {
_getText = function () {
throw new Error('dojo/text not supported on this platform');
};
}
function getText(resourceId, load, moduleRequire) {
var cacheId = 'url:' + resourceId;
if (require.cache && require.cache[cacheId] != null) {
load(require.cache[cacheId]);
}
else {
_getText(moduleRequire ? moduleRequire.toUrl(resourceId) : resourceId, load);
}
}
getText.dynamic = true;
getText.load = function (resourceId, require, load) {
getText(resourceId, load, require);
};
return getText;
});