Created
January 26, 2013 00:22
-
-
Save zgohr/4639125 to your computer and use it in GitHub Desktop.
Focus, blur, keyup, keydown, and keypress AngularJS 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
| .directive( [ 'focus', 'blur', 'keyup', 'keydown', 'keypress' ].reduce( function ( container, name ) { | |
| var directiveName = 'ng' + name[ 0 ].toUpperCase( ) + name.substr( 1 ); | |
| container[ directiveName ] = [ '$parse', function ( $parse ) { | |
| return function ( scope, element, attr ) { | |
| var fn = $parse( attr[ directiveName ] ); | |
| element.bind( name, function ( event ) { | |
| scope.$apply( function ( ) { | |
| fn( scope, { | |
| $event : event | |
| } ); | |
| } ); | |
| } ); | |
| }; | |
| } ]; | |
| return container; | |
| }, { } ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment