refactor JS
Rather than having all the JS all in one big file, separate the code into modules.
This commit is contained in:
27
src/main/resources/static/js/multitool/imageHighlighter.js
Normal file
27
src/main/resources/static/js/multitool/imageHighlighter.js
Normal 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;
|
||||
Reference in New Issue
Block a user