UNPKG

1.45 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 SyntheticEvent = require('./SyntheticEvent');
12
13var getEventTarget = require('./getEventTarget');
14
15/**
16 * @interface UIEvent
17 * @see http://www.w3.org/TR/DOM-Level-3-Events/
18 */
19var UIEventInterface = {
20 view: function (event) {
21 if (event.view) {
22 return event.view;
23 }
24
25 var target = getEventTarget(event);
26 if (target.window === target) {
27 // target is a window object
28 return target;
29 }
30
31 var doc = target.ownerDocument;
32 // TODO: Figure out why `ownerDocument` is sometimes undefined in IE8.
33 if (doc) {
34 return doc.defaultView || doc.parentWindow;
35 } else {
36 return window;
37 }
38 },
39 detail: function (event) {
40 return event.detail || 0;
41 }
42};
43
44/**
45 * @param {object} dispatchConfig Configuration used to dispatch this event.
46 * @param {string} dispatchMarker Marker identifying the event target.
47 * @param {object} nativeEvent Native browser event.
48 * @extends {SyntheticEvent}
49 */
50function SyntheticUIEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {
51 return SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);
52}
53
54SyntheticEvent.augmentClass(SyntheticUIEvent, UIEventInterface);
55
56module.exports = SyntheticUIEvent;
\No newline at end of file