Animate episode thumbnails on hover
This commit is contained in:
+28
-2
@@ -130,7 +130,6 @@ function renderDetails(title) {
|
||||
<button id="editMetaBtn" type="button">Edit</button>
|
||||
<button id="fetchMetadataBtn" type="button">Metadata</button>
|
||||
<button id="makeThumbBtn" type="button">Thumbnail</button>
|
||||
<button id="playAllBtn" class="primary" type="button">Play all</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="metaView" class="meta-view">
|
||||
@@ -142,6 +141,9 @@ function renderDetails(title) {
|
||||
<div id="metaEditMount"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="episode-toolbar">
|
||||
<button id="playAllBtn" class="primary" type="button">Play all</button>
|
||||
</div>
|
||||
<div class="seasons">
|
||||
${title.seasons.map(renderSeason).join("")}
|
||||
</div>
|
||||
@@ -236,7 +238,14 @@ function renderSeason(season) {
|
||||
${season.videos.map((video) => `
|
||||
<button class="episode" type="button" data-video-id="${escapeAttr(video.id)}">
|
||||
<span class="episode__thumb">
|
||||
<img src="${escapeAttr(video.thumbnail)}" alt="" loading="lazy" onerror="this.hidden=true">
|
||||
<img
|
||||
src="${escapeAttr(video.thumbnail)}"
|
||||
data-still="${escapeAttr(video.thumbnail)}"
|
||||
data-animated="${escapeAttr(video.animatedThumbnail)}"
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onerror="this.hidden=true"
|
||||
>
|
||||
<span class="episode__play">Play</span>
|
||||
</span>
|
||||
<span class="episode__name">${escapeHtml(video.name)}</span>
|
||||
@@ -255,6 +264,23 @@ function flattenVideos(title) {
|
||||
function wireEpisodeCards(title) {
|
||||
const videos = flattenVideos(title);
|
||||
document.querySelectorAll("[data-video-id]").forEach((node) => {
|
||||
const image = node.querySelector("img");
|
||||
const showAnimated = () => {
|
||||
if (image?.dataset.animated && image.src !== new URL(image.dataset.animated, window.location.href).href) {
|
||||
image.hidden = false;
|
||||
image.src = image.dataset.animated;
|
||||
}
|
||||
};
|
||||
const showStill = () => {
|
||||
if (image?.dataset.still && image.src !== new URL(image.dataset.still, window.location.href).href) {
|
||||
image.hidden = false;
|
||||
image.src = image.dataset.still;
|
||||
}
|
||||
};
|
||||
node.addEventListener("mouseenter", showAnimated);
|
||||
node.addEventListener("focus", showAnimated);
|
||||
node.addEventListener("mouseleave", showStill);
|
||||
node.addEventListener("blur", showStill);
|
||||
node.addEventListener("click", () => {
|
||||
const index = videos.findIndex((video) => video.id === node.dataset.videoId);
|
||||
startPlaylist(videos, Math.max(index, 0));
|
||||
|
||||
Reference in New Issue
Block a user