[jQuery] keyup() + clicking = hmmm...
I'm working on a script thats somewhat similar to a directory listing
script and I'm trying to emulate the ability to select multiple files
at once by holding down the shift key (its really more like the Ctrl
or Apple key action instead of the shift key, but w/e).
By themselves, keydown() and keyup() work fine. However, I seem to
have run into a major issue. Clicking in the interface seems to kill
keyup() and cause it not to fire once the Shift key is released.
However, if you don't click anywhere, it works just fine. Does anyone
know some kind of workaround to this by any chance? Any help would be
appreciated. Here's the code I have concerning these events:
$(window).keydown(function(event){
if(event.keyCode == 16)
{
enableMultiSelect();
}
});
$(window).keyup(function(event){
if(event.keyCode == 16)
{
disableMultiSelect();
}
});
function enableMultiSelect()
{
$('.file').bind('click',function(){
if(!$(this).hasClass('multi-select'))
{
$(this).addClass('multi-select');
}
else
{
$(this).removeClass('multi-select');
}
});
}
function disableMultiSelect()
{
$('.file').unbind('click');
}