I have a photo galery with following simple function to navigate to the previous / next photo with the arrow keys on keyboard:
$(function() {
var navEnabled = true;
$(document).keyup(function(e) {
if (navEnabled) {
switch(e.keyCode) {
case 37 : window.location = $('.prev').attr('href'); break;
case 39 : window.location = $('.next').attr('href'); break;
}
}
});
$('#comment_area').bind('focus', function (event) {
navEnabled = false;
}).bind('blur', function (event) {
navEnabled = true;
});
});
Below each photo I have a html textarea element (! which is loaded via AJAX while page load!) with the id #comment_area to leave a comment to a photo, and I'm looking for a solution to disable the keyboard photo navigation while typing and turn on after again. The code above seems not to work, and I guess it's because the textarea element was loaded via AJAX. I tried to move the .bind function code into the AJAX request, so it will know about the #comment_area id, but then the navEnabled variable is unknown.