lity icon indicating copy to clipboard operation
lity copied to clipboard

Stop event propagation when I close a light box

Open denbyangus opened this issue 3 years ago • 1 comments

I have implemented a window close when the user clicks the ESC key. Unfortunately the event propagates from the Lity close event (also triggered by an ESC action) and closes the window too.

I tried the following but I fear I'm too late.

$(document).on('lity:close', function(event, instance) {
  console.log('Lity lightbox closed');
  event.stopPropagation();
});

Is there a handle closer to the close that I can use to insert the stopPropagation?

denbyangus avatar Mar 19 '21 06:03 denbyangus

All good. I came up with a solution using a flag. :) vat lityon = false;

The flag is set when the lity object instantiates $(document).on('lity:ready' ... lityon = true;

and unset when the object is removed: $(document).on('lity:remove',... lityon = false;

I check the flag when I handle the keyup event to ensure I don't close the window after closing the lightbox.

denbyangus avatar Mar 19 '21 07:03 denbyangus