Created
December 27, 2012 17:37
-
-
Save gauntface/4390186 to your computer and use it in GitHub Desktop.
focusController.js - Adding and removing focusable items
This file contains hidden or 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
| ... | |
| /** | |
| * 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