-
Notifications
You must be signed in to change notification settings - Fork 6
/
jqShim.js
42 lines (42 loc) · 1.27 KB
/
jqShim.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
(function() {
"use strict";
var q = [], shim = {}, qfunc, shjq, shjqDone, ind;
// only do this if jQuery hasn't been loaded yet
if (!window.jQuery) {
qfunc = function(f) {
q.push(f);
}
shim.ready = function(f) {
qfunc(f);
}
shjq = window.jQuery = window.$ = function(arg) {
if (typeof arg == 'function') {
qfunc(arg);
}
return shim;
}
window.checkJQ = function() {
if (!shjqDone()) {
ind = setTimeout(checkJQ, 100);
}
}
// we will wait for jQuery to exist
ind = setTimeout(checkJQ, 100);
shjqDone = function() {
// only do this if a jQuery other than our's is now present
if (window.jQuery !== shjq) {
clearTimeout(ind);
var f = q.shift();
// hurray, jQuery is here now! Send our friends over there
while(f) {
jQuery(f);
f = q.shift();
}
// we are done, clean up
ind = shim = qfunc = shjq = shjqDone = window.checkJQ = null;
return true
}
return false
}
}
})();