UNPKG

1.94 kBJavaScriptView Raw
1/**
2 * Copyright 2013-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 */
10
11'use strict';
12
13var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
14
15var useHasFeature;
16if (ExecutionEnvironment.canUseDOM) {
17 useHasFeature = document.implementation && document.implementation.hasFeature &&
18 // always returns true in newer browsers as per the standard.
19 // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
20 document.implementation.hasFeature('', '') !== true;
21}
22
23/**
24 * Checks if an event is supported in the current execution environment.
25 *
26 * NOTE: This will not work correctly for non-generic events such as `change`,
27 * `reset`, `load`, `error`, and `select`.
28 *
29 * Borrows from Modernizr.
30 *
31 * @param {string} eventNameSuffix Event name, e.g. "click".
32 * @param {?boolean} capture Check if the capture phase is supported.
33 * @return {boolean} True if the event is supported.
34 * @internal
35 * @license Modernizr 3.0.0pre (Custom Build) | MIT
36 */
37function isEventSupported(eventNameSuffix, capture) {
38 if (!ExecutionEnvironment.canUseDOM || capture && !('addEventListener' in document)) {
39 return false;
40 }
41
42 var eventName = 'on' + eventNameSuffix;
43 var isSupported = eventName in document;
44
45 if (!isSupported) {
46 var element = document.createElement('div');
47 element.setAttribute(eventName, 'return;');
48 isSupported = typeof element[eventName] === 'function';
49 }
50
51 if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
52 // This is the only way to test support for the `wheel` event in IE9+.
53 isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
54 }
55
56 return isSupported;
57}
58
59module.exports = isEventSupported;
\No newline at end of file