1 /*
2 * Sybase Hybrid App version 2.3
3 *
4 * PlatformIdentification.js
5 * This file will not be regenerated, so it is possible to modify it, but it
6 * is not recommended.
7 *
8 * Original file date: 2012-Oct-22
9 * Copyright (c) 2012 Sybase Inc. All rights reserved.
10 */
11
12 /**
13 * The namespace for the Hybrid Web Container javascript
14 * @namespace
15 */
16 hwc = (typeof hwc === "undefined" || !hwc) ? {} : hwc; // SUP 'namespace'
17
18 (function(hwc, window, undefined) {
19 // private variables
20 // platform identifiers are all calculated once and cached
21 var _isIOS = false, _isIPad = false, _isIOS5 = false, _isIOS6 = false, _isIOS7 = false, _isIOS4 = false,
22 _isBB = false, _isBB5 = false, _isBB5Touch = false, _isBB6NonTouch = false, _isBB7 = false,
23 _isAndroid = false, _isAndroid3 = false,
24 _isWindows = false, _isWinMobile = false;
25
26 // public API
27 /**
28 * Returns true if the hybrid app application is being run on an iOS (e.g. iPhone, iPad) platform.
29 * @feature Platform
30 * @return {Boolean} True if the hybrid app application is being run on an iOS (e.g. iPhone, iPad) platform.
31 * @memberOf hwc
32 * @public
33 */
34 hwc.isIOS = function() { return _isIOS; };
35 /**
36 * Returns true if the hybrid app application is being run on an iPad.
37 * @feature Platform
38 * @return {Boolean} True if the hybrid app application is being run on an iPad.
39 * @memberOf hwc
40 * @public
41 */
42 hwc.isIPad = function() { return _isIPad; };
43 /**
44 * Returns true if the hybrid app application is being run on iOS5
45 * @feature Platform
46 * @return {Boolean} True if the hybrid app application is being run on iOS5
47 * @memberOf hwc
48 * @public
49 */
50 hwc.isIOS5 = function() { return _isIOS5; };
51 /**
52 * Returns true if the hybrid app application is being run on iOS6
53 * @public
54 * @return {Boolean} True if the hybrid app application is being run on iOS6
55 * @memberOf hwc
56 * @public
57 */
58 hwc.isIOS6 = function() { return _isIOS6; };
59 /**
60 * Returns true if the hybrid app application is being run on iOS7
61 * @public
62 * @return {Boolean} True if the hybrid app application is being run on iOS7
63 * @memberOf hwc
64 * @public
65 */
66 hwc.isIOS7 = function() { return _isIOS7; };
67
68 /**
69 * Returns true if the hybrid app application is being run on iOS4
70 * @feature Platform
71 * @return {Boolean} True if the hybrid app application is being run on iOS4
72 * @memberOf hwc
73 * @public
74 */
75 hwc.isIOS4 = function() { return _isIOS4; };
76
77 /**
78 * Returns true if the hybrid app application is being run on a BlackBerry platform.
79 * @feature Platform
80 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry platform.
81 * @memberOf hwc
82 * @public
83 */
84 hwc.isBlackBerry = function() { return _isBB; };
85 /**
86 * Returns true if the hybrid app application is being run on a BlackBerry 5.0 OS
87 * @feature Platform
88 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 5.0 OS
89 * @memberOf hwc
90 * @public
91 */
92 hwc.isBlackBerry5 = function() { return _isBB5; };
93 /**
94 * Returns true if the hybrid app application is being run on a BlackBerry 7.x OS
95 * @feature Platform
96 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 7.x OS
97 * @memberOf hwc
98 * @public
99 */
100 hwc.isBlackBerry7 = function() { return _isBB7; };
101 /**
102 * Returns true if the hybrid app application is being run on a BlackBerry 5.0 OS with a touch screen
103 * @feature Platform
104 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 5.0 OS with a touch screen
105 * @memberOf hwc
106 * @public
107 */
108 hwc.isBlackBerry5WithTouchScreen = function() { return _isBB5Touch; };
109 /**
110 * Returns true if the hybrid app application is being run on a BlackBerry 6.0 OS without a touch screen
111 * @feature Platform
112 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 6.0 OS without a touch screen
113 * @memberOf hwc
114 * @public
115 */
116 hwc.isBlackBerry6NonTouchScreen = function() { return _isBB6NonTouch; };
117
118 /**
119 * Returns true if the hybrid app application is being run on a Windows Mobile platform.
120 * @feature Platform
121 * @return {Boolean} True if the hybrid app application is being run on a Windows Mobile platform.
122 * @memberOf hwc
123 * @public
124 */
125 hwc.isWindowsMobile = function() { return _isWinMobile; };
126 /**
127 * Returns true if the hybrid app application is being run on a Windows platform.
128 * @feature Platform
129 * @return {Boolean} True if the hybrid app application is being run on a Windows platform.
130 * @memberOf hwc
131 * @public
132 */
133 hwc.isWindows = function() { return _isWindows; };
134
135 /**
136 * Returns true if the hybrid app application is being run on an Android 3.0 OS
137 * @feature Platform
138 * @return {Boolean} True if the hybrid app application is being run on an Android 3.0 OS
139 * @memberOf hwc
140 * @public
141 */
142 hwc.isAndroid3 = function() { return _isAndroid3; };
143 /**
144 * Returns true if the hybrid app application is being run on an Android platform.
145 * @feature Platform
146 * @return {Boolean} True if the hybrid app application is being run on an Android platform.
147 * @memberOf hwc
148 * @public
149 */
150 hwc.isAndroid = function() { return _isAndroid; };
151
152
153 /**
154 * @private
155 * @return {Boolean} True if this code is running on a Blackberry 5 OS
156 */
157 function _isBlackBerry5() {
158 var ua = navigator.userAgent;
159 if (ua.indexOf("BlackBerry 9800") >= 0) {
160 return false;
161 }
162 if (ua.match(/5\.[0-9]\.[0-9]/i) !== null) {
163 return true;
164 }
165 return false;
166 }
167
168 /**
169 * @private
170 * @return {Boolean} True if this code is running on a Blackberry 5 OS with a touch screen
171 */
172 function _isBlackBerry5WithTouchScreen() {
173 if (isBlackBerry5()) {
174 var ua = navigator.userAgent;
175 if (ua.length > 12 && ua.substring(0, 12) === "BlackBerry95") {
176 return true;
177 }
178 }
179 return false;
180 }
181
182 /**
183 * @private
184 * @return {Boolean} True if this code is running on a Blackberry 6 OS with no touch screen
185 */
186 function _isBlackBerry6NonTouchScreen() {
187 if (navigator.userAgent.match(/Version\/6./i)) {
188 var ua = navigator.userAgent;
189 if ((ua.indexOf('9780') > 0) || (ua.indexOf('9700') > 0) || (ua.indexOf('9650') > 0) || (ua.indexOf('9300') > 0) || (ua.indexOf('9330') > 0)) {
190 return true;
191 }
192 }
193 return false;
194 }
195
196 /**
197 * @private
198 * @return {Boolean} True if this code is running on a Blackberry & OS
199 */
200 function _isBlackBerry7() {
201 if (navigator.userAgent.match(/Version\/7\.[0-9]\.[0-9]/i) !== null){
202 return true;
203 }
204 else {
205 return false;
206 }
207 }
208
209
210 /**
211 * Execute once to identify and cache
212 */
213 {
214 // apple products
215 _isIOS = ((navigator.platform.indexOf("i") === 0));
216 if( _isIOS ) {
217 _isIOS4 = (navigator.userAgent.match(/OS 4_[0-9_]+ like Mac OS X/i) !== null);
218 _isIOS5 = (navigator.userAgent.match(/OS 5_[0-9_]+ like Mac OS X/i) !== null);
219 _isIOS6 = (navigator.userAgent.match(/OS 6_[0-9_]+ like Mac OS X/i) !== null);
220 _isIOS7 = (navigator.userAgent.match(/OS 7_[0-9_]+ like Mac OS X/i) !== null);
221 _isIPad = (navigator.userAgent.match(/iPad/i) !== null);
222 }
223
224 // BlackBerry
225 _isBB = (navigator.platform === "BlackBerry");
226 if( _isBB ) {
227 _isBB5 = _isBlackBerry5();
228 _isBB7 = _isBlackBerry7();
229 _isBB5Touch = _isBlackBerry5WithTouchScreen();
230 _isBB6NonTouch = _isBlackBerry6NonTouchScreen();
231 }
232
233 // Android
234 _isAndroid = (navigator.userAgent.indexOf("Android") > -1);
235 if( _isAndroid ) {
236 _isAndroid3 = (navigator.userAgent.indexOf("3.0") > -1);
237 }
238
239 // Windows
240 _isWinMobile = (navigator.platform === "WinCE");
241 _isWindows = ( (navigator.platform === "Win32") || (navigator.platform === "Win64") || (navigator.platform === "MacIntel") ||
242 ( !_isAndroid && (navigator.platform.indexOf("Linux") === 0) ) );
243
244 //alert("Platform Identified: Win=" + _isWindows + ", BB=" + _isBB);
245 }
246 })(hwc, window);
247
248
249
250 /**
251 * Returns true if the hybrid app application is being run on an iOS (e.g. iPhone, iPad) platform.
252 * @private
253 * @return {Boolean} True if the hybrid app application is being run on an iOS (e.g. iPhone, iPad) platform.
254 */
255 function isIOS() { return hwc.isIOS(); }
256
257 /**
258 * Returns true if the hybrid app application is being run on iOS5
259 * @private
260 * @return {Boolean} True if the hybrid app application is being run on iOS5
261 */
262 function isIOS5() { return hwc.isIOS5(); }
263
264 /**
265 * Returns true if the hybrid app application is being run on an iPad.
266 * @private
267 * @return {Boolean} True if the hybrid app application is being run on an iPad.
268 */
269 function isIPad() { return hwc.isIPad(); }
270
271 /**
272 * Returns true if the hybrid app application is being run on a BlackBerry platform.
273 * @private
274 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry platform.
275 */
276 function isBlackBerry() { return hwc.isBlackBerry(); }
277
278 /**
279 * Returns true if the hybrid app application is being run on a BlackBerry 5.0 OS
280 * @private
281 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 5.0 OS
282 */
283 function isBlackBerry5() { return hwc.isBlackBerry5(); }
284
285 /**
286 * Returns true if the hybrid app application is being run on a BlackBerry 5.0 OS with a touch screen
287 * @private
288 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 5.0 OS with a touch screen
289 */
290 function isBlackBerry5WithTouchScreen() { return hwc.isBlackBerry5WithTouchScreen(); }
291
292 /**
293 * Returns true if the hybrid app application is being run on a BlackBerry 6.0 OS without a touch screen
294 * @private
295 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 6.0 OS without a touch screen
296 */
297 function isBlackBerry6NonTouchScreen() { return hwc.isBlackBerry6NonTouchScreen(); }
298
299 /**
300 * Returns true if the hybrid app application is being run on a BlackBerry 7.x OS
301 * @private
302 * @return {Boolean} True if the hybrid app application is being run on a BlackBerry 7.x OS
303 */
304 function isBlackBerry7() { return hwc.isBlackBerry7(); }
305
306 /**
307 * Returns true if the hybrid app application is being run on a Windows Mobile platform.
308 * @private
309 * @return {Boolean} True if the hybrid app application is being run on a Windows Mobile platform.
310 */
311 function isWindowsMobile() { return hwc.isWindowsMobile(); }
312
313 /**
314 * Returns true if the hybrid app application is being run on a Windows platform.
315 * @private
316 * @return {Boolean} True if the hybrid app application is being run on a Windows platform.
317 */
318 function isWindows() { return hwc.isWindows(); }
319
320 /**
321 * Returns true if the hybrid app application is being run on an Android platform.
322 * @private
323 * @return {Boolean} True if the hybrid app application is being run on an Android platform.
324 */
325 function isAndroid() { return hwc.isAndroid(); }
326
327 /**
328 * Returns true if the hybrid app application is being run on an Android 3.0 OS
329 * @private
330 * @return {Boolean} True if the hybrid app application is being run on an Android 3.0 OS
331 */
332 function isAndroid3() { return hwc.isAndroid3(); }
333