diff --git a/src/touch.js b/src/touch.js index c31595089..4b4cfd65f 100644 --- a/src/touch.js +++ b/src/touch.js @@ -3,7 +3,8 @@ // Zepto.js may be freely distributed under the MIT license. ;(function($){ - var touch = {}, touchTimeout + var touch = {}, touchTimeout, tapTimeout + var longTapDelay = 750, longTapTimeout function parentIfText(node){ return 'tagName' in node ? node : node.parentNode @@ -14,8 +15,6 @@ return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down') } - var longTapDelay = 750, longTapTimeout - function longTap(){ longTapTimeout = null if (touch.last) { @@ -29,6 +28,14 @@ longTapTimeout = null } + function cancelAll() { + if (touchTimeout) clearTimeout(touchTimeout) + if (tapTimeout) clearTimeout(tapTimeout) + if (longTapTimeout) clearTimeout(longTapTimeout) + longTapTimeout = touchTimeout = null + touch = {} + } + $(document).ready(function(){ var now, delta @@ -63,7 +70,9 @@ // normal tap } else if ('last' in touch) { - touch.el.trigger('tap') + tapTimeout = setTimeout(function() { + touch.el.trigger('tap') + }, 0); touchTimeout = setTimeout(function(){ touchTimeout = null @@ -71,12 +80,9 @@ touch = {} }, 250) } - }).bind('touchcancel', function(){ - if (touchTimeout) clearTimeout(touchTimeout) - if (longTapTimeout) clearTimeout(longTapTimeout) - longTapTimeout = touchTimeout = null - touch = {} - }) + }).bind('touchcancel', cancelAll) + + $(window).bind('scroll', cancelAll) }) ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){ diff --git a/test/touch_functional.html b/test/touch_functional.html index 0145e387e..27fbd5811 100644 --- a/test/touch_functional.html +++ b/test/touch_functional.html @@ -12,10 +12,14 @@