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
Closing PhotoSwipe with pswp.close() causes JS error #822
Comments
No, there is no way to suppress the error, as you're destroying PhotoSwipe in the middle of a process. For now there are no plans to add extra checks to allow closing in events like beforeChange, you may use afterChange. Perform your checks on arrows click by editing UI, or override prev/next functions, e.g.: pswp.next = function() {
if(something) {
pswp.goTo( pswp.getCurrentIndex() + 1);
}
} |
Thanks Dmitry, unfortunately afterChange throws a similar error, "Uncaught TypeError: Cannot read property 'mainScrollAnimComplete' of null". It never occurred to me I could override prev/next, very useful! Unfortunately I need to handle the drag move too - from the user's point of view a click on next is the same kind of event as a left drag to the next slide. This is a problem for me, as I'm being asked to change the flow to make the gallery close at the end of the series. So if there are three images and the user launches the gallery at image 2, the swipe sequence is 2-3-1-close. |
Dunno if it's any use to you Dmitry, but I've found I can fix this by just checking if _listeners is defined in _shout:
This seems like a small change that makes it possible to close the gallery from a beforeChange callback. I can do this as a pull request if you want. (Thanks for a brilliant app by the way, it's extremely nicely done and very useful!) |
It's a step, but it needs more testing – maybe something else should be changed, as memory leaks can appear if destroy is called during this action. Send a pull request just to |
I see - thanks! will do. |
I was able to get a similar error: related to the listeners when doing the following - Open a gallery, then close it. Check this codepen to reproduce the error - http://codepen.io/anon/pen/ZGoeQo Autoplay works fine the first time you open it, and I can start/stop the autoplay with no issues. But when I open it the 2nd time then try to stop then start again I get errors and images disappear. |
@jacobschweitzer, you aren't clearing intervals and events after PhotoSwipe is closed. |
Well in my actual code I am doing this: gallery.listen('close', function() { and I tried this: but those didn't work. What do you mean about clearing events? Is there a way I can completely re-initialize Photoswipe when it opens? It seems like when it opens the 2nd time there is some things being carried over. |
Hey Dmitry, thank you for your help! You pointed me in the right direction and I figured it out just now 😅 , it was the click binding on the slideshow start / stop button . So now my close listener looks like this: gallery.listen('close', function() { Thank you for making this great piece of JavaScript and helping those who use it! 👍 |
When I close PhotoSwipe with a call to the close() method the close, unbindEvents and destroy events fire, but afterwards I get "Uncaught TypeError: Cannot read property 'gettingData' of null" from the second line of this function in core.js:
Is there any way I can suppress this error?
Here's an example http://codepen.io/andfinally/pen/wavZxp.
The text was updated successfully, but these errors were encountered: