Created
November 6, 2012 18:02
-
-
Save mhuneke/4026406 to your computer and use it in GitHub Desktop.
Angular ng-tap directive
This file contains hidden or 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
(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
You can test in Chrome, Developer Console -> (press escape) -> Emulation -> Sensors -> Emulate Touch Screen