Class: Dommy::Event
- Inherits:
-
Object
show all
- Defined in:
- lib/dommy/event.rb
Direct Known Subclasses
BeforeUnloadEvent, ClipboardEvent, CloseEvent, CompositionEvent, CookieChangeEvent, CustomEvent, FocusEvent, InputEvent, KeyboardEvent, MediaQueryListEvent, MessageEvent, MouseEvent, ProgressEvent, TouchEvent
Constant Summary
collapse
- JS_METHOD_NAMES =
Methods routed through js_call (keep in sync with its when-arms).
%w[preventDefault stopPropagation stopImmediatePropagation composedPath initEvent].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(type, init = nil) ⇒ Event
Returns a new instance of Event.
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/dommy/event.rb', line 212
def initialize(type, init = nil)
@type = type.to_s
@bubbles = !!read_init(init, "bubbles")
@cancelable = !!read_init(init, "cancelable")
@composed = !!read_init(init, "composed")
@default_prevented = false
@propagation_stopped = false
@immediate_propagation_stopped = false
@target = nil
@current_target = nil
@composed_path = []
@time_stamp = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000.0)
end
|
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
229
230
231
|
# File 'lib/dommy/event.rb', line 229
def type
@type
end
|
Instance Method Details
#__internal_prepare_for_dispatch__(target) ⇒ Object
247
248
249
|
# File 'lib/dommy/event.rb', line 247
def __internal_prepare_for_dispatch__(target)
@target ||= target
end
|
#__internal_record_path__(targets) ⇒ Object
Filled in by EventTarget#dispatch_event as the event walks the bubble path so ‘composedPath()` returns the right list.
Per spec, ‘load` events do not propagate to the Window when composed paths are computed (resource-finished signal stays at the target).
335
336
337
338
339
340
341
|
# File 'lib/dommy/event.rb', line 335
def __internal_record_path__(targets)
@composed_path = if @type == "load"
targets.reject { |t| t.is_a?(Window) }
else
targets
end
end
|
#__internal_set_current_target__(target) ⇒ Object
251
252
253
|
# File 'lib/dommy/event.rb', line 251
def __internal_set_current_target__(target)
@current_target = target
end
|
#__js_call__(method, args) ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/dommy/event.rb', line 297
def __js_call__(method, args)
case method
when "preventDefault"
@default_prevented = true if @cancelable
nil
when "stopPropagation"
@propagation_stopped = true
nil
when "stopImmediatePropagation"
@propagation_stopped = true
@immediate_propagation_stopped = true
nil
when "composedPath"
@composed_path.dup
when "initEvent"
init_event(args[0], args[1], args[2])
end
end
|
#__js_get__(key) ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/dommy/event.rb', line 255
def __js_get__(key)
case key
when "type"
@type
when "bubbles"
@bubbles
when "cancelable"
@cancelable
when "composed"
@composed
when "defaultPrevented"
@default_prevented
when "target"
@target
when "currentTarget"
@current_target
when "timeStamp"
@time_stamp
when "cancelBubble"
@propagation_stopped
when "eventPhase"
event_phase
end
end
|
#__js_method_names__ ⇒ Object
293
294
295
|
# File 'lib/dommy/event.rb', line 293
def __js_method_names__
JS_METHOD_NAMES
end
|
#__js_set__(key, value) ⇒ Object
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/dommy/event.rb', line 280
def __js_set__(key, value)
case key
when "cancelBubble"
@propagation_stopped = true if value
end
nil
end
|
#bubbles? ⇒ Boolean
231
232
233
|
# File 'lib/dommy/event.rb', line 231
def bubbles?
@bubbles
end
|
#default_prevented? ⇒ Boolean
235
236
237
|
# File 'lib/dommy/event.rb', line 235
def default_prevented?
@default_prevented
end
|
243
244
245
|
# File 'lib/dommy/event.rb', line 243
def immediate_propagation_stopped?
@immediate_propagation_stopped
end
|
#init_event(type, bubbles = false, cancelable = false) ⇒ Object
Deprecated ‘Event#initEvent(type, bubbles, cancelable)` — older browsers used `document.createEvent(“Event”).initEvent(…)`. Resets internal flags as a side effect.
319
320
321
322
323
324
325
326
327
|
# File 'lib/dommy/event.rb', line 319
def init_event(type, bubbles = false, cancelable = false)
@type = type.to_s
@bubbles = !!bubbles
@cancelable = !!cancelable
@default_prevented = false
@propagation_stopped = false
@immediate_propagation_stopped = false
nil
end
|
#propagation_stopped? ⇒ Boolean
239
240
241
|
# File 'lib/dommy/event.rb', line 239
def propagation_stopped?
@propagation_stopped
end
|