Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
277 lines (231 loc) · 9.84 KB
/
Copy pathscript.js
File metadata and controls
277 lines (231 loc) · 9.84 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
// Clean URL Address Bar Handler (Strips .html instantly on load)
if (window.location.pathname.endsWith('.html')) {
const cleanPath = window.location.pathname.slice(0, -5);
window.history.replaceState(null, '', cleanPath + window.location.search + window.location.hash);
}
document.addEventListener('DOMContentLoaded', () => {
// Resolve base path dynamically (handles /cssa/ proxy and subpaths)
const pathParts = window.location.pathname.split('/');
let basePath = '';
if (pathParts[1] && pathParts[1].toLowerCase() === 'cssa') {
basePath = '/' + pathParts[1];
}
// Rewrite all internal links to work seamlessly with subpaths and fallback to .html files under the hood
document.querySelectorAll('a').forEach(link => {
let href = link.getAttribute('href');
if (href && !href.startsWith('http') && !href.startsWith('#') && !href.startsWith('//') && href !== '/') {
// Clean leading and trailing slashes
href = href.replace(/^\//, '').replace(/\.html$/, '');
// Map to clean path subpath routing
link.setAttribute('href', basePath + '/' + href);
}
});
// Expandable Accordion Toggle (Events page)
const accordions = document.querySelectorAll('.event-accordion');
accordions.forEach(accordion => {
accordion.addEventListener('click', () => {
accordion.classList.toggle('open');
});
});
// Contact Form Submission Handler
const contactForm = document.getElementById('contactForm');
if (contactForm) {
const feedback = document.getElementById('formFeedback');
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
if (name && email && message) {
if (feedback) {
feedback.style.display = 'block';
feedback.style.backgroundColor = 'rgba(25, 135, 84, 0.1)';
feedback.style.color = '#198754';
feedback.style.border = '1px solid #198754';
feedback.textContent = `Thank you, ${name}! Your message has been received. The CSSA team will get back to you shortly.`;
} else {
alert(`Thank you, ${name}! Your message has been received.`);
}
contactForm.reset();
}
});
}
// Mobile Nav Toggle
const navToggle = document.querySelector('.nav-toggle');
const siteNav = document.getElementById('site-nav');
if (navToggle && siteNav) {
navToggle.addEventListener('click', () => {
const expanded = navToggle.getAttribute('aria-expanded') === 'true';
navToggle.setAttribute('aria-expanded', !expanded);
siteNav.classList.toggle('open');
navToggle.classList.toggle('active');
});
}
// --- Client-Side Search, Filter, and Pagination for Activities Page ---
const eventRows = document.querySelectorAll('.event-row');
const eventFilter = document.getElementById('event-filter');
const eventSearch = document.getElementById('event-search');
const paginationContainer = document.querySelector('.pagination');
if (eventRows.length > 0) {
let currentPage = 1;
const itemsPerPage = 4;
function updateEvents() {
const searchTerm = eventSearch ? eventSearch.value.toLowerCase().trim() : '';
const filterVal = eventFilter ? eventFilter.value.toLowerCase() : 'all';
// Filter rows by search and tag
const matchedRows = Array.from(eventRows).filter(row => {
const title = (row.getAttribute('data-title') || '').toLowerCase();
const tags = (row.getAttribute('data-tags') || '').toLowerCase();
const matchesSearch = title.includes(searchTerm);
const matchesFilter = filterVal === 'all' || tags.includes(filterVal);
return matchesSearch && matchesFilter;
});
// Hide all rows
eventRows.forEach(row => row.style.display = 'none');
// Calculate pagination slice
const totalItems = matchedRows.length;
const totalPages = Math.ceil(totalItems / itemsPerPage) || 1;
// Keep currentPage in valid range
if (currentPage > totalPages) currentPage = totalPages;
if (currentPage < 1) currentPage = 1;
const start = (currentPage - 1) * itemsPerPage;
const end = start + itemsPerPage;
matchedRows.slice(start, end).forEach(row => {
row.style.display = 'flex';
});
// Render pagination numbers
if (paginationContainer) {
paginationContainer.innerHTML = '';
for (let i = 1; i <= totalPages; i++) {
const span = document.createElement('span');
span.className = `num${i === currentPage ? ' active' : ''}`;
span.textContent = i;
span.addEventListener('click', () => {
currentPage = i;
updateEvents();
});
paginationContainer.appendChild(span);
}
}
}
// Attach event listeners for filters
if (eventFilter) eventFilter.addEventListener('change', () => { currentPage = 1; updateEvents(); });
if (eventSearch) eventSearch.addEventListener('input', () => { currentPage = 1; updateEvents(); });
const resetLink = document.querySelector('[data-filter-reset]');
if (resetLink) {
resetLink.addEventListener('click', (e) => {
e.preventDefault();
if (eventFilter) eventFilter.value = 'all';
if (eventSearch) eventSearch.value = '';
currentPage = 1;
updateEvents();
});
}
// Initialize first page
updateEvents();
// Toggle event details accordion
eventRows.forEach(row => {
row.addEventListener('click', (e) => {
// Toggle the open class
row.classList.toggle('open');
});
});
}
// Trigger smooth page load fade-in
document.body.classList.add('loaded');
// Intercept hash anchor clicks for smooth offset scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const targetId = this.getAttribute('href');
if (targetId && targetId !== '#') {
e.preventDefault();
const targetElement = document.querySelector(targetId);
if (targetElement) {
const offsetTop = targetElement.getBoundingClientRect().top + window.pageYOffset - 90;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
}
});
});
// --- ScrollSpy for Academics / Side Navigation Pages ---
const sideLinks = document.querySelectorAll('.side-nav a');
const sideSections = document.querySelectorAll('.side-section');
if (sideLinks.length > 0 && sideSections.length > 0) {
function updateActiveLink() {
let activeSectionId = '';
const scrollPos = window.scrollY || window.pageYOffset;
sideSections.forEach(section => {
// Offset matches the navigation scroll offset
const sectionTop = section.offsetTop - 140;
const sectionHeight = section.offsetHeight;
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
activeSectionId = section.getAttribute('id');
}
});
sideLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${activeSectionId}`) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', updateActiveLink);
window.addEventListener('resize', updateActiveLink);
updateActiveLink(); // Run on page load
}
// --- Client-Side Search, Filter, and Pagination for FAQs ---
const listRows = document.querySelectorAll('.list-row');
const faqFilter = document.getElementById('faq-filter');
const faqSearch = document.getElementById('faq-search');
const faqPaginationContainer = document.querySelector('#faqs .pagination');
if (listRows.length > 0) {
let currentFaqPage = 1;
const faqsPerPage = 4;
function updateFaqs() {
const searchTerm = faqSearch ? faqSearch.value.toLowerCase().trim() : '';
const filterVal = faqFilter ? faqFilter.value.toLowerCase() : 'all';
const matchedFaqs = Array.from(listRows).filter(row => {
const title = (row.getAttribute('data-title') || '').toLowerCase();
const tags = (row.getAttribute('data-tags') || '').toLowerCase();
const matchesSearch = title.includes(searchTerm);
const matchesFilter = filterVal === 'all' || tags.includes(filterVal);
return matchesSearch && matchesFilter;
});
listRows.forEach(row => row.style.display = 'none');
const totalItems = matchedFaqs.length;
const totalPages = Math.ceil(totalItems / faqsPerPage) || 1;
if (currentFaqPage > totalPages) currentFaqPage = totalPages;
if (currentFaqPage < 1) currentFaqPage = 1;
const start = (currentFaqPage - 1) * faqsPerPage;
const end = start + faqsPerPage;
matchedFaqs.slice(start, end).forEach(row => {
row.style.display = 'flex';
});
if (faqPaginationContainer) {
faqPaginationContainer.innerHTML = '';
for (let i = 1; i <= totalPages; i++) {
const span = document.createElement('span');
span.className = `num${i === currentFaqPage ? ' active' : ''}`;
span.textContent = i;
span.addEventListener('click', () => {
currentFaqPage = i;
updateFaqs();
});
faqPaginationContainer.appendChild(span);
}
}
}
if (faqFilter) faqFilter.addEventListener('change', () => { currentFaqPage = 1; updateFaqs(); });
if (faqSearch) faqSearch.addEventListener('input', () => { currentFaqPage = 1; updateFaqs(); });
// Attach click listener to toggle open FAQ accordion
listRows.forEach(row => {
row.addEventListener('click', () => {
row.classList.toggle('open');
});
});
updateFaqs();
}
});