• Resolved pattn

    (@pattn)


    Hey Arno,
    is it possible to hook on photoswipe events like beforeClose? I had to switch from another Lightbox tool to Photoswipe. Previously I hooked on beforeClose, to scroll to the last shown image in the Lightbox.

    thanks a lot!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Arno Welzel

    (@awelzel)

    As long as the lightbox is open, you have the global object lbwpsPhotoSwipe available which provides access to the lightbox. Using this you should be able to catch “beforeClose”:

    
    lbwpsPhotoSwipe.listen('close', function() {
    
    alert('lightbox closing now');
    
    });
    

    Also see https://photoswipe.com/documentation/api.html about all available options.

    However – lbwpsPhotoSwipe does not exist before the lightbox is open, so this may not be pratical for you as you would need to implement some kind of polling to check wether this object exists or not before you can use these hooks. I could add an option in the backend to call a custom function when the lightbox opens so you can add your handler then – would this be helpful for you?

    Thread Starter pattn

    (@pattn)

    Works like charme,

    no need for a hook now ?? Thank you!

    Thread Starter pattn

    (@pattn)

    Me again, maybe you have an idea. I’m using barba.js as page-transition script. Basically it’s an ajax loader. Lightbox opens as expected but the .listen() function isnt executed. Any idea? Thanks Arno!

    Thread Starter pattn

    (@pattn)

    Ok, stupid me. Just found the solution after writing. Sorry!

    bitobeats

    (@vitorrloureiro)

    Hi!

    Thanks for this awesome plugin, Arno.

    This idea you proposed would be awesome:

    I could add an option in the backend to call a custom function when the lightbox opens so you can add your handler then – would this be helpful for you?

    Thread Starter pattn

    (@pattn)

    Hi Arno,
    irgendwie funktioniert
    lbwpsPhotoSwipe.listen('close', function() {}
    nicht mehr, seit dem letzten Update. Hat sich da irgendwas ver?ndert? Zuvor habe ich die Funktion abgerufen, sobald die Lightbox ge?ffnet wurde. Nun kommt allerdings der Error:

    Cannot read properties of null (reading 'listen')

    Plugin Author Arno Welzel

    (@awelzel)

    No, there was no change – the lbwpsPhotoSwipe object is still there.

    Go to https://wordpress-demo.arnowelzel.de/lightbox-with-photoswipe/#&gid=1&pid=1 and see for yourself in the developer console of your browser.

    Also adding

    lbwpsPhotoSwipe.listen('close', function() { alert('lightbox closing now'); });

    In the console works as before as long as the lightbox is open.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hook on photoswipe events’ is closed to new replies.