Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 460363f

Browse files
Tr4v1stravis
authored and
travis
committed
fix(ngClick): subract processing time of the click action
subract the time it takes for the browser to process the click action for preventing the ghost click. long running processes or slower devices where a lot of rendering is happening would get the ghost click every time.
1 parent 25e8c59 commit 460363f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ngTouch/directive/ngClick.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
5757

5858
var ACTIVE_CLASS_NAME = 'ng-click-active';
5959
var lastPreventedTime;
60+
var processingTime;
6061
var touchCoordinates;
6162
var lastLabelClickCoordinates;
6263

@@ -121,7 +122,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
121122
// Global click handler that prevents the click if it's in a bustable zone and preventGhostClick
122123
// was called recently.
123124
function onClick(event) {
124-
if (Date.now() - lastPreventedTime > PREVENT_DURATION) {
125+
if (Date.now() - lastPreventedTime - processingTime > PREVENT_DURATION) {
125126
return; // Too old.
126127
}
127128

@@ -197,6 +198,14 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
197198
checkAllowableRegions(touchCoordinates, x, y);
198199
}
199200

201+
function calculateProcessingTime() {
202+
//use the now - last prevented time on a timeout
203+
processingTime = 0;
204+
$timeout(function() {
205+
processingTime = Date.now() - lastPreventedTime;
206+
}, 0);
207+
}
208+
200209
// Actual linking function.
201210
return function(scope, element, attr) {
202211
var clickHandler = $parse(attr.ngClick),
@@ -251,6 +260,7 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
251260
if (tapping && diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
252261
// Call preventGhostClick so the clickbuster will catch the corresponding click.
253262
preventGhostClick(x, y);
263+
calculateProcessingTime();
254264

255265
// Blur the focused element (the button, probably) before firing the callback.
256266
// This doesn't work perfectly on Android Chrome, but seems to work elsewhere.

0 commit comments

Comments
 (0)