Skip to content

Instantly share code, notes, and snippets.

@jodaka
Forked from mhuneke/ngTap.js
Created July 9, 2013 17:41
Show Gist options
  • Save jodaka/5959466 to your computer and use it in GitHub Desktop.
Save jodaka/5959466 to your computer and use it in GitHub Desktop.
(function(angular) {
'use strict';
var directives = angular.module('app.directives', []);
directives.directive('ngTap', function() {
return function(scope, element, attrs) {
var tapping;
tapping = false;
element.bind('touchstart', function(e) {
element.addClass('active');
tapping = true;
});
element.bind('touchmove', function(e) {
element.removeClass('active');
tapping = false;
});
element.bind('touchend', function(e) {
element.removeClass('active');
if (tapping) {
scope.$apply(attrs['ngTap'], element);
}
});
};
});
})(angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment