Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 views
1
/**
2
* Copyright 2013-2014, 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
* @providesModule isEventSupported
10
*/
11
12
"use strict";
13
14
var ExecutionEnvironment = require('ExecutionEnvironment');
15
16
var useHasFeature;
17
if (ExecutionEnvironment.canUseDOM) {
18
useHasFeature =
19
document.implementation &&
20
document.implementation.hasFeature &&
21
// always returns true in newer browsers as per the standard.
22
// @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
23
document.implementation.hasFeature('', '') !== true;
24
}
25
26
/**
27
* Checks if an event is supported in the current execution environment.
28
*
29
* NOTE: This will not work correctly for non-generic events such as `change`,
30
* `reset`, `load`, `error`, and `select`.
31
*
32
* Borrows from Modernizr.
33
*
34
* @param {string} eventNameSuffix Event name, e.g. "click".
35
* @param {?boolean} capture Check if the capture phase is supported.
36
* @return {boolean} True if the event is supported.
37
* @internal
38
* @license Modernizr 3.0.0pre (Custom Build) | MIT
39
*/
40
function isEventSupported(eventNameSuffix, capture) {
41
if (!ExecutionEnvironment.canUseDOM ||
42
capture && !('addEventListener' in document)) {
43
return false;
44
}
45
46
var eventName = 'on' + eventNameSuffix;
47
var isSupported = eventName in document;
48
49
if (!isSupported) {
50
var element = document.createElement('div');
51
element.setAttribute(eventName, 'return;');
52
isSupported = typeof element[eventName] === 'function';
53
}
54
55
if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
56
// This is the only way to test support for the `wheel` event in IE9+.
57
isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
58
}
59
60
return isSupported;
61
}
62
63
module.exports = isEventSupported;
64
65