-
Notifications
You must be signed in to change notification settings - Fork 129
/
ready.js
30 lines (23 loc) · 857 Bytes
/
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
/*!
* domready (c) Dustin Diaz 2014 - License MIT
*/
!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 fns = [], listener
, doc = typeof document === 'object' && document
, hack = doc && 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)
}
});