refactored code according to discussion in #2064

This commit is contained in:
Timotheus Kampik 2015-10-09 12:08:29 +02:00
parent 1b80100dff
commit 06ac2a0059

View File

@ -260,20 +260,21 @@ var Documentation = {
*/ */
initOnKeyListeners: function() { initOnKeyListeners: function() {
$(document).keyup(function(event) { $(document).keyup(function(event) {
if (!$(document.activeElement).is('input')) { //don't navigate when in search box var activeElementType = $(document.activeElement).prop('tagName');
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT') { // don't navigate when in search box or textarea
switch (event.keyCode) { switch (event.keyCode) {
case 37: //left case 37: // left
var prevElement = $('link[rel="prev"]')[0]; var prevHref = $('link[rel="prev"]').prop('href');
if (prevElement) { if (prevHref) {
window.location.href = prevElement.href; window.location.href = prevHref;
} }
break; return false;
case 39: //right case 39: // right
var nextElement = $('link[rel="next"]')[0]; var nextHref = $('link[rel="next"]').prop('href');
if (nextElement) { if (nextHref) {
window.location.href = nextElement.href; window.location.href = nextHref;
} }
break; return false;
} }
} }
}); });