Skip to content

Instantly share code, notes, and snippets.

@ilmsg
Forked from geelen/input.coffee
Created May 20, 2013 09:27
Show Gist options
  • Save ilmsg/5611256 to your computer and use it in GitHub Desktop.
Save ilmsg/5611256 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