Page MenuHomeSealhub

input-image-preview.stimulus.ts
No OneTemporary

input-image-preview.stimulus.ts

import { Controller } from "stimulus";
export default class InputImagePreview extends Controller {
id: string;
handleChange() {
let img = this.element.querySelector("img");
if (!img) {
img = document.createElement("img");
img.setAttribute("style", "height: 40px; width: 40px");
this.element
.querySelector(".image-preview-container")
?.appendChild(img);
}
window.URL.revokeObjectURL(img.src);
const file = this.element.querySelector("input")?.files?.[0];
if (!file) {
console.warn("No file");
return;
}
const new_url = window.URL.createObjectURL(file);
img.src = new_url;
img.parentNode;
img.parentElement
?.querySelectorAll("source")
.forEach((e) => e.parentNode?.removeChild(e));
img.style.aspectRatio = "1";
}
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Nov 28, 15:10 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1062991
Default Alt Text
input-image-preview.stimulus.ts (773 B)

Event Timeline