1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-env.FeatureDetector'>/**
2 </span> * @class Ext.env.FeatureDetector
4 Ext.define('Ext.env.FeatureDetector', {
9 var element = this.getTestElement('canvas');
10 return !!(element && element.getContext && element.getContext('2d'));
13 var doc = Ext.global.document;
15 return !!(doc.createElementNS && !!doc.createElementNS("http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect);
18 var element = this.getTestElement(),
21 element.innerHTML = "<!--[if vml]><br><br><![endif]-->";
22 ret = (element.childNodes.length === 2);
23 element.innerHTML = "";
28 return ('ontouchstart' in Ext.global) && !(Ext.platform && Ext.platform.name.match(/Windows|MacOSX|Linux/));
30 Orientation: function() {
31 return ('orientation' in Ext.global);
33 Geolocation: function() {
34 return !!Ext.global.navigator.geolocation;
36 SqlDatabase: function() {
37 return !!Ext.global.openDatabase;
39 Websockets: function() {
40 return 'WebSocket' in Ext.global;
43 return !!(Ext.global.history && Ext.global.history.pushState);
45 CSSTransforms: function() {
46 return this.isStyleSupported('transform');
48 CSS3DTransforms: function() {
49 return this.has('csstransforms') && this.isStyleSupported('perspective');
51 CSSAnimations: function() {
52 return this.isStyleSupported('animationName');
54 CSSTransitions: function() {
55 return this.isStyleSupported('transitionProperty');
58 return !!this.getTestElement('audio').canPlayType;
61 return !!this.getTestElement('video').canPlayType;
65 stylePrefixes: ['Webkit', 'Moz', 'O', 'ms']
68 constructor: function() {
71 this.testElements = {};
73 this.registerTests(this.self.defaultTests, true);
79 if (!this.hasTest(name)) {
82 else if (this.has.hasOwnProperty(name)) {
83 return this.has[name];
86 return this.getTestResult(name);
90 getTestResult: function(name) {
91 return !!this.getTest(name).call(this);
94 getTestElement: function(tag) {
99 if (!this.testElements[tag]) {
100 this.testElements[tag] = Ext.global.document.createElement(tag);
103 return this.testElements[tag];
106 registerTest: function(name, fn, isDefault) {
108 if (this.hasTest(name)) {
110 sourceClass: "Ext.env.FeatureDetector",
111 sourceMethod: "registerTest",
112 msg: "Test name " + name + " has already been registered"
117 this.tests[name] = fn;
120 this.has[name] = this.getTestResult(name);
126 registerTests: function(tests, isDefault) {
127 Ext.Object.each(tests, function(name, fn) {
128 this.registerTest(name, fn, isDefault);
134 hasTest: function(name) {
135 return this.tests.hasOwnProperty(name);
138 getTest: function(name) {
140 if (!this.hasTest(name)) {
142 sourceClass: "Ext.env.FeatureDetector",
143 sourceMethod: "getTest",
144 msg: "Test name " + name + " does not exist"
149 return this.tests[name];
152 getTests: function() {
156 isStyleSupported: function(name, tag) {
157 var elementStyle = this.getTestElement(tag).style,
158 cName = Ext.String.capitalize(name),
159 i = this.self.stylePrefixes.length;
161 if (elementStyle[name] !== undefined) {
166 if (elementStyle[this.self.stylePrefixes[i] + cName] !== undefined) {
174 isEventSupported: function(name, tag) {
175 var element = this.getTestElement(tag),
176 eventName = 'on' + name,
179 // When using `setAttribute`, IE skips "unload", WebKit skips
180 // "unload" and "resize", whereas `in` "catches" those
181 isSupported = (eventName in element);
184 if (element.setAttribute && element.removeAttribute) {
185 element.setAttribute(eventName, '');
186 isSupported = typeof element[eventName] === 'function';
188 // If property was created, "remove it" (by setting value to `undefined`)
189 if (typeof element[eventName] !== 'undefined') {
190 element[eventName] = undefined;
193 element.removeAttribute(eventName);
203 * Global convenient instance of {@link Ext.env.FeatureDetector Ext.env.FeatureDetector}
204 * @member Ext features
206 Ext.features = new Ext.env.FeatureDetector();
209 </pre></pre></body></html>