Skip to content

Instantly share code, notes, and snippets.

@marcmartino
Created June 5, 2012 03:21
Show Gist options
  • Save marcmartino/2872416 to your computer and use it in GitHub Desktop.
Save marcmartino/2872416 to your computer and use it in GitHub Desktop.
getHoverElement: function(autoBox) { //should look through the autocomplete box and find which one is hovering and return {prev: previousElement, hover: elementWithHover, next: nextElement}
//if there are no hovers the return should be {prev: firstElement, hover: null, lastElement}, if there are no elements in the box the return should be null
var items = autoBox.getElementsByTagName("li"),
m = items.length - 1,
returnValues = {
prev: null,
hover: null,
next: items[m]
};
if (m > -1) {
for (; m + 1; m--) {
if (items[m].getAttribute("data-faux-hover") == 1) {
returnValues.hover = items[m];
items[m + 1] && (returnValues.next = items[m + 1]);
return returnValues;
}
else {
returnValues.prev = items[m];
}
};
returnValues.prev = items[m];
return returnValues;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment