Sha256: a669266daaa91f7497ec73e5d4796370f9518209b046596396aaa79c948e6dd0

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# Wraps native jQuery event objects.
class Event
  def initialize(native)
    @native = native
  end

  def [](name)
    `#@native[name]`
  end

  def type
    `#@native.type`
  end

  ##
  # Element

  def current_target
    `$(#@native.currentTarget)`
  end

  def target
    `$(#@native.target)`
  end

  ##
  # Propagation

  def prevented?
    `#@native.isDefaultPrevented()`
  end

  def prevent
    `#@native.preventDefault()`
  end

  def stopped?
    `#@native.propagationStopped()`
  end

  def stop
    `#@native.stopPropagation()`
  end

  def stop_immediate
    `#@native.stopImmediatePropagation()`
  end

  # Stops propagation and prevents default action.
  def kill
    stop
    prevent
  end

  # to be removed?
  alias default_prevented? prevented?
  alias prevent_default prevent
  alias propagation_stopped? stopped?
  alias stop_propagation stop
  alias stop_immediate_propagation stop_immediate

  ##
  # Keyboard/Mouse/Touch

  def page_x
    `#@native.pageX`
  end

  def page_y
    `#@native.pageY`
  end

  def touch_x
    `#@native.originalEvent.touches[0].pageX`
  end

  def touch_y
    `#@native.originalEvent.touches[0].pageY`
  end

  def ctrl_key
    `#@native.ctrlKey`
  end

  def key_code
    `#@native.keyCode`
  end

  def which
    `#@native.which`
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-jquery-0.2.0 opal/opal-jquery/event.rb