dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.26k stars 3.31k forks source link

Dynamic size adjustment #879

Open magnusheino opened 9 years ago

magnusheino commented 9 years ago

Hi.

I had this code working with 4.0:

        var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);

        gallery.listen('imageLoadComplete', function(index, item) {
            item.w = item.img.width;
            item.h = item.img.height;
            gallery.updateSize();
        });

        gallery.init();

Now images were loaded and resized no matter what size they had (and they have all different sizes).

Introduced in this commit for 4.0.8 item.img is nulled before imageLoadComplete is called...

https://github.com/dimsemenov/PhotoSwipe/commit/0c277a72dc4b203854c4fa926f5cf574f3c2de0a#diff-9d2f0c76c6ba44a976558eb4e8d40d2aL382

Is this indented behaviour ? Would it be possible to first call imageLoadComplete, then null the reference?

dimsemenov commented 9 years ago

Would it be possible to first call imageLoadComplete, then null the reference?

I think it won't hurt. Yoy may send PR for items-controller.js if you want. Or I'll update it by myself in next update.

Anyway, you can access image directly via gallery.currItem.container.lastChild.

fxmaxvl commented 7 years ago

For me this is still actual issue, may I send PR?