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
94 * Read-only - the full name of the current browser
95 * Possible values are: IE, Firefox, Safari, Chrome, Opera and Other
101 * Read-only, refer to {@link Ext.Version}
107 * Read-only - the full name of the current browser's engine
108 * Possible values are: WebKit, Gecko, Presto, Trident and Other
114 * Read-only, refer to {@link Ext.Version}
119 constructor: function() {
120 var userAgent = this.userAgent = Ext.global.navigator.userAgent,
121 selfClass = this.statics(),
122 browserMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.browserPrefixes).join(')|(?:') + '))([\\d\\._]+)')),
123 engineMatch = userAgent.match(new RegExp('((?:' + Ext.Object.getValues(selfClass.enginePrefixes).join(')|(?:') + '))([\\d\\._]+)')),
124 browserName = selfClass.browserNames.other,
126 engineName = selfClass.engineNames.other,
129 this.is = function(name) {
130 return this.is[name] === true;
134 browserName = selfClass.browserNames[Ext.Object.getKey(selfClass.browserPrefixes, browserMatch[1])];
135 browserVersion = browserMatch[2];
139 engineName = selfClass.engineNames[Ext.Object.getKey(selfClass.enginePrefixes, engineMatch[1])];
140 engineVersion = engineMatch[2];
144 engineName: engineName,
145 engineVersion: new Ext.Version(engineVersion),
147 version: new Ext.Version(browserVersion)
150 this.is[this.name] = true;
151 this.is[this.name + (this.version.getMajor() || '')] = true;
152 this.is[this.name + this.version.getShortVersion()] = true;
153 Ext.Object.each(selfClass.browserNames, function(key, name) {
154 this.is[name] = (this.name === name);
157 this.is[this.name] = true;
158 this.is[this.engineName + (this.engineVersion.getMajor() || '')] = true;
159 this.is[this.engineName + this.engineVersion.getShortVersion()] = true;
160 Ext.Object.each(selfClass.engineNames, function(key, name) {
161 this.is[name] = (this.engineName === name);
165 this.isSecure = /^https/i.test(Ext.global.location.protocol);
167 this.isStrict = Ext.global.document.compatMode === "CSS1Compat";
174 Ext.browser = new Ext.env.Browser();