Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+14 −4
Split
View
@@ -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() {