Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Small touchmove's will be accepted before longTap is cancelled #529

Closed
wants to merge 1 commit into from

2 participants

@jpbochi

We implemented a small threshold (of 10px by default) of movement that is accepted before a longTap is cancelled.

@madrobby
Owner

Although I do like the idea, this is missing tests. Feel free to open a new pull request based on current master with tests added.

@madrobby madrobby closed this
@jpbochi

@madrobby I think there were no tests at all for longTap when I submitted this PR.

@madrobby
Owner

@jpbochi time to add them! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. @jpbochi
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/touch.js
View
18 src/touch.js
@@ -16,11 +16,13 @@
return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
}
+ var longTapDelay = 750, longTapThreshold = 100, longTapTimeout
+
function longTap() {
longTapTimeout = null
if (touch.last) {
touch.el.trigger('longTap')
- touch = {}
+ touch.isLongTap = true
}
}
@@ -54,17 +56,25 @@
longTapTimeout = setTimeout(longTap, longTapDelay)
})
.bind('touchmove', function(e){
- cancelLongTap()
touch.x2 = e.touches[0].pageX
touch.y2 = e.touches[0].pageY
- if (Math.abs(touch.x1 - touch.x2) > 10)
+
+ var dx = (touch.x1 - touch.x2)
+ var dy = (touch.y1 - touch.y2)
+ var dsquared = (dx*dx) + (dy*dy)
+ if (dsquared > longTapThreshold) {
+ cancelLongTap()
e.preventDefault()
+ }
})
.bind('touchend', function(e){
cancelLongTap()
+ if (touch.isLongTap) {
+ touch = {};
+
// swipe
- if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
+ } else if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
(touch.y2 && Math.abs(touch.y1 - touch.y2) > 30))
swipeTimeout = setTimeout(function() {
Something went wrong with that request. Please try again.