From f5bb023ef7ced843b7efc0e44d44dfa573d007be Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 9 Jun 2014 22:00:35 -0500 Subject: [PATCH] fix(tap): cancel simulated click w/ hold events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gesture hold event and ionic’s tap will both fire since the tap has no strict duration between its start and end (a click will always fire no matter how long the press is held). If a hold event fires from ionic.Gesture, then the simulated click which would fire on touchend/mouseup should be canceled. --- js/utils/gestures.js | 4 +++- js/utils/tap.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/utils/gestures.js b/js/utils/gestures.js index 99b48aa4480..65e61f31fc1 100644 --- a/js/utils/gestures.js +++ b/js/utils/gestures.js @@ -1030,6 +1030,7 @@ // we trigger the hold event this.timer = setTimeout(function() { if(ionic.Gestures.detection.current.name == 'hold') { + ionic.tap.cancelClick(); inst.trigger('hold', ev); } }, inst.options.hold_timeout); @@ -1088,8 +1089,9 @@ // do a single tap if(!did_doubletap || inst.options.tap_always) { + ionic.tap.cancelClick(); ionic.Gestures.detection.current.name = 'tap'; - inst.trigger(ionic.Gestures.detection.current.name, ev); + inst.trigger('tap', ev); } } } diff --git a/js/utils/tap.js b/js/utils/tap.js index 414495e1d0b..a6eaf1a295a 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -239,6 +239,12 @@ ionic.tap = { setTolerance: function(releaseTolerance, releaseButtonTolerance) { TAP_RELEASE_TOLERANCE = releaseTolerance; TAP_RELEASE_BUTTON_TOLERANCE = releaseButtonTolerance; + }, + + cancelClick: function() { + // used to cancel any simulated clicks which may happen on a touchend/mouseup + // gestures uses this method within its tap and hold events + tapPointerMoved = true; } };