Created
October 22, 2012 17:29
-
-
Save heath/3932795 to your computer and use it in GitHub Desktop.
An attempt to avoid a long list of if statements
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
//all of this is within a pretty long method for handling key events | |
var groupChoices = { | |
65 : 'a', 66 : 'b', 67 : 'c', | |
68 : 'd', 69 : 'e', 70 : 'f', | |
71 : 'g', 72 : 'h', 73 : 'i', | |
74 : 'j', 75 : 'k', 96 : '0', | |
97 : '1', 98 : '2', 99 : '3', | |
100 : '4', 101 : '5', 102 : '6', | |
103 : '7', 104 : '8', 105 : '9' | |
}; | |
var navChoices = { | |
33 : function() {this.selectedWidget().imagePrev()}, | |
34 : function() {this.selectedWidget().imageNext()}, | |
35 : function() {this.selectNext()}, | |
36 : function() {this.selectPrev()}, | |
106 : function() {this.sendNode()} | |
}; | |
var checkKeys = function(e) { | |
for (prop in groupChoices) { | |
//implicit string conversion | |
if (e.keyCode == prop) { | |
sendNode(groupChoices[prop]); | |
} | |
} | |
for (prop in navChoices) { | |
if (e.keyCode == prop) { | |
navChoices[prop](); | |
} | |
} | |
}; | |
checkKeys(e); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment