diff --git a/src/touch.js b/src/touch.js index ea3f9d258..7d7bec09c 100644 --- a/src/touch.js +++ b/src/touch.js @@ -40,7 +40,7 @@ } $(document).ready(function(){ - var now, delta, firstTouch + var now, delta, deltaX = 0, deltaY = 0, firstTouch if ('MSGesture' in window) { gesture = new MSGesture() @@ -78,6 +78,9 @@ cancelLongTap() touch.x2 = firstTouch.pageX touch.y2 = firstTouch.pageY + + deltaX += Math.abs(touch.x1 - touch.x2) + deltaY += Math.abs(touch.y1 - touch.y2) }) .on('touchend MSPointerUp', function(e){ if(e.type == 'MSPointerUp' && !isPrimaryTouch(e)) return; @@ -95,31 +98,39 @@ // normal tap else if ('last' in touch) - // delay by one tick so we can cancel the 'tap' event if 'scroll' fires - // ('tap' fires before 'scroll') - tapTimeout = setTimeout(function() { - - // trigger universal 'tap' with the option to cancelTouch() - // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) - var event = $.Event('tap') - event.cancelTouch = cancelAll - touch.el.trigger(event) - - // trigger double tap immediately - if (touch.isDoubleTap) { - touch.el.trigger('doubleTap') - touch = {} - } - - // trigger single tap after 250ms of inactivity - else - touchTimeout = setTimeout(function(){ - touchTimeout = null - touch.el.trigger('singleTap') + // don't fire tap when delta position changed by more than 30 pixels, + // for instance when moving to a point and back to origin + if (deltaX < 30 && deltaY < 30) { + // delay by one tick so we can cancel the 'tap' event if 'scroll' fires + // ('tap' fires before 'scroll') + tapTimeout = setTimeout(function() { + + // trigger universal 'tap' with the option to cancelTouch() + // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) + var event = $.Event('tap') + event.cancelTouch = cancelAll + touch.el.trigger(event) + + // trigger double tap immediately + if (touch.isDoubleTap) { + touch.el.trigger('doubleTap') touch = {} - }, 250) + } + + // trigger single tap after 250ms of inactivity + else { + touchTimeout = setTimeout(function(){ + touchTimeout = null + touch.el.trigger('singleTap') + touch = {} + }, 250) + } + }, 0) + } else { + touch = {} + } + deltaX = deltaY = 0 - }, 0) }) // when the browser window loses focus, // for example when a modal dialog is shown, diff --git a/test/touch.html b/test/touch.html index 1d7a35772..fea08f8a8 100644 --- a/test/touch.html +++ b/test/touch.html @@ -255,6 +255,30 @@