-
-
Save sukima/3933058 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 checkKeys1 = function(e) { | |
var code = parseInt(e.keyCode); | |
if (groupChoices[code]) { | |
sendNode(groupChoices[code]); | |
} | |
if (navChoices[code]) { | |
navChoices[code].call(); | |
} | |
}; | |
var checkKeys2 = function(myArray) { | |
var code; | |
for (e in myArray) { | |
code = parseInt(e.keyCode); | |
if (groupChoices[code]) { | |
sendNode(groupChoices[code]); | |
} | |
if (navChoices[code]) { | |
navChoices[code].call(); | |
} | |
} | |
}; | |
checkKeys1(e); | |
checkKeys2([e]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment