Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created April 10, 2012 20:02
Show Gist options
  • Save tkh44/2354090 to your computer and use it in GitHub Desktop.
Save tkh44/2354090 to your computer and use it in GitHub Desktop.
handle key
function keyHandle(keyCode){
var categories = elements.categories;
var shownPages = SELECT.query("ul.sub li:not(.hide)");
var selectedPage = DOM.getElementsByClassName('selected')[0];
var pageIndex = shownPages.indexOf(selectedPage);
if(keyCode === keys.down){
console.log(selectedPage);
//if no items are selected we highlight the first item
//if we are at the end of the list loop back around
if(pageIndex === -1 || pageIndex+1 >= shownPages.length) {//if no items are selected we highlight the first item
console.log(pageIndex);
DOM.removeClass(shownPages[pageIndex], 'selected');
DOM.addClass(shownPages[0], 'selected');
selectedPage = DOM.getElementsByClassName('selected')[0];//reset current selected page
} else {
var nextCategory = shownPages[pageIndex+1].parentNode.parentNode;
//if(DOM.hasClass(nextCategory, "closed") && !DOM.hasClass(nextCategory, "hide")){
if(DOM.hasClass(nextCategory, "closed")){
//DOM.addClass(nextCategory.id + "_header", "selected");
DOM.removeClass(shownPages[pageIndex], 'selected');
DOM.addClass(shownPages[pageIndex + DOM.getChildren(nextCategory).length + 1], 'selected');
}
//DOM.replaceClass(shownPages[pageIndex+1].parentNode.parentNode, "closed", "open")
DOM.removeClass(shownPages[pageIndex], 'selected');
DOM.addClass(shownPages[pageIndex+1], 'selected');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment