Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created December 27, 2012 15:58
Show Gist options
  • Save gauntface/4389305 to your computer and use it in GitHub Desktop.
Save gauntface/4389305 to your computer and use it in GitHub Desktop.
focusController.js - Key Handling
/**
* 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