0

I'm creating a website using jquery mobile and almost everything works great. But i have slight problem and it has something to do with Photoswipe (http://www.photoswipe.com/).

This is what happens:

I have several different casepages divided up in categories. When i enter a casesite i can click up the gallery, the images show up and works great. However if I go from this casepage, directly to another casepage and try to open that gallery. Nothing happens. But if i dont go directly to another casepage and go ta page between (wich has no gallery) and then to a new case. The gallery will open up. I use jquery mobile standard ajax handling so every page is loaded with ajax and is no different then the other in the <head>.

The gallery images is loaded with PHP and MySQL but the id for the <ul> is always the same; #Gallery.

Could it have something to do with this, that when going directly between pages where there are galleries with the same id. It messes something up? This is my code:

Javascript:

(function(window, $, PhotoSwipe){
            $(document).ready(function(){

                $('div.gallery-page')
                    .live('pageshow', function(e){

                        var 
                            currentPage = $(e.target),
                            options = {},
                            photoSwipeInstance = $("ul.gallery a", e.target).photoSwipe(options,  currentPage.attr('id'));

                        return true;

                    })

                    .live('pagehide', function(e){

                        var 
                            currentPage = $(e.target),
                            photoSwipeInstance = PhotoSwipe.getInstance(currentPage.attr('id'));

                        if (typeof photoSwipeInstance != "undefined" && photoSwipeInstance != null) {
                            PhotoSwipe.detatch(photoSwipeInstance);
                        }

                        return true;

                    });

});     
}(window, window.jQuery, window.Code.PhotoSwipe));


$('div:jqmData(role="page")').live('pageinit',function(){

    var options = {
        jQueryMobile: true
    };
    $("#Gallery a").photoSwipe(options);

});

HTML

<ul id="Gallery" class="gallery">
<li><a href="01.jpg" rel="external"><img src="01.jpg" alt="1" /></a></li>
<li><a href="02.jpg" rel="external"><img src="02.jpg" alt="2" /></a></li>
</ul>
Paparappa
  • 2,099
  • 3
  • 18
  • 35
  • I am suffering from the same problem. I can get the swipe to load if I use the standard jquery call, but when zooming the page goes black. If not, I cannot get it to register the links as "swipeable". – Rick Rat May 15 '12 at 00:10
  • Well the problem actually was that i uses #IDs intsead of .Classes. So change it to classes and it will work. – Paparappa Jun 11 '12 at 15:06

1 Answers1

0

Replace the class name "gallery" to "gallery-page".

Manikandan K
  • 1,081
  • 1
  • 9
  • 17