2024-08-29 11:07:31 +02:00
|
|
|
class ImageHighlighter {
|
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;
|
2024-09-15 10:31:19 -07:00
|
|
|
bigImg.style.rotate = highlightEvent.target.style.rotate;
|
2024-02-16 22:49:06 +01:00
|
|
|
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;
|
|
|
|
}
|
2024-08-29 11:07:31 +02:00
|
|
|
|
|
|
|
async addImageFile(file, nextSiblingElement) {
|
|
|
|
const div = document.createElement("div");
|
|
|
|
div.classList.add("page-container");
|
|
|
|
|
|
|
|
var img = document.createElement("img");
|
|
|
|
img.classList.add("page-image");
|
|
|
|
img.src = URL.createObjectURL(file);
|
|
|
|
div.appendChild(img);
|
|
|
|
|
|
|
|
this.pdfAdapters.forEach((adapter) => {
|
|
|
|
adapter.adapt?.(div);
|
|
|
|
});
|
|
|
|
if (nextSiblingElement) {
|
|
|
|
this.pagesContainer.insertBefore(div, nextSiblingElement);
|
|
|
|
} else {
|
|
|
|
this.pagesContainer.appendChild(div);
|
|
|
|
}
|
|
|
|
}
|
2023-04-28 21:20:56 +02:00
|
|
|
}
|
|
|
|
|
2024-08-29 11:07:31 +02:00
|
|
|
export default ImageHighlighter;
|