Created
November 25, 2014 00:11
-
-
Save kentcdodds/5590d8cc7b65e0ac30ae to your computer and use it in GitHub Desktop.
accessible ng-click
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
angular.module('atac.common').directive('azAction', function azActionDirective() { | |
'use strict'; | |
return { | |
restrict: 'A', | |
link: function(scope, el, attrs) { | |
el.attr('tabindex', 0); | |
el.on('click', action); | |
el.on('keyup', function(event) { | |
if (event.which === 32 || event.which === 13) { | |
action(); | |
} | |
}); | |
function action() { | |
scope.$eval(attrs.azAction); | |
scope.$safeApply(); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment