Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const dropZone = document.getElementById('drop-zone');
+ const fileInput = document.getElementById('file-input');
+ const gallery = document.getElementById('image-gallery');
+
+ // Store images in memory (in a real app, you'd use a backend)
+ const images = [];
+
+ // Drag and drop handlers
+ dropZone.addEventListener('dragover', (e) => {
+ e.preventDefault();
+ dropZone.classList.add('dragover');
+ });
+
+ dropZone.addEventListener('dragleave', () => {
+ dropZone.classList.remove('dragover');
+ });
+
+ dropZone.addEventListener('drop', (e) => {
+ e.preventDefault();
+ dropZone.classList.remove('dragover');
+ handleFiles(e.dataTransfer.files);
+ });
+
+ fileInput.addEventListener('change', (e) => {
+ handleFiles(e.target.files);
+ });
+
+ function handleFiles(files) {
+ const file = files[0];
+ if (file && file.type.startsWith('image/')) {
+ const reader = new FileReader();
+
+ reader.onload = (e) => {
+ const imageUrl = e.target.result;
+ images.unshift(imageUrl);
+ updateGallery();
+ };
+
+ reader.readAsDataURL(file);
+ }
+ }
+
+ function updateGallery() {
+ gallery.innerHTML = '';
+ images.forEach(imageUrl => {
+ const item = document.createElement('div');
+ item.className = 'gallery-item';
+
+ const img = document.createElement('img');
+ img.src = imageUrl;
+ img.alt = 'Uploaded image';
+ img.loading = 'lazy';
+
+ item.appendChild(img);
+ gallery.appendChild(item);
+ });
+ }
+ });