Files
Stirling-PDF/src/main/resources/static/js/multitool/imageHighlighter.js
jordy e8a91d2631 refactor JS
Rather than having all the JS all in one big file, separate the code into modules.
2023-04-28 21:20:56 +02:00

27 lines
951 B
JavaScript

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;