UNPKG

1.01 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
13/**
14 * Gets the target node from a native browser event by accounting for
15 * inconsistencies in browser DOM APIs.
16 *
17 * @param {object} nativeEvent Native browser event.
18 * @return {DOMEventTarget} Target node.
19 */
20
21function getEventTarget(nativeEvent) {
22 var target = nativeEvent.target || nativeEvent.srcElement || window;
23
24 // Normalize SVG <use> element events #4963
25 if (target.correspondingUseElement) {
26 target = target.correspondingUseElement;
27 }
28
29 // Safari may fire events on text nodes (Node.TEXT_NODE is 3).
30 // @see http://www.quirksmode.org/js/events_properties.html
31 return target.nodeType === 3 ? target.parentNode : target;
32}
33
34module.exports = getEventTarget;
\No newline at end of file