2024-10-14 23:09:27 +02:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
2024-04-30 18:38:33 +01:00
|
|
|
|
|
|
|
export default class extends Controller {
|
2024-10-14 23:09:27 +02:00
|
|
|
static targets = [
|
2024-10-23 11:20:55 -04:00
|
|
|
"attachedImage",
|
|
|
|
"previewImage",
|
|
|
|
"placeholderImage",
|
|
|
|
"deleteProfileImage",
|
|
|
|
"input",
|
2024-10-14 23:09:27 +02:00
|
|
|
"clearBtn",
|
2025-04-18 18:53:10 +05:30
|
|
|
"uploadText",
|
|
|
|
"changeText",
|
|
|
|
"cameraIcon"
|
2024-10-14 23:09:27 +02:00
|
|
|
];
|
2024-04-30 18:38:33 +01:00
|
|
|
|
2024-10-23 11:20:55 -04:00
|
|
|
clearFileInput() {
|
|
|
|
this.inputTarget.value = null;
|
|
|
|
this.clearBtnTarget.classList.add("hidden");
|
|
|
|
this.placeholderImageTarget.classList.remove("hidden");
|
|
|
|
this.attachedImageTarget.classList.add("hidden");
|
|
|
|
this.previewImageTarget.classList.add("hidden");
|
|
|
|
this.deleteProfileImageTarget.value = "1";
|
2025-04-18 18:53:10 +05:30
|
|
|
this.uploadTextTarget.classList.remove("hidden");
|
|
|
|
this.changeTextTarget.classList.add("hidden");
|
|
|
|
this.changeTextTarget.setAttribute("aria-hidden", "true");
|
|
|
|
this.uploadTextTarget.setAttribute("aria-hidden", "false");
|
|
|
|
this.cameraIconTarget.classList.remove("!hidden");
|
|
|
|
|
2024-04-30 18:38:33 +01:00
|
|
|
}
|
|
|
|
|
2024-10-23 11:20:55 -04:00
|
|
|
showFileInputPreview(event) {
|
|
|
|
const file = event.target.files[0];
|
|
|
|
if (!file) return;
|
|
|
|
|
|
|
|
this.placeholderImageTarget.classList.add("hidden");
|
|
|
|
this.attachedImageTarget.classList.add("hidden");
|
|
|
|
this.previewImageTarget.classList.remove("hidden");
|
|
|
|
this.clearBtnTarget.classList.remove("hidden");
|
|
|
|
this.deleteProfileImageTarget.value = "0";
|
2025-04-18 18:53:10 +05:30
|
|
|
this.uploadTextTarget.classList.add("hidden");
|
|
|
|
this.changeTextTarget.classList.remove("hidden");
|
|
|
|
this.changeTextTarget.setAttribute("aria-hidden", "false");
|
|
|
|
this.uploadTextTarget.setAttribute("aria-hidden", "true");
|
|
|
|
this.cameraIconTarget.classList.add("!hidden");
|
2024-10-23 11:20:55 -04:00
|
|
|
this.previewImageTarget.querySelector("img").src =
|
|
|
|
URL.createObjectURL(file);
|
2024-04-30 18:38:33 +01:00
|
|
|
}
|
|
|
|
}
|