codecomputerlove/PhotoSwipe — Issue #239: photoswipe in a jquery-mobile multipage breaks on non-photoswipe pages
Author: frequent
Created: 2012-01-14 14:05:08+00:00
State: open

I'm trying to use photoswipe inside a multipage document. All works well, except that when I go to an embedded page that does not have a photoswipe trigger, I get an error message, telling me that:

Code.Photoswipe.createInstance: No images to passed

My setup is a little non-standard JQM in that I use a wrapper JQM page #some with a panel and nested JQM pages inside.

I'm triggering photoswipe on the wrapper page using your gallery examples like this:

// trigger photoSwipe
$(function(window, $, PhotoSwipe){

$(document).ready(function(){
$('#some').live('pageshow', function(e){
var currentPage = $(e.target),
options = {},
photoSwipeInstance = $(".triggerElement 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));

So when the wrapper page is loaded photoswipe is also initiated.

This works nice as long as I have a photoswipe-able element on every nested page - I guess because my setup triggers a "pageshow" of the wrapper page on every internal transition, too. So if I have 10 internal pages, each with it's photoswipe gallery, this works well!

But if I add a another blank JQM page and try to transition to it, photoswipe gives me the above error and the page is broken.

Makes sense. No images on the page and photoswipe tries to init.

Would a workaround be to check whether the trigger class is there and only fire photoswipe if so (and if it includes a-images)?

Cheers!

Frequent