-
Notifications
You must be signed in to change notification settings - Fork 4
/
cordova.js
47 lines (40 loc) · 1 KB
/
cordova.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
var cordova = {
initialize: function () {
/* istanbul ignore if */
if (window.cordova) {
this.present = true;
} else {
this.present = false;
}
if (this.present) {
document.addEventListener('deviceready', this.onReady.bind(this));
} else {
window.addEventListener('load', this.onReady.bind(this));
}
this.isReady = false;
this.readyCallbacks = [];
},
_onReady: function () {
this.iOS = /iP(hone|ad|od)/.test(window.navigator.userAgent);
this.iOS7App = (this.present &&
window.device.platform === 'iOS' &&
parseInt(window.device.version) >= 7);
},
onReady: function () {
this.isReady = true;
this._onReady();
for (var i = 0, v = this.readyCallbacks, n = v.length; i < n; i++) {
v[i]();
}
v.length = [];
},
ready: function (cb) {
if (this.isReady) {
cb();
} else {
this.readyCallbacks.push(cb);
}
}
};
cordova.initialize();
module.exports = cordova;