3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * Provides useful information about the current operating system environment.
18 * Access the global instance stored in {@link Ext#os}. Example:
20 * if (Ext.os.is.Windows) {
21 * // Windows specific code here
24 * if (Ext.os.is.iOS) {
25 * // iPad, iPod, iPhone, etc.
28 * console.log("Version " + Ext.os.version);
30 * For a full list of supported values, refer to: {@link Ext.env.OS#is}
32 Ext.define('Ext.env.OS', {
39 blackberry: 'BlackBerry',
48 blackberry: 'BlackBerry ',
54 * A "hybrid" property, can be either accessed as a method call, i.e:
56 * if (Ext.os.is('Android')) { ... }
58 * or as an object with boolean properties, i.e:
60 * if (Ext.os.is.Android) { ... }
62 * Versions can be conveniently checked as well. For example:
64 * if (Ext.os.is.Android2) { ... } // Equivalent to (Ext.os.is.Android && Ext.os.version.equals(2))
66 * if (Ext.os.is.iOS32) { ... } // Equivalent to (Ext.os.is.iOS && Ext.os.version.equals(3.2))
68 * Note that only {@link Ext.Version#getMajor major component} and {@link Ext.Version#getShortVersion shortVersion}
69 * value of the version are available via direct property checking.
71 * Supported values are: iOS, iPad, iPhone, iPod, Android, WebOS, BlackBerry, MacOSX, Windows, Linux and Other
73 * @param {String} value The OS name to check
80 * @property {String} name
81 * Read-only - the full name of the current operating system
82 * Possible values are: iOS, Android, WebOS, BlackBerry, MacOSX, Windows, Linux and Other
87 * @property {Ext.Version} version
88 * Read-only, refer to {@link Ext.Version}
92 constructor: function() {
93 var userAgent = Ext.global.navigator.userAgent,
94 platform = Ext.global.navigator.platform,
95 selfClass = this.statics(),
96 osMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.osPrefixes).join(')|(?:') + '))([^\\s;]+)')),
102 name = selfClass.osNames[Ext.Object.getKey(selfClass.osPrefixes, osMatch[1])];
103 version = osMatch[2];
105 if (name === 'BlackBerry') {
106 actualVersionMatch = userAgent.match(/Version\/([\d\._]+)/);
108 if (actualVersionMatch) {
109 version = actualVersionMatch[1];
114 name = selfClass.osNames[(userAgent.toLowerCase().match(/mac|win|linux/i) || ['other'])[0]];
119 version: new Ext.Version(version)
122 this.is = function(name) {
123 return this.is[name] === true;
126 if (name === 'iOS') {
127 this.is[platform] = true;
130 this.is[this.name] = true;
131 this.is[this.name + (this.version.getMajor() || '')] = true;
132 this.is[this.name + this.version.getShortVersion()] = true;
134 Ext.Object.each(selfClass.osNames, function(key, name) {
135 this.is[name] = (this.name === name);
143 * @property {Ext.env.OS} os
145 * Global convenient instance of {@link Ext.env.OS}.
147 Ext.os = new Ext.env.OS();