Last active
December 11, 2015 12:29
-
-
Save mrrooijen/4601096 to your computer and use it in GitHub Desktop.
Adds the `ng-tap` directive for mobile "tap" events. Falls back to a "click" event in case "touch" events aren't present at runtime. For example, when on iOS the tap event would invoke (removing the 300ms click delay) and cancel the Click event (that has the 300ms delay). But, if in a Desktop (mouse) environment, "touch" events are ignored and t…
This file contains 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", -> | |
($scope, $element, $attributes) -> | |
tapped = false | |
$element.bind "click", -> | |
$scope.$apply($attributes["ngTap"]) unless tapped | |
$element.bind "touchstart", (event) -> | |
tapped = true | |
$element.bind "touchmove", (event) -> | |
tapped = false | |
event.stopImmediatePropagation() # Will otherwise interfere with -webkit-overflow-scrolling: touch | |
$element.bind "touchend", -> | |
$scope.$apply($attributes["ngTap"]) if tapped | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment