-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
249 lines (239 loc) · 11 KB
/
script.js
File metadata and controls
249 lines (239 loc) · 11 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
// Initialize AOS with performance settings
AOS.init({
duration: 1000,
once: true,
offset: 100,
easing: 'ease-out-cubic',
disable: window.innerWidth < 768 ? 'mobile' : false
});
// Enhanced Video Control with Audio Fade
const video = document.getElementById('scrollVideo');
const videoSection = document.querySelector('#video');
const muteBtn = document.getElementById('muteToggle');
let played = false;
let currentVolume = 0;
let targetVolume = 0;
let audioAnimationFrame = null;
// Smooth audio fade function
function smoothAudioTransition() {
const difference = targetVolume - currentVolume;
const step = difference * 0.05; // Smooth transition speed
if (Math.abs(difference) > 0.01) {
currentVolume += step;
video.volume = Math.max(0, Math.min(1, currentVolume));
audioAnimationFrame = requestAnimationFrame(smoothAudioTransition);
} else {
currentVolume = targetVolume;
video.volume = currentVolume;
}
}
// Intersection Observer for video
const observerOptions = {
threshold: [0, 0.25, 0.5, 0.75, 1],
rootMargin: '0px'
};
const videoObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
const ratio = entry.intersectionRatio;
if (entry.isIntersecting) {
if (!played) {
video.play().catch(e => console.log('Autoplay prevented:', e));
played = true;
videoSection.classList.add('active');
}
// Fade in audio based on scroll position
if (!video.muted) {
targetVolume = Math.min(ratio * 1.2, 0.7); // Max 70% volume
if (!audioAnimationFrame) {
smoothAudioTransition();
}
}
} else {
// Fade out audio when leaving viewport
targetVolume = 0;
if (!audioAnimationFrame) {
smoothAudioTransition();
}
}
});
}, observerOptions);
videoObserver.observe(videoSection);
// Mute toggle with smooth transition
muteBtn.addEventListener('click', () => {
video.muted = !video.muted;
const icon = muteBtn.querySelector('i');
const text = muteBtn.querySelector('span');
if (video.muted) {
icon.className = 'fas fa-volume-mute';
text.textContent = 'Unmute';
targetVolume = 0;
} else {
icon.className = 'fas fa-volume-up';
text.textContent = 'Mute';
const rect = videoSection.getBoundingClientRect();
const viewportHeight = window.innerHeight;
const visibleRatio = Math.min(1, Math.max(0, (viewportHeight - rect.top) / viewportHeight));
targetVolume = Math.min(visibleRatio * 1.2, 0.7);
}
smoothAudioTransition();
});
// Mobile menu toggle with smooth animation
const mobileBtn = document.getElementById('mobileBtn');
const mobileMenu = document.getElementById('mobileMenu');
let menuOpen = false;
mobileBtn.addEventListener('click', () => {
menuOpen = !menuOpen;
const icon = mobileBtn.querySelector('i');
if (menuOpen) {
mobileMenu.style.maxHeight = mobileMenu.scrollHeight + 'px';
icon.className = 'fas fa-times';
mobileBtn.style.transform = 'rotate(90deg)';
} else {
mobileMenu.style.maxHeight = '0';
icon.className = 'fas fa-bars';
mobileBtn.style.transform = 'rotate(0deg)';
}
});
// Close mobile menu on link click
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
if (menuOpen) {
mobileMenu.style.maxHeight = '0';
mobileBtn.querySelector('i').className = 'fas fa-bars';
mobileBtn.style.transform = 'rotate(0deg)';
menuOpen = false;
}
});
});
// Navbar scroll effect
let lastScroll = 0;
const nav = document.querySelector('nav');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
nav.style.padding = '0.5rem 0';
nav.style.backgroundColor = 'rgba(0, 0, 0, 0.9)';
} else {
nav.style.padding = '0.75rem 0 sm:1.25rem 0';
nav.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
}
lastScroll = currentScroll;
}, { passive: true });
// GitHub Data with Enhanced Error Handling
const ORG = 'BengalEmpire';
let dataLoaded = false;
async function loadOrgData() {
try {
const [org, reposRes, membersRes] = await Promise.all([
fetch(`https://api.github.com/orgs/${ORG}`).then(r => { if (!r.ok) throw new Error('Failed to fetch org'); return r.json(); }),
fetch(`https://api.github.com/orgs/${ORG}/repos?per_page=100&sort=stars`).then(r => { if (!r.ok) throw new Error('Failed to fetch repos'); return r.json(); }),
fetch(`https://api.github.com/orgs/${ORG}/public_members?per_page=100`).then(r => { if (!r.ok) throw new Error('Failed to fetch members'); return r.json(); })
]);
// Hide loader and show bio
const bioContainer = document.getElementById('orgBioContainer');
const bioElement = document.getElementById('orgBio');
bioContainer.style.display = 'none';
bioElement.innerHTML = org.description || "A fearless open-source collective reviving Bengal's golden age through code.";
bioElement.style.opacity = '1';
// Calculate stats
const stats = {
repos: reposRes.length,
stars: reposRes.reduce((a,r) => a + r.stargazers_count, 0),
forks: reposRes.reduce((a,r) => a + r.forks_count, 0),
members: membersRes.length,
topRepos: reposRes.sort((a,b) => b.stargazers_count - a.stargazers_count).slice(0, 9)
};
// Animated counter function
function animateCounter(element, target, duration = 2000) {
const start = 0;
const startTime = performance.now();
function updateCounter(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const easeProgress = 1 - Math.pow(1 - progress, 3); // Ease out cubic
const current = Math.floor(start + (target - start) * easeProgress);
element.textContent = current.toLocaleString();
if (progress < 1) {
requestAnimationFrame(updateCounter);
} else {
element.textContent = target.toLocaleString();
}
}
requestAnimationFrame(updateCounter);
}
// Render stats with animation
const statsGrid = document.getElementById('statsGrid');
statsGrid.innerHTML = `
<div data-aos="flip-up"><div class="stat-number">0</div><p class="text-xl sm:text-2xl text-gray-400 mt-3 sm:mt-4">Repositories</p></div>
<div data-aos="flip-up" data-aos-delay="200"><div class="stat-number">0</div><p class="text-xl sm:text-2xl text-gray-400 mt-3 sm:mt-4">Stars</p></div>
<div data-aos="flip-up" data-aos-delay="400"><div class="stat-number">0</div><p class="text-xl sm:text-2xl text-gray-400 mt-3 sm:mt-4">Forks</p></div>
<div data-aos="flip-up" data-aos-delay="600"><div class="stat-number">0</div><p class="text-xl sm:text-2xl text-gray-400 mt-3 sm:mt-4">Warriors</p></div>
`;
const counterElements = statsGrid.querySelectorAll('.stat-number');
animateCounter(counterElements[0], stats.repos);
animateCounter(counterElements[1], stats.stars);
animateCounter(counterElements[2], stats.forks);
animateCounter(counterElements[3], stats.members);
// Render projects
document.getElementById('repos').innerHTML = stats.topRepos.map((r, i) => `
<a href="${r.html_url}" target="_blank" class="card group" data-aos="fade-up" data-aos-delay="${i * 100}">
<h3 class="text-2xl sm:text-3xl font-bold group-hover:text-bengal transition">${r.name}</h3>
<p class="text-gray-400 my-4 sm:my-6 text-base sm:text-lg">${r.description || 'No description'}</p>
<div class="flex gap-4 sm:gap-6 text-base sm:text-lg">
${r.language ? `<span class="px-3 sm:px-4 py-1 sm:py-2 bg-gray-800 rounded-full">${r.language}</span>` : ''}
<span>⭐ ${r.stargazers_count}</span>
<span>⑂ ${r.forks_count}</span>
</div>
</a>
`).join('');
// Render members
const membersGrid = document.getElementById('membersGrid');
membersGrid.innerHTML = membersRes.length > 0 ? membersRes.map((m, i) => `
<a href="${m.html_url}" target="_blank" class="card group text-center" data-aos="fade-up" data-aos-delay="${i * 100}">
<img src="${m.avatar_url}" alt="${m.login}" class="w-24 h-24 sm:w-32 sm:h-32 rounded-full mx-auto mb-4 ring-4 ring-bengal/60 group-hover:ring-bengal transition" />
<h3 class="text-xl sm:text-2xl font-bold group-hover:text-bengal transition">${m.login}</h3>
</a>
`).join('') : '<p class="col-span-full text-gray-400 text-center">No public members yet. Join us!</p>';
// Language Chart
const langCount = {};
reposRes.forEach(r => {
if (r.language) {
langCount[r.language] = (langCount[r.language] || 0) + 1;
}
});
if (typeof Chart !== 'undefined' && Object.keys(langCount).length > 0) {
new Chart(document.getElementById('langChart'), {
type: 'doughnut',
data: {
labels: Object.keys(langCount),
datasets: [{
data: Object.values(langCount),
backgroundColor: ['#f57c00','#1976d2','#43a047','#e91e63','#00bcd4','#ff9800','#9c27b0']
}]
},
options: {
plugins: {
legend: {
labels: {
color: '#fff',
font: { size: 14, sm:16 }
}
}
},
responsive: true,
maintainAspectRatio: false
}
});
} else {
document.getElementById('langChart').parentNode.innerHTML = '<p class="text-red-500">Failed to load chart. Please check console for errors.</p>';
}
} catch (e) {
console.error("Error in loadOrgData:", e);
// Show error messages
document.getElementById('orgBioContainer').innerHTML = '<p class="text-red-500">Failed to load organization info. Please try again later.</p>';
document.getElementById('statsGrid').innerHTML = '<p class="col-span-full text-red-500">Failed to load stats.</p>';
document.getElementById('repos').innerHTML = '<p class="col-span-full text-red-500">Failed to load projects.</p>';
document.getElementById('membersGrid').innerHTML = '<p class="col-span-full text-red-500">Failed to load members.</p>';
}
}
window.addEventListener('load', loadOrgData);