Skip to content

Commit

Permalink
feat(banner-image): prevent same src crossfade
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrie25 committed Jul 7, 2024
1 parent 3ba3ec5 commit 192863c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Comfy/theme.script.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ todo:

const frame = document.createElement("div");
const banner = [document.createElement("img"), document.createElement("img")];
let bannerLock = false;

frame.className = "comfy-banner-frame";
banner.forEach(image => {
Expand Down Expand Up @@ -1898,6 +1899,17 @@ todo:
const crossfadeBanner = banner.find(image => !image.src || image.classList.contains("inactive"));
const activeBanner = banner.find(image => image.classList.contains("active"));

if (activeBanner?.src === source) {
console.debug("[Comfy-Warning]: Same source, skipping crossfade");
return;
}

if (bannerLock) {
console.debug("[Comfy-Warning]: Crossfade in progress, skipping");
return;
}
bannerLock = true;

crossfadeBanner.src = source;
crossfadeBanner.addEventListener(
"load",
Expand All @@ -1910,11 +1922,18 @@ todo:

activeBanner?.classList.remove("active");
activeBanner?.classList.add("inactive");

bannerLock = false;
});
});
},
{ once: true }
);

crossfadeBanner.addEventListener("error", () => {
crossfadeBanner.src = "";
bannerLock = false;
});
}
}

Expand Down

0 comments on commit 192863c

Please sign in to comment.