class FileUploader {
constructor(uploadAreaId, onUpload) {
this.uploadArea = document.getElementById(uploadAreaId);
this.fileInput = document.getElementById('file-input');
this.onUpload = onUpload;
this.init();
}
init() {
this.uploadArea.addEventListener('click', () => {
this.fileInput.click();
});
this.fileInput.addEventListener('change', () => {
this.handleFiles(this.fileInput.files);
});
this.uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
});
this.uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
this.handleFiles(e.dataTransfer.files);
});
}
handleFiles(files) {
if (files.length > 0) {
this.onUpload(files);
}
}
}