Search code examples
cordovajquery-mobilephotoswipe

back button issue after opening a page over photoswipe carousel


i have a similar problem like this

http://forum.jquery.com/topic/jqm-1-0a3-dialog-url-state-appears-in-history

i am using photoswipe + jquerymobile + phonegap, the issue is when the gallery loads and i click on any image which takes me to carousel mode now from here if i goto another page and click back button this occures at the end of the url in the browser address bar

&ui-state=dialog

but it does not goes back to the carousel mode.so when i click again back button it takes me to the gallery page skipping the carousel mode.


Solution

  • There are two things you need to do: 1) remove the ps-active class from the body tag 2) find all photoswipe instances and unset them

    The following code worked for me:

     $(document).bind('pagebeforechange', function(e) {
     if ($('.ps-carousel').length) {
      $('body').removeClass('ps-active');
      $('div.gallery-page').each(function(){
        var photoSwipe = window.Code.PhotoSwipe;
        var photoSwipeInstance = photoSwipe.getInstance($(this).attr('id'));
        if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) {
            photoSwipe.unsetActivateInstance(photoSwipeInstance);
         }
       });
     }
      });
    

    Please check this link for more information .