Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Missing touchcancel protections #554

Closed
wants to merge 1 commit into from

4 participants

Kevin Decker Ryan Eastridge Piotr Rochala Thomas Fuchs
Kevin Decker

When using preventDefault of touchevents in parallel event handlers
the touchcancel event doesn't always trigger, leaving the touch
events in an inconsistent state. This fixes two errors resulting
from this:

  • Phantom swipe events
  • NPE on singleTap trigger
Kevin Decker kpdecker Missing touchcancel protections
When using preventDefault of touchevents in parallel event handlers
the touchcancel event doesn't always trigger, leaving the touch
events in an inconsistent state. This fixes two errors resulting
from this:

- Phantom swipe events
- NPE on singleTap trigger
0acd2b5
Piotr Rochala

+1.

Without this fix I'm getting TypeError: 'undefined' is not an object (evaluating 'touch.el.trigger') at zepto.js.

In my case error is triggered when I try to tap on an element with click/touchstart handler attached using Backbone.

Thomas Fuchs
Owner

Fixed in 03e07e8

Thomas Fuchs madrobby closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 20, 2012
  1. Kevin Decker

    Missing touchcancel protections

    kpdecker authored
    When using preventDefault of touchevents in parallel event handlers
    the touchcancel event doesn't always trigger, leaving the touch
    events in an inconsistent state. This fixes two errors resulting
    from this:
    
    - Phantom swipe events
    - NPE on singleTap trigger
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/touch.js
9 src/touch.js
View
@@ -43,6 +43,13 @@
$(document.body)
.bind('touchstart', function(e){
+ if (e.touches.length === 1 && touch.x2) {
+ // Clear out touch movement data if we have it sticking around
+ // This can occur if touchcancel doesn't fire due to preventDefault, etc.
+ touch.x2 = undefined
+ touch.y2 = undefined
+ }
+
now = Date.now()
delta = now - (touch.last || now)
touch.el = $(parentIfText(e.touches[0].target))
@@ -94,7 +101,7 @@
else {
touchTimeout = setTimeout(function(){
touchTimeout = null
- touch.el.trigger('singleTap')
+ if (touch.el) touch.el.trigger('singleTap')
touch = {}
}, 250)
}
Something went wrong with that request. Please try again.