class Browser::Event

Wrapper for JS events

Public Class Methods

new(native) click to toggle source

@param [JS] the native event to wrap

# File lib/browser/event.rb, line 5
def initialize native
  @native = native
end

Public Instance Methods

alt?() click to toggle source

@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
code() click to toggle source

@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
ctrl?() click to toggle source

@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
meta?() click to toggle source

@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
method_missing(name, *args) click to toggle source

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() click to toggle source

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
prevented?() click to toggle source

@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
shift?() click to toggle source

@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
stop_propagation() click to toggle source

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
target() click to toggle source

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
to_n() click to toggle source

@return [JS] the native event wrapped by this object.

# File lib/browser/event.rb, line 88
def to_n
  @native
end