Skip to content

Commit

Permalink
fix: add temporary backup url for github permanent url image availabi…
Browse files Browse the repository at this point in the history
…lity delay
  • Loading branch information
srijitcoder committed Jan 17, 2025
1 parent 8e4014d commit 392aaa7
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions elements/storytelling/src/helpers/render-html-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,41 @@ function processNode(node, initDispatchFunc) {
const lightboxElements = [];

const images = node.querySelectorAll("img");
// Loop over each image
images.forEach((img) => {
const videos = node.querySelectorAll("video");

// Loop over each image/video
[...images, ...videos].forEach((media) => {
// Check if the image is already inside a link (to avoid double wrapping)
const mode = img.getAttribute("mode");
const mode = media.getAttribute("mode");

if (img.parentNode.tagName !== "A" && mode !== "hero") {
img.style.cursor = "zoom-in";
img.addEventListener("click", () => {
if (media.parentNode.tagName !== "A" && mode !== "hero") {
media.style.cursor = "zoom-in";
media.addEventListener("click", () => {
lightboxGallery.open();
});

media.onerror = () => {
if (
document.body.contains(media) &&
media.title.includes("temp-backup-url=")
) {
media.src = media.title.replace("temp-backup-url=", "");
media.title = "";
}
};

media.onload = () => {
if (
document.body.contains(media) &&
media.title.includes("temp-backup-url=")
) {
media.title = "";
}
};

lightboxElements.push({
type: "image",
href: img.src,
href: media.src,
});
}
});
Expand Down

0 comments on commit 392aaa7

Please sign in to comment.