Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created March 24, 2013 15:48
Show Gist options
  • Save mertenvg/5232401 to your computer and use it in GitHub Desktop.
Save mertenvg/5232401 to your computer and use it in GitHub Desktop.
Basic key listener
function keyListener () {
var $next;
// if (event.keyCode === 37) { // left
//
// }
if (event.keyCode === 38) { // up
$next = $customerTypeOptionsItems.find('.active').prev();
if ($next.length === 0) {
$next = $customerTypeOptionsItems.last();
}
}
// if (event.keyCode === 39) { // right
//
// }
else if (event.keyCode === 40) { // down
$next = $customerTypeOptionsItems.find('.active').next();
if ($next.length === 0) {
$next = $customerTypeOptionsItems.first();
}
}
else if (event.keyCode === 13 || event.keyCode === 27) { // enter or escape
$customerTypeInput.blur();
return;
}
else {
return;
}
$customerTypeInput.val($next.text());
$customerTypeOptionsItems.removeClass('active');
$next.addClass('active');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment