Path: blob/trunk/third_party/closure/goog/useragent/platform.js
4504 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Utilities for getting details about the user's platform.8*/910goog.provide('goog.userAgent.platform');1112goog.require('goog.string');13goog.require('goog.userAgent');141516/**17* Detects the version of the OS/platform the browser is running in. Not18* supported for Linux, where an empty string is returned.19*20* @private21* @return {string} The platform version.22*/23goog.userAgent.platform.determineVersion_ = function() {24'use strict';25var re;26if (goog.userAgent.WINDOWS) {27re = /Windows NT ([0-9.]+)/;28var match = re.exec(goog.userAgent.getUserAgentString());29if (match) {30return match[1];31} else {32return '0';33}34} else if (goog.userAgent.MAC) {35re = /1[0|1][_.][0-9_.]+/;36var match = re.exec(goog.userAgent.getUserAgentString());37// Note: some old versions of Camino do not report an OSX version.38// Default to 10.39return match ? match[0].replace(/_/g, '.') : '10';40} else if (goog.userAgent.ANDROID) {41re = /Android\s+([^\);]+)(\)|;)/;42var match = re.exec(goog.userAgent.getUserAgentString());43return match ? match[1] : '';44} else if (45goog.userAgent.IPHONE || goog.userAgent.IPAD || goog.userAgent.IPOD) {46re = /(?:iPhone|CPU)\s+OS\s+(\S+)/;47var match = re.exec(goog.userAgent.getUserAgentString());48// Report the version as x.y.z and not x_y_z49return match ? match[1].replace(/_/g, '.') : '';50}5152return '';53};545556/**57* The version of the platform. We don't determine the version of Linux.58* For Windows, we only look at the NT version. Non-NT-based versions59* (e.g. 95, 98, etc.) are given version 0.0.60* @type {string}61*/62goog.userAgent.platform.VERSION = goog.userAgent.platform.determineVersion_();636465/**66* Whether the user agent platform version is higher or the same as the given67* version.68*69* @param {string|number} version The version to check.70* @return {boolean} Whether the user agent platform version is higher or the71* same as the given version.72*/73goog.userAgent.platform.isVersion = function(version) {74'use strict';75return goog.string.compareVersions(76goog.userAgent.platform.VERSION, version) >= 0;77};787980