Skip to content

Instantly share code, notes, and snippets.

@gauntface
Created December 27, 2012 17:37
Show Gist options
  • Select an option

  • Save gauntface/4390186 to your computer and use it in GitHub Desktop.

Select an option

Save gauntface/4390186 to your computer and use it in GitHub Desktop.
focusController.js - Adding and removing focusable items
...
/**
* Remove a focusable item from the controller
* @param {FocusableItem} item The item to remove
*/
this.removeFocusableItem = function (item) {
for(var i = 0; i < focusableItems.length; i++) {
if(focusableItems[i] == item) {
focusableItems.splice(i, 1);
return true;
}
}
return false;
};
...
/**
* This method will add a focusable item to the controller
* @function
* @param {FocusableItem} item Focusable item to be handled by this
* FocusController
*/
FocusController.prototype.addFocusableItem = function (item) {
if(this.isFocusableItem(item)) {
return;
}
var itemIndex = this.getFocusableItemCount();
this.pushFocusableItem(item);
// This is essentially the dom element of the focusable item
var element = item.getElement();
element.bind('mouseenter.keycontroller', {itemIndex: itemIndex}, function(event) {
if(this.isMoving()) {
return;
}
var itemIndex = event.data.itemIndex;
this.handleFocusChangeToItem(itemIndex);
event.stopPropagation();
}.bind(this));
element.bind('click.keycontroller', {itemIndex: itemIndex}, function(event) {
if(this.isMoving()) {
return;
}
var itemIndex = event.data.itemIndex;
if(this.getCurrentlyFocusedItem()) {
this.getCurrentlyFocusedItem().onItemClick();
}
}.bind(this));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment