-
-
Save scottmas/8028874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
}); | |
} | |
}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added in support for passing in $event to the directive.