dealhub/resources/js/image-input.js
kusowl ccb5a2ed5e refactor: consolidate alert components and improve functionality
- replaced `alert-error` and `alert-success` components with a single reusable `alert` component
- added JS functionality for dismissible alerts
- updated related views to use the new `alert` component
- adjusted broker profile logic to display initials and verification status dynamically
- refactored morph relations from `type` to `role`
- enhanced image preview behavior for file inputs
- made broker migration fields nullable and added safeguards against registration errors
- Added confirmation when a user wants delete deal
- Add dynamic initials for user profile picture
- make image file name non-overidding with timestamp
2026-01-14 12:19:20 +05:30

46 lines
1.4 KiB
JavaScript

const previewImage = document.getElementById('preview-image');
function upload(size) {
const imageInput = document.getElementById("image-input");
const closeModalBtn = document.getElementById("close-modal");
const cancelBtn = document.getElementById("cancel-modal");
const modal = document.getElementById("image-modal");
let imageUrl = '';
const image = imageInput.files[0];
if (!image || !image.type.includes("image")) {
alert("Please upload a valid image");
return;
}
if (image.size > size * 1000000) {
alert(`Max size of image is ${size} MB`);
return;
}
// Creating a FileReader class to convert image blob to base64
const fileReader = new FileReader();
fileReader.readAsDataURL(image);
fileReader.onload = (e) => {
const imagePlaceholder = document.getElementById("image-placeholder");
imagePlaceholder.src = imageUrl = e.target.result;
modal.showModal();
}
closeModalBtn.addEventListener('click', () => {
// this closes then modal and sets the preview image
previewImage.src = imageUrl;
previewImage.style.display = "block";
modal.close();
})
cancelBtn.addEventListener('click', () => {
// clears the file from image input field and closes the modal
imageInput.value = "";
modal.close();
})
}
document.upload = upload;