1 | module Hyalite |
||
2 | class SimpleEventPlugin |
||
3 | EVENT_TYPES = { |
||
4 | blur: { |
||
5 | phasedRegistrationNames: { |
||
6 | bubbled: :onBlur, |
||
7 | captured: :onBlurCapture |
||
8 | } |
||
9 | }, |
||
10 | click: { |
||
11 | phasedRegistrationNames: { |
||
12 | bubbled: :onClick, |
||
13 | captured: :onClickCapture |
||
14 | } |
||
15 | }, |
||
16 | contextMenu: { |
||
17 | phasedRegistrationNames: { |
||
18 | bubbled: :onContextMenu, |
||
19 | captured: :onContextMenuCapture |
||
20 | } |
||
21 | }, |
||
22 | copy: { |
||
23 | phasedRegistrationNames: { |
||
24 | bubbled: :onCopy, |
||
25 | captured: :onCopyCapture |
||
26 | } |
||
27 | }, |
||
28 | cut: { |
||
29 | phasedRegistrationNames: { |
||
30 | bubbled: :onCut, |
||
31 | captured: :onCutCapture |
||
32 | } |
||
33 | }, |
||
34 | doubleClick: { |
||
35 | phasedRegistrationNames: { |
||
36 | bubbled: :onDoubleClick, |
||
37 | captured: :onDoubleClickCapture |
||
38 | } |
||
39 | }, |
||
40 | drag: { |
||
41 | phasedRegistrationNames: { |
||
42 | bubbled: :onDrag, |
||
43 | captured: :onDragCapture |
||
44 | } |
||
45 | }, |
||
46 | dragEnd: { |
||
47 | phasedRegistrationNames: { |
||
48 | bubbled: :onDragEnd, |
||
49 | captured: :onDragEndCapture |
||
50 | } |
||
51 | }, |
||
52 | dragEnter: { |
||
53 | phasedRegistrationNames: { |
||
54 | bubbled: :onDragEnter, |
||
55 | captured: :onDragEnterCapture |
||
56 | } |
||
57 | }, |
||
58 | dragExit: { |
||
59 | phasedRegistrationNames: { |
||
60 | bubbled: :onDragExit, |
||
61 | captured: :onDragExitCapture |
||
62 | } |
||
63 | }, |
||
64 | dragLeave: { |
||
65 | phasedRegistrationNames: { |
||
66 | bubbled: :onDragLeave, |
||
67 | captured: :onDragLeaveCapture |
||
68 | } |
||
69 | }, |
||
70 | dragOver: { |
||
71 | phasedRegistrationNames: { |
||
72 | bubbled: :onDragOver, |
||
73 | captured: :onDragOverCapture |
||
74 | } |
||
75 | }, |
||
76 | dragStart: { |
||
77 | phasedRegistrationNames: { |
||
78 | bubbled: :onDragStart, |
||
79 | captured: :onDragStartCapture |
||
80 | } |
||
81 | }, |
||
82 | drop: { |
||
83 | phasedRegistrationNames: { |
||
84 | bubbled: :onDrop, |
||
85 | captured: :onDropCapture |
||
86 | } |
||
87 | }, |
||
88 | focus: { |
||
89 | phasedRegistrationNames: { |
||
90 | bubbled: :onFocus, |
||
91 | captured: :onFocusCapture |
||
92 | } |
||
93 | }, |
||
94 | input: { |
||
95 | phasedRegistrationNames: { |
||
96 | bubbled: :onInput, |
||
97 | captured: :onInputCapture |
||
98 | } |
||
99 | }, |
||
100 | keyDown: { |
||
101 | phasedRegistrationNames: { |
||
102 | bubbled: :onKeyDown, |
||
103 | captured: :onKeyDownCapture |
||
104 | } |
||
105 | }, |
||
106 | keyPress: { |
||
107 | phasedRegistrationNames: { |
||
108 | bubbled: :onKeyPress, |
||
109 | captured: :onKeyPressCapture |
||
110 | } |
||
111 | }, |
||
112 | keyUp: { |
||
113 | phasedRegistrationNames: { |
||
114 | bubbled: :onKeyUp, |
||
115 | captured: :onKeyUpCapture |
||
116 | } |
||
117 | }, |
||
118 | load: { |
||
119 | phasedRegistrationNames: { |
||
120 | bubbled: :onLoad, |
||
121 | captured: :onLoadCapture |
||
122 | } |
||
123 | }, |
||
124 | error: { |
||
125 | phasedRegistrationNames: { |
||
126 | bubbled: :onError, |
||
127 | captured: :onErrorCapture |
||
128 | } |
||
129 | }, |
||
130 | mouseDown: { |
||
131 | phasedRegistrationNames: { |
||
132 | bubbled: :onMouseDown, |
||
133 | captured: :onMouseDownCapture |
||
134 | } |
||
135 | }, |
||
136 | mouseMove: { |
||
137 | phasedRegistrationNames: { |
||
138 | bubbled: :onMouseMove, |
||
139 | captured: :onMouseMoveCapture |
||
140 | } |
||
141 | }, |
||
142 | mouseOut: { |
||
143 | phasedRegistrationNames: { |
||
144 | bubbled: :onMouseOut, |
||
145 | captured: :onMouseOutCapture |
||
146 | } |
||
147 | }, |
||
148 | mouseOver: { |
||
149 | phasedRegistrationNames: { |
||
150 | bubbled: :onMouseOver, |
||
151 | captured: :onMouseOverCapture |
||
152 | } |
||
153 | }, |
||
154 | mouseUp: { |
||
155 | phasedRegistrationNames: { |
||
156 | bubbled: :onMouseUp, |
||
157 | captured: :onMouseUpCapture |
||
158 | } |
||
159 | }, |
||
160 | paste: { |
||
161 | phasedRegistrationNames: { |
||
162 | bubbled: :onPaste, |
||
163 | captured: :onPasteCapture |
||
164 | } |
||
165 | }, |
||
166 | reset: { |
||
167 | phasedRegistrationNames: { |
||
168 | bubbled: :onReset, |
||
169 | captured: :onResetCapture |
||
170 | } |
||
171 | }, |
||
172 | scroll: { |
||
173 | phasedRegistrationNames: { |
||
174 | bubbled: :onScroll, |
||
175 | captured: :onScrollCapture |
||
176 | } |
||
177 | }, |
||
178 | submit: { |
||
179 | phasedRegistrationNames: { |
||
180 | bubbled: :onSubmit, |
||
181 | captured: :onSubmitCapture |
||
182 | } |
||
183 | }, |
||
184 | touchCancel: { |
||
185 | phasedRegistrationNames: { |
||
186 | bubbled: :onTouchCancel, |
||
187 | captured: :onTouchCancelCapture |
||
188 | } |
||
189 | }, |
||
190 | touchEnd: { |
||
191 | phasedRegistrationNames: { |
||
192 | bubbled: :onTouchEnd, |
||
193 | captured: :onTouchEndCapture |
||
194 | } |
||
195 | }, |
||
196 | touchMove: { |
||
197 | phasedRegistrationNames: { |
||
198 | bubbled: :onTouchMove, |
||
199 | captured: :onTouchMoveCapture |
||
200 | } |
||
201 | }, |
||
202 | touchStart: { |
||
203 | phasedRegistrationNames: { |
||
204 | bubbled: :onTouchStart, |
||
205 | captured: :onTouchStartCapture |
||
206 | } |
||
207 | }, |
||
208 | wheel: { |
||
209 | phasedRegistrationNames: { |
||
210 | bubbled: :onWheel, |
||
211 | captured: :onWheelCapture |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | |||
216 | TOP_LEVEL_EVENTS_TO_DISPATCH_CONFIG = { |
||
217 | topBlur: EVENT_TYPES[:blur], |
||
218 | topClick: EVENT_TYPES[:click], |
||
219 | topContextMenu: EVENT_TYPES[:contextMenu], |
||
220 | topCopy: EVENT_TYPES[:copy], |
||
221 | topCut: EVENT_TYPES[:cut], |
||
222 | topDoubleClick: EVENT_TYPES[:doubleClick], |
||
223 | topDrag: EVENT_TYPES[:drag], |
||
224 | topDragEnd: EVENT_TYPES[:dragEnd], |
||
225 | topDragEnter: EVENT_TYPES[:dragEnter], |
||
226 | topDragExit: EVENT_TYPES[:dragExit], |
||
227 | topDragLeave: EVENT_TYPES[:dragLeave], |
||
228 | topDragOver: EVENT_TYPES[:dragOver], |
||
229 | topDragStart: EVENT_TYPES[:dragStart], |
||
230 | topDrop: EVENT_TYPES[:drop], |
||
231 | topError: EVENT_TYPES[:error], |
||
232 | topFocus: EVENT_TYPES[:focus], |
||
233 | topInput: EVENT_TYPES[:input], |
||
234 | topKeyDown: EVENT_TYPES[:keyDown], |
||
235 | topKeyPress: EVENT_TYPES[:keyPress], |
||
236 | topKeyUp: EVENT_TYPES[:keyUp], |
||
237 | topLoad: EVENT_TYPES[:load], |
||
238 | topMouseDown: EVENT_TYPES[:mouseDown], |
||
239 | topMouseMove: EVENT_TYPES[:mouseMove], |
||
240 | topMouseOut: EVENT_TYPES[:mouseOut], |
||
241 | topMouseOver: EVENT_TYPES[:mouseOver], |
||
242 | topMouseUp: EVENT_TYPES[:mouseUp], |
||
243 | topPaste: EVENT_TYPES[:paste], |
||
244 | topReset: EVENT_TYPES[:reset], |
||
245 | topScroll: EVENT_TYPES[:scroll], |
||
246 | topSubmit: EVENT_TYPES[:submit], |
||
247 | topTouchCancel: EVENT_TYPES[:touchCancel], |
||
248 | topTouchEnd: EVENT_TYPES[:touchEnd], |
||
249 | topTouchMove: EVENT_TYPES[:touchMove], |
||
250 | topTouchStart: EVENT_TYPES[:touchStart], |
||
251 | topWheel: EVENT_TYPES[:wheel] |
||
252 | } |
||
253 | |||
254 | def initialize |
||
255 | TOP_LEVEL_EVENTS_TO_DISPATCH_CONFIG.each do |type, dispatch_config| |
||
256 | dispatch_config[:dependencies] = [type] |
||
257 | end |
||
258 | end |
||
259 | |||
260 | def event_types |
||
261 | EVENT_TYPES |
||
262 | end |
||
263 | View Code Duplication | ||
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
264 | def extract_event(top_level_type, top_level_target, top_level_target_id, event) |
||
265 | dispatch_config = TOP_LEVEL_EVENTS_TO_DISPATCH_CONFIG[top_level_type] |
||
266 | return [] unless dispatch_config |
||
267 | |||
268 | SyntheticEvent.new(event).tap do |synthetic_event| |
||
269 | InstanceHandles.traverse_two_phase(top_level_target_id) do |target_id, upwards| |
||
270 | listener = BrowserEvent.listener_at_phase(target_id, dispatch_config, upwards ? :bubbled : :captured) |
||
271 | synthetic_event.add_listener(listener, target_id) if listener |
||
272 | end |
||
273 | end |
||
274 | end |
||
275 | end |
||
276 | end |
||
277 |