-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathjquip.docready.js
79 lines (71 loc) · 2.2 KB
/
jquip.docready.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$['plug']("docready", function ($) {
var win = window,
doc = document,
DOMContentLoaded,
readyBound,
readyList = [],
isReady = false,
readyWait = 1;
$['hook'](function (sel, ctx) {
if (typeof sel == "function") {
this['ready'](sel);
return true;
}
});
function doScrollCheck() {
if (isReady) return;
try {
doc.documentElement.doScroll("left");
} catch (e) {
setTimeout(doScrollCheck, 1);
return;
}
ready();
}
function ready(wait) {
if (wait === true) readyWait--;
if (!readyWait || (wait !== true && !isReady)) {
if (!doc.body) return setTimeout(ready, 1);
isReady = true;
if (wait !== true && --readyWait > 0) return;
if (readyList) {
var fn, i = 0, ready = readyList;
readyList = null;
while ((fn = ready[i++])) fn.call(doc, $);
if ($['fn']['trigger']) $(doc)['trigger']("ready")['unbind']("ready");
}
}
} $['ready'] = ready;
DOMContentLoaded = doc.addEventListener
? function () {
doc.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
ready(); }
: function () {
if (doc.readyState === "complete") {
doc.detachEvent("onreadystatechange", DOMContentLoaded);
ready();
}
};
$['bindReady'] = function() {
if (readyBound) return;
readyBound = true;
if (doc.readyState === "complete") return setTimeout(ready, 1);
if (doc.addEventListener) {
doc.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
win.addEventListener("load", ready, false);
} else if (doc.attachEvent) {
doc.attachEvent("onreadystatechange", DOMContentLoaded);
win.attachEvent("onload", ready);
var toplevel = false;
try { toplevel = window.frameElement == null; } catch (e) { }
if (doc.documentElement.doScroll && toplevel) doScrollCheck();
}
};
$['fn']['ready'] = function (fn) {
$['bindReady']();
if (isReady) fn.call(doc, $);
else if (readyList) readyList.push(fn);
return this;
};
if (!$['init']) $(document)['ready']($['onload']);
});