Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 1aeb1bc

Browse files
committed
created
1 parent 6a85eea commit 1aeb1bc

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

css.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var waitSeconds = 10;
2+
3+
var head = document.getElementsByTagName('head')[0];
4+
5+
var isWebkit = !!window.navigator.userAgent.match(/AppleWebKit\/([^ ;]*)/);
6+
var webkitLoadCheck = function(link, callback) {
7+
setTimeout(function() {
8+
for (var i = 0; i < document.styleSheets.length; i++) {
9+
var sheet = document.styleSheets[i];
10+
if (sheet.href == link.href)
11+
return callback();
12+
}
13+
webkitLoadCheck(link, callback);
14+
}, 10);
15+
}
16+
17+
var noop = function() {}
18+
19+
var loadCSS = function(url, callback, errback) {
20+
var timeout = setTimeout(function() {
21+
errback('Unable to load CSS');
22+
}, waitSeconds * 1000);
23+
var _callback = function() {
24+
clearTimeout(timeout);
25+
link.onload = noop;
26+
setTimeout(callback, 7);
27+
}
28+
var link = document.createElement('link') ;
29+
link.type = 'text/css';
30+
link.rel = 'stylesheet';
31+
link.href = url;
32+
33+
if (!isWebkit)
34+
link.onload = _callback;
35+
else
36+
webkitLoadCheck(link, _callback);
37+
38+
head.appendChild(link);
39+
}
40+
41+
42+
module.exports = function(name, address, fetch, callback, errback) {
43+
loadCSS(address, callback, errback);
44+
}

0 commit comments

Comments
 (0)