Skip to content

Instantly share code, notes, and snippets.

@heath
Created October 22, 2012 17:29
Show Gist options
  • Save heath/3932795 to your computer and use it in GitHub Desktop.
Save heath/3932795 to your computer and use it in GitHub Desktop.
An attempt to avoid a long list of if statements
//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