Debian Codegraph @

closure-library/closure/goog/labs/useragent/device.js

raw
1 // Copyright 2013 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Closure user device detection (based on user agent).
17 * @see http://en.wikipedia.org/wiki/User_agent
18 * For more information on browser brand, platform, or engine see the other
19 * sub-namespaces in goog.labs.userAgent (browser, platform, and engine).
20 *
21 */
22
23 goog.provide('goog.labs.userAgent.device');
24
25 goog.require('goog.labs.userAgent.util');
26
27
28 /**
29 * Currently we detect the iPhone, iPod and Android mobiles (devices that have
30 * both Android and Mobile in the user agent string).
31 *
32 * @return {boolean} Whether the user is using a mobile device.
33 */
34 goog.labs.userAgent.device.isMobile = function() {
35 return !goog.labs.userAgent.device.isTablet() &&
36 (goog.labs.userAgent.util.matchUserAgent('iPod') ||
37 goog.labs.userAgent.util.matchUserAgent('iPhone') ||
38 goog.labs.userAgent.util.matchUserAgent('Android') ||
39 goog.labs.userAgent.util.matchUserAgent('IEMobile'));
40 };
41
42
43 /**
44 * Currently we detect Kindle Fire, iPad, and Android tablets (devices that have
45 * Android but not Mobile in the user agent string).
46 *
47 * @return {boolean} Whether the user is using a tablet.
48 */
49 goog.labs.userAgent.device.isTablet = function() {
50 return goog.labs.userAgent.util.matchUserAgent('iPad') ||
51 (goog.labs.userAgent.util.matchUserAgent('Android') &&
52 !goog.labs.userAgent.util.matchUserAgent('Mobile')) ||
53 goog.labs.userAgent.util.matchUserAgent('Silk');
54 };
55
56
57 /**
58 * @return {boolean} Whether the user is using a desktop computer (which we
59 * assume to be the case if they are not using either a mobile or tablet
60 * device).
61 */
62 goog.labs.userAgent.device.isDesktop = function() {
63 return !goog.labs.userAgent.device.isMobile() &&
64 !goog.labs.userAgent.device.isTablet();
65 };