Skip to content
Merged
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
28 changes: 27 additions & 1 deletion src/ion-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,31 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [
};

// click handler on the input field which
var scrolling = {
moved: false,
startX: 0,
startY: 0
};
var onTouchStart = function(e) {
scrolling.moved = false;
scrolling.startX = e.touches[0].clientX;
scrolling.startY = e.touches[0].clientY;
};

var onTouchMove = function(e) {
// If finger moves more than 10px flag to cancel
if (Math.abs(e.touches[0].clientX - scrolling.startX) > 10 ||
Math.abs(e.touches[0].clientY - scrolling.startY) > 10) {
scrolling.moved = true;
}
};

var onClick = function (event) {
// Only open the dialog if was not touched at the beginning of
// a legitimate scroll event
if (scrolling.moved) {
return;
}

// prevent the default event and the propagation
event.preventDefault();
Expand Down Expand Up @@ -212,8 +236,10 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [
};

// bind the onClick handler to the click and touchend events
element.bind('click', onClick);
element.bind('touchstart', onTouchStart);
element.bind('touchmove', onTouchMove);
element.bind('touchend', onClick);
element.bind('click', onClick);

// cancel handler for the cancel button which clears the search input field model and hides the
// search container and the ionic backdrop
Expand Down