-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathjs.js
40 lines (37 loc) · 1.11 KB
/
js.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
/**
* ESL (Enterprise Standard Loader)
* Copyright 2013 Baidu Inc. All rights reserved.
*
* @file JS Loader-Plugin
* @author errorrik([email protected])
*/
// 构建环境暂不支持分析,为了能合并该plugin到loader里,
// 只能暂时使用具名id
define('js', {
load: function (resourceId, req, load) {
var script = document.createElement('script');
script.src = req.toUrl(resourceId);
script.async = true;
if (script.readyState) {
script.onreadystatechange = onload;
}
else {
script.onload = onload;
}
function onload() {
var readyState = script.readyState;
if (
typeof readyState === 'undefined'
|| /^(loaded|complete)$/.test(readyState)
) {
script.onload = script.onreadystatechange = null;
script = null;
load(true);
}
}
var parent = document.getElementsByTagName('head')[0]
|| document.body;
parent.appendChild(script);
parent = null;
}
});