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.
16 * Provides useful information about the current browser.
17 * Should not be manually instantiated unless for unit-testing; access the global instance
18 * stored in {@link Ext#browser} instead. Example:
20 * if (Ext.browser.is.IE) {
21 * // IE specific code here
24 * if (Ext.browser.is.WebKit) {
25 * // WebKit specific code here
28 * console.log("Version " + Ext.browser.version);
30 * For a full list of supported values, refer to: {@link Ext.env.Browser#is}
32 Ext.define('Ext.env.Browser', {
50 webkit: 'AppleWebKit/',
65 * @property {Boolean} isSecure
66 * True if the page is running over SSL
71 * @property {Boolean} isStrict
72 * True if the document is in strict mode
77 * A "hybrid" property, can be either accessed as a method call, i.e:
79 * if (Ext.browser.is('IE')) { ... }
81 * or as an object with boolean properties, i.e:
83 * if (Ext.browser.is.IE) { ... }
85 * Versions can be conveniently checked as well. For example:
87 * if (Ext.browser.is.IE6) { ... } // Equivalent to (Ext.browser.is.IE && Ext.browser.version.equals(6))
89 * Note that only {@link Ext.Version#getMajor major component} and {@link Ext.Version#getShortVersion shortVersion}
90 * value of the version are available via direct property checking.
92 * Supported values are: IE, Firefox, Safari, Chrome, Opera, WebKit, Gecko, Presto, Trident and Other
94 * @param {String} value The OS name to check
101 * @property {String} name
102 * Read-only - the full name of the current browser
103 * Possible values are: IE, Firefox, Safari, Chrome, Opera and Other
108 * @property {Ext.Version} version
109 * Read-only, refer to {@link Ext.Version}
114 * @property {String} engineName
115 * Read-only - the full name of the current browser's engine
116 * Possible values are: WebKit, Gecko, Presto, Trident and Other
121 * @property {String} engineVersion
122 * Read-only, refer to {@link Ext.Version}
126 constructor: function() {
127 var userAgent = this.userAgent = Ext.global.navigator.userAgent,
128 selfClass = this.statics(),
129 browserMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.browserPrefixes).join(')|(?:') + '))([\\d\\._]+)')),
130 engineMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.enginePrefixes).join(')|(?:') + '))([\\d\\._]+)')),
131 browserName = selfClass.browserNames.other,
133 engineName = selfClass.engineNames.other,
136 this.is = function(name) {
137 return this.is[name] === true;
141 browserName = selfClass.browserNames[Ext.Object.getKey(selfClass.browserPrefixes, browserMatch[1])];
142 browserVersion = browserMatch[2];
146 engineName = selfClass.engineNames[Ext.Object.getKey(selfClass.enginePrefixes, engineMatch[1])];
147 engineVersion = engineMatch[2];
151 engineName: engineName,
152 engineVersion: new Ext.Version(engineVersion),
154 version: new Ext.Version(browserVersion)
157 this.is[this.name] = true;
158 this.is[this.name + (this.version.getMajor() || '')] = true;
159 this.is[this.name + this.version.getShortVersion()] = true;
160 Ext.Object.each(selfClass.browserNames, function(key, name) {
161 this.is[name] = (this.name === name);
164 this.is[this.name] = true;
165 this.is[this.engineName + (this.engineVersion.getMajor() || '')] = true;
166 this.is[this.engineName + this.engineVersion.getShortVersion()] = true;
167 Ext.Object.each(selfClass.engineNames, function(key, name) {
168 this.is[name] = (this.engineName === name);
172 this.isSecure = /^https/i.test(Ext.global.location.protocol);
174 this.isStrict = Ext.global.document.compatMode === "CSS1Compat";
182 * @property {Ext.env.Browser} browser
184 * Global convenient instance of {@link Ext.env.Browser}.
186 Ext.browser = new Ext.env.Browser();