Created
April 15, 2014 13:03
-
-
Save jvelo/10730764 to your computer and use it in GitHub Desktop.
A better ng-tap
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
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