Skip to content

Instantly share code, notes, and snippets.

@snapwich
Created June 23, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snapwich/4b08dd09521005a515d2 to your computer and use it in GitHub Desktop.
Save snapwich/4b08dd09521005a515d2 to your computer and use it in GitHub Desktop.
// keyboard and accessibility directive
.directive("ngClick", function() {
var KEY_ENTER = 13,
KEY_SPACE = 32;
return {
restrict: "A",
link: function(scope, elem, attrs) {
elem.css({
cursor: "pointer"
});
elem.on("keyup", function(e) {
switch(e.which) {
case KEY_ENTER:
case KEY_SPACE:
scope.$apply(function() {
scope.$eval(attrs.ngClick);
});
break;
}
})
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment