codecomputerlove/PhotoSwipe — Issue #166: Uncaught Code.PhotoSwipe.createInstance: No images to passed.
Author: sfire38
Created: 2011-10-20 22:45:49+00:00
State: open

I have PhotoSwipe 2.1.6 implemented on a jQuery Mobile 1.0rc2 site. I use the following JS (loaded before JQM) to implement PhotoSwipe:

(function(window, $, PhotoSwipe){

$(document).ready(function(){

$('div.listings-show').live('pageshow', function(e){

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

return true;
}
})
.live('pagehide', function(e){

if( $('.listing-gallery', e.target) ){
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));

This works fine if there is a gallery on that page, but some pages do not have galleries. I added the "if( $('.listing-gallery', e.target) )" code to try and check if the gallery exists on that page but that does not work. If I add a blank gallery div on the page and hide it, it works fine. But that's not the cleanest solution.

Any thoughts?