Created
February 26, 2012 02:04
-
-
Save chsh/1912270 to your computer and use it in GitHub Desktop.
Handle all keyevents and react if digit or return key.
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
class DigKey | |
constructor: (@catch_elm, @disp_elm, @form_elm) -> | |
$(@catch_elm).keydown (event) => | |
kc = event.keyCode | |
$(@disp_elm).append dig(kc) if is_num(kc) | |
if is_cr(kc) | |
$(@form_elm).submit | |
else | |
$(@disp_elm).append '<br/>' if is_cr(kc) | |
is_num = (key_code) -> | |
return true if key_code >= 48 && key_code <= 58 | |
is_cr = (key_code) -> | |
key_code == 13 | |
dig = (key_code) -> (key_code - 48) + '' | |
window.DigKey = DigKey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment