brewlog/static/js/components/photo-capture.js
Jon Seager a3cfc22f09
fix(ui): show native camera/gallery picker on mobile photo capture
Remove capture="environment" from the file input so mobile browsers
present the OS-native action sheet instead of opening the camera directly.
2026-02-07 10:27:32 +00:00

25 lines
785 B
JavaScript

customElements.define("brew-photo-capture", class extends HTMLElement {
connectedCallback() {
const input = document.createElement("input");
input.type = "file";
input.accept = "image/*";
input.hidden = true;
this.appendChild(input);
this.addEventListener("click", (e) => {
if (e.target !== input) input.click();
});
input.addEventListener("change", () => {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = () => {
document.getElementById(this.getAttribute("target-input")).value = reader.result;
document.getElementById(this.getAttribute("target-form")).requestSubmit();
};
reader.readAsDataURL(file);
input.value = "";
});
}
});