duncanmcdougall / Responsive-Lightbox

Lightweight, image only responsive, jQuery lightbox plugin
https://www.belter.io/responsive-lightbox/
113 stars 47 forks source link

Unbinding all keydown functions. #36

Open codesignist opened 7 years ago

codesignist commented 7 years ago

In the close function, this code unbinds all keydown events: $(document).off('keydown');

Need to describe a keyDown function:

keyDownEvent: function (e) {
    // Close lightbox with ESC
    if (e.keyCode === 27) {
        plugin.close();
    }
    // Go to next image pressing the right key
    if (e.keyCode === 39) {
        plugin.next();
    }
    // Go to previous image pressing the left key
    if (e.keyCode === 37) {
        plugin.previous();
    }
}

and need to add: $(document).on('keydown', plugin.keyDownEvent);

and to remove only this function: $(document).unbind('keydown', plugin.keyDownEvent);