@samitouri / QOS-React-2 / commits / 7264cbcdfb

Further cleanup of isEventSupported

Andreas Svensson committed Jan 2, 2014 at 15:36 UTC 7264cbcdfbadc6bb216c65331ccff04c14621401
1 file changed +8 -7
src/dom/isEventSupported.js
+8 -7
@@ -20,13 +20,13 @@
20
21 var ExecutionEnvironment = require('ExecutionEnvironment');
22
23 -var testNode, useHasFeature;
23 +var useHasFeature;
24 if (ExecutionEnvironment.canUseDOM) {
25 - testNode = document.createElement('div');
25 useHasFeature =
26 document.implementation &&
27 document.implementation.hasFeature &&
29 - // `hasFeature` always returns true in Firefox 19+.
28 + // always returns true in newer browsers as per the standard.
29 + // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
30 document.implementation.hasFeature('', '') !== true;
31 }
32
@@ -45,15 +45,16 @@ if (ExecutionEnvironment.canUseDOM) {
45 * @license Modernizr 3.0.0pre (Custom Build) | MIT
46 */
47 function isEventSupported(eventNameSuffix, capture) {
48 - if (!testNode || (capture && !testNode.addEventListener)) {
48 + if (!ExecutionEnvironment.canUseDOM ||
49 + capture && !('addEventListener' in document)) {
50 return false;
51 }
51 - var element = document.createElement('div');
52 -
52 +
53 var eventName = 'on' + eventNameSuffix;
54 - var isSupported = eventName in element;
54 + var isSupported = eventName in document;
55
56 if (!isSupported) {
57 + var element = document.createElement('div');
58 element.setAttribute(eventName, 'return;');
59 isSupported = typeof element[eventName] === 'function';
60 }