pakdeveloper commited on
Commit
d7b3974
·
verified ·
1 Parent(s): 362a53c

Update index.html

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