From f3bd258c9ee39503c9d34d85ad31c754fff0c03c Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 1 Apr 2014 10:34:35 -0500 Subject: [PATCH] fix(tap): Prevent "clicking" when scrolling --- js/ext/angular/test/list.html | 120 ++++++++++++++++++++++++++++------ js/utils/tap.js | 16 ++--- 2 files changed, 107 insertions(+), 29 deletions(-) diff --git a/js/ext/angular/test/list.html b/js/ext/angular/test/list.html index 7fcd7802cd8..14b48b03ecb 100644 --- a/js/ext/angular/test/list.html +++ b/js/ext/angular/test/list.html @@ -8,20 +8,42 @@
CLICK!
- +
Mouse Move!
+
Touch Move!
+
@@ -35,7 +57,8 @@

List Tests

- List Tests option-buttons="optionButtons1"> - +

{{item.from}}

{{item.text}}

@@ -122,13 +145,13 @@

YELLOW {{slideBox.slideIndex}}

- + diff --git a/js/utils/tap.js b/js/utils/tap.js index 66dee8e2d4d..aa8f4a4705c 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -135,10 +135,10 @@ return false; } - return (c.x > startCoordinates.x + HIT_RADIUS || - c.x < startCoordinates.x - HIT_RADIUS || - c.y > startCoordinates.y + HIT_RADIUS || - c.y < startCoordinates.y - HIT_RADIUS); + return (c.x > startCoordinates.x + TOUCH_TOLERANCE_X || + c.x < startCoordinates.x - TOUCH_TOLERANCE_X || + c.y > startCoordinates.y + TOUCH_TOLERANCE_Y || + c.y < startCoordinates.y - TOUCH_TOLERANCE_Y); } function recordCoordinates(event) { @@ -180,7 +180,6 @@ clickPreventTimerId = setTimeout(function(){ var tap = isRecentTap(e); if(tap) delete tapCoordinates[tap.id]; - startCoordinates = {}; }, REMOVE_PREVENT_DELAY); } @@ -206,10 +205,12 @@ } var tapCoordinates = {}; // used to remember coordinates to ignore if they happen again quickly - var startCoordinates = {}; // used to remember where the coordinates of the start of the tap + var startCoordinates = {}; // used to remember where the coordinates of the start of a touch var CLICK_PREVENT_DURATION = 1500; // max milliseconds ghostclicks in the same area should be prevented var REMOVE_PREVENT_DELAY = 380; // delay after a touchend/mouseup before removing the ghostclick prevent - var HIT_RADIUS = 15; + var HIT_RADIUS = 15; // surrounding area of a click that if a ghostclick happens it would get ignored + var TOUCH_TOLERANCE_X = 4; // how much the X coordinates can be off between start/end, but still a click + var TOUCH_TOLERANCE_Y = 2; // how much the Y coordinates can be off between start/end, but still a click ionic.Platform.ready(function(){ @@ -230,7 +231,6 @@ // in the case the user touched the screen, then scrolled, it shouldn't fire the click document.addEventListener('touchstart', recordStartCoordinates, false); - document.addEventListener('mousedown', recordStartCoordinates, false); }); })(this, document, ionic);