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