2020-08-03 13:38:14 -04:00
|
|
|
(function() {
|
2020-07-17 09:51:39 -04:00
|
|
|
'use strict';
|
2020-07-17 06:29:13 -04:00
|
|
|
|
2020-08-03 13:38:14 -04:00
|
|
|
function getById(id) { return document.getElementById(id); }
|
|
|
|
|
|
|
|
let mainfig = getById('mainfig');
|
|
|
|
let mainimg = getById('mainimg');
|
|
|
|
let mainlink = getById('mainlink');
|
2020-07-21 04:56:55 -04:00
|
|
|
|
2020-08-03 13:38:14 -04:00
|
|
|
function openCW(caption, focusLink) {
|
|
|
|
mainfig.removeChild(caption);
|
|
|
|
mainlink.tabIndex = 0;
|
|
|
|
if (focusLink) mainlink.focus();
|
2020-07-17 06:29:13 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:38:14 -04:00
|
|
|
function addCWListeners(caption) {
|
|
|
|
if (caption) {
|
|
|
|
caption.addEventListener('click', e => openCW(caption));
|
|
|
|
caption.addEventListener('keyup',
|
|
|
|
e => { if (e.key == 'Enter') openCW(caption, true) });
|
|
|
|
}
|
|
|
|
}
|
2020-07-17 06:29:13 -04:00
|
|
|
|
|
|
|
function setImage(src, href, cw) {
|
|
|
|
let caption = getById('cw');
|
2020-08-03 13:38:14 -04:00
|
|
|
let cwText = `<span id=cw-text>cw: <b>${cw}</b></span>`;
|
|
|
|
|
|
|
|
if (cw && caption) {
|
|
|
|
caption.innerHTML = cwText;
|
|
|
|
} else if (caption) {
|
|
|
|
openCW(caption);
|
|
|
|
} else if (cw) {
|
|
|
|
let template = document.createElement('template');
|
|
|
|
template.innerHTML = `
|
|
|
|
<figcaption id=cw aria-role=button tabindex=0>
|
|
|
|
${cwText}
|
|
|
|
</figcaption>`;
|
|
|
|
let content = template.content;
|
|
|
|
addCWListeners(content.getElementById('cw'));
|
|
|
|
mainfig.insertBefore(content, mainlink);
|
|
|
|
mainlink.tabIndex = -1;
|
2020-07-17 06:29:13 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:38:14 -04:00
|
|
|
mainimg.src = src;
|
|
|
|
mainlink.href = href;
|
2020-07-17 06:29:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function activateButton(button) {
|
|
|
|
setImage(button.value, button.dataset.link, button.dataset.warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup() {
|
2020-08-03 13:38:14 -04:00
|
|
|
for (let button of document.querySelectorAll('#alts input')) {
|
|
|
|
button.onchange = e => { if (button.checked) activateButton(button); };
|
2020-07-17 06:29:13 -04:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:38:14 -04:00
|
|
|
addCWListeners(getById('cw'));
|
2020-07-17 06:29:13 -04:00
|
|
|
}
|
|
|
|
|
2020-07-21 04:56:55 -04:00
|
|
|
window.addEventListener('load', setup);
|
|
|
|
|
|
|
|
})();
|