forked from Prinzhorn/twitter-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (51 loc) · 1.24 KB
/
index.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
(function(window) {
var TwitterWidgetsLoader = {
src: 'https://platform.twitter.com/widgets.js',
loading: false,
listeners: [],
interval: 50,
load: function(callback) {
var _this = this;
if(callback) {
this.listeners.push(callback);
}
if (window.twttr && window.twttr.widgets) {
setTimeout(function() {
_this._done();
});
return;
}
if (this.loading) {
return;
}
this.loading = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = this.src;
script.addEventListener('error', function() {
_this._done(new Error('Twitter widgets JS failed to load. Is there an ad blocker enabled?'));
});
document.body.appendChild(script);
this._poll();
},
_poll: function() {
if (window.twttr && window.twttr.widgets) {
return this._done();
}
var _this = this;
setTimeout(function() {
_this._poll();
}, this.interval);
},
_done: function(error) {
while (this.listeners.length) {
this.listeners.pop()(error, window.twttr);
}
}
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = TwitterWidgetsLoader;
} else {
window.TwitterWidgetsLoader = TwitterWidgetsLoader;
}
})(window);