react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ui / dom / isEventSupported.js
81159 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule isEventSupported9*/1011"use strict";1213var ExecutionEnvironment = require('ExecutionEnvironment');1415var useHasFeature;16if (ExecutionEnvironment.canUseDOM) {17useHasFeature =18document.implementation &&19document.implementation.hasFeature &&20// always returns true in newer browsers as per the standard.21// @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature22document.implementation.hasFeature('', '') !== true;23}2425/**26* Checks if an event is supported in the current execution environment.27*28* NOTE: This will not work correctly for non-generic events such as `change`,29* `reset`, `load`, `error`, and `select`.30*31* Borrows from Modernizr.32*33* @param {string} eventNameSuffix Event name, e.g. "click".34* @param {?boolean} capture Check if the capture phase is supported.35* @return {boolean} True if the event is supported.36* @internal37* @license Modernizr 3.0.0pre (Custom Build) | MIT38*/39function isEventSupported(eventNameSuffix, capture) {40if (!ExecutionEnvironment.canUseDOM ||41capture && !('addEventListener' in document)) {42return false;43}4445var eventName = 'on' + eventNameSuffix;46var isSupported = eventName in document;4748if (!isSupported) {49var element = document.createElement('div');50element.setAttribute(eventName, 'return;');51isSupported = typeof element[eventName] === 'function';52}5354if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {55// This is the only way to test support for the `wheel` event in IE9+.56isSupported = document.implementation.hasFeature('Events.wheel', '3.0');57}5859return isSupported;60}6162module.exports = isEventSupported;636465