class Browser::Event
Wrapper for JS events
Public Class Methods
@param [JS] the native event to wrap
# File lib/browser/event.rb, line 5 def initialize native @native = native end
Public Instance Methods
@return [Boolean] true if the Alt key was pressed when this event fired,
false otherwise
# File lib/browser/event.rb, line 55 def alt? `#@native.altKey` end
@return [Numeric] the key code associated with this event. Only useful for
keyboard-based events.
# File lib/browser/event.rb, line 69 def code `#@native.keyCode` end
@return [Boolean] true if the Ctrl key was pressed when this event fired,
false otherwise
# File lib/browser/event.rb, line 49 def ctrl? `#@native.ctrlKey` end
@return [Boolean] true if the Meta/Command/Windows key was pressed when
this event fired, false otherwise
# File lib/browser/event.rb, line 37 def meta? `#@native.metaKey` end
Return properties on the event not covered by Ruby methods.
# File lib/browser/event.rb, line 74 def method_missing name, *args property = name.gsub(/_[a-z]/) { |match| match[-1, 1].upcase } value = `#@native[property]` if `!!value && #{Proc === value}` value.call(*args) elsif `value == null` nil else value end end
Prevent the runtime from executing this event's default behavior. For example, prevent navigation after clicking a link.
@return [Browser::Event] self
# File lib/browser/event.rb, line 13 def prevent `#@native.preventDefault()` self end
@return [Boolean] true if `prevent` has been called on this event, false
otherwise
# File lib/browser/event.rb, line 31 def prevented? `#@native.defaultPrevented` end
@return [Boolean] true if the Shift key was pressed when this event fired,
false otherwise
# File lib/browser/event.rb, line 43 def shift? `#@native.shiftKey` end
Prevent the runtime from bubbling this event up the hierarchy. This is typically used to keep an event local to the element on which it was triggered, such as keeping a click event on a button from unintentionally triggering a handler on a parent element.
@return self
# File lib/browser/event.rb, line 24 def stop_propagation `#@native.stopPropagation()` self end
The target for this event
@return [Browser::Element] the element on which this event was triggered @todo Handle non-DOM events here
# File lib/browser/event.rb, line 63 def target Element.new(`#@native.target`) end
@return [JS] the native event wrapped by this object.
# File lib/browser/event.rb, line 88 def to_n @native end