Make files opaque until loaded
This commit is contained in:
@@ -287,6 +287,11 @@ body {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-file-loading {
|
||||||
|
opacity: .4;
|
||||||
|
transition: opacity .2s;
|
||||||
|
}
|
||||||
|
|
||||||
.post-img-info {
|
.post-img-info {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
|||||||
@@ -37,14 +37,21 @@ function insertHeaderReplies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function togglePostFile(el) {
|
function togglePostFile(el) {
|
||||||
|
function makeOpaqueUntilReady(el, readyEvt) {
|
||||||
|
el.classList.add('post-file-loading');
|
||||||
|
el.addEventListener(readyEvt, () => el.classList.remove('post-file-loading'), { once: true });
|
||||||
|
}
|
||||||
|
|
||||||
const imgEl = el.parentElement.parentElement.querySelector("img");
|
const imgEl = el.parentElement.parentElement.querySelector("img");
|
||||||
const isVideo = imgEl.dataset.full.endsWith(".mp4") || imgEl.dataset.full.endsWith(".webm") || imgEl.dataset.full.endsWith(".ogg");
|
const isVideo = imgEl.dataset.full.endsWith(".mp4") || imgEl.dataset.full.endsWith(".webm") || imgEl.dataset.full.endsWith(".ogg");
|
||||||
|
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
const vidEl = imgEl.parentElement.querySelector("video");
|
const vidEl = imgEl.parentElement.querySelector("video");
|
||||||
|
|
||||||
const closeVidBtn = imgEl.parentElement.querySelector(".link-button");
|
const closeVidBtn = imgEl.parentElement.querySelector(".link-button");
|
||||||
if (vidEl.style.display === "none") {
|
if (vidEl.style.display === "none") {
|
||||||
vidEl.src = "/media/posts/full/" + imgEl.dataset.full;
|
vidEl.src = "/media/posts/full/" + imgEl.dataset.full;
|
||||||
|
makeOpaqueUntilReady(vidEl, 'canplay');
|
||||||
vidEl.style.display = "";
|
vidEl.style.display = "";
|
||||||
imgEl.style.display = "none";
|
imgEl.style.display = "none";
|
||||||
closeVidBtn.style.display = "";
|
closeVidBtn.style.display = "";
|
||||||
@@ -64,6 +71,8 @@ function togglePostFile(el) {
|
|||||||
else {
|
else {
|
||||||
imgEl.classList.add("post-img-full");
|
imgEl.classList.add("post-img-full");
|
||||||
imgEl.src = "/media/posts/full/" + imgEl.dataset.full;
|
imgEl.src = "/media/posts/full/" + imgEl.dataset.full;
|
||||||
|
if (!imgEl.complete)
|
||||||
|
makeOpaqueUntilReady(imgEl, 'load');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user