forked from Public/pics
33 lines
942 B
JavaScript
33 lines
942 B
JavaScript
function enableKeyDownNavigation() {
|
|
document.addEventListener("keydown", function (event) {
|
|
if (event.keyCode == 37) {
|
|
var target = document.querySelector("ul.pagination > :first-child a");
|
|
if (target && target.href) {
|
|
event.preventDefault();
|
|
document.location.href = target.href;
|
|
}
|
|
}
|
|
else if (event.keyCode == 39) {
|
|
var target = document.querySelector("ul.pagination > :last-child a");
|
|
if (target && target.href) {
|
|
event.preventDefault();
|
|
document.location.href = target.href;
|
|
}
|
|
}
|
|
}, false);
|
|
}
|
|
|
|
function disableKeyDownPropagation(obj) {
|
|
for (var x = 0; x < obj.length; x++) {
|
|
obj[x].addEventListener("keydown", function (event) {
|
|
if (event.keyCode == 37 || event.keyCode == 39) {
|
|
event.stopPropagation();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
enableKeyDownNavigation();
|
|
disableKeyDownPropagation(document.getElementsByTagName("textarea"));
|
|
disableKeyDownPropagation(document.getElementsByTagName("input"));
|