-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
58 lines (55 loc) · 1.93 KB
/
script.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
51
52
53
54
55
56
57
58
'use strict';
(function(root, doc) {
function createElementFromHTML(htmlString) {
var div = doc.createElement('div');
div.innerHTML = htmlString.trim();
return div.firstChild;
}
function loadDeferredStyles() {
var loading = 0,
loaded = doc.styleSheets.length;
doc.head
.querySelectorAll('.webpack-plugin-defer')
.forEach(function(node) {
if (/^\s*<link[\s\S]+rel="stylesheet"/.test(node.textContent)) {
doc.head.replaceChild(
createElementFromHTML(node.textContent),
node
);
loading++;
}
});
var expected = loaded + loading;
var check = setInterval(function() {
if (doc.styleSheets.length >= expected) {
setTimeout(function() {
doc.getElementById(
'webpack-plugin-loader'
).style.opacity = 0;
setTimeout(function() {
doc.querySelectorAll(
'#webpack-plugin-loader,' +
'script[src*="webpack-loading.js"],' +
'link[href*="webpack-loading.css"]'
).forEach(function(node) {
node.parentElement.removeChild(node);
});
}, 500);
}, 500);
clearInterval(check);
}
}, 10);
}
var raf =
root.requestAnimationFrame ||
root.mozRequestAnimationFrame ||
root.webkitRequestAnimationFrame ||
root.msRequestAnimationFrame;
if (raf) {
raf(function() {
root.setTimeout(loadDeferredStyles, 0);
});
} else {
root.addEventListener('load', loadDeferredStyles);
}
})(window, document);