keep cw up until new images loads when needed

fixes #18
This commit is contained in:
rhiannon morris 2024-08-05 21:27:23 +02:00
parent ff906f8b5e
commit 70e3e36244
2 changed files with 17 additions and 14 deletions

View file

@ -62,7 +62,7 @@ make' root siteName prefix nsfw _dataDir dir
let updates = sort $ updatesFor nsfw info
let updatesList = makeUpdates updates
let makePrefetch img = [b|<link rel=preload as=image href=$path'>|]
let makePrefetch img = [b|<link rel=prefetch as=image href=$path'>|]
where path' = bigFile img
let prefetches = map makePrefetch otherImages

View file

@ -22,25 +22,28 @@ function addCWListeners(id: string | null, caption: HTMLElement): void {
}
function setImage(id: string, src: string, href: string, cw: string): void {
const caption = document.getElementById('cw');
const checked = skipAll ? skipAll.checked : false;
const curCw = document.getElementById('cw');
const coverNew = cw != '' && !opened.has(id) && !skipAll.checked;
if (!checked && !opened.has(id) && cw) {
const template = document.getElementById('cw-template') as HTMLTemplateElement;
const newCaption = template.content.firstElementChild!.cloneNode(true) as HTMLElement;
newCaption.querySelector('#cw-text')!.innerHTML = cw;
if (curCw && !coverNew) {
// keep old cover until load
mainimg.addEventListener('load', () => openCW(null, curCw), {once: true});
} else if (coverNew) {
// place new cover
const newCw =
(document.getElementById('cw-template') as HTMLTemplateElement)
.content.firstElementChild!.cloneNode(true) as HTMLElement;
newCw.querySelector('#cw-text')!.innerHTML = cw;
if (caption) openCW(null, caption);
mainfig.insertBefore(newCaption, mainlink);
if (curCw) openCW(null, curCw);
mainfig.insertBefore(newCw, mainlink);
mainlink.tabIndex = -1;
addCWListeners(id, newCaption);
} else {
if (caption) openCW(null, caption);
addCWListeners(id, newCw);
}
// else no cover before or after
mainimg.src = src;
mainimg.src = src;
mainlink.href = href;
}