Sha256: 6a374b54f5ac1cd5165d9f4acde33ee88caccc89996109bbfb202ccc0681f942

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# backtick_javascript: true

module Browser; class Event

class Touch < Event
  handles 'touchcancel', 'touchend', 'touchleave', 'touchmove', 'touchstart'

  def self.supported?
    Browser.supports? 'Event.Touch'
  end

  class Definition < Definition
    def alt!
      `#@native.altKey = true`
    end

    def ctrl!
      `#@native.ctrlKey = true`
    end

    def meta!
      `#@native.metaKey = true`
    end

    def shift!
      `#@native.shiftKey = true`
    end
  end

  if Browser.supports? 'Event.constructor'
    def self.construct(name, desc)
      `new TouchEvent(#{name}, #{desc})`
    end
  end if supported?

  alias_native :alt?, :altKey
  alias_native :ctrl?, :ctrlKey
  alias_native :meta?, :metaKey
  alias_native :shift?, :shiftKey

  # TODO: implement touches and targetTouches

  def cancel?
    name.downcase == 'touchcancel'
  end

  def end?
    name.downcase == 'touchend'
  end

  def leave?
    name.downcase == 'touchleave'
  end

  def move?
    name.downcase == 'touchmove'
  end

  def start?
    name.downcase == 'touchstart'
  end
end

end; end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-browser-0.3.5 opal/browser/event/touch.rb
opal-browser-0.3.4 opal/browser/event/touch.rb