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 features.
17 * Don't instantiate directly, but use the {@link Ext#features} property instead.
19 Ext.define('Ext.env.FeatureDetector', {
25 * True if canvas element supported.
28 var element = this.getTestElement('canvas');
29 return !!(element && element.getContext && element.getContext('2d'));
33 * True if SVG supported.
36 var doc = Ext.global.document;
38 return !!(doc.createElementNS && !!doc.createElementNS("http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect);
42 * True if VML supported.
45 var element = this.getTestElement(),
48 element.innerHTML = "<!--[if vml]><br><br><![endif]-->";
49 ret = (element.childNodes.length === 2);
50 element.innerHTML = "";
56 * True if we're in Sencha Touch environment.
59 return ('ontouchstart' in Ext.global) && !(Ext.platform && Ext.platform.name.match(/Windows|MacOSX|Linux/));
63 * True if orientation API supported.
65 Orientation: function() {
66 return ('orientation' in Ext.global);
70 * True if geolocation API supported.
72 Geolocation: function() {
73 return !!Ext.global.navigator.geolocation;
77 * True if openDatabase API supported.
79 SqlDatabase: function() {
80 return !!Ext.global.openDatabase;
84 * True if WebSocket API supported.
86 Websockets: function() {
87 return 'WebSocket' in Ext.global;
91 * True if history.pushState supported.
94 return !!(Ext.global.history && Ext.global.history.pushState);
98 * True if CSS transforms supported.
100 CSSTransforms: function() {
101 return this.isStyleSupported('transform');
104 * @property {Boolean}
105 * True if CSS 3D transforms supported.
107 CSS3DTransforms: function() {
108 return this.has('csstransforms') && this.isStyleSupported('perspective');
111 * @property {Boolean}
112 * True if CSS animations supported.
114 CSSAnimations: function() {
115 return this.isStyleSupported('animationName');
118 * @property {Boolean}
119 * True if CSS transitions supported.
121 CSSTransitions: function() {
122 return this.isStyleSupported('transitionProperty');
125 * @property {Boolean}
126 * True if audio element supported.
129 return !!this.getTestElement('audio').canPlayType;
132 * @property {Boolean}
133 * True if video element supported.
136 return !!this.getTestElement('video').canPlayType;
140 stylePrefixes: ['Webkit', 'Moz', 'O', 'ms']
143 constructor: function() {
146 this.testElements = {};
148 this.registerTests(this.self.defaultTests, true);
153 has: function(name) {
154 if (!this.hasTest(name)) {
157 else if (this.has.hasOwnProperty(name)) {
158 return this.has[name];
161 return this.getTestResult(name);
165 getTestResult: function(name) {
166 return !!this.getTest(name).call(this);
169 getTestElement: function(tag) {
174 if (!this.testElements[tag]) {
175 this.testElements[tag] = Ext.global.document.createElement(tag);
178 return this.testElements[tag];
181 registerTest: function(name, fn, isDefault) {
183 if (this.hasTest(name)) {
185 sourceClass: "Ext.env.FeatureDetector",
186 sourceMethod: "registerTest",
187 msg: "Test name " + name + " has already been registered"
192 this.tests[name] = fn;
195 this.has[name] = this.getTestResult(name);
201 registerTests: function(tests, isDefault) {
202 Ext.Object.each(tests, function(name, fn) {
203 this.registerTest(name, fn, isDefault);
209 hasTest: function(name) {
210 return this.tests.hasOwnProperty(name);
213 getTest: function(name) {
215 if (!this.hasTest(name)) {
217 sourceClass: "Ext.env.FeatureDetector",
218 sourceMethod: "getTest",
219 msg: "Test name " + name + " does not exist"
224 return this.tests[name];
227 getTests: function() {
231 isStyleSupported: function(name, tag) {
232 var elementStyle = this.getTestElement(tag).style,
233 cName = Ext.String.capitalize(name),
234 i = this.self.stylePrefixes.length;
236 if (elementStyle[name] !== undefined) {
241 if (elementStyle[this.self.stylePrefixes[i] + cName] !== undefined) {
249 isEventSupported: function(name, tag) {
250 var element = this.getTestElement(tag),
251 eventName = 'on' + name,
254 // When using `setAttribute`, IE skips "unload", WebKit skips
255 // "unload" and "resize", whereas `in` "catches" those
256 isSupported = (eventName in element);
259 if (element.setAttribute && element.removeAttribute) {
260 element.setAttribute(eventName, '');
261 isSupported = typeof element[eventName] === 'function';
263 // If property was created, "remove it" (by setting value to `undefined`)
264 if (typeof element[eventName] !== 'undefined') {
265 element[eventName] = undefined;
268 element.removeAttribute(eventName);
278 * @property {Ext.env.FeatureDetector} features
280 * Global convenient instance of {@link Ext.env.FeatureDetector}.
282 Ext.features = new Ext.env.FeatureDetector();