-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
358 lines (306 loc) · 12.2 KB
/
script.js
File metadata and controls
358 lines (306 loc) · 12.2 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
document.addEventListener('DOMContentLoaded', () => {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
// Toggle hamburger menu with a slight delay for better animation
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
// Prevent scrolling when menu is open
document.body.style.overflow = navMenu.classList.contains('active') ? 'hidden' : '';
// Add touch feedback
hamburger.style.transform = 'scale(0.9)';
setTimeout(() => {
hamburger.style.transform = 'scale(1)';
}, 150);
});
// Close menu when clicking on a link
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (navMenu.classList.contains('active') &&
!navMenu.contains(e.target) &&
!hamburger.contains(e.target)) {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = '';
}
});
// Release pagination functionality
if (document.querySelector('.releases-container')) {
const prevButton = document.getElementById('prev-page');
const nextButton = document.getElementById('next-page');
const currentPageElement = document.getElementById('current-page');
const totalPagesElement = document.getElementById('total-pages');
const releaseItems = document.querySelectorAll('.release-item');
// Calculate total pages dynamically based on number of releases
// Each page can hold up to 8 releases
const releasesPerPage = 8;
const totalReleases = releaseItems ? releaseItems.length : 0;
const totalPages = Math.ceil(totalReleases / releasesPerPage) || 1;
// Initialize page variables
let currentPage = 1;
let isAnimating = false;
// Set data-page attribute for all release items if not already set
if (totalReleases > 0 && releaseItems) {
releaseItems.forEach((item, index) => {
const pageNum = Math.ceil((index + 1) / releasesPerPage);
if (!item.getAttribute('data-page')) {
item.setAttribute('data-page', pageNum);
}
});
// Update total pages in UI
if (totalPagesElement) {
totalPagesElement.textContent = totalPages;
}
// Create page dots dynamically if needed
const pageDotContainer = document.querySelector('.page-dots');
if (pageDotContainer) {
// Clear existing dots
pageDotContainer.innerHTML = '';
// Create new dots based on total pages
for (let i = 1; i <= totalPages; i++) {
const dot = document.createElement('span');
dot.classList.add('dot');
if (i === 1) dot.classList.add('active');
dot.setAttribute('data-page', i);
dot.addEventListener('click', () => {
if (!isAnimating && currentPage !== i) {
navigateToPage(i);
}
});
pageDotContainer.appendChild(dot);
}
}
}
// Initialize page display
updatePageDisplay();
// Event listeners for navigation buttons
if (prevButton) {
prevButton.addEventListener('click', () => {
if (!isAnimating && currentPage > 1) {
navigateToPage(currentPage - 1);
}
});
}
if (nextButton) {
nextButton.addEventListener('click', () => {
if (!isAnimating && currentPage < totalPages) {
navigateToPage(currentPage + 1);
}
});
}
// Make sure buttons are properly initialized
updatePageDisplay();
// Add click event listeners to all dot elements
const dots = document.querySelectorAll('.dot');
dots.forEach(dot => {
dot.addEventListener('click', () => {
const pageNum = parseInt(dot.getAttribute('data-page'), 10);
if (!isAnimating && currentPage !== pageNum) {
navigateToPage(pageNum);
}
});
});
// Function to navigate to a specific page with optimized performance
function navigateToPage(page) {
if (isAnimating) return;
if (page < 1) page = 1;
if (page > totalPages) page = totalPages;
isAnimating = true;
currentPage = page;
console.log("Navigating to page", page, "of", totalPages);
// Use requestAnimationFrame for smoother animations
window.requestAnimationFrame(() => {
// Hide all release items efficiently with a smooth fade
releaseItems.forEach(item => {
item.style.opacity = '0';
item.style.display = 'none';
item.classList.remove('active');
});
// Show only items for current page with staggered animation
const currentPageItems = document.querySelectorAll(`.release-item[data-page="${currentPage}"]`);
// Use a more efficient way to handle staggered animations
if (currentPageItems.length > 0) {
currentPageItems.forEach((item, index) => {
setTimeout(() => {
item.style.display = 'flex';
// Use another requestAnimationFrame to ensure CSS transitions work properly
requestAnimationFrame(() => {
item.style.opacity = '1';
item.classList.add('active');
// Mark animation as complete after the last item
if (index === currentPageItems.length - 1) {
setTimeout(() => {
isAnimating = false;
}, 100);
}
});
}, Math.min(index * 50, 300)); // Better staggered animation
});
} else {
isAnimating = false;
}
// Update dot navigation
updateDotNavigation();
// Update navigation buttons state
updatePageDisplay();
// Scroll to top of releases grid for better UX
const releaseCatalog = document.querySelector('.release-catalog');
if (releaseCatalog) {
releaseCatalog.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
}
// Function to update the dot navigation based on current page
function updateDotNavigation() {
const dots = document.querySelectorAll('.dot');
dots.forEach(dot => {
dot.classList.remove('active');
if (parseInt(dot.getAttribute('data-page'), 10) === currentPage) {
dot.classList.add('active');
}
});
}
// Update page number display and button states
function updatePageDisplay() {
try {
if (currentPageElement) {
currentPageElement.textContent = currentPage;
}
if (totalPagesElement) {
totalPagesElement.textContent = totalPages;
}
if (prevButton) {
prevButton.disabled = currentPage <= 1;
prevButton.style.opacity = prevButton.disabled ? "0.5" : "1";
prevButton.classList.toggle("disabled", prevButton.disabled);
}
if (nextButton) {
nextButton.disabled = currentPage >= totalPages;
nextButton.style.opacity = nextButton.disabled ? "0.5" : "1";
nextButton.classList.toggle("disabled", nextButton.disabled);
}
console.log("Page display updated:", currentPage, "of", totalPages);
} catch (error) {
console.error("Error updating page display:", error);
}
}
// Add search and filter functionality
const searchInput = document.getElementById('release-search');
const filterButtons = document.querySelectorAll('.filter-btn');
let currentFilter = 'all';
if (searchInput) {
// Add search functionality
searchInput.addEventListener('input', filterReleases);
// Add filter functionality
filterButtons.forEach(button => {
button.addEventListener('click', () => {
filterButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
currentFilter = button.getAttribute('data-genre');
filterReleases();
});
});
}
function filterReleases() {
const searchTerm = searchInput.value.toLowerCase();
const releasesContainer = document.getElementById('releases-container');
const allReleaseItems = document.querySelectorAll('.release-item');
// Remove existing "no results" message if present
const existingNoResults = document.querySelector('.no-results');
if (existingNoResults) {
existingNoResults.remove();
}
let itemsFound = 0;
allReleaseItems.forEach(item => {
const title = item.querySelector('h3').textContent.toLowerCase();
const description = item.querySelector('.release-description').textContent.toLowerCase();
const matchesSearch = title.includes(searchTerm) || description.includes(searchTerm);
// Match genre filter
let matchesGenre = true;
if (currentFilter !== 'all') {
matchesGenre = description.includes(currentFilter.toLowerCase());
}
if (matchesSearch && matchesGenre) {
item.classList.remove('filtered-out');
itemsFound++;
} else {
item.classList.add('filtered-out');
}
});
// Show "no results" message if needed
if (itemsFound === 0) {
const noResults = document.createElement('div');
noResults.className = 'no-results';
noResults.textContent = `No releases found matching "${searchTerm}" ${currentFilter !== 'all' ? `in ${currentFilter}` : ''}.`;
const br = document.createElement('br');
noResults.appendChild(br);
noResults.appendChild(document.createTextNode(' Try a different search term or filter.'));
releasesContainer.appendChild(noResults);
}
// Reset pagination when filtering
if (searchTerm !== '' || currentFilter !== 'all') {
// Hide pagination controls
const paginationControls = document.querySelector('.pagination-controls');
const releasesNavigation = document.querySelector('.releases-navigation');
if (paginationControls) paginationControls.style.display = 'none';
if (releasesNavigation) releasesNavigation.style.display = 'none';
// Show all matching items
allReleaseItems.forEach(item => {
if (!item.classList.contains('filtered-out')) {
item.style.display = 'flex';
item.style.opacity = '1';
} else {
item.style.display = 'none';
item.style.opacity = '0';
}
});
} else {
// Restore pagination when filter is cleared
const paginationControls = document.querySelector('.pagination-controls');
const releasesNavigation = document.querySelector('.releases-navigation');
if (paginationControls) paginationControls.style.display = 'flex';
if (releasesNavigation) releasesNavigation.style.display = 'flex';
// Reset to page 1
navigateToPage(1);
}
}
// Add keyboard navigation for accessibility
document.addEventListener('keydown', (e) => {
if (document.querySelector('.releases-container')) {
if (e.key === 'ArrowLeft' && prevButton && !prevButton.disabled) {
prevButton.click();
} else if (e.key === 'ArrowRight' && nextButton && !nextButton.disabled) {
nextButton.click();
}
}
});
// Initial setup - make sure only page 1 items are visible
// Set data attributes for all release items based on their index
releaseItems.forEach((item, index) => {
const pageNum = Math.ceil((index + 1) / releasesPerPage);
item.setAttribute('data-page', pageNum);
});
// Make sure navigation works properly
navigateToPage(1);
// Force button state update
if (totalPages > 1 && nextButton) {
nextButton.disabled = false;
nextButton.style.opacity = "1";
}
}
});
window.addEventListener('DOMContentLoaded', function() {
const upcomingSection = document.querySelector('.upcoming-highlight');
if (upcomingSection) {
setTimeout(() => {
upcomingSection.scrollIntoView({behavior: 'smooth', block: 'center'});
}, 400);
}
});