pakdeveloper commited on
Commit
7a7d90f
·
verified ·
1 Parent(s): d7b3974

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +348 -289
index.html CHANGED
@@ -1,226 +1,274 @@
1
- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Image Gallery</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; }
2
- body {
3
- min-height: 100vh;
4
- background: #FAFAFA;
5
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
6
- }
7
- .container {
8
- max-width: 1200px;
9
- margin: 0 auto;
10
- padding: 2rem;
11
- }
12
- h1 {
13
- font-size: 1.875rem;
14
- font-weight: bold;
15
- color: #262626;
16
- margin-bottom: 2rem;
17
- }
18
- .upload-zone {
19
- background: white;
20
- border: 2px dashed #e2e8f0;
21
- border-radius: 0.5rem;
22
- padding: 2rem;
23
- margin-bottom: 2rem;
24
- cursor: pointer;
25
- transition: all 0.2s;
26
- }
27
- .upload-zone:hover,
28
- .upload-zone.dragging {
29
- border-color: #405DE6;
30
- background: #f8fafc;
31
- }
32
- .upload-zone-content {
33
- display: flex;
34
- flex-direction: column;
35
- align-items: center;
36
- gap: 1rem;
37
- }
38
- .upload-icon {
39
- width: 3rem;
40
- height: 3rem;
41
- color: #405DE6;
42
- }
43
- .upload-text {
44
- font-size: 1.125rem;
45
- font-weight: 600;
46
- }
47
- .upload-subtext {
48
- font-size: 0.875rem;
49
- color: #64748b;
50
- }
51
- .select-button {
52
- margin-top: 1rem;
53
- padding: 0.5rem 1rem;
54
- background: white;
55
- border: 1px solid #e2e8f0;
56
- border-radius: 0.375rem;
57
- font-size: 0.875rem;
58
- cursor: pointer;
59
- transition: all 0.2s;
60
- }
61
- .select-button:hover {
62
- background: #405DE6;
63
- color: white;
64
- }
65
- .gallery {
66
- display: grid;
67
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
68
- gap: 1rem;
69
- }
70
- .image-card {
71
- position: relative;
72
- background: white;
73
- border-radius: 0.5rem;
74
- overflow: hidden;
75
- box-shadow: 0 1px 3px rgba(0,0,0,0.1);
76
- }
77
- .image-card img {
78
- width: 100%;
79
- aspect-ratio: 1;
80
- object-fit: cover;
81
- cursor: pointer;
82
- }
83
- .image-overlay {
84
- position: absolute;
85
- inset: 0;
86
- background: rgba(0,0,0,0.4);
87
- opacity: 0;
88
- transition: opacity 0.2s;
89
- display: flex;
90
- align-items: center;
91
- justify-content: center;
92
- }
93
- .image-card:hover .image-overlay {
94
- opacity: 1;
95
- }
96
- .delete-button {
97
- background: white;
98
- border: none;
99
- border-radius: 9999px;
100
- width: 2.5rem;
101
- height: 2.5rem;
102
- cursor: pointer;
103
- display: flex;
104
- align-items: center;
105
- justify-content: center;
106
- transition: all 0.2s;
107
- }
108
- .delete-button:hover {
109
- background: #ef4444;
110
- color: white;
111
- }
112
- .modal {
113
- position: fixed;
114
- inset: 0;
115
- background: rgba(0,0,0,0.9);
116
- display: none;
117
- align-items: center;
118
- justify-content: center;
119
- z-index: 50;
120
- padding: 20px;
121
- }
122
- .modal.active {
123
- display: flex;
124
- }
125
- .modal img {
126
- max-width: 95%;
127
- max-height: 95vh;
128
- object-fit: contain;
129
- }
130
- .toast {
131
- position: fixed;
132
- bottom: 1rem;
133
- right: 1rem;
134
- padding: 1rem;
135
- background: #262626;
136
- color: white;
137
- border-radius: 0.375rem;
138
- display: none;
139
- animation: slideIn 0.2s ease-out;
140
- }
141
- .url-input-container {
142
- margin: 20px 0;
143
- display: flex;
144
- gap: 10px;
145
- width: 100%;
146
- max-width: 600px;
147
- }
148
- .url-input {
149
- flex: 1;
150
- padding: 8px;
151
- border: 1px solid #ccc;
152
- border-radius: 4px;
153
- font-size: 14px;
154
- }
155
- .url-button {
156
- padding: 8px 16px;
157
- background: #405DE6;
158
- color: white;
159
- border: none;
160
- border-radius: 4px;
161
- cursor: pointer;
162
- }
163
- .url-button:hover {
164
- background: #304BD6;
165
- }
166
- .url-button:disabled {
167
- background: #ccc;
168
- cursor: not-allowed;
169
- }
170
- @keyframes slideIn {
171
- from {
172
- transform: translateY(100%);
173
  opacity: 0;
 
 
 
 
174
  }
175
- to {
176
- transform: translateY(0);
177
  opacity: 1;
178
  }
179
- }
180
- </style>
181
- </head> <body> <div class="container"> <h1>Image Gallery</h1> <div class="upload-zone" id="uploadZone"> <div class="upload-zone-content"> <svg class="upload-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/> </svg> <div class="upload-text">Click or drag and drop your images here</div> <div class="upload-subtext">Supports: JPG, PNG, GIF</div> <button class="select-button">Select Image</button> </div> <input type="file" id="fileInput" accept="image/*" multiple hidden> </div> <div class="url-input-container"> <input type="text" id="urlInput" placeholder="Or paste image URL here" class="url-input"> <button class="url-button" onclick="addImageFromUrl()">Add URL</button> </div> <div class="gallery" id="gallery"></div> </div> <div class="modal" id="modal"> <img id="modalImage" src="" alt="Full size image"> </div> <div class="toast" id="toast"></div>
182
- <script>
183
- const uploadZone = document.getElementById('uploadZone');
184
- const fileInput = document.getElementById('fileInput');
185
- const gallery = document.getElementById('gallery');
186
- const modal = document.getElementById('modal');
187
- const modalImage = document.getElementById('modalImage');
188
- const toast = document.getElementById('toast');
189
- let images = [];
190
- function showToast(message) {
191
- toast.textContent = message;
192
- toast.style.display = 'block';
193
- setTimeout(() => {
194
- toast.style.display = 'none';
195
- }, 3000);
196
- }
197
- function handleDrag(e) {
198
- e.preventDefault();
199
- e.stopPropagation();
200
-
201
- if (e.type === "dragenter" || e.type === "dragover") {
202
- uploadZone.classList.add('dragging');
203
- } else if (e.type === "dragleave" || e.type === "drop") {
204
- uploadZone.classList.remove('dragging');
205
- }
206
- }
207
- uploadZone.addEventListener('click', () => fileInput.click());
208
- uploadZone.addEventListener('dragenter', handleDrag);
209
- uploadZone.addEventListener('dragover', handleDrag);
210
- uploadZone.addEventListener('dragleave', handleDrag);
211
- uploadZone.addEventListener('drop', (e) => {
212
- handleDrag(e);
213
- const files = Array.from(e.dataTransfer.files);
214
- handleFiles(files);
215
- });
216
- fileInput.addEventListener('change', (e) => {
217
- const files = Array.from(e.target.files || []);
218
- handleFiles(files);
219
- fileInput.value = '';
220
- });
221
- function handleFiles(files) {
222
- files.forEach(file => {
223
- if (file.type.startsWith('image/')) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  const reader = new FileReader();
225
  reader.onload = (e) => {
226
  addImage({
@@ -230,76 +278,87 @@
230
  showToast('Image uploaded successfully');
231
  };
232
  reader.readAsDataURL(file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  });
235
- }
236
- function validateImageUrl(url) {
237
- return new Promise((resolve, reject) => {
238
- const img = new Image();
239
- img.onload = () => resolve(true);
240
- img.onerror = () => reject(new Error('Invalid image URL'));
241
- img.src = url;
242
- });
243
- }
244
- async function addImageFromUrl() {
245
- const urlInput = document.getElementById('urlInput');
246
- const url = urlInput.value.trim();
247
-
248
- if (!url) {
249
- showToast('Please enter an image URL');
250
- return;
251
- }
252
- try {
253
- new URL(url);
254
-
255
- const addButton = document.querySelector('.url-button');
256
- addButton.disabled = true;
257
- addButton.textContent = 'Loading...';
258
- await validateImageUrl(url);
259
- addImage({
260
- id: Date.now(),
261
- url: url
262
- });
263
-
264
- urlInput.value = '';
265
- showToast('Image added successfully');
266
- } catch (error) {
267
- showToast(error.message || 'Invalid image URL');
268
- } finally {
269
- const addButton = document.querySelector('.url-button');
270
- addButton.disabled = false;
271
- addButton.textContent = 'Add URL';
272
- }
273
- }
274
- function addImage(image) {
275
- images.unshift(image);
276
- renderGallery();
277
- }
278
- function deleteImage(id) {
279
- images = images.filter(img => img.id !== id);
280
- renderGallery();
281
- showToast('Image deleted successfully');
282
- }
283
- function showModal(url) {
284
- modalImage.src = url;
285
- modal.classList.add('active');
286
- }
287
- modal.addEventListener('click', () => {
288
- modal.classList.remove('active');
289
- });
290
- function renderGallery() {
291
- gallery.innerHTML = images.map(img => `
292
- <div class="image-card">
293
- <img src="${img.url}" alt="Gallery image" onclick="showModal('${img.url}')">
294
- <div class="image-overlay">
295
- <button class="delete-button" onclick="deleteImage(${img.id})">
296
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
297
- <path d="M18 6L6 18M6 6l12 12"/>
298
- </svg>
299
- </button>
300
  </div>
301
- </div>
302
- `).join('');
303
- }
304
- </script>
305
- </body> </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Image Gallery</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+ body {
14
+ min-height: 100vh;
15
+ background: #FAFAFA;
16
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
17
+ }
18
+ .container {
19
+ max-width: 1200px;
20
+ margin: 0 auto;
21
+ padding: 2rem;
22
+ }
23
+ h1 {
24
+ font-size: 1.875rem;
25
+ font-weight: bold;
26
+ color: #262626;
27
+ margin-bottom: 2rem;
28
+ }
29
+ .upload-zone {
30
+ background: white;
31
+ border: 2px dashed #e2e8f0;
32
+ border-radius: 0.5rem;
33
+ padding: 2rem;
34
+ margin-bottom: 2rem;
35
+ cursor: pointer;
36
+ transition: all 0.2s;
37
+ }
38
+ .upload-zone:hover,
39
+ .upload-zone.dragging {
40
+ border-color: #405DE6;
41
+ background: #f8fafc;
42
+ }
43
+ .upload-zone-content {
44
+ display: flex;
45
+ flex-direction: column;
46
+ align-items: center;
47
+ gap: 1rem;
48
+ }
49
+ .upload-icon {
50
+ width: 3rem;
51
+ height: 3rem;
52
+ color: #405DE6;
53
+ }
54
+ .upload-text {
55
+ font-size: 1.125rem;
56
+ font-weight: 600;
57
+ }
58
+ .upload-subtext {
59
+ font-size: 0.875rem;
60
+ color: #64748b;
61
+ }
62
+ .select-button {
63
+ margin-top: 1rem;
64
+ padding: 0.5rem 1rem;
65
+ background: white;
66
+ border: 1px solid #e2e8f0;
67
+ border-radius: 0.375rem;
68
+ font-size: 0.875rem;
69
+ cursor: pointer;
70
+ transition: all 0.2s;
71
+ }
72
+ .select-button:hover {
73
+ background: #405DE6;
74
+ color: white;
75
+ }
76
+ .gallery {
77
+ display: grid;
78
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
79
+ gap: 1rem;
80
+ }
81
+ .image-card {
82
+ position: relative;
83
+ background: white;
84
+ border-radius: 0.5rem;
85
+ overflow: hidden;
86
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
87
+ }
88
+ .image-card img {
89
+ width: 100%;
90
+ aspect-ratio: 1;
91
+ object-fit: cover;
92
+ cursor: pointer;
93
+ }
94
+ .image-overlay {
95
+ position: absolute;
96
+ inset: 0;
97
+ background: rgba(0,0,0,0.4);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  opacity: 0;
99
+ transition: opacity 0.2s;
100
+ display: flex;
101
+ align-items: center;
102
+ justify-content: center;
103
  }
104
+ .image-card:hover .image-overlay {
 
105
  opacity: 1;
106
  }
107
+ .delete-button {
108
+ background: white;
109
+ border: none;
110
+ border-radius: 9999px;
111
+ width: 2.5rem;
112
+ height: 2.5rem;
113
+ cursor: pointer;
114
+ display: flex;
115
+ align-items: center;
116
+ justify-content: center;
117
+ transition: all 0.2s;
118
+ }
119
+ .delete-button:hover {
120
+ background: #ef4444;
121
+ color: white;
122
+ }
123
+ .modal {
124
+ position: fixed;
125
+ inset: 0;
126
+ background: rgba(0,0,0,0.9);
127
+ display: none;
128
+ align-items: center;
129
+ justify-content: center;
130
+ z-index: 50;
131
+ padding: 20px;
132
+ }
133
+ .modal.active {
134
+ display: flex;
135
+ }
136
+ .modal img {
137
+ max-width: 95%;
138
+ max-height: 95vh;
139
+ object-fit: contain;
140
+ }
141
+ .toast {
142
+ position: fixed;
143
+ bottom: 1rem;
144
+ right: 1rem;
145
+ padding: 1rem;
146
+ background: #262626;
147
+ color: white;
148
+ border-radius: 0.375rem;
149
+ display: none;
150
+ animation: slideIn 0.2s ease-out;
151
+ }
152
+ .url-input-container {
153
+ margin: 20px 0;
154
+ display: flex;
155
+ gap: 10px;
156
+ width: 100%;
157
+ max-width: 600px;
158
+ }
159
+ .url-input {
160
+ flex: 1;
161
+ padding: 8px;
162
+ border: 1px solid #ccc;
163
+ border-radius: 4px;
164
+ font-size: 14px;
165
+ }
166
+ .url-button {
167
+ padding: 8px 16px;
168
+ background: #405DE6;
169
+ color: white;
170
+ border: none;
171
+ border-radius: 4px;
172
+ cursor: pointer;
173
+ }
174
+ .url-button:hover {
175
+ background: #304BD6;
176
+ }
177
+ .url-button:disabled {
178
+ background: #ccc;
179
+ cursor: not-allowed;
180
+ }
181
+ @keyframes slideIn {
182
+ from {
183
+ transform: translateY(100%);
184
+ opacity: 0;
185
+ }
186
+ to {
187
+ transform: translateY(0);
188
+ opacity: 1;
189
+ }
190
+ }
191
+ </style>
192
+ </head>
193
+ <body>
194
+ <div class="container">
195
+ <h1>Image Gallery</h1>
196
+ <div class="upload-zone" id="uploadZone">
197
+ <div class="upload-zone-content">
198
+ <svg class="upload-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
199
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"/>
200
+ </svg>
201
+ <div class="upload-text">Click or drag and drop your images here</div>
202
+ <div class="upload-subtext">Supports: JPG, PNG, GIF</div>
203
+ <button class="select-button">Select Image</button>
204
+ </div>
205
+ <input type="file" id="fileInput" accept="image/*" multiple hidden>
206
+ </div>
207
+ <div class="url-input-container">
208
+ <input type="text" id="urlInput" placeholder="Or paste image URL here" class="url-input">
209
+ <button class="url-button" onclick="addImageFromUrl()">Add URL</button>
210
+ </div>
211
+ <div class="gallery" id="gallery"></div>
212
+ </div>
213
+ <div class="modal" id="modal">
214
+ <img id="modalImage" src="" alt="Full size image">
215
+ </div>
216
+ <div class="toast" id="toast"></div>
217
+
218
+ <script>
219
+ const uploadZone = document.getElementById('uploadZone');
220
+ const fileInput = document.getElementById('fileInput');
221
+ const gallery = document.getElementById('gallery');
222
+ const modal = document.getElementById('modal');
223
+ const modalImage = document.getElementById('modalImage');
224
+ const toast = document.getElementById('toast');
225
+ let images = [];
226
+
227
+ function showToast(message) {
228
+ toast.textContent = message;
229
+ toast.style.display = 'block';
230
+ setTimeout(() => {
231
+ toast.style.display = 'none';
232
+ }, 3000);
233
+ }
234
+
235
+ function handleDrag(e) {
236
+ e.preventDefault();
237
+ e.stopPropagation();
238
+
239
+ if (e.type === "dragenter" || e.type === "dragover") {
240
+ uploadZone.classList.add('dragging');
241
+ } else if (e.type === "dragleave" || e.type === "drop") {
242
+ uploadZone.classList.remove('dragging');
243
+ }
244
+ }
245
+
246
+ uploadZone.addEventListener('click', () => fileInput.click());
247
+ uploadZone.addEventListener('dragenter', handleDrag);
248
+ uploadZone.addEventListener('dragover', handleDrag);
249
+ uploadZone.addEventListener('dragleave', handleDrag);
250
+ uploadZone.addEventListener('drop', (e) => {
251
+ handleDrag(e);
252
+ const files = Array.from(e.dataTransfer.files);
253
+ handleFiles(files);
254
+ });
255
+
256
+ fileInput.addEventListener('change', (e) => {
257
+ const files = Array.from(e.target.files || []);
258
+ handleFiles(files);
259
+ fileInput.value = '';
260
+ });
261
+
262
+ function handleFiles(files) {
263
+ files.forEach(file => {
264
+ if (!file.type.startsWith('image/')) {
265
+ showToast('Unsupported file format');
266
+ return;
267
+ }
268
+ if (file.size > 5 * 1024 * 1024) {
269
+ showToast('File size exceeds 5MB limit');
270
+ return;
271
+ }
272
  const reader = new FileReader();
273
  reader.onload = (e) => {
274
  addImage({
 
278
  showToast('Image uploaded successfully');
279
  };
280
  reader.readAsDataURL(file);
281
+ });
282
+ }
283
+
284
+ function validateImageUrl(url) {
285
+ const proxyUrl = `https://cors-anywhere.herokuapp.com/${url}`;
286
+ return new Promise((resolve, reject) => {
287
+ const img = new Image();
288
+ img.onload = () => resolve(true);
289
+ img.onerror = () => reject(new Error('Failed to load image. Please check the URL.'));
290
+ img.src = proxyUrl;
291
+ });
292
+ }
293
+
294
+ async function addImageFromUrl() {
295
+ const urlInput = document.getElementById('urlInput');
296
+ const url = urlInput.value.trim();
297
+
298
+ if (!url) {
299
+ showToast('Please enter an image URL');
300
+ return;
301
  }
302
+
303
+ try {
304
+ new URL(url); // Validate that the input is a valid URL
305
+
306
+ const addButton = document.querySelector('.url-button');
307
+ addButton.disabled = true;
308
+ addButton.textContent = 'Loading...';
309
+
310
+ await validateImageUrl(url);
311
+
312
+ addImage({
313
+ id: Date.now(),
314
+ url: url
315
+ });
316
+
317
+ urlInput.value = '';
318
+ showToast('Image added successfully');
319
+ } catch (error) {
320
+ showToast(error.message || 'Failed to add image. Please check the URL.');
321
+ } finally {
322
+ const addButton = document.querySelector('.url-button');
323
+ addButton.disabled = false;
324
+ addButton.textContent = 'Add URL';
325
+ }
326
+ }
327
+
328
+ function addImage(image) {
329
+ images.unshift(image);
330
+ renderGallery();
331
+ }
332
+
333
+ function deleteImage(id) {
334
+ images = images.filter(img => img.id !== id);
335
+ renderGallery();
336
+ showToast('Image deleted successfully');
337
+ }
338
+
339
+ function showModal(url) {
340
+ modalImage.src = url;
341
+ modal.classList.add('active');
342
+ }
343
+
344
+ modal.addEventListener('click', () => {
345
+ modal.classList.remove('active');
346
  });
347
+
348
+ function renderGallery() {
349
+ gallery.innerHTML = images.map(img => `
350
+ <div class="image-card">
351
+ <img src="${img.url}" alt="Gallery image" onclick="showModal('${img.url}')">
352
+ <div class="image-overlay">
353
+ <button class="delete-button" onclick="deleteImage(${img.id})">
354
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
355
+ <path d="M18 6L6 18M6 6l12 12"/>
356
+ </svg>
357
+ </button>
358
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  </div>
360
+ `).join('');
361
+ }
362
+ </script>
363
+ </body>
364
+ </html>