Reputation: 11
I am trying to add pictures(from an array) dynamically to photoswipe. I have tried to use the "append" Method of jquery without a success.I also readed all about what people wrote about this issue on the web but i did not find the rigth answer.Any helps are welcome.
Upvotes: 1
Views: 670
Reputation: 426
I found a way to add images dynamically to photoswipe, but it is a bit hackish.
There are 3 tings one must do:
I did this with the following code:
var images, image, i, metaData, src,caption,
Util =window.Code.Util;
images=$('#addedImages').find('a');
instance.originalImages = $('#all-photo-swipe-images').find('.a');
for (i = 0; i < images.length; i++) {
image = images[i];
src = instance.settings.getImageSource(image);
caption = instance.settings.getImageCaption(image);
metaData = instance.settings.getImageMetaData(image);
image.__photoSwipeClickHandler = PhotoSwipe.onTriggerElementClick.bind(instance);
Util.Events.remove(image, 'click', image.__photoSwipeClickHandler);
Util.Events.add(image, 'click', image.__photoSwipeClickHandler);
image = new PhotoSwipe.Image.ImageClass(image, src, caption, metaData);
instance.cache.images.push(image);
Upvotes: 1