Skip to content

Instantly share code, notes, and snippets.

@jrmedd
Created June 23, 2016 16:58
Show Gist options
  • Save jrmedd/20d91c2179c4a5ee0af0d1f46df35755 to your computer and use it in GitHub Desktop.
Save jrmedd/20d91c2179c4a5ee0af0d1f46df35755 to your computer and use it in GitHub Desktop.
/*
LOAD THIS SCRIPT AFTER THE MAIN TWINE ENGINE
*/
function keySelectOption(inputs) {
for (var i=0; i<inputs.length; i++) {
document.onkeydown = function(e) {
var option = document.activeElement;
if (e.keyCode==40) {
var node = option.nextSibling;
while (node) {
if (node.tagName=='A') {
node.focus();
break;
}
node = node.nextSibling;
}
}
else if (e.keyCode==38) {
var node = option.previousSibling;
while (node) {
if (node.tagName=='A') {
node.focus();
break;
}
node = node.previousSibling;
}
}
};
};
}
keySelectOption(document.getElementsByTagName('a'));
document.getElementsByTagName('a')[0].focus();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment