-
Notifications
You must be signed in to change notification settings - Fork 3
/
modules-environment.js
125 lines (111 loc) · 3.03 KB
/
modules-environment.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
(function() {
var mod = {};
// TODO: Should also plug the CocoonJs app extensions with CocoonJS.App.DeviceInfo
// There is multiple things on the object navigator aslo
/**
* window.force.modules.environment.isEjecta()
*/
mod.isEjecta = function () {
return ((window.ejecta && window.ejecta.include && window.ejecta.openURL) ? true : false);
};
/**
* window.force.modules.environment.isCocoonJs()
*/
mod.isCocoonJs = function () {
return navigator.isCocoonJS ? true : false;
};
/**
* window.force.modules.environment.isIos()
*/
mod.isIos = function() {
return mod.getIosVersion() ? true : false;
};
/**
* window.force.modules.environment.isTizen()
*/
mod.isTizen = function() {
return window.tizen ? true : false;
};
/**
* window.force.modules.environment.isAndroid()
*/
mod.isAndroid = function() {
return navigator.userAgent.match(/Android/i) ? true : false;
};
/**
* window.force.modules.environment.isBlackBerry()
*/
mod.isBlackBerry = function() {
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
};
/**
* window.force.modules.environment.isWindowsMobile()
*/
mod.isWindowsMobile = function() {
return navigator.userAgent.match(/IEMobile/i) ? true : false;
};
/**
* window.force.modules.environment.isOperaMini()
*/
mod.isOperaMini = function() {
return navigator.userAgent.match(/Opera Mini/i) ? true : false;
};
/**
* window.force.modules.environment.getIosVersion()
* return an array with each version number, ex: [5, 1, 1] for 5.1.1
*/
mod.getIosVersion = function() {
// This function is only for browser, Ejecta && CocoonJs should be managed differently
// TODO: what about Cordova?
if (!mod.isCocoonJs() && !mod.isEjecta()) {
if (navigator && navigator.platform && /iP(hone|od|ad)/.test(navigator.platform)) {
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
}
return null;
};
/**
* window.force.modules.environment.getIosDeviceType()
*/
mod.getIosDeviceType = function() {
if (navigator && navigator.platform) {
var s = navigator.platform;
if (/iPhone/.test(s)) {
return 'iPhone';
} else if (/iPad/.test(s)) {
return 'iPad';
} else if (/iPod/.test(s)) {
return 'iPod';
}
}
return null;
};
/**
* window.force.modules.environment.isDesktopBrowser()
*/
mod.isDesktopBrowser = function() {
return (
!mod.isEjecta() &&
!mod.isCocoonJs() &&
!mod.isIos() &&
!mod.isTizen() &&
!mod.isAndroid() &&
!mod.isBlackBerry() &&
!mod.isWindowsMobile() &&
!mod.isOperaMini()
);
};
/**
* window.force.modules.environment.reboot()
*/
mod.reboot = function() {
if (mod.isCocoonJs()) {
CocoonJS.App.reload();
} else {
window.location.reload();
}
};
// expose module
window.force.expose('window.force.modules.environment', mod);
})();