refactor JS

Rather than having all the JS all in one big file, separate the code into modules.
This commit is contained in:
jordy
2023-04-28 21:20:56 +02:00
parent 6cce2ee70a
commit e8a91d2631
6 changed files with 541 additions and 455 deletions

View File

@@ -0,0 +1,27 @@
const getImageHighlighterCallback = (id) => {
const imageHighlighter = document.getElementById(id);
imageHighlighter.onclick = () => {
imageHighlighter.childNodes.forEach((child) => {
child.classList.add('remove');
setTimeout(() => {
imageHighlighter.removeChild(child);
}, 100)
})
}
const imageHighlightCallback = (highlightEvent) => {
var bigImg = document.createElement('img');
bigImg.onclick = (imageClickEvent) => {
// This prevents the highlighter's onClick from closing the image when clicking on the image
// instead of next to it.
imageClickEvent.preventDefault();
imageClickEvent.stopPropagation();
};
bigImg.src = highlightEvent.target.src;
imageHighlighter.appendChild(bigImg);
};
return imageHighlightCallback
}
export default getImageHighlighterCallback;