Created
December 27, 2012 15:58
-
-
Save gauntface/4389305 to your computer and use it in GitHub Desktop.
focusController.js - Key Handling
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
/** | |
* On a key press this method will handle moving the focus | |
* @function | |
* @param {int} event Browser key code | |
*/ | |
FocusController.prototype.onKeyDown = function (event) { | |
switch(event.keyCode) { | |
case 9: | |
// Tab | |
break; | |
case 37: | |
// Left | |
this.moveFocus({x: -1, y: 0}); | |
break; | |
case 38: | |
// Up | |
this.moveFocus({x: 0, y: 1}); | |
break; | |
case 39: | |
// Right | |
this.moveFocus({x: 1, y: 0}); | |
break; | |
case 40: | |
// Down | |
this.moveFocus({x: 0, y: -1}); | |
break; | |
case 13: | |
// Enter | |
if(this.getCurrentlyFocusedItem()) { | |
this.getCurrentlyFocusedItem().onItemClick(); | |
} | |
break; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment