Skip to content

Instantly share code, notes, and snippets.

@jvelo
Created April 15, 2014 13:03
Show Gist options
  • Save jvelo/10730764 to your computer and use it in GitHub Desktop.
Save jvelo/10730764 to your computer and use it in GitHub Desktop.
A better ng-tap
myapp.directive("ngTap", ['$parse', function($parse) {
return {
link: function ($scope, $element, $attributes) {
var fun = $parse($attributes["ngTap"])
if (!('ontouchstart' in document.documentElement)) {
$element.bind("click", function (event) {
return $scope.$apply(function () {
fun($scope, {$event: event});
});
});
}
else {
var tapped = false;
$element.bind("touchstart", function (event) {
return tapped = true;
});
$element.bind("touchmove", function (event) {
tapped = false;
return event.stopImmediatePropagation();
});
$element.bind("touchend", function (event) {
if (tapped) {
return $scope.$apply(function () {
fun($scope, {$event: event});
});
}
});
}
}
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment