2020-07-17 09:51:39 -04:00
|
|
|
'use strict';
|
2020-07-17 06:29:13 -04:00
|
|
|
|
|
|
|
function defined(x) {
|
|
|
|
return x !== null && typeof x !== 'undefined';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getById(id) { return document.getElementById(id); }
|
|
|
|
|
|
|
|
function setImage(src, href, cw) {
|
|
|
|
let mainfig = getById('mainfig');
|
|
|
|
let mainimg = getById('mainimg');
|
|
|
|
let mainlink = getById('mainlink');
|
|
|
|
let caption = getById('cw');
|
|
|
|
|
|
|
|
if (defined(caption) && defined(cw)) {
|
|
|
|
caption.innerHTML = cw;
|
|
|
|
} else if (defined(caption)) {
|
|
|
|
mainfig.removeChild(caption);
|
|
|
|
} else if (defined(cw)) {
|
|
|
|
let newCaption = document.createElement('figcaption');
|
|
|
|
newCaption.id = 'cw';
|
2020-07-18 05:45:59 -04:00
|
|
|
newCaption.innerHTML = `<span id=cw-text>cw: <b>${cw}</b></span>`;
|
2020-07-17 06:29:13 -04:00
|
|
|
newCaption.onclick = openCW;
|
|
|
|
mainfig.insertBefore(newCaption, mainlink);
|
|
|
|
}
|
|
|
|
|
|
|
|
mainimg.src = src;
|
|
|
|
mainlink.href= href;
|
|
|
|
}
|
|
|
|
|
|
|
|
function activateButton(button) {
|
|
|
|
setImage(button.value, button.dataset.link, button.dataset.warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
function openCW() {
|
|
|
|
let mainfig = getById('mainfig');
|
|
|
|
let caption = getById('cw');
|
|
|
|
if (defined(caption)) {
|
|
|
|
mainfig.removeChild(caption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
for (let button of document.querySelectorAll('#altlist input')) {
|
|
|
|
button.onchange = function(e) {
|
|
|
|
if (button.checked) activateButton(button);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let caption = getById('cw');
|
|
|
|
if (defined(caption)) {
|
|
|
|
caption.onclick = openCW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = setup;
|