-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
33 lines (28 loc) · 1.14 KB
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
var loadingProgress = document.querySelector('.loading.progress'),
loadingDeley = 400;
function loadDeferredStyles() {
var head = document.head || document.getElementsByTagName('head')[0],
stylesDeferred = document.querySelector('.deferred.styles');
head.innerHTML += stylesDeferred.textContent;
// Use the last <img> if any otherwise <link> as a sentinel of page readiness
var loadingSentinel = document.querySelector('img:last-child') ||
document.querySelector('link:last-child');
if (loadingSentinel && !loadingSentinel.complete) {
loadingSentinel.onload = hideLoadingScreen;
loadingSentinel.onerror = hideLoadingScreen;
return;
}
hideLoadingScreen();
};
function hideLoadingScreen() {
window.setTimeout(function() {
loadingProgress.className += ' hidden';
}, loadingDeley);
}
var reqAniFrame =
window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
if (reqAniFrame)
reqAniFrame(loadDeferredStyles);
else
window.addEventListener('load', loadDeferredStyles);