/**1* Copyright 2013-2015, Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*15* @providesModule EventListener16* @typechecks17*/1819var emptyFunction = require("./emptyFunction");2021/**22* Upstream version of event listener. Does not take into account specific23* nature of platform.24*/25var EventListener = {26/**27* Listen to DOM events during the bubble phase.28*29* @param {DOMEventTarget} target DOM element to register listener on.30* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.31* @param {function} callback Callback function.32* @return {object} Object with a `remove` method.33*/34listen: function(target, eventType, callback) {35if (target.addEventListener) {36target.addEventListener(eventType, callback, false);37return {38remove: function() {39target.removeEventListener(eventType, callback, false);40}41};42} else if (target.attachEvent) {43target.attachEvent('on' + eventType, callback);44return {45remove: function() {46target.detachEvent('on' + eventType, callback);47}48};49}50},5152/**53* Listen to DOM events during the capture phase.54*55* @param {DOMEventTarget} target DOM element to register listener on.56* @param {string} eventType Event type, e.g. 'click' or 'mouseover'.57* @param {function} callback Callback function.58* @return {object} Object with a `remove` method.59*/60capture: function(target, eventType, callback) {61if (!target.addEventListener) {62if ("production" !== process.env.NODE_ENV) {63console.error(64'Attempted to listen to events during the capture phase on a ' +65'browser that does not support the capture phase. Your application ' +66'will not receive some events.'67);68}69return {70remove: emptyFunction71};72} else {73target.addEventListener(eventType, callback, true);74return {75remove: function() {76target.removeEventListener(eventType, callback, true);77}78};79}80},8182registerDefault: function() {}83};8485module.exports = EventListener;868788