dimsemenov / photoswipe-dynamic-caption-plugin

A dynamic caption plugin for PhotoSwipe v5. Automatically positions the caption aside or below the image.
MIT License
65 stars 12 forks source link

Dynamic-caption-plugin not working with videos #1

Open acwolff opened 3 years ago

acwolff commented 3 years ago

I use both images and videos:

<div id="gallery" class="thumbs-jg thumbsgallery" >

<a  href= "slides/IMG_0877.mp4" data-pswp-is-video="true" data-pswp-is-poster="slides/IMG_0877.jpg"
data-pswp-width="608" data-pswp-height="1080"  id="0"  data-caption=''>
<img src="slides/IMG_0877.jpg" class="video"  width="90" height="160"  alt="2013-05-06" title="2013-05-06" />
</a>

<a  href= "slides/170814-133529_Erfgoedroute.jpg" data-pswp-width="1584" data-pswp-height="1080"  id="1"
data-caption='etc'

And use the dynamic-caption-plugin:

const captionPlugin = new PhotoSwipeDynamicCaption(lightbox, {
    type: 'auto',
    captionContent: (slide) => {
        return slide.data.element.dataset.caption;
    }
});
lightbox.init();

If you open the Light box by clicking on the first video thumbnail in this album with this code, you get a crash:

VM8 index.htm:683 Uncaught (in promise) TypeError: Cannot read property 'dataset' of undefined at PhotoSwipeDynamicCaption.captionContent (VM8 index.htm:683) at PhotoSwipeDynamicCaption.getCaptionHTML (photoswipe-dynamic-caption-plugin.esm.js:331) at PhotoSwipeDynamicCaption.updateCaptionHTML (photoswipe-dynamic-caption-plugin.esm.js:353) at PhotoSwipe. (photoswipe-dynamic-caption-plugin.esm.js:60) at photoswipe.esm.js:3703 at Array.forEach () at PhotoSwipe.dispatch (photoswipe.esm.js:3702) at PhotoSwipe.init (photoswipe.esm.js:4345) at PhotoSwipeLightbox._openPhotoswipe (photoswipe-lightbox.esm.js:633) at photoswipe-lightbox.esm.js:590

To prevent this, I use this code:

    captionContent: (slide) => {
        try {
            return slide.data.element.dataset.caption;
        }
        catch(err) {
            return null; //'',   false or null;
        }

    }

What is the best value to return in the catch(err) code? Any chance this will be resolved, so that I can add captions to video's?

acwolff commented 2 years ago

When is the next update?

acwolff commented 8 months ago

Any progress with the solution of this bug?

acwolff commented 8 months ago

See also at the end of this issue: https://github.com/dimsemenov/PhotoSwipe/issues/2084