-
Notifications
You must be signed in to change notification settings - Fork 8
/
loader.js
54 lines (42 loc) · 1 KB
/
loader.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
// Fixed a Broken UMD from twitter-widgets
// aka https://github.com/Prinzhorn/twitter-widgets
var TwitterWidgetsLoader = {
src: '//platform.twitter.com/widgets.js',
loading: false,
listeners: [],
interval: 50,
load: function (callback) {
var _this = this
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
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 () {
while (this.listeners.length) {
this.listeners.pop()(window.twttr)
}
}
}
module.exports = TwitterWidgetsLoader