This commit is contained in:
+57
-28
@@ -49,6 +49,20 @@ const resultModalMediaFrame = document.getElementById("resultModalMediaFrame");
|
||||
const resultModalVideo = document.getElementById("resultModalVideo");
|
||||
const resultModalThumbnail = document.getElementById("resultModalThumbnail");
|
||||
const resultModalEmbedNotice = document.getElementById("resultModalEmbedNotice");
|
||||
const resultModalReady = Boolean(
|
||||
resultModal &&
|
||||
resultModalTitle &&
|
||||
resultModalSource &&
|
||||
resultModalSnippet &&
|
||||
resultModalReason &&
|
||||
resultModalOpenExternal &&
|
||||
resultModalDownload &&
|
||||
closeResultModal &&
|
||||
resultModalMediaFrame &&
|
||||
resultModalVideo &&
|
||||
resultModalThumbnail &&
|
||||
resultModalEmbedNotice,
|
||||
);
|
||||
|
||||
let pendingDownload = null;
|
||||
let cropStart = 0;
|
||||
@@ -349,6 +363,9 @@ function hideModal(element) {
|
||||
}
|
||||
|
||||
function resetResultModalMedia() {
|
||||
if (!resultModalReady) {
|
||||
return;
|
||||
}
|
||||
resultModalVideo.pause();
|
||||
detachVideoSource(resultModalVideo);
|
||||
resultModalMediaFrame.style.aspectRatio = "";
|
||||
@@ -420,6 +437,10 @@ async function prepareDirectDownload(targetUrl) {
|
||||
}
|
||||
|
||||
function openResultModal(item) {
|
||||
if (!resultModalReady) {
|
||||
logEvent("result:modal:error", { message: "result modal is not fully initialized" });
|
||||
return;
|
||||
}
|
||||
activeResultItem = item;
|
||||
resultModalTitle.textContent = item.title || "Untitled";
|
||||
resultModalSource.textContent = item.source || "";
|
||||
@@ -444,6 +465,9 @@ function openResultModal(item) {
|
||||
}
|
||||
|
||||
function closeResultViewer() {
|
||||
if (!resultModalReady) {
|
||||
return;
|
||||
}
|
||||
if (!resultModal.classList.contains("hidden")) {
|
||||
logEvent("result:modal:close", { title: activeResultItem?.title || "" });
|
||||
}
|
||||
@@ -586,24 +610,27 @@ confirmDownload.addEventListener("click", async () => {
|
||||
});
|
||||
|
||||
closePreviewModal.addEventListener("click", closeModal);
|
||||
closeResultModal.addEventListener("click", closeResultViewer);
|
||||
resultModal.addEventListener("click", (event) => {
|
||||
if (event.target === resultModal) {
|
||||
closeResultViewer();
|
||||
}
|
||||
});
|
||||
resultModalDownload.addEventListener("click", async () => {
|
||||
if (!activeResultItem?.link) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
closeResultViewer();
|
||||
await prepareDirectDownload(activeResultItem.link);
|
||||
} catch (error) {
|
||||
downloadResult.textContent = error.message;
|
||||
logEvent("download:preview:error", { message: error.message, data: error.data || null, source: activeResultItem?.source || "" });
|
||||
}
|
||||
});
|
||||
if (resultModalReady) {
|
||||
closeResultModal.addEventListener("click", closeResultViewer);
|
||||
resultModal.addEventListener("click", (event) => {
|
||||
if (event.target === resultModal) {
|
||||
closeResultViewer();
|
||||
}
|
||||
});
|
||||
resultModalDownload.addEventListener("click", async () => {
|
||||
if (!activeResultItem?.link) {
|
||||
return;
|
||||
}
|
||||
const currentItem = activeResultItem;
|
||||
try {
|
||||
closeResultViewer();
|
||||
await prepareDirectDownload(currentItem.link);
|
||||
} catch (error) {
|
||||
downloadResult.textContent = error.message;
|
||||
logEvent("download:preview:error", { message: error.message, data: error.data || null, source: currentItem?.source || "" });
|
||||
}
|
||||
});
|
||||
}
|
||||
previewModal.addEventListener("click", (event) => {
|
||||
if (event.target === previewModal) {
|
||||
closeModal();
|
||||
@@ -663,16 +690,18 @@ previewThumbnail.addEventListener("load", () => {
|
||||
previewMediaFrame.style.aspectRatio = `${previewThumbnail.naturalWidth} / ${previewThumbnail.naturalHeight}`;
|
||||
}
|
||||
});
|
||||
resultModalVideo.addEventListener("loadedmetadata", () => {
|
||||
if (resultModalVideo.videoWidth > 0 && resultModalVideo.videoHeight > 0) {
|
||||
resultModalMediaFrame.style.aspectRatio = `${resultModalVideo.videoWidth} / ${resultModalVideo.videoHeight}`;
|
||||
}
|
||||
});
|
||||
resultModalThumbnail.addEventListener("load", () => {
|
||||
if (!resultModalVideo.src && resultModalThumbnail.naturalWidth > 0 && resultModalThumbnail.naturalHeight > 0) {
|
||||
resultModalMediaFrame.style.aspectRatio = `${resultModalThumbnail.naturalWidth} / ${resultModalThumbnail.naturalHeight}`;
|
||||
}
|
||||
});
|
||||
if (resultModalReady) {
|
||||
resultModalVideo.addEventListener("loadedmetadata", () => {
|
||||
if (resultModalVideo.videoWidth > 0 && resultModalVideo.videoHeight > 0) {
|
||||
resultModalMediaFrame.style.aspectRatio = `${resultModalVideo.videoWidth} / ${resultModalVideo.videoHeight}`;
|
||||
}
|
||||
});
|
||||
resultModalThumbnail.addEventListener("load", () => {
|
||||
if (!resultModalVideo.src && resultModalThumbnail.naturalWidth > 0 && resultModalThumbnail.naturalHeight > 0) {
|
||||
resultModalMediaFrame.style.aspectRatio = `${resultModalThumbnail.naturalWidth} / ${resultModalThumbnail.naturalHeight}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const button of platformToggles) {
|
||||
button.addEventListener("click", () => {
|
||||
const platform = button.dataset.platformToggle;
|
||||
|
||||
Reference in New Issue
Block a user