Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Last active December 11, 2015 12:29
Show Gist options
  • Save mrrooijen/4601096 to your computer and use it in GitHub Desktop.
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…
@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