Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
222 lines (198 loc) · 6.38 KB
/
Copy pathscript.js
File metadata and controls
222 lines (198 loc) · 6.38 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
function toggleTheme() {
const html = document.documentElement;
const currentTheme = html.getAttribute("data-theme");
// Toggle between dark and light (corrected logic)
if (currentTheme === "dark") {
html.setAttribute("data-theme", "light");
localStorage.setItem("theme", "light");
} else {
html.setAttribute("data-theme", "dark");
localStorage.setItem("theme", "dark");
}
}
// Optimized page load function
document.addEventListener("DOMContentLoaded", function () {
// Apply the saved theme or set default
const savedTheme = localStorage.getItem("theme") || "dark";
document.documentElement.setAttribute("data-theme", savedTheme);
// Add event listener to theme toggle button
const themeToggle = document.getElementById("theme-toggle");
if (themeToggle) {
themeToggle.addEventListener("click", toggleTheme);
}
// Back to top button functionality
const backToTopButton = document.querySelector(".back-to-top");
if (backToTopButton) {
window.addEventListener("scroll", function () {
backToTopButton.classList.toggle("active", window.pageYOffset > 300);
});
backToTopButton.addEventListener("click", function (e) {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
}
// Mobile menu toggle - optimized
const navToggle = document.getElementById("navToggle");
const mainNav = document.getElementById("mainNav");
if (navToggle && mainNav) {
navToggle.addEventListener("click", function () {
mainNav.classList.toggle("active");
this.classList.toggle("active");
});
// Close menu when clicking outside
document.addEventListener("click", function (event) {
if (
mainNav.classList.contains("active") &&
!mainNav.contains(event.target) &&
!navToggle.contains(event.target)
) {
mainNav.classList.remove("active");
navToggle.classList.remove("active");
}
});
}
// Simplified navigation highlighting
const sections = document.querySelectorAll("section[id]");
const navLinks = document.querySelectorAll(".main-nav a");
if (sections.length > 0 && navLinks.length > 0) {
window.addEventListener("scroll", function () {
const scrollPosition = window.pageYOffset + 100;
sections.forEach((section) => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute("id");
if (
scrollPosition >= sectionTop &&
scrollPosition < sectionTop + sectionHeight
) {
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${sectionId}`) {
link.classList.add("active");
}
});
}
});
});
}
});
// Optimized animations with IntersectionObserver
document.addEventListener("DOMContentLoaded", function () {
const animatedElements = document.querySelectorAll(
".event-card, .team-card, .alumni-card, .about-image, .contact-item"
);
// Only set up observer if there are elements to animate
if (animatedElements.length > 0) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("animate");
observer.unobserve(entry.target);
}
});
},
{
root: null,
threshold: 0.15,
rootMargin: "0px",
}
);
// Observe each element
animatedElements.forEach((el) => {
observer.observe(el);
});
}
});
// Hero Slideshow
function startHeroSlideshow() {
const slides = document.querySelectorAll(".slideshow-container .slide-img");
let current = 0;
setInterval(() => {
slides[current].style.display = "none";
current = (current + 1) % slides.length;
slides[current].style.display = "block";
}, 3000);
}
document.addEventListener("DOMContentLoaded", startHeroSlideshow);
function setupHeroImageSlider() {
const slider = document.querySelector(".hero-image-slider");
if (!slider) return;
const images = slider.querySelectorAll(".slider-img");
let current = 0;
function showImage(idx) {
images.forEach((img, i) => {
img.classList.toggle("active", i === idx);
});
}
function prevImage(e) {
if (e) e.preventDefault();
current = (current - 1 + images.length) % images.length;
showImage(current);
}
function nextImage(e) {
if (e) e.preventDefault();
current = (current + 1) % images.length;
showImage(current);
}
if (images.length > 0) {
const prevBtn = document.getElementById("heroSliderPrev");
const nextBtn = document.getElementById("heroSliderNext");
showImage(current);
// Slideshow functionality
let slideshowInterval = null;
function startSlideshow() {
if (slideshowInterval) return;
slideshowInterval = setInterval(() => {
nextImage();
}, 4000); // 4 seconds
}
function stopSlideshow() {
clearInterval(slideshowInterval);
slideshowInterval = null;
}
// Start slideshow by default
startSlideshow();
// Pause on hover/focus, resume on leave/blur
slider.addEventListener("mouseenter", stopSlideshow);
slider.addEventListener("mouseleave", startSlideshow);
slider.addEventListener("focusin", stopSlideshow);
slider.addEventListener("focusout", startSlideshow);
// Keyboard arrow key support, synced with slideshow
document.addEventListener("keydown", function (e) {
if (
document.activeElement.tagName === "INPUT" ||
document.activeElement.tagName === "TEXTAREA"
)
return; // Don't interfere with typing
if (e.key === "ArrowLeft") {
prevImage();
stopSlideshow();
startSlideshow();
} else if (e.key === "ArrowRight") {
nextImage();
stopSlideshow();
startSlideshow();
}
});
// Arrow button click support, synced with slideshow
if (prevBtn && nextBtn) {
prevBtn.addEventListener("click", function (e) {
prevImage(e);
stopSlideshow();
startSlideshow();
});
nextBtn.addEventListener("click", function (e) {
nextImage(e);
stopSlideshow();
startSlideshow();
});
}
}
}
document.addEventListener("DOMContentLoaded", function () {
setupHeroImageSlider();
});