jquery fancy box
i'm using fancy box for some content editing in my backoffice. I recently added an image manager wich i create with javascript. It's kind of like a fancybox, but i had to do it from scractch for it to be able to overlay the first one.
My problem is this:
I want to have the user being able to press the escape key to close my manager, but if i use $(window).keypress
when i press the esc key, both the boxes close.
I have tried $(window).unbind('keypress')
when i start loading my box, and i have tried to look through the fancybox js file, but it is minimized.
Does anyone know how i can disable and afterwards enable the escape key (during runtime) on the fancybox?
Thanx
Well I tried e.preventDefault() that i was forgetting, still nothing. I looked at the unpacked js file and i get this:
_set_navigation = function() {
if (currentOpts.enableEscapeButton || currentOpts.enableKeyboardNav) {
$(document).bind('keydown.fb', function(e) {
开发者_Python百科 if (e.keyCode == 27 && currentOpts.enableEscapeButton) {
e.preventDefault();
$.fancybox.close();
} else if ((e.keyCode == 37 || e.keyCode == 39) && currentOpts.enableKeyboardNav && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
e.preventDefault();
$.fancybox[ e.keyCode == 37 ? 'prev' : 'next']();
}
});
}...
is this of any help?
So this works, but it's definitely a hack.
function closeImageManager(){
$(document).unbind('keydown.fb');
// Insert code to close your image manager
$(document).bind('keydown.fb', function(e) {
if (e.keyCode == 27) {
e.preventDefault();
$.fancybox.close();
} else if ((e.keyCode == 37 || e.keyCode == 39) && e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA' && e.target.tagName !== 'SELECT') {
e.preventDefault();
$.fancybox[ e.keyCode == 37 ? 'prev' : 'next']();
}
});
}
Basically you have your close function do the following:
- Unbind the namespaced
keydown
event - Close your window
- Rebind the namespaced
keydown
event to the publicly exposed$.fancybox.close();
Problems with this:
- When
closeImageManager
rebinds thekeydown
event, it won't checkcurrentOpts.enableEscapeButton
orcurrentOpts.enableKeyboardNav
because those options do not appear to be publicly exposed. - It requires the repetition of the code that binds the
keydown
event (once in fancybox.js and once in thecloseImageManager
function).
精彩评论