Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop event propagation when I close a light box #272

Open
denbyangus opened this issue Mar 19, 2021 · 1 comment
Open

Stop event propagation when I close a light box #272

denbyangus opened this issue Mar 19, 2021 · 1 comment

Comments

@denbyangus
Copy link

denbyangus commented Mar 19, 2021

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant