2023-04-29 12:43:12 +02:00
|
|
|
class ImageHiglighter {
|
2024-02-16 22:49:06 +01:00
|
|
|
imageHighlighter;
|
|
|
|
constructor(id) {
|
|
|
|
this.imageHighlighter = document.getElementById(id);
|
|
|
|
this.imageHighlightCallback = this.imageHighlightCallback.bind(this);
|
2023-04-30 13:38:30 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
var styleElement = document.createElement("link");
|
|
|
|
styleElement.rel = "stylesheet";
|
|
|
|
styleElement.href = "css/imageHighlighter.css";
|
2023-04-30 13:38:30 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
document.head.appendChild(styleElement);
|
2023-04-30 13:38:30 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
this.imageHighlighter.onclick = () => {
|
|
|
|
this.imageHighlighter.childNodes.forEach((child) => {
|
|
|
|
child.classList.add("remove");
|
|
|
|
setTimeout(() => {
|
|
|
|
this.imageHighlighter.removeChild(child);
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2023-04-28 21:20:56 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
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();
|
2023-04-28 21:20:56 +02:00
|
|
|
};
|
2024-02-16 22:49:06 +01:00
|
|
|
bigImg.src = highlightEvent.target.src;
|
|
|
|
this.imageHighlighter.appendChild(bigImg);
|
|
|
|
}
|
2023-04-28 21:20:56 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
setActions() {
|
|
|
|
// not needed in this case
|
|
|
|
}
|
2023-04-29 12:43:12 +02:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
adapt(div) {
|
|
|
|
const img = div.querySelector(".page-image");
|
|
|
|
img.addEventListener("click", this.imageHighlightCallback);
|
|
|
|
return div;
|
|
|
|
}
|
2023-04-28 21:20:56 +02:00
|
|
|
}
|
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
export default ImageHiglighter;
|