Created
March 28, 2015 17:42
-
-
Save barneycarroll/31c1e305a37999a3473f to your computer and use it in GitHub Desktop.
onkeypress : onKey( 'enter', save ), etc
This file contains 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
var onKey = (function(){ | |
var keymap = { | |
'enter' : 13, | |
'space' : 31, | |
'tab' : 9, | |
'esc' : 27, | |
'left' : 37, | |
'up' : 38, | |
'right' : 39, | |
'down' : 40 | |
}; | |
return function bind( key, callback ){ | |
if( key in keymap ){ | |
key = keymap[ key ]; | |
} | |
return function handler( e ){ | |
if( e && key === e.keyCode || key === String.fromCharCode( e.keyCode ) ){ | |
callback.call( this, e ); | |
} | |
else { | |
m.redraw.strategy( 'none' ); | |
} | |
}; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage