diff --git a/script/single.js b/script/single.js index 5d63b5f..5e3347f 100644 --- a/script/single.js +++ b/script/single.js @@ -25,21 +25,23 @@ function addCWListeners(id, caption) { function setImage(id, src, width, height, href, cw, firstLoad) { let caption = document.getElementById('cw'); - let cwText = `cw: ${cw}`; + let newCaption; - if (!opened.has(id) && cw && caption) { - caption.innerHTML = cwText; - } else if (caption) { - openCW(id, caption); - } else if (!opened.has(id) && cw) { + if (!opened.has(id) && cw) { let template = document.createElement('template'); template.innerHTML = `
- ${cwText} + cw: ${cw}
`; - let content = template.content; - addCWListeners(id, content.getElementById('cw')); - mainfig.insertBefore(content, mainlink); + newCaption = template.content; + addCWListeners(id, newCaption.getElementById('cw')); + } + + if (caption) { + openCW(null, caption); + } + if (newCaption) { + mainfig.insertBefore(newCaption, mainlink); mainlink.tabIndex = -1; }