2 * @class Ext.env.Browser
4 * Provide useful information about the current browser.
5 * Should not be manually instantiated unless for unit-testing; access the global instance stored in Ext.browser instead. Example:
7 * if (Ext.browser.is.IE) {
8 * // IE specific code here
11 * if (Ext.browser.is.WebKit) {
12 * // WebKit specific code here
15 * console.log("Version " + Ext.browser.version);
18 * For a full list of supported values, refer to: {@link Ext.env.Browser#is}
20 * @borrows Ext.Base.extend
22 Ext.define('Ext.env.Browser', {
40 webkit: 'AppleWebKit/',
55 * True if the page is running over SSL
61 * True if the document is in strict mode
67 * A "hybrid" property, can be either accessed as a method call, i.e:
69 * if (Ext.browser.is('IE')) { ... }
72 * or as an object with boolean properties, i.e:
74 * if (Ext.browser.is.IE) { ... }
77 * Versions can be conveniently checked as well. For example:
79 * if (Ext.browser.is.IE6) { ... } // Equivalent to (Ext.browser.is.IE && Ext.browser.version.equals(6))
82 * Note that only {@link Ext.Version#getMajor major component} and {@link Ext.Version#getShortVersion shortVersion}
83 * value of the version are available via direct property checking.
85 * Supported values are: IE, Firefox, Safari, Chrome, Opera, WebKit, Gecko, Presto, Trident and Other
87 * @param {String} value The OS name to check
93 * Read-only - the full name of the current browser
94 * Possible values are: IE, Firefox, Safari, Chrome, Opera and Other
100 * Read-only, refer to {@link Ext.Version}
106 * Read-only - the full name of the current browser's engine
107 * Possible values are: WebKit, Gecko, Presto, Trident and Other
113 * Read-only, refer to {@link Ext.Version}
118 constructor: function() {
119 var userAgent = this.userAgent = Ext.global.navigator.userAgent,
120 selfClass = this.statics(),
121 browserMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.browserPrefixes).join(')|(?:') + '))([\\d\\._]+)')),
122 engineMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.enginePrefixes).join(')|(?:') + '))([\\d\\._]+)')),
123 browserName = selfClass.browserNames.other,
125 engineName = selfClass.engineNames.other,
128 this.is = function(name) {
129 return this.is[name] === true;
133 browserName = selfClass.browserNames[Ext.Object.getKey(selfClass.browserPrefixes, browserMatch[1])];
134 browserVersion = browserMatch[2];
138 engineName = selfClass.engineNames[Ext.Object.getKey(selfClass.enginePrefixes, engineMatch[1])];
139 engineVersion = engineMatch[2];
143 engineName: engineName,
144 engineVersion: new Ext.Version(engineVersion),
146 version: new Ext.Version(browserVersion)
149 this.is[this.name] = true;
150 this.is[this.name + (this.version.getMajor() || '')] = true;
151 this.is[this.name + this.version.getShortVersion()] = true;
152 Ext.Object.each(selfClass.browserNames, function(key, name) {
153 this.is[name] = (this.name === name);
156 this.is[this.name] = true;
157 this.is[this.engineName + (this.engineVersion.getMajor() || '')] = true;
158 this.is[this.engineName + this.engineVersion.getShortVersion()] = true;
159 Ext.Object.each(selfClass.engineNames, function(key, name) {
160 this.is[name] = (this.engineName === name);
164 this.isSecure = /^https/i.test(Ext.global.location.protocol);
166 this.isStrict = Ext.global.document.compatMode === "CSS1Compat";
173 Ext.browser = new Ext.env.Browser();