Skip to content
Permalink
Browse files

Merge pull request #512 from koenbok/feature/pointerevent-support

Add support for pointer events
  • Loading branch information
nvh committed Jun 9, 2017
2 parents c9450ed + 8a786de commit 580846c424833dbe64feaa7b3598b6360ff69883
Showing with 25 additions and 10 deletions.
  1. +22 −4 framer/Events.coffee
  2. +3 −6 framer/Extras/Hints.coffee
@@ -5,6 +5,7 @@ Utils = require "./Utils"

Events = {}


# Standard dom events
Events.MouseUp = "mouseup"
Events.MouseDown = "mousedown"
@@ -15,8 +16,18 @@ Events.MouseWheel = "mousewheel"
Events.DoubleClick = "dblclick"
Events.MouseDoubleClick = "dblclick" # Alias for consistent naming

supportsPointerEvents = window.onpointerdown is null and window.onpointermove is null and window.onpointerup is null

Events.PointerUp = "pointerup"
Events.PointerDown = "pointerdown"
Events.PointerOver = "pointerover"
Events.PointerOut = "pointerout"
Events.PointerMove = "pointermove"

# Standard touch events
Events.enableEmulatedTouchEvents = (enable=true) ->
# never emulate if the browsers supports pointer events
return if supportsPointerEvents
if enable
Events.TouchStart = Events.MouseDown
Events.TouchEnd = Events.MouseUp
@@ -26,11 +37,18 @@ Events.enableEmulatedTouchEvents = (enable=true) ->
Events.TouchEnd = "touchend"
Events.TouchMove = "touchmove"

Events.enableEmulatedTouchEvents(false)

# Let's make sure the touch events work on desktop too
if not Utils.isTouch()
Events.enableEmulatedTouchEvents()
Events.enableEmulatedTouchEvents(not Utils.isTouch())

if supportsPointerEvents
Events.MouseUp = Events.PointerUp
Events.MouseDown = Events.PointerDown
Events.MouseOver = Events.PointerOver
Events.MouseOut = Events.PointerOut
Events.MouseMove = Events.PointerMove
Events.TouchStart = Events.PointerDown
Events.TouchEnd = Events.PointerUp
Events.TouchMove = Events.PointerMove

Events.Click = Events.TouchEnd

@@ -8,12 +8,9 @@ class Hints
@_context.index = 10000

@_context.run =>
if Utils.isTouch()
Events.wrap(document).addEventListener("touchstart", @_handleDown, capture=true)
Events.wrap(document).addEventListener("touchend", @_handleUp, capture=true)
else
Events.wrap(document).addEventListener("mousedown", @_handleDown, capture=true)
Events.wrap(document).addEventListener("mouseup", @_handleUp, capture=true)
# Events.TouchStart and TouchEnd are mapped to Mouse or Pointer events automatically
Events.wrap(document).addEventListener(Events.TouchStart, @_handleDown, capture=true)
Events.wrap(document).addEventListener(Events.TouchEnd, @_handleUp, capture=true)

_handleDown: (event) =>
return if @_isPreloading()

0 comments on commit 580846c

Please sign in to comment.
You can’t perform that action at this time.