Created
March 24, 2013 15:48
-
-
Save mertenvg/5232401 to your computer and use it in GitHub Desktop.
Basic key listener
This file contains 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
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