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

fix(ngClick): make ngTouch adhere to MOVE_TOLERANCE on click event #6330

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/ngTouch/directive/ngClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
tapElement, // Used to blur the element after a tap.
startTime, // Used to check if the tap was held too long.
touchStartX,
touchStartY;
touchStartY,
clickStartX,
clickStartY;

function resetState() {
tapping = false;
Expand Down Expand Up @@ -258,13 +260,23 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement',
// - 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.
element.on('click', function(event, touchend) {
if (!touchend) {
// If we have no touchend event, we should still check MOVE_TOLERANCE
// for standard browser clicks. Otherwise if we create directives that
// use the `swipe` service, the element will still receive clicks.
var x = event.clientX, y = event.clientY;
var dist = Math.sqrt( Math.pow(x - clickStartX, 2) + Math.pow(y - clickStartY, 2) );
if (dist >= MOVE_TOLERANCE) return;
}
scope.$apply(function() {
clickHandler(scope, {$event: (touchend || event)});
});
});

element.on('mousedown', function(event) {
element.addClass(ACTIVE_CLASS_NAME);
clickStartX = event.clientX;
clickStartY = event.clientY;
});

element.on('mousemove mouseup', function(event) {
Expand Down