From 89da8f42a2493f0017a64ed43ae3be60b51d751c Mon Sep 17 00:00:00 2001 From: Norik Davtian Date: Mon, 16 Mar 2015 23:57:58 -0700 Subject: [PATCH 1/2] ngClick using ngTouch fires twice issue on iOS This closes #6251 --- src/ngTouch/directive/ngClick.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ngTouch/directive/ngClick.js b/src/ngTouch/directive/ngClick.js index 90274aba7322..1ddacfccfacf 100644 --- a/src/ngTouch/directive/ngClick.js +++ b/src/ngTouch/directive/ngClick.js @@ -52,12 +52,13 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers. var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click var CLICKBUSTER_THRESHOLD = 25; // 25 pixels in any dimension is the limit for busting clicks. + var EVENT_REFIRE_THRESHOLD = 100; // 100ms is reasonable enough for accepting next event var ACTIVE_CLASS_NAME = 'ng-click-active'; var lastPreventedTime; var touchCoordinates; var lastLabelClickCoordinates; - + var lastEventTriggeredTime; // TAP EVENTS AND GHOST CLICKS // @@ -274,10 +275,14 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', // - On mobile browsers, the simulated "fast" click will call this. // - But the browser's follow-up slow click will be "busted" before it reaches this handler. // Therefore it's safe to use this directive on both mobile and desktop. + // Debounce the click event to make sure only one click event is fired within set threshold. element.on('click', function(event, touchend) { - scope.$apply(function() { - clickHandler(scope, {$event: (touchend || event)}); - }); + if(!lastEventTriggeredTime || (event.timeStamp - lastEventTriggeredTime > EVENT_REFIRE_THRESHOLD)){ + lastEventTriggeredTime = event.timeStamp; + scope.$apply(function() { + clickHandler(scope, {$event: (touchend || event)}); + }); + } }); element.on('mousedown', function(event) { From d07dfd774a763830a5d45aebd6e22e3a59989ae3 Mon Sep 17 00:00:00 2001 From: Norik Davtian Date: Tue, 17 Mar 2015 00:56:44 -0700 Subject: [PATCH 2/2] fixes ngClick using ngTouch fires twice issue Reduced the EVENT_REFIRE_THRESHOLD to 25ms.. in most cases the bug event double fire happens withing 6-12ms Closes #6251 --- src/ngTouch/directive/ngClick.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngTouch/directive/ngClick.js b/src/ngTouch/directive/ngClick.js index 1ddacfccfacf..ce65e1a94c4d 100644 --- a/src/ngTouch/directive/ngClick.js +++ b/src/ngTouch/directive/ngClick.js @@ -52,7 +52,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', var MOVE_TOLERANCE = 12; // 12px seems to work in most mobile browsers. var PREVENT_DURATION = 2500; // 2.5 seconds maximum from preventGhostClick call to click var CLICKBUSTER_THRESHOLD = 25; // 25 pixels in any dimension is the limit for busting clicks. - var EVENT_REFIRE_THRESHOLD = 100; // 100ms is reasonable enough for accepting next event + var EVENT_REFIRE_THRESHOLD = 25; // 25ms is reasonable enough for accepting next event var ACTIVE_CLASS_NAME = 'ng-click-active'; var lastPreventedTime;