From 7e2d01ccd8ab58dd70ead8872688f81f6448b228 Mon Sep 17 00:00:00 2001 From: Mike Calvanese Date: Thu, 5 Feb 2015 17:40:35 -0500 Subject: [PATCH] fix(ngTouch): don't prevent click event after a touchmove Remove the touchmove handler so that resetState is not called on touchmove. The touchend event handler already prevents the click from being triggered if the distance moved exceeds the MOVE_TOLERANCE, so detection of touchmove is not needed. Previously, because of resetState on touchmove, the click would not be triggered even if the event coordinates changed by only 1px or 2px, which seems to be very common for taps on mobile browsers. --- src/ngTouch/directive/ngClick.js | 8 ++------ test/ngTouch/directive/ngClickSpec.js | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/ngTouch/directive/ngClick.js b/src/ngTouch/directive/ngClick.js index 90274aba7322..57650a3f7ad3 100644 --- a/src/ngTouch/directive/ngClick.js +++ b/src/ngTouch/directive/ngClick.js @@ -66,7 +66,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', // double-tapping, and then fire a click event. // // This delay sucks and makes mobile apps feel unresponsive. - // So we detect touchstart, touchmove, touchcancel and touchend ourselves and determine when + // So we detect touchstart, touchcancel and touchend ourselves and determine when // the user has tapped on something. // // What happens when the browser then generates a click event? @@ -78,7 +78,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', // So the sequence for a tap is: // - global touchstart: Sets an "allowable region" at the point touched. // - element's touchstart: Starts a touch - // (- touchmove or touchcancel ends the touch, no click follows) + // (- touchcancel ends the touch, no click follows) // - element's touchend: Determines if the tap is valid (didn't move too far away, didn't hold // too long) and fires the user's tap handler. The touchend also calls preventGhostClick(). // - preventGhostClick() removes the allowable region the global touchstart created. @@ -227,10 +227,6 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', touchStartY = e.clientY; }); - element.on('touchmove', function(event) { - resetState(); - }); - element.on('touchcancel', function(event) { resetState(); }); diff --git a/test/ngTouch/directive/ngClickSpec.js b/test/ngTouch/directive/ngClickSpec.js index 921c64578b2b..4a7900cebecf 100644 --- a/test/ngTouch/directive/ngClickSpec.js +++ b/test/ngTouch/directive/ngClickSpec.js @@ -97,7 +97,7 @@ describe('ngClick (touch)', function() { })); - it('should not click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) { + it('should not prevent click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) { element = $compile('
')($rootScope); $rootElement.append(element); $rootScope.$digest(); @@ -112,11 +112,11 @@ describe('ngClick (touch)', function() { browserTrigger(element, 'touchmove'); browserTrigger(element, 'touchend',{ keys: [], - x: 400, - y: 400 + x: 15, + y: 15 }); - expect($rootScope.tapped).toBeUndefined(); + expect($rootScope.tapped).toEqual(true); })); it('should add the CSS class while the element is held down, and then remove it', inject(function($rootScope, $compile, $rootElement) {