Skip to content

Instantly share code, notes, and snippets.

@geelen
Created June 5, 2012 08:23
Show Gist options
  • Save geelen/2873603 to your computer and use it in GitHub Desktop.
Save geelen/2873603 to your computer and use it in GitHub Desktop.
window.stoppingPropagation = (callback) -> (e) ->
e.stopPropagation()
callback(e)
angular.module('myApp',[]).directive 'ngTap', ->
(scope, element, attrs) ->
tapping = false
element.bind 'touchstart', stoppingPropagation (e) -> tapping = true
element.bind 'touchmove', stoppingPropagation (e) -> tapping = false
element.bind 'touchend', stoppingPropagation (e) -> scope.$apply(attrs['ngTap']) if tapping
window.stoppingPropagation = function(callback) {
return function(e) {
e.stopPropagation();
return callback(e);
};
};
angular.module('myApp', []).directive('ngTap', function() {
return function(scope, element, attrs) {
var tapping;
tapping = false;
element.bind('touchstart', stoppingPropagation(function(e) {
return tapping = true;
}));
element.bind('touchmove', stoppingPropagation(function(e) {
return tapping = false;
}));
return element.bind('touchend', stoppingPropagation(function(e) {
if (tapping) {
return scope.$apply(attrs['ngTap']);
}
}));
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment