UNPKG

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