Skip to content

Instantly share code, notes, and snippets.

@scottmas
Forked from mhuneke/ngTap.js
Created December 18, 2013 20:01
Show Gist options
  • Save scottmas/8028874 to your computer and use it in GitHub Desktop.
Save scottmas/8028874 to your computer and use it in GitHub Desktop.
app.directive("ngTap", ["$parse", function($parse) {
return function($scope, $element, $attributes) {
var tapped;
tapped = false;
$element.bind("click", function(event) {
if (!tapped) {
var fn = $parse($attributes["ngTap"]);
$scope.$apply(function() {
fn($scope, {$event:event});
});
}
});
$element.bind("touchstart", function(event) {
return tapped = true;
});
$element.bind("touchmove", function(event) {
tapped = false;
return event.stopImmediatePropagation();
});
return $element.bind("touchend", function() {
if (tapped) {
var fn = $parse($attributes["ngTap"]);
$scope.$apply(function() {
fn($scope, {$event:event});
});
}
});
};
}]);
@scottmas
Copy link
Author

Added in support for passing in $event to the directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment