lokesh / lightbox2

THE original Lightbox script (v2).
http://lokeshdhakar.com/projects/lightbox2/
MIT License
6.2k stars 1.77k forks source link

Capture ESCAPE keypress #663

Closed rkyoku closed 5 years ago

rkyoku commented 5 years ago

When pressing the ESCAPE key, lightbox closes itself. Nice! :)

However, it does not capture the event, which therefore bubbles up in another plugin I have, and I cannot modify the plugin code.

I will try and modify lightbox code instead, whilst waiting for an input on this one.

EDIT: more info: I am using MaterializeCSS modals. Inside some of them, I have some images that I use lightbox with. When lightbox is open on top of the modal and pressing the ESCAPE key (which closes the modal by default), lightbox should be the first to handle the event, and it should (IMHO) catch it and not let it propagate. That way, the modal does not closes whenever I close lightbox.

Thanks in advance!

Best,

lokesh commented 5 years ago

@rkyoku I do understand your use case, but the solution isn't as simple as stopping propagation of the event. Since they are attached to the document.

I'm going to investigate a fix for your situation today. The changes I am planning:

  1. Attach the keyboard event handlers to the two root notes of the Lightbox script output: the overlay and the lightbox image container.
  2. On opening Lightbox, update the active/focused element from the trigger to the lightbox overlay which has the new handlers.
Sahil107-coder commented 4 years ago

sir, I am having trouble creating a website with LightBox