-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
1611 lines (1354 loc) · 49.6 KB
/
Copy pathscript.js
File metadata and controls
1611 lines (1354 loc) · 49.6 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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (window.location.hostname.includes("github.io")) {
window.location.replace("https://www.utstar.ca");
}
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', (e) => {
e.preventDefault();
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a nav link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
// Close mobile menu when clicking on dropdown links (Constitution page)
document.querySelectorAll('.dropdown-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
// Enhanced Navbar - Active Section Highlighting
function updateActiveNavLink() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
const scrollPos = window.scrollY + 100; // Offset for navbar height
// Find the section that's currently most visible
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
// If no section detected, find the closest one
if (!current) {
let closest = null;
let closestDistance = Infinity;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const distance = Math.abs(scrollPos - sectionTop);
if (distance < closestDistance) {
closestDistance = distance;
closest = section.getAttribute('id');
}
});
current = closest;
}
// Map section IDs to navbar links (handle special cases)
let targetLink = current;
if (current === 'presidents-message') {
targetLink = 'about'; // President's message should highlight "About" button
}
navLinks.forEach(link => {
link.classList.remove('active');
const linkHref = link.getAttribute('href');
if (linkHref === `#${targetLink}`) {
link.classList.add('active');
}
});
}
// Enhanced Navbar - Scroll Effects
let lastScrollY = window.scrollY;
const navbar = document.querySelector('.navbar');
function handleNavbarScroll() {
const currentScrollY = window.scrollY;
// Update active nav link
updateActiveNavLink();
// Dynamic navbar styling based on scroll using classes
if (currentScrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScrollY = currentScrollY;
}
// Add scroll event listener with performance optimization
let ticking = false;
function optimizedScrollHandler() {
handleNavbarScroll();
ticking = false;
}
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(optimizedScrollHandler);
ticking = true;
}
}, { passive: true });
// Enhanced navbar button interactions
document.querySelectorAll('.nav-link').forEach(link => {
// Add click ripple effect
link.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.cssText = `
position: absolute;
width: ${size}px;
height: ${size}px;
left: ${x}px;
top: ${y}px;
background: rgba(10, 132, 255, 0.6);
border-radius: 50%;
transform: scale(0);
animation: ripple 0.6s ease-out;
pointer-events: none;
`;
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
// Add magnetic effect
link.addEventListener('mousemove', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
this.style.transform = `translateY(-3px) scale(1.05) translate(${x * 0.1}px, ${y * 0.1}px)`;
});
link.addEventListener('mouseleave', function() {
this.style.transform = '';
});
});
// Add ripple animation CSS
const rippleStyle = document.createElement('style');
rippleStyle.textContent = `
@keyframes ripple {
0% { transform: scale(0); opacity: 1; }
100% { transform: scale(2); opacity: 0; }
}
`;
document.head.appendChild(rippleStyle);
// Add logo click animation with improved handling
let logoAnimating = false;
let currentRotation = 0;
document.querySelector('.nav-logo').addEventListener('click', () => {
if (!logoAnimating) {
logoAnimating = true;
const logoImg = document.querySelector('.logo-img');
// Calculate next rotation to always go forward
currentRotation += 360;
logoImg.style.transform = `rotate(${currentRotation}deg)`;
logoImg.style.transition = 'transform 0.8s cubic-bezier(0.4, 0, 0.2, 1)';
setTimeout(() => {
logoAnimating = false;
// Keep the rotation state, don't reset
}, 800);
}
});
// Fix hover interaction - don't interfere with click animation
document.querySelector('.nav-logo').addEventListener('mouseenter', () => {
if (!logoAnimating) {
const logoImg = document.querySelector('.logo-img');
logoImg.style.transform = `rotate(${currentRotation}deg) scale(1.05)`;
logoImg.style.transition = 'transform 0.3s ease';
}
});
document.querySelector('.nav-logo').addEventListener('mouseleave', () => {
if (!logoAnimating) {
const logoImg = document.querySelector('.logo-img');
logoImg.style.transform = `rotate(${currentRotation}deg)`;
logoImg.style.transition = 'transform 0.3s ease';
}
});
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const href = this.getAttribute('href');
// Skip if href is just '#' or empty
if (!href || href === '#') {
return;
}
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar scroll effect - Cool dark theme (optimized)
let navbarTicking = false;
function updateNavbarStyle() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 100) {
// Scrolled down - make navbar more solid and add glow effect
navbar.style.background = 'rgba(13, 17, 23, 0.95)';
navbar.style.backdropFilter = 'blur(16px)';
navbar.style.borderBottom = '1px solid rgba(10, 132, 255, 0.3)';
navbar.style.boxShadow = '0 4px 32px rgba(10, 132, 255, 0.1), 0 2px 8px rgba(0, 0, 0, 0.3)';
} else {
// At top - more transparent and subtle
navbar.style.background = 'rgba(13, 17, 23, 0.85)';
navbar.style.backdropFilter = 'blur(8px)';
navbar.style.borderBottom = '1px solid rgba(255, 255, 255, 0.05)';
navbar.style.boxShadow = 'none';
}
navbarTicking = false;
}
window.addEventListener('scroll', () => {
if (!navbarTicking) {
requestAnimationFrame(updateNavbarStyle);
navbarTicking = true;
}
}, { passive: true });
// Enhanced Intersection Observer for staggered animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// Stagger animations
setTimeout(() => {
entry.target.classList.add('visible');
// Add special animations based on element type
if (entry.target.classList.contains('feature')) {
entry.target.style.animationDelay = `${index * 0.2}s`;
}
if (entry.target.classList.contains('project-card')) {
entry.target.style.animationDelay = `${index * 0.3}s`;
}
if (entry.target.classList.contains('team-member')) {
entry.target.style.animationDelay = `${index * 0.15}s`;
}
}, index * 100);
}
});
}, observerOptions);
// Initialize the "Other" program functionality when DOM is loaded
function handleOtherProgramSelection() {
const otherCheckbox = document.querySelector('input[name="program[]"][value="other"]');
const checkboxGroup = document.querySelector('.checkbox-group');
if (!otherCheckbox) return;
// Create the "Other" text input container
const otherInputContainer = document.createElement('div');
otherInputContainer.className = 'other-program-input';
otherInputContainer.style.display = 'none';
otherInputContainer.innerHTML = `
<input type="text"
id="otherProgram"
name="otherProgram"
placeholder="Enter your programs..."
style="width: 100%;
padding: 12px;
margin-top: 0.5rem;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--glass);
color: var(--ink);
font-size: 0.9rem;">
<small style="color: var(--muted);
font-size: 0.8rem;
margin-top: 0.25rem;
display: block;">
Example: Biology, Chemistry, Environmental Science
</small>
`;
// Insert after the checkbox group
checkboxGroup.parentNode.insertBefore(otherInputContainer, checkboxGroup.nextSibling);
// Add event listener to the "Other" checkbox
otherCheckbox.addEventListener('change', function() {
const otherInput = document.getElementById('otherProgram');
if (this.checked) {
// Show the input field with slide down animation
otherInputContainer.style.display = 'block';
otherInputContainer.style.maxHeight = '200px'; // Allow enough space for content
otherInputContainer.style.marginTop = '1rem';
otherInputContainer.style.padding = '1rem';
otherInputContainer.style.opacity = '1';
otherInputContainer.style.transform = 'translateY(0)';
setTimeout(() => {
otherInput.focus(); // Auto-focus for better UX
}, 150);
} else {
// Hide the input field with slide up animation
otherInputContainer.style.maxHeight = '0';
otherInputContainer.style.marginTop = '0';
otherInputContainer.style.padding = '0 1rem';
otherInputContainer.style.opacity = '0';
otherInputContainer.style.transform = 'translateY(-20px)';
setTimeout(() => {
otherInput.value = ''; // Clear the input when hidden
}, 300);
}
});
// Style the input container for smooth slide animation - initially hidden
otherInputContainer.style.cssText += `
max-height: 0;
margin-top: 0;
padding: 0 1rem;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 12px;
backdrop-filter: blur(10px);
opacity: 0;
transform: translateY(-20px);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
overflow: hidden;
display: block;
`;
// Add focus styling to the input
const otherInput = otherInputContainer.querySelector('input');
otherInput.addEventListener('focus', function() {
this.style.borderColor = 'var(--primary-color)';
this.style.background = 'var(--glass-hover)';
this.style.boxShadow = '0 0 0 3px rgba(10, 132, 255, 0.1)';
});
otherInput.addEventListener('blur', function() {
this.style.borderColor = 'var(--border)';
this.style.background = 'var(--glass)';
this.style.boxShadow = 'none';
});
}
// Consolidated DOMContentLoaded handler
document.addEventListener('DOMContentLoaded', function() {
// Initialize back to top button for any page
initBackToTopButton();
// Initialize Constitution page features
setupConstitutionSectionObserver();
// Initialize team profile pictures
loadTeamProfilePictures();
// Initialize trivia game (only on trivia page)
if (document.getElementById('startBtn')) {
triviaGame = new TriviaGame();
}
// Initialize website data manager
websiteDataManager = new WebsiteDataManager();
// Handle "Other" program selection (index.html contact form)
handleOtherProgramSelection();
// Add fade-in class to elements and observe them with enhanced animations
const animatedElements = document.querySelectorAll('.feature, .project-card, .event-item, .team-member');
animatedElements.forEach((el, index) => {
el.classList.add('fade-in');
el.style.animationDelay = `${index * 0.1}s`;
observer.observe(el);
});
// Add hover effects to icons
const icons = document.querySelectorAll('.feature i, .project-icon i');
icons.forEach(icon => {
icon.addEventListener('mouseenter', () => {
icon.style.transform = 'scale(1.2) rotate(10deg)';
icon.style.color = 'var(--accent)';
});
icon.addEventListener('mouseleave', () => {
icon.style.transform = 'scale(1) rotate(0deg)';
icon.style.color = 'var(--primary-color)';
});
});
// Add floating animation to nav logo
const navLogo = document.querySelector('.nav-logo i');
if (navLogo) {
navLogo.style.animation = 'float 3s ease-in-out infinite';
}
// Add typing effect to highlight text
const highlightText = document.querySelector('.highlight');
if (highlightText) {
highlightText.addEventListener('mouseenter', () => {
highlightText.style.animation = 'pulse 1s ease-in-out';
});
}
// Initialize typing effect when page loads
const heroTitle = document.querySelector('.hero-title');
if (heroTitle) {
const originalText = heroTitle.innerHTML;
// Uncomment the line below to enable typing effect
// typeWriter(heroTitle, originalText.replace(/<[^>]*>/g, ''), 50);
}
// Initialize smooth reveal animations for sections
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(50px)';
section.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
revealObserver.observe(section);
});
});
// Contact form handling
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const name = formData.get('name');
const email = formData.get('email');
const message = formData.get('message');
// Get selected programs including "Other"
const selectedPrograms = Array.from(document.querySelectorAll('input[name="program[]"]:checked')).map(checkbox => checkbox.value);
const otherProgram = formData.get('otherProgram');
// Build final programs list
let finalPrograms = [...selectedPrograms];
// If "Other" is selected and has custom text, replace it with the custom programs
if (selectedPrograms.includes('other') && otherProgram && otherProgram.trim()) {
// Remove "other" from the list
finalPrograms = finalPrograms.filter(program => program !== 'other');
// Split the custom programs by commas and add them
const customPrograms = otherProgram.split(',').map(program => program.trim()).filter(program => program);
finalPrograms.push(...customPrograms);
}
// Simple validation
if (!name || !email || !finalPrograms.length || !message) {
showNotification('Please fill in all fields.', 'error');
return;
}
// Check if "Other" is selected but no custom program is specified
if (selectedPrograms.includes('other') && (!otherProgram || !otherProgram.trim())) {
showNotification('Please specify your program(s) in the "Other" field.', 'error');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address.', 'error');
return;
}
// Show success message with the programs list
const programsList = finalPrograms.join(', ');
showNotification(`Thank you ${name}! We received your interest for: ${programsList}. We'll get back to you soon!`, 'success');
// Log the form data for debugging (remove in production)
console.log('Form submitted:', {
name,
email,
programs: finalPrograms,
otherProgram,
message
});
contactForm.reset();
// Reset the "Other" input field if it exists
const otherInputContainer = document.querySelector('.other-program-input');
if (otherInputContainer) {
otherInputContainer.style.display = 'none';
const otherInput = document.getElementById('otherProgram');
if (otherInput) otherInput.value = '';
}
});
}
// Email validation function
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Notification system
function showNotification(message, type = 'info') {
// Remove any existing notifications from container
const existingNotification = document.querySelector('#notification-container .notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.innerHTML = `
<div class="notification-content">
<span class="notification-message">${message}</span>
<button class="notification-close">×</button>
</div>
`;
// Create isolated container for notification to avoid stacking context issues
let notificationContainer = document.getElementById('notification-container');
if (!notificationContainer) {
notificationContainer = document.createElement('div');
notificationContainer.id = 'notification-container';
notificationContainer.style.cssText = `
position: fixed !important;
top: 0 !important;
left: 0 !important;
width: 100vw !important;
height: 100vh !important;
pointer-events: none !important;
z-index: 999999 !important;
filter: none !important;
`;
document.documentElement.appendChild(notificationContainer);
}
// Add notification styles
const style = document.createElement('style');
style.textContent = `
.notification {
position: fixed !important;
top: 20px !important;
right: 20px !important;
z-index: 999999 !important;
min-width: 300px;
max-width: 500px;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(10px);
transform: translateX(100%);
transition: all 0.3s ease;
pointer-events: auto;
/* Explicitly inherit the website's font styling */
font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif !important;
font-size: 14px;
line-height: 1.6;
color: white;
}
.notification.show {
transform: translateX(0);
}
.notification-success {
background: linear-gradient(135deg, #48bb78, #38a169);
color: white;
border: 2px solid rgba(72, 187, 120, 0.5);
}
.notification-error {
background: linear-gradient(135deg, #f56565, #e53e3e);
color: white;
border: 2px solid rgba(245, 101, 101, 0.5);
}
.notification-info {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: 2px solid rgba(102, 126, 234, 0.5);
}
.notification-content {
display: flex;
align-items: center;
justify-content: space-between;
padding: 15px 20px;
font-family: inherit;
}
.notification-message {
flex: 1;
font-weight: 500;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
.notification-close {
background: none;
border: none;
color: white;
font-size: 20px;
cursor: pointer;
margin-left: 15px;
opacity: 0.8;
transition: opacity 0.2s ease;
font-family: inherit;
}
.notification-close:hover {
opacity: 1;
}
`;
if (!document.querySelector('#notification-styles')) {
style.id = 'notification-styles';
document.head.appendChild(style);
}
// Add to isolated container (not body)
notificationContainer.appendChild(notification);
// Force reflow and show notification
notification.offsetHeight; // Force reflow
requestAnimationFrame(() => {
notification.classList.add('show');
// Ensure it's visible
notification.style.display = 'block';
notification.style.visibility = 'visible';
notification.style.pointerEvents = 'auto';
});
// Add close functionality
const closeBtn = notification.querySelector('.notification-close');
closeBtn.addEventListener('click', () => {
notification.remove();
});
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentNode) {
notification.classList.remove('show');
setTimeout(() => {
if (notification.parentNode) {
notification.remove();
}
}, 300);
}
}, 5000);
}
// Parallax effect for hero section (optimized)
let parallaxTicking = false;
function updateParallaxEffect() {
const scrolled = window.pageYOffset;
const heroAnimation = document.querySelector('.hero-animation');
if (heroAnimation) {
heroAnimation.style.transform = `translateY(${scrolled * 0.5}px)`;
}
parallaxTicking = false;
}
window.addEventListener('scroll', () => {
if (!parallaxTicking) {
requestAnimationFrame(updateParallaxEffect);
parallaxTicking = true;
}
}, { passive: true });
// Dynamic typing effect for hero title
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Add CSS for active nav link
const activeNavStyle = document.createElement('style');
activeNavStyle.textContent = `
.nav-link.active {
color: var(--primary-color);
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(activeNavStyle);
// Add loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Smooth reveal animations for sections
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, {
threshold: 0.1
});
// Back to top functionality - useful for both index.html and Constitution.html
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
// Scroll to table of contents (Constitution page specific)
function scrollToTOC() {
const toc = document.querySelector('.constitution-nav');
if (toc) {
toc.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// Show/hide back to top button - works for any page with a backToTop element
function initBackToTopButton() {
const backToTopBtn = document.getElementById('backToTop');
if (backToTopBtn) {
let backToTopTicking = false;
function updateBackToTopButton() {
if (window.pageYOffset > 300) {
backToTopBtn.classList.add('visible');
} else {
backToTopBtn.classList.remove('visible');
}
backToTopTicking = false;
}
window.addEventListener('scroll', function() {
if (!backToTopTicking) {
requestAnimationFrame(updateBackToTopButton);
backToTopTicking = true;
}
}, { passive: true });
}
}
// Constitution page: Highlight active section in table of contents and dropdown using Intersection Observer
function setupConstitutionSectionObserver() {
// Only run on Constitution page
if (!document.querySelector('.constitution-article')) return;
const sections = document.querySelectorAll('.constitution-article');
const tocLinks = document.querySelectorAll('.constitution-toc a');
const dropdownLinks = document.querySelectorAll('.dropdown-link[href^="#article"]');
// console.log(`Constitution observer setup: ${sections.length} sections, ${tocLinks.length} TOC links, ${dropdownLinks.length} dropdown links`);
let currentSection = '';
const observer = new IntersectionObserver((entries) => {
// Find the section that's most visible
let maxRatio = 0;
let mostVisibleSection = '';
entries.forEach(entry => {
if (entry.intersectionRatio > maxRatio) {
maxRatio = entry.intersectionRatio;
mostVisibleSection = entry.target.getAttribute('id');
}
});
// Only update if we have a significantly visible section
if (maxRatio > 0.1) {
currentSection = mostVisibleSection;
// console.log(`Active section: ${currentSection}, visibility: ${maxRatio}`);
// Update table of contents
tocLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + currentSection) {
link.classList.add('active');
// console.log(`TOC link activated: ${link.getAttribute('href')}`);
}
});
// Update dropdown menu
dropdownLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + currentSection) {
link.classList.add('active');
// console.log(`Dropdown link activated: ${link.getAttribute('href')}`);
}
});
}
}, {
threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
rootMargin: '-100px 0px -100px 0px' // Account for navbar
});
// Observe all sections
sections.forEach(section => {
observer.observe(section);
// console.log(`Observing section: ${section.getAttribute('id')}`);
});
}
// Team Profile Pictures Loader
function loadTeamProfilePictures() {
// Add a small delay to ensure dynamically loaded content is ready
setTimeout(() => {
const teamMembers = document.querySelectorAll('.team-member');
if (teamMembers.length === 0) return;
teamMembers.forEach(member => {
const nameElement = member.querySelector('h3');
const photoElement = member.querySelector('.member-photo');
if (!nameElement || !photoElement) return;
const fullName = nameElement.textContent.trim();
const initials = photoElement.textContent.trim(); // Store original initials as fallback
// Convert name to filename format (remove spaces, keep camelCase)
const filename = fullName.replace(/\s+/g, '');
// Try different image extensions
const extensions = ['webp', 'png', 'jpeg', 'jpg'];
let imageLoaded = false;
function tryLoadImage(index) {
if (index >= extensions.length || imageLoaded) {
return; // All extensions tried or image already loaded
}
const ext = extensions[index];
const imagePath = `Images/TeamExecs/${filename}.${ext}`;
// Create a test image to check if file exists
const img = new Image();
img.onload = function() {
// Image loaded successfully
imageLoaded = true;
photoElement.style.backgroundImage = `url('${imagePath}')`;
photoElement.style.backgroundSize = 'cover';
photoElement.style.backgroundPosition = 'center';
photoElement.style.backgroundRepeat = 'no-repeat';
photoElement.textContent = ''; // Remove initials
photoElement.setAttribute('data-has-image', 'true');
// Add a subtle border to indicate it's a photo
photoElement.style.border = '2px solid rgba(10, 132, 255, 0.3)';
photoElement.style.boxShadow = '0 4px 12px rgba(10, 132, 255, 0.2)';
};
img.onerror = function() {
// Image failed to load, try next extension
tryLoadImage(index + 1);
};
img.src = imagePath; // Put the image path
}
// Start trying to load images
tryLoadImage(0);
// Set a timeout fallback to ensure initials stay if no image loads
setTimeout(() => {
if (!imageLoaded) {
photoElement.textContent = initials; // Keep original initials
photoElement.setAttribute('data-has-image', 'false');
}
}, 2000); // 2 second timeout
});
}, 500); // Wait 500ms for dynamic content to load
}
// Trivia Game Functionality
class TriviaGame {
constructor() {
this.questions = [];
this.currentQuestionIndex = 0;
this.score = 0;
this.correctAnswers = 0;
this.selectedAnswer = null;
this.startTime = null;
this.questionStartTime = null;
this.timeLimit = 30; // seconds per question
this.timer = null;
this.shuffledCorrectIndex = 0;
this.init();
}
init() {
// Only initialize if we're on the trivia page
if (!document.getElementById('startBtn')) {
return;
}
this.loadQuestions();
this.bindEvents();
this.updateStats();
}
async loadQuestions() {
try {
// Use globally loaded data from trivia-questions.js
if (typeof window.triviaQuestions !== 'undefined') {
this.questions = [...window.triviaQuestions]; // Copy array to avoid modifying original
this.shuffleArray(this.questions);
this.updateStats();
return;
}
// Fallback to fetch for HTTP environments
const response = await fetch('trivia-questions.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
this.questions = await response.json();
// Shuffle questions for random order
this.shuffleArray(this.questions);
this.updateStats();
} catch (error) {
console.error('Error loading trivia questions:', error);
if (typeof showNotification === 'function') {
showNotification('Error loading questions. Please refresh the page.', 'error');
}
// Fallback: show error message in UI
const startBtn = document.getElementById('startBtn');
if (startBtn) {
startBtn.textContent = 'Error loading questions';
startBtn.disabled = true;
}
}
}
shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
bindEvents() {
const startBtn = document.getElementById('startBtn');
const restartBtn = document.getElementById('restartBtn');
const nextBtn = document.getElementById('nextBtn');
// Use arrow functions to preserve 'this' context
// Start button initializes the game
if (startBtn) {
startBtn.addEventListener('click', () => this.startGame());
}
// Restart button resets the game to the initial state