Skip to content

Commit

Permalink
Fix gesture events on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Bok committed Mar 1, 2016
1 parent 460cf79 commit dd2301c
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions framer/GestureInputRecognizer.coffee
Expand Up @@ -12,6 +12,14 @@ GestureInputMinimumFingerDistance = 30

{DOMEventManager} = require "./DOMEventManager"

TouchStart = "touchstart"
TouchMove = "touchmove"
TouchEnd = "touchend"

if not Utils.isTouch()
TouchStart = "mousedown"
TouchMove = "mousemove"
TouchEnd = "mouseup"

Utils.sanitizeRotation = ->
previous = null
Expand All @@ -24,7 +32,7 @@ class exports.GestureInputRecognizer

constructor: ->
@em = new DOMEventManager()
@em.wrap(window).addEventListener("touchstart", @touchstart)
@em.wrap(window).addEventListener(TouchStart, @touchstart)

destroy: ->
@em.removeAllListeners()
Expand All @@ -38,8 +46,8 @@ class exports.GestureInputRecognizer
# Only fire if we are not already in a session
return if @session

@em.wrap(window).addEventListener("touchmove", @touchmove)
@em.wrap(window).addEventListener("touchend", @touchend)
@em.wrap(window).addEventListener(TouchMove, @touchmove)
@em.wrap(window).addEventListener(TouchEnd, @touchend)
@em.wrap(window).addEventListener("webkitmouseforcechanged", @_updateMacForce)

@session =
Expand Down Expand Up @@ -71,13 +79,14 @@ class exports.GestureInputRecognizer
touchend: (event) =>
# Only fire if there are no fingers left on the screen

if Utils.isTouch()
return unless (event.touches.length == 0)
else
return unless (event.touches.length == event.changedTouches.length)
if event.touches?
if Utils.isTouch()
return unless (event.touches.length == 0)
else
return unless (event.touches.length == event.changedTouches.length)

@em.wrap(window).removeEventListener("touchmove", @touchmove)
@em.wrap(window).removeEventListener("touchend", @touchend)
@em.wrap(window).removeEventListener(TouchMove, @touchmove)
@em.wrap(window).removeEventListener(TouchEnd, @touchend)
@em.wrap(window).removeEventListener("webkitmouseforcechanged", @_updateMacForce)

event = @_getGestureEvent(event)
Expand Down

0 comments on commit dd2301c

Please sign in to comment.