Path: blob/trunk/third_party/closure/goog/labs/useragent/device.js
4140 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Closure user device detection (based on user agent).8* @see http://en.wikipedia.org/wiki/User_agent9* For more information on browser brand, platform, or engine see the other10* sub-namespaces in goog.labs.userAgent (browser, platform, and engine).11*/1213goog.provide('goog.labs.userAgent.device');1415goog.require('goog.labs.userAgent');16goog.require('goog.labs.userAgent.util');1718/**19* Currently we detect the iPhone, iPod and Android mobiles (devices that have20* both Android and Mobile in the user agent string).21*22* @return {boolean} Whether the user is using a mobile device.23*/24goog.labs.userAgent.device.isMobile = function() {25'use strict';26if (goog.labs.userAgent.util.ASSUME_CLIENT_HINTS_SUPPORT ||27goog.labs.userAgent.useClientHints() &&28goog.labs.userAgent.util.getUserAgentData()) {29return goog.labs.userAgent.util.getUserAgentData().mobile;30}31return !goog.labs.userAgent.device.isTablet() &&32(goog.labs.userAgent.util.matchUserAgent('iPod') ||33goog.labs.userAgent.util.matchUserAgent('iPhone') ||34goog.labs.userAgent.util.matchUserAgent('Android') ||35goog.labs.userAgent.util.matchUserAgent('IEMobile'));36};373839/**40* Currently we detect Kindle Fire, iPad, and Android tablets (devices that have41* Android but not Mobile in the user agent string).42*43* @return {boolean} Whether the user is using a tablet.44*/45goog.labs.userAgent.device.isTablet = function() {46'use strict';47if (goog.labs.userAgent.util.ASSUME_CLIENT_HINTS_SUPPORT ||48(goog.labs.userAgent.useClientHints() &&49goog.labs.userAgent.util.getUserAgentData())) {50return !goog.labs.userAgent.util.getUserAgentData().mobile &&51(goog.labs.userAgent.util.matchUserAgent('iPad') ||52goog.labs.userAgent.util.matchUserAgent('Android') ||53goog.labs.userAgent.util.matchUserAgent('Silk'));54}55return goog.labs.userAgent.util.matchUserAgent('iPad') ||56(goog.labs.userAgent.util.matchUserAgent('Android') &&57!goog.labs.userAgent.util.matchUserAgent('Mobile')) ||58goog.labs.userAgent.util.matchUserAgent('Silk');59};606162/**63* @return {boolean} Whether the user is using a desktop computer (which we64* assume to be the case if they are not using either a mobile or tablet65* device).66*/67goog.labs.userAgent.device.isDesktop = function() {68'use strict';69return !goog.labs.userAgent.device.isMobile() &&70!goog.labs.userAgent.device.isTablet();71};727374