1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var _assign = require('object-assign');
|
12 |
|
13 | var EventPluginRegistry = require('./EventPluginRegistry');
|
14 | var ReactEventEmitterMixin = require('./ReactEventEmitterMixin');
|
15 | var ViewportMetrics = require('./ViewportMetrics');
|
16 |
|
17 | var getVendorPrefixedEventName = require('./getVendorPrefixedEventName');
|
18 | var isEventSupported = require('./isEventSupported');
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | var hasEventPageXY;
|
76 | var alreadyListeningTo = {};
|
77 | var isMonitoringScrollValue = false;
|
78 | var reactTopListenersCounter = 0;
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | var topEventMapping = {
|
84 | topAbort: 'abort',
|
85 | topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
|
86 | topAnimationIteration: getVendorPrefixedEventName('animationiteration') || 'animationiteration',
|
87 | topAnimationStart: getVendorPrefixedEventName('animationstart') || 'animationstart',
|
88 | topBlur: 'blur',
|
89 | topCanPlay: 'canplay',
|
90 | topCanPlayThrough: 'canplaythrough',
|
91 | topChange: 'change',
|
92 | topClick: 'click',
|
93 | topCompositionEnd: 'compositionend',
|
94 | topCompositionStart: 'compositionstart',
|
95 | topCompositionUpdate: 'compositionupdate',
|
96 | topContextMenu: 'contextmenu',
|
97 | topCopy: 'copy',
|
98 | topCut: 'cut',
|
99 | topDoubleClick: 'dblclick',
|
100 | topDrag: 'drag',
|
101 | topDragEnd: 'dragend',
|
102 | topDragEnter: 'dragenter',
|
103 | topDragExit: 'dragexit',
|
104 | topDragLeave: 'dragleave',
|
105 | topDragOver: 'dragover',
|
106 | topDragStart: 'dragstart',
|
107 | topDrop: 'drop',
|
108 | topDurationChange: 'durationchange',
|
109 | topEmptied: 'emptied',
|
110 | topEncrypted: 'encrypted',
|
111 | topEnded: 'ended',
|
112 | topError: 'error',
|
113 | topFocus: 'focus',
|
114 | topInput: 'input',
|
115 | topKeyDown: 'keydown',
|
116 | topKeyPress: 'keypress',
|
117 | topKeyUp: 'keyup',
|
118 | topLoadedData: 'loadeddata',
|
119 | topLoadedMetadata: 'loadedmetadata',
|
120 | topLoadStart: 'loadstart',
|
121 | topMouseDown: 'mousedown',
|
122 | topMouseMove: 'mousemove',
|
123 | topMouseOut: 'mouseout',
|
124 | topMouseOver: 'mouseover',
|
125 | topMouseUp: 'mouseup',
|
126 | topPaste: 'paste',
|
127 | topPause: 'pause',
|
128 | topPlay: 'play',
|
129 | topPlaying: 'playing',
|
130 | topProgress: 'progress',
|
131 | topRateChange: 'ratechange',
|
132 | topScroll: 'scroll',
|
133 | topSeeked: 'seeked',
|
134 | topSeeking: 'seeking',
|
135 | topSelectionChange: 'selectionchange',
|
136 | topStalled: 'stalled',
|
137 | topSuspend: 'suspend',
|
138 | topTextInput: 'textInput',
|
139 | topTimeUpdate: 'timeupdate',
|
140 | topTouchCancel: 'touchcancel',
|
141 | topTouchEnd: 'touchend',
|
142 | topTouchMove: 'touchmove',
|
143 | topTouchStart: 'touchstart',
|
144 | topTransitionEnd: getVendorPrefixedEventName('transitionend') || 'transitionend',
|
145 | topVolumeChange: 'volumechange',
|
146 | topWaiting: 'waiting',
|
147 | topWheel: 'wheel'
|
148 | };
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | var topListenersIDKey = '_reactListenersID' + String(Math.random()).slice(2);
|
154 |
|
155 | function getListeningForDocument(mountAt) {
|
156 |
|
157 |
|
158 | if (!Object.prototype.hasOwnProperty.call(mountAt, topListenersIDKey)) {
|
159 | mountAt[topListenersIDKey] = reactTopListenersCounter++;
|
160 | alreadyListeningTo[mountAt[topListenersIDKey]] = {};
|
161 | }
|
162 | return alreadyListeningTo[mountAt[topListenersIDKey]];
|
163 | }
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | var ReactBrowserEventEmitter = _assign({}, ReactEventEmitterMixin, {
|
176 | |
177 |
|
178 |
|
179 | ReactEventListener: null,
|
180 |
|
181 | injection: {
|
182 | |
183 |
|
184 |
|
185 | injectReactEventListener: function (ReactEventListener) {
|
186 | ReactEventListener.setHandleTopLevel(ReactBrowserEventEmitter.handleTopLevel);
|
187 | ReactBrowserEventEmitter.ReactEventListener = ReactEventListener;
|
188 | }
|
189 | },
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 | setEnabled: function (enabled) {
|
197 | if (ReactBrowserEventEmitter.ReactEventListener) {
|
198 | ReactBrowserEventEmitter.ReactEventListener.setEnabled(enabled);
|
199 | }
|
200 | },
|
201 |
|
202 | |
203 |
|
204 |
|
205 | isEnabled: function () {
|
206 | return !!(ReactBrowserEventEmitter.ReactEventListener && ReactBrowserEventEmitter.ReactEventListener.isEnabled());
|
207 | },
|
208 |
|
209 | |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | listenTo: function (registrationName, contentDocumentHandle) {
|
231 | var mountAt = contentDocumentHandle;
|
232 | var isListening = getListeningForDocument(mountAt);
|
233 | var dependencies = EventPluginRegistry.registrationNameDependencies[registrationName];
|
234 |
|
235 | for (var i = 0; i < dependencies.length; i++) {
|
236 | var dependency = dependencies[i];
|
237 | if (!(isListening.hasOwnProperty(dependency) && isListening[dependency])) {
|
238 | if (dependency === 'topWheel') {
|
239 | if (isEventSupported('wheel')) {
|
240 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'wheel', mountAt);
|
241 | } else if (isEventSupported('mousewheel')) {
|
242 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'mousewheel', mountAt);
|
243 | } else {
|
244 |
|
245 |
|
246 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topWheel', 'DOMMouseScroll', mountAt);
|
247 | }
|
248 | } else if (dependency === 'topScroll') {
|
249 | if (isEventSupported('scroll', true)) {
|
250 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topScroll', 'scroll', mountAt);
|
251 | } else {
|
252 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topScroll', 'scroll', ReactBrowserEventEmitter.ReactEventListener.WINDOW_HANDLE);
|
253 | }
|
254 | } else if (dependency === 'topFocus' || dependency === 'topBlur') {
|
255 | if (isEventSupported('focus', true)) {
|
256 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topFocus', 'focus', mountAt);
|
257 | ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent('topBlur', 'blur', mountAt);
|
258 | } else if (isEventSupported('focusin')) {
|
259 |
|
260 |
|
261 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topFocus', 'focusin', mountAt);
|
262 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent('topBlur', 'focusout', mountAt);
|
263 | }
|
264 |
|
265 |
|
266 | isListening.topBlur = true;
|
267 | isListening.topFocus = true;
|
268 | } else if (topEventMapping.hasOwnProperty(dependency)) {
|
269 | ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(dependency, topEventMapping[dependency], mountAt);
|
270 | }
|
271 |
|
272 | isListening[dependency] = true;
|
273 | }
|
274 | }
|
275 | },
|
276 |
|
277 | trapBubbledEvent: function (topLevelType, handlerBaseName, handle) {
|
278 | return ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(topLevelType, handlerBaseName, handle);
|
279 | },
|
280 |
|
281 | trapCapturedEvent: function (topLevelType, handlerBaseName, handle) {
|
282 | return ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(topLevelType, handlerBaseName, handle);
|
283 | },
|
284 |
|
285 | |
286 |
|
287 |
|
288 |
|
289 |
|
290 | supportsEventPageXY: function () {
|
291 | if (!document.createEvent) {
|
292 | return false;
|
293 | }
|
294 | var ev = document.createEvent('MouseEvent');
|
295 | return ev != null && 'pageX' in ev;
|
296 | },
|
297 |
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 | ensureScrollValueMonitoring: function () {
|
310 | if (hasEventPageXY === undefined) {
|
311 | hasEventPageXY = ReactBrowserEventEmitter.supportsEventPageXY();
|
312 | }
|
313 | if (!hasEventPageXY && !isMonitoringScrollValue) {
|
314 | var refresh = ViewportMetrics.refreshScrollValues;
|
315 | ReactBrowserEventEmitter.ReactEventListener.monitorScrollValue(refresh);
|
316 | isMonitoringScrollValue = true;
|
317 | }
|
318 | }
|
319 | });
|
320 |
|
321 | module.exports = ReactBrowserEventEmitter; |
\ | No newline at end of file |