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 * Provide useful information about the current operating system environment. Access the global instance stored in Ext.os. Example:
19 * if (Ext.os.is.Windows) {
20 * // Windows specific code here
23 * if (Ext.os.is.iOS) {
24 * // iPad, iPod, iPhone, etc.
27 * console.log("Version " + Ext.os.version);
30 * For a full list of supported values, refer to: {@link Ext.env.OS#is 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')) { ... }
59 * or as an object with boolean properties, i.e:
61 * if (Ext.os.is.Android) { ... }
64 * Versions can be conveniently checked as well. For example:
66 * if (Ext.os.is.Android2) { ... } // Equivalent to (Ext.os.is.Android && Ext.os.version.equals(2))
68 * if (Ext.os.is.iOS32) { ... } // Equivalent to (Ext.os.is.iOS && Ext.os.version.equals(3.2))
71 * Note that only {@link Ext.Version#getMajor major component} and {@link Ext.Version#getShortVersion shortVersion}
72 * value of the version are available via direct property checking.
74 * Supported values are: iOS, iPad, iPhone, iPod, Android, WebOS, BlackBerry, MacOSX, Windows, Linux and Other
76 * @param {String} value The OS name to check
83 * Read-only - the full name of the current operating system
84 * Possible values are: iOS, Android, WebOS, BlackBerry, MacOSX, Windows, Linux and Other
90 * Read-only, refer to {@link Ext.Version}
95 constructor: function() {
96 var userAgent = Ext.global.navigator.userAgent,
97 platform = Ext.global.navigator.platform,
98 selfClass = this.statics(),
99 osMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.osPrefixes).join(')|(?:') + '))([^\\s;]+)')),
105 name = selfClass.osNames[Ext.Object.getKey(selfClass.osPrefixes, osMatch[1])];
106 version = osMatch[2];
108 if (name === 'BlackBerry') {
109 actualVersionMatch = userAgent.match(/Version\/([\d\._]+)/);
111 if (actualVersionMatch) {
112 version = actualVersionMatch[1];
117 name = selfClass.osNames[(userAgent.toLowerCase().match(/mac|win|linux/i) || ['other'])[0]];
122 version: new Ext.Version(version)
125 this.is = function(name) {
126 return this.is[name] === true;
129 if (name === 'iOS') {
130 this.is[platform] = true;
133 this.is[this.name] = true;
134 this.is[this.name + (this.version.getMajor() || '')] = true;
135 this.is[this.name + this.version.getShortVersion()] = true;
137 Ext.Object.each(selfClass.osNames, function(key, name) {
138 this.is[name] = (this.name === name);
145 Ext.os = new Ext.env.OS();