-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallerypage.php
More file actions
324 lines (279 loc) · 11.7 KB
/
gallerypage.php
File metadata and controls
324 lines (279 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gallery - AKBIF</title>
<link rel="stylesheet" href="gallery.css">
</head>
<body>
<!-- Navigation -->
<nav class="navbar" id="navbar">
<div class="nav-container">
<div class="logo">
<img src="logo.png" alt="AKBIF Logo">
</div>
<ul class="nav-links" id="navLinks">
<li style="--i: 0"><a href="homepage.html">Home</a></li>
<li style="--i: 1"><a href="about.html">About Us</a></li>
<li style="--i: 2"><a href="mosqueproject.html">Project</a></li>
<li style="--i: 3"><a href="sadaqah.html">Sadaqah Jariyah</a></li>
<li style="--i: 4"><a href="#gallery" class="active">Gallery</a></li>
<li style="--i: 5"><a href="blogpost.php">Updates</a></li>
<li style="--i: 6"><a href="contactUs.html">Contact Us</a></li>
</ul>
<button class="donate-btn">Donate Now</button>
<button class="mobile-menu-btn" id="mobileMenuBtn">☰</button>
</div>
</nav>
<!-- Hero Section -->
<section class="gallery-hero">
<div class="gallery-hero-content">
<h1>Photo Gallery</h1>
<p>Explore our visual journey through community projects, events, and memorable moments</p>
</div>
</section>
<!-- Main Content -->
<div class="gallery-container">
<!-- Category Filter -->
<div class="category-filter">
<h3>Browse by Category</h3>
<div class="filter-buttons" id="filterButtons">
<button class="filter-btn active" data-category="all">All Images</button>
<!-- Category buttons will be loaded here -->
</div>
</div>
<!-- Loading State -->
<div class="loading" id="loadingState">
<div class="spinner"></div>
<p>Loading gallery...</p>
</div>
<!-- Gallery Content -->
<div id="galleryContent">
<!-- Gallery sections will be loaded here -->
</div>
<!-- Empty State -->
<div class="empty-state" id="emptyState" style="display: none;">
<h3>No Images Found</h3>
<p>There are no images available in the gallery at the moment.</p>
</div>
</div>
<!-- Image Modal -->
<div id="imageModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="modalImage">
<div class="modal-info" id="modalInfo">
<h3 id="modalTitle"></h3>
<p id="modalDate"></p>
<p id="modalCategory"></p>
</div>
</div>
<script>
// Global variables
let allImages = [];
let categories = [];
let currentFilter = 'all';
// DOM Content Loaded
document.addEventListener('DOMContentLoaded', function() {
loadGalleryData();
setupModal();
setupMobileMenu();
});
// Load gallery data from API
async function loadGalleryData() {
try {
showLoading(true);
const response = await fetch('public-gallery.php');
const result = await response.json();
if (result.success) {
allImages = result.data.images_by_category || [];
categories = result.data.categories || [];
renderFilterButtons();
renderGallery();
} else {
showError('Failed to load gallery: ' + result.message);
}
} catch (error) {
console.error('Error loading gallery:', error);
showError('Failed to load gallery. Please try again later.');
} finally {
showLoading(false);
}
}
// Render category filter buttons
function renderFilterButtons() {
const filterButtons = document.getElementById('filterButtons');
// Clear existing buttons except "All Images"
const allButton = filterButtons.querySelector('[data-category="all"]');
filterButtons.innerHTML = '';
filterButtons.appendChild(allButton);
// Add category buttons
categories.forEach(category => {
if (category.image_count > 0) {
const button = document.createElement('button');
button.className = 'filter-btn';
button.setAttribute('data-category', category.id);
button.textContent = `${category.name} (${category.image_count})`;
button.addEventListener('click', () => filterGallery(category.id));
filterButtons.appendChild(button);
}
});
// Add event listener to "All Images" button
allButton.addEventListener('click', () => filterGallery('all'));
}
// Filter gallery by category
function filterGallery(categoryId) {
currentFilter = categoryId;
// Update active filter button
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.remove('active');
});
document.querySelector(`[data-category="${categoryId}"]`).classList.add('active');
// Render filtered gallery
renderGallery();
}
// Render gallery content
function renderGallery() {
const galleryContent = document.getElementById('galleryContent');
const emptyState = document.getElementById('emptyState');
let imagesToShow = allImages;
// Filter images if specific category is selected
if (currentFilter !== 'all') {
imagesToShow = allImages.filter(categoryGroup =>
categoryGroup.category_id == currentFilter
);
}
// Check if we have images to show
const totalImages = imagesToShow.reduce((total, categoryGroup) =>
total + categoryGroup.images.length, 0
);
if (totalImages === 0) {
galleryContent.innerHTML = '';
emptyState.style.display = 'block';
return;
} else {
emptyState.style.display = 'none';
}
// Render gallery sections
let html = '';
if (currentFilter === 'all') {
// Show all categories as separate sections
imagesToShow.forEach(categoryGroup => {
if (categoryGroup.images.length > 0) {
html += renderCategorySection(categoryGroup);
}
});
} else {
// Show single category section
imagesToShow.forEach(categoryGroup => {
html += renderCategoryGrid(categoryGroup.images);
});
}
galleryContent.innerHTML = html;
}
// Render a category section with header
function renderCategorySection(categoryGroup) {
const categoryName = categoryGroup.category_name || 'Uncategorized';
const imageCount = categoryGroup.images.length;
return `
<div class="gallery-section">
<div class="section-header">
<h2 class="section-title">${escapeHtml(categoryName)}</h2>
<p class="section-subtitle">${imageCount} image${imageCount !== 1 ? 's' : ''}</p>
</div>
${renderCategoryGrid(categoryGroup.images)}
</div>
`;
}
// Render grid of images
function renderCategoryGrid(images) {
if (!images || images.length === 0) {
return '<p class="empty-state">No images in this category.</p>';
}
let gridHTML = '<div class="gallery-grid">';
images.forEach(image => {
gridHTML += `
<div class="gallery-item" onclick="openModal('${escapeHtml(image.url)}', '${escapeHtml(image.name)}', '${escapeHtml(image.category_name || 'Uncategorized')}', '${formatDate(image.uploaded_at)}')">
<img src="${escapeHtml(image.url)}" alt="${escapeHtml(image.name)}" loading="lazy">
<div class="gallery-overlay">
<h4>${escapeHtml(image.name)}</h4>
<p class="date">${formatDate(image.uploaded_at)}</p>
</div>
</div>
`;
});
gridHTML += '</div>';
return gridHTML;
}
// Modal functions
function setupModal() {
const modal = document.getElementById('imageModal');
const closeBtn = document.querySelector('.close');
closeBtn.addEventListener('click', closeModal);
modal.addEventListener('click', function(e) {
if (e.target === modal) {
closeModal();
}
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeModal();
}
});
}
function openModal(imageSrc, title, category, date) {
const modal = document.getElementById('imageModal');
const modalImage = document.getElementById('modalImage');
const modalTitle = document.getElementById('modalTitle');
const modalDate = document.getElementById('modalDate');
const modalCategory = document.getElementById('modalCategory');
modalImage.src = imageSrc;
modalTitle.textContent = title;
modalDate.textContent = `Uploaded: ${date}`;
modalCategory.textContent = `Category: ${category}`;
modal.style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closeModal() {
const modal = document.getElementById('imageModal');
modal.style.display = 'none';
document.body.style.overflow = 'auto';
}
// Mobile menu setup
function setupMobileMenu() {
const mobileMenuBtn = document.getElementById('mobileMenuBtn');
const navLinks = document.getElementById('navLinks');
mobileMenuBtn.addEventListener('click', function() {
navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex';
});
}
// Utility functions
function showLoading(show) {
const loadingState = document.getElementById('loadingState');
loadingState.style.display = show ? 'block' : 'none';
}
function showError(message) {
const galleryContent = document.getElementById('galleryContent');
galleryContent.innerHTML = `
<div class="empty-state">
<h3>Error</h3>
<p>${message}</p>
</div>
`;
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
}
</script>
</body>
</html>