Path: blob/trunk/third_party/closure/goog/labs/useragent/device.js
2868 views
// Copyright 2013 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Closure user device detection (based on user agent).16* @see http://en.wikipedia.org/wiki/User_agent17* For more information on browser brand, platform, or engine see the other18* sub-namespaces in goog.labs.userAgent (browser, platform, and engine).19*20*/2122goog.provide('goog.labs.userAgent.device');2324goog.require('goog.labs.userAgent.util');252627/**28* Currently we detect the iPhone, iPod and Android mobiles (devices that have29* both Android and Mobile in the user agent string).30*31* @return {boolean} Whether the user is using a mobile device.32*/33goog.labs.userAgent.device.isMobile = function() {34return !goog.labs.userAgent.device.isTablet() &&35(goog.labs.userAgent.util.matchUserAgent('iPod') ||36goog.labs.userAgent.util.matchUserAgent('iPhone') ||37goog.labs.userAgent.util.matchUserAgent('Android') ||38goog.labs.userAgent.util.matchUserAgent('IEMobile'));39};404142/**43* Currently we detect Kindle Fire, iPad, and Android tablets (devices that have44* Android but not Mobile in the user agent string).45*46* @return {boolean} Whether the user is using a tablet.47*/48goog.labs.userAgent.device.isTablet = function() {49return goog.labs.userAgent.util.matchUserAgent('iPad') ||50(goog.labs.userAgent.util.matchUserAgent('Android') &&51!goog.labs.userAgent.util.matchUserAgent('Mobile')) ||52goog.labs.userAgent.util.matchUserAgent('Silk');53};545556/**57* @return {boolean} Whether the user is using a desktop computer (which we58* assume to be the case if they are not using either a mobile or tablet59* device).60*/61goog.labs.userAgent.device.isDesktop = function() {62return !goog.labs.userAgent.device.isMobile() &&63!goog.labs.userAgent.device.isTablet();64};656667