This commit is contained in:
tobi 2025-03-18 12:20:54 +01:00
commit e5d6587c23
2 changed files with 30 additions and 15 deletions

View file

@ -76,6 +76,7 @@ lightbox.addFilter('itemData', (item) => {
width: parseInt(el.dataset.pswpWidth), width: parseInt(el.dataset.pswpWidth),
height: parseInt(el.dataset.pswpHeight), height: parseInt(el.dataset.pswpHeight),
parentStatus: el.dataset.pswpParentStatus, parentStatus: el.dataset.pswpParentStatus,
attachmentId: el.dataset.pswpAttachmentId,
}; };
} }
return item; return item;
@ -180,29 +181,40 @@ Array.from(document.getElementsByClassName("plyr-video")).forEach((video) => {
let player = new Plyr(video, { let player = new Plyr(video, {
title: video.title, title: video.title,
settings: ["loop"], settings: [],
controls: ['play-large', 'play', 'progress', 'current-time', 'volume', 'mute', 'fullscreen'],
disableContextMenu: false, disableContextMenu: false,
hideControls: false, hideControls: false,
tooltips: { controls: true, seek: true }, tooltips: { controls: true, seek: true },
iconUrl: "/assets/plyr.svg", iconUrl: "/assets/plyr.svg",
invertTime: false,
listeners: { listeners: {
fullscreen: () => { fullscreen: () => {
// Check if the photoswipe lightbox is
// open with this as the current slide.
const alreadyInLightbox = (
lightbox.pswp !== undefined &&
video.dataset.pswpAttachmentId === lightbox.pswp.currSlide.data.attachmentId
);
if (lightbox.pswp !== undefined) { if (alreadyInLightbox) {
console.log(lightbox.pswp.currSlide); // If this video is already open as the
// current photoswipe slide, the fullscreen
// button toggles proper fullscreen.
player.fullscreen.toggle();
} else {
// Otherwise the fullscreen button opens
// the video as current photoswipe slide.
//
// (Don't pause the video while it's
// being transitioned to a slide.)
if (player.playing) {
setTimeout(() => player.play(), 1);
}
lightbox.loadAndOpen(parseInt(video.dataset.pswpIndex), {
gallery: video.closest(".photoswipe-gallery")
});
} }
// Continue playing the video
// after it's been fullscreened.
if (player.playing) {
setTimeout(() => player.play(), 1);
}
// Open the video as a photoswipe slide.
lightbox.loadAndOpen(parseInt(video.dataset.pswpIndex), {
gallery: video.closest(".photoswipe-gallery")
});
return false; return false;
} }
} }

View file

@ -99,6 +99,7 @@
playsinline playsinline
data-pswp-index="{{- .Index -}}" data-pswp-index="{{- .Index -}}"
data-pswp-parent-status="{{- .Item.ParentStatusLink -}}" data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
data-pswp-attachment-id="{{- .Item.ID -}}"
poster="{{- .Item.PreviewURL -}}" poster="{{- .Item.PreviewURL -}}"
data-pswp-width="{{- .Item.Meta.Original.Width -}}px" data-pswp-width="{{- .Item.Meta.Original.Width -}}px"
data-pswp-height="{{- .Item.Meta.Original.Height -}}px" data-pswp-height="{{- .Item.Meta.Original.Height -}}px"
@ -117,6 +118,7 @@
playsinline playsinline
data-pswp-index="{{- .Index -}}" data-pswp-index="{{- .Index -}}"
data-pswp-parent-status="{{- .Item.ParentStatusLink -}}" data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
data-pswp-attachment-id="{{- .Item.ID -}}"
{{- if and .Item.PreviewURL .Item.Meta.Small.Width }} {{- if and .Item.PreviewURL .Item.Meta.Small.Width }}
poster="{{- .Item.PreviewURL -}}" poster="{{- .Item.PreviewURL -}}"
data-pswp-width="{{- .Item.Meta.Small.Width -}}px" data-pswp-width="{{- .Item.Meta.Small.Width -}}px"
@ -138,6 +140,7 @@
class="photoswipe-slide" class="photoswipe-slide"
data-pswp-index="{{- .Index -}}" data-pswp-index="{{- .Index -}}"
data-pswp-parent-status="{{- .Item.ParentStatusLink -}}" data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
data-pswp-attachment-id="{{- .Item.ID -}}"
href="{{- .Item.URL -}}" href="{{- .Item.URL -}}"
target="_blank" target="_blank"
data-pswp-width="{{- .Item.Meta.Original.Width -}}px" data-pswp-width="{{- .Item.Meta.Original.Width -}}px"