forked from ded/domready
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ready.js
39 lines (36 loc) · 1.07 KB
/
ready.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
/*!
* domready (c) Dustin Diaz 2014 - License MIT
* ie10 fix - Mikael Kristiansson 2019
*/
!(function(name, definition) {
if (typeof module != "undefined") module.exports = definition();
else if (typeof define == "function" && typeof define.amd == "object")
define(definition);
else this[name] = definition();
})("domready", function() {
var ie10 = false;
if (navigator.appVersion.indexOf("MSIE 10") !== -1) {
ie10 = true;
}
var fns = [],
listener,
doc = typeof document === "object" && document,
hack = ie10
? doc.documentElement.doScroll("left")
: doc.documentElement.doScroll,
domContentLoaded = "DOMContentLoaded",
loaded =
doc && (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
if (!loaded && doc)
doc.addEventListener(
domContentLoaded,
(listener = function() {
doc.removeEventListener(domContentLoaded, listener);
loaded = 1;
while ((listener = fns.shift())) listener();
})
);
return function(fn) {
loaded ? setTimeout(fn, 0) : fns.push(fn);
};
});