ps: improve thumb behavior

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/504/head
Varun Patil 2023-03-19 01:15:08 -07:00
parent efec80523a
commit d6a8198660
3 changed files with 27 additions and 48 deletions

View File

@ -14,6 +14,7 @@ export default class ImageContentSetup {
lightbox.on("zoomPanUpdate", this.zoomPanUpdate.bind(this)); lightbox.on("zoomPanUpdate", this.zoomPanUpdate.bind(this));
lightbox.on("slideActivate", this.slideActivate.bind(this)); lightbox.on("slideActivate", this.slideActivate.bind(this));
lightbox.addFilter("isContentLoading", this.isContentLoading.bind(this)); lightbox.addFilter("isContentLoading", this.isContentLoading.bind(this));
lightbox.addFilter("placeholderSrc", this.placeholderSrc.bind(this));
} }
isContentLoading(isLoading: boolean, content: any) { isContentLoading(isLoading: boolean, content: any) {
@ -33,16 +34,14 @@ export default class ImageContentSetup {
e.preventDefault(); e.preventDefault();
} }
placeholderSrc(placeholderSrc: string, content: any) {
return content.data.msrc || placeholderSrc;
}
getXImgElem(content: any, onLoad: () => void): HTMLImageElement { getXImgElem(content: any, onLoad: () => void): HTMLImageElement {
const img = document.createElement("img"); const img = document.createElement("img");
img.classList.add("pswp__img", "ximg"); img.classList.add("pswp__img", "ximg");
img.style.visibility = "hidden";
// Load thumbnail in case the user is scrolling fast
if (content.data.msrc) {
img.src = content.data.msrc;
} else {
img.style.visibility = "hidden";
}
// Fetch with Axios // Fetch with Axios
fetchImage(content.data.src).then((blob) => { fetchImage(content.data.src).then((blob) => {

View File

@ -44,10 +44,6 @@ class VideoContentSetup {
lightbox.on("contentDeactivate", this.onContentDeactivate.bind(this)); lightbox.on("contentDeactivate", this.onContentDeactivate.bind(this));
lightbox.on("contentResize", this.onContentResize.bind(this)); lightbox.on("contentResize", this.onContentResize.bind(this));
lightbox.addFilter(
"isKeepingPlaceholder",
this.isKeepingPlaceholder.bind(this)
);
lightbox.addFilter("isContentZoomable", this.isContentZoomable.bind(this)); lightbox.addFilter("isContentZoomable", this.isContentZoomable.bind(this));
lightbox.addFilter( lightbox.addFilter(
"useContentPlaceholder", "useContentPlaceholder",
@ -240,8 +236,8 @@ class VideoContentSetup {
} }
destroyVideo(content: any) { destroyVideo(content: any) {
if (isVideoContent(content) && content.videojs) { if (isVideoContent(content)) {
content.videojs.dispose?.(); content.videojs?.dispose?.();
content.videojs = null; content.videojs = null;
content.plyr?.elements?.container?.remove(); content.plyr?.elements?.container?.remove();
@ -438,12 +434,7 @@ class VideoContentSetup {
} }
onContentDestroy({ content }) { onContentDestroy({ content }) {
if (isVideoContent(content)) { this.destroyVideo(content);
if (content.videojs) {
content.videojs.dispose?.();
content.videojs = null;
}
}
} }
onContentResize(e) { onContentResize(e) {
@ -471,18 +462,8 @@ class VideoContentSetup {
} }
} }
isKeepingPlaceholder(isZoomable, content) {
if (isVideoContent(content)) {
return false;
}
return isZoomable;
}
isContentZoomable(isZoomable, content) { isContentZoomable(isZoomable, content) {
if (isVideoContent(content)) { return !isVideoContent(content) && isZoomable;
return false;
}
return isZoomable;
} }
onContentActivate({ content }) { onContentActivate({ content }) {
@ -497,40 +478,30 @@ class VideoContentSetup {
const content = e.content; const content = e.content;
if (!isVideoContent(e.content)) return; if (!isVideoContent(e.content)) return;
// stop default content load // Stop default content load
e.preventDefault(); e.preventDefault();
content.type = "video";
if (content.element) return; if (content.element) return;
// Create DIV // Create DIV
content.element = document.createElement("div"); content.element = document.createElement("div");
content.element.classList.add("pswp__img"); content.element.classList.add("video-container");
content.element.style.background = `url(${content.data.msrc})`;
content.element.style.backgroundSize = "cover";
if (config_videoIsSetup) { // Stop if video not setup
content.state = "loading"; if (!config_videoIsSetup) {
content.type = "video";
} else {
// Stop if video not setup
content.element.innerHTML = t( content.element.innerHTML = t(
"memories", "memories",
"Video not configured. Run occ memories:video-setup" "Video not configured. Run occ memories:video-setup"
); );
content.element.style.color = "red"; content.element.classList.add("error");
content.element.style.display = "flex";
content.element.style.alignItems = "center";
content.element.style.justifyContent = "center";
} }
content.onLoaded(); content.onLoaded();
} }
useContentPlaceholder(usePlaceholder, content) { useContentPlaceholder(usePlaceholder: boolean, content: any) {
if (isVideoContent(content)) { return isVideoContent(content) || usePlaceholder;
return true;
}
return usePlaceholder;
} }
} }

View File

@ -1256,6 +1256,15 @@ export default defineComponent({
.pswp__top-bar { .pswp__top-bar {
background: linear-gradient(0deg, transparent, rgba(0, 0, 0, 0.3)); background: linear-gradient(0deg, transparent, rgba(0, 0, 0, 0.3));
} }
.video-container {
&.error {
color: red;
display: flex;
align-items: center;
justify-content: center;
}
}
} }
:deep .video-js .vjs-big-play-button { :deep .video-js .vjs-big-play-button {