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 updates = sort $ updatesFor nsfw info
let updatesList = makeUpdates updates 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 where path' = bigFile img
let prefetches = map makePrefetch otherImages 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 { function setImage(id: string, src: string, href: string, cw: string): void {
const caption = document.getElementById('cw'); const curCw = document.getElementById('cw');
const checked = skipAll ? skipAll.checked : false; const coverNew = cw != '' && !opened.has(id) && !skipAll.checked;
if (!checked && !opened.has(id) && cw) { if (curCw && !coverNew) {
const template = document.getElementById('cw-template') as HTMLTemplateElement; // keep old cover until load
const newCaption = template.content.firstElementChild!.cloneNode(true) as HTMLElement; mainimg.addEventListener('load', () => openCW(null, curCw), {once: true});
newCaption.querySelector('#cw-text')!.innerHTML = cw; } 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); if (curCw) openCW(null, curCw);
mainfig.insertBefore(newCw, mainlink);
mainfig.insertBefore(newCaption, mainlink);
mainlink.tabIndex = -1; mainlink.tabIndex = -1;
addCWListeners(id, newCaption); addCWListeners(id, newCw);
} else {
if (caption) openCW(null, caption);
} }
// else no cover before or after
mainimg.src = src; mainimg.src = src;
mainlink.href = href; mainlink.href = href;
} }