-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (42 loc) · 1.08 KB
/
index.js
File metadata and controls
49 lines (42 loc) · 1.08 KB
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
'use strict'
class Platform {
constructor () {
this.windowLoadListenderAttached = false
this.isReady = false
this.readyCallbacks = []
let waitForWindow = () => {
this.windowLoadListenderAttached = true
window.addEventListener('load', onWindowLoad, false)
}
let onWindowLoad = () => {
if (window.cordova) {
document.addEventListener('deviceready', onDeviceReady, false)
} else {
onDeviceReady()
}
if (this.windowLoadListenderAttached) {
window.removeEventListener('load', onWindowLoad, false)
}
}
let onDeviceReady = () => {
this.isReady = true
this.readyCallbacks.forEach((cb) => { cb() })
this.readyCallbacks = []
}
// Wait for window to load before listening for deviceready
if (document.readyState === 'complete') {
onWindowLoad()
} else {
waitForWindow()
}
}
ready (cb) {
if (this.isReady) {
cb()
} else {
this.readyCallbacks.push(cb)
}
}
}
// Expose `Platform` as a node module
module.exports = new Platform()