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 * @class Ext.env.Browser
18 * Provide useful information about the current browser.
19 * Should not be manually instantiated unless for unit-testing; access the global instance stored in Ext.browser instead. Example:
21 * if (Ext.browser.is.IE) {
22 * // IE specific code here
25 * if (Ext.browser.is.WebKit) {
26 * // WebKit specific code here
29 * console.log("Version " + Ext.browser.version);
32 * For a full list of supported values, refer to: {@link Ext.env.Browser#is}
34 * @borrows Ext.Base.extend
36 Ext.define('Ext.env.Browser', {
54 webkit: 'AppleWebKit/',
69 * True if the page is running over SSL
75 * True if the document is in strict mode
81 * A "hybrid" property, can be either accessed as a method call, i.e:
83 * if (Ext.browser.is('IE')) { ... }
86 * or as an object with boolean properties, i.e:
88 * if (Ext.browser.is.IE) { ... }
91 * Versions can be conveniently checked as well. For example:
93 * if (Ext.browser.is.IE6) { ... } // Equivalent to (Ext.browser.is.IE && Ext.browser.version.equals(6))
96 * Note that only {@link Ext.Version#getMajor major component} and {@link Ext.Version#getShortVersion shortVersion}
97 * value of the version are available via direct property checking.
99 * Supported values are: IE, Firefox, Safari, Chrome, Opera, WebKit, Gecko, Presto, Trident and Other
101 * @param {String} value The OS name to check
108 * Read-only - the full name of the current browser
109 * Possible values are: IE, Firefox, Safari, Chrome, Opera and Other
115 * Read-only, refer to {@link Ext.Version}
121 * Read-only - the full name of the current browser's engine
122 * Possible values are: WebKit, Gecko, Presto, Trident and Other
128 * Read-only, refer to {@link Ext.Version}
133 constructor: function() {
134 var userAgent = this.userAgent = Ext.global.navigator.userAgent,
135 selfClass = this.statics(),
136 browserMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.browserPrefixes).join(')|(?:') + '))([\\d\\._]+)')),
137 engineMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.enginePrefixes).join(')|(?:') + '))([\\d\\._]+)')),
138 browserName = selfClass.browserNames.other,
140 engineName = selfClass.engineNames.other,
143 this.is = function(name) {
144 return this.is[name] === true;
148 browserName = selfClass.browserNames[Ext.Object.getKey(selfClass.browserPrefixes, browserMatch[1])];
149 browserVersion = browserMatch[2];
153 engineName = selfClass.engineNames[Ext.Object.getKey(selfClass.enginePrefixes, engineMatch[1])];
154 engineVersion = engineMatch[2];
158 engineName: engineName,
159 engineVersion: new Ext.Version(engineVersion),
161 version: new Ext.Version(browserVersion)
164 this.is[this.name] = true;
165 this.is[this.name + (this.version.getMajor() || '')] = true;
166 this.is[this.name + this.version.getShortVersion()] = true;
167 Ext.Object.each(selfClass.browserNames, function(key, name) {
168 this.is[name] = (this.name === name);
171 this.is[this.name] = true;
172 this.is[this.engineName + (this.engineVersion.getMajor() || '')] = true;
173 this.is[this.engineName + this.engineVersion.getShortVersion()] = true;
174 Ext.Object.each(selfClass.engineNames, function(key, name) {
175 this.is[name] = (this.engineName === name);
179 this.isSecure = /^https/i.test(Ext.global.location.protocol);
181 this.isStrict = Ext.global.document.compatMode === "CSS1Compat";
188 Ext.browser = new Ext.env.Browser();