-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
183 lines (159 loc) · 6.05 KB
/
Copy pathscript.js
File metadata and controls
183 lines (159 loc) · 6.05 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
// ─── THEME ───
function switchTheme(e) {
const theme = e.target.checked ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
}
// ─── TYPEWRITER ───
const typewriterTexts = [
"Validating AI-powered early prediction systems for agriculture.",
"Detecting insect pests and diseases across diverse geographies.",
"Deploying UAVs for bio-pesticide spraying and field sensing.",
"Building Digital Twins for agricultural data and prediction.",
"Enabling privacy-preserving federated learning on farm data.",
"Scaling Vision-Language Models for crop diagnostics.",
"Connecting maize and rice farmers across four nations.",
"Standardizing cross-regional agricultural validation protocols.",
"Integrating IoT sensors, drones, and AI at the field edge.",
"Sustaining food systems through transparent data governance.",
"Bridging US, Australia, India, and Japan through Quad AI.",
"Innovating for resilient and sustainable agriculture."
];
let typewriterElement;
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typingSpeed = 50;
const delayAfterTyping = 3000;
const delayAfterDeleting = 500;
function typeWriter() {
if (!typewriterElement) {
typewriterElement = document.getElementById('typewriter-text');
if (!typewriterElement) return;
}
const currentText = typewriterTexts[textIndex];
if (isDeleting) {
typewriterElement.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
typingSpeed = 30;
} else {
typewriterElement.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
typingSpeed = 50;
}
if (!isDeleting && charIndex === currentText.length) {
typingSpeed = delayAfterTyping;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % typewriterTexts.length;
typingSpeed = delayAfterDeleting;
}
setTimeout(typeWriter, typingSpeed);
}
// ─── IMAGE SLIDER ───
let currentSlide = 0;
let sliderInterval;
let isSliderPaused = false;
function moveSlide(dir) {
const track = document.querySelector('.slider-track');
if (!track) return;
const total = track.querySelectorAll('img').length;
currentSlide = (currentSlide + dir + total) % total;
updateSlider();
}
function goToSlide(index) {
currentSlide = index;
updateSlider();
}
function updateSlider() {
const track = document.querySelector('.slider-track');
if (!track) return;
track.style.transform = `translateX(-${currentSlide * 100}%)`;
document.querySelectorAll('.dot').forEach((d, i) =>
d.classList.toggle('active', i === currentSlide)
);
}
function initSlider() {
const track = document.querySelector('.slider-track');
if (!track) return;
// Static event binding for navigation targets
document.getElementById('slider-prev')?.addEventListener('click', () => moveSlide(-1));
document.getElementById('slider-next')?.addEventListener('click', () => moveSlide(1));
document.querySelectorAll('.dot').forEach((dot, index) => {
dot.addEventListener('click', () => goToSlide(index));
});
// Auto-advance checking paused flag states
sliderInterval = setInterval(() => {
if (!isSliderPaused) moveSlide(1);
}, 4000);
// Pause on hover overrides
const sliderEl = document.querySelector('.about-slider');
if (sliderEl) {
sliderEl.addEventListener('mouseenter', () => { isSliderPaused = true; });
sliderEl.addEventListener('mouseleave', () => { isSliderPaused = false; });
}
// Touch swipe support
let touchStartX = 0;
track.addEventListener('touchstart', e => {
touchStartX = e.touches[0].clientX;
}, { passive: true });
track.addEventListener('touchend', e => {
const diff = touchStartX - e.changedTouches[0].clientX;
if (Math.abs(diff) > 40) moveSlide(diff > 0 ? 1 : -1);
}, { passive: true });
}
// ─── SCROLL FADE-IN ───
function initFadeIn() {
const obs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
obs.unobserve(e.target);
}
});
}, { threshold: 0.12 });
document.querySelectorAll('.fade-in').forEach(el => obs.observe(el));
}
// ─── SMOOTH SCROLL ───
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const attr = this.getAttribute('href');
const target = document.querySelector(attr === '#top' ? '#top' : attr);
if (target) {
window.scrollTo({
top: attr === '#top' ? 0 : target.offsetTop - 64,
behavior: 'smooth'
});
document.getElementById('nav-links')?.classList.remove('open');
}
});
});
}
// ─── MOBILE MENU ───
function initMobileMenu() {
const btn = document.getElementById('mobile-menu-btn');
const links = document.getElementById('nav-links');
if (btn && links) {
btn.addEventListener('click', () => links.classList.toggle('open'));
}
}
// ─── INIT ───
document.addEventListener('DOMContentLoaded', () => {
// Theme setup configuration defaults
const cb = document.getElementById('checkbox');
const saved = localStorage.getItem('theme');
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (saved === 'dark' || (!saved && prefersDark)) {
document.documentElement.setAttribute('data-theme', 'dark');
if (cb) cb.checked = true;
}
if (cb) cb.addEventListener('change', switchTheme);
initMobileMenu();
initSmoothScroll();
initSlider();
initFadeIn();
if (document.getElementById('typewriter-text')) typeWriter();
});