-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
261 lines (220 loc) · 8.65 KB
/
script.js
File metadata and controls
261 lines (220 loc) · 8.65 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
// ===== Smooth scroll for anchor links =====
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href === '#') return;
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// ===== Navbar scroll effect =====
const nav = document.querySelector('.nav');
let lastScrollY = 0;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY > 100) {
nav.style.background = 'rgba(10, 10, 15, 0.95)';
nav.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.4)';
} else {
nav.style.background = 'rgba(10, 10, 15, 0.8)';
nav.style.boxShadow = 'none';
}
lastScrollY = currentScrollY;
});
// ===== Intersection Observer for animations =====
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll('.feature-card, .ecosystem-card, .step, .faq-item').forEach(el => {
el.style.opacity = '0';
observer.observe(el);
});
// ===== Active nav link highlighting =====
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a[href^="#"]');
window.addEventListener('scroll', () => {
let current = '';
const scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.style.color = '';
if (link.getAttribute('href') === `#${current}`) {
link.style.color = 'var(--color-primary)';
}
});
});
// ===== Copy code functionality =====
document.querySelectorAll('.code-content, .step-code').forEach(codeBlock => {
codeBlock.style.cursor = 'pointer';
codeBlock.title = 'Click to copy';
codeBlock.addEventListener('click', async () => {
// Get text content and remove $ prompt symbols
const code = codeBlock.textContent
.split('\n')
.map(line => line.replace(/^\$\s*/, '')) // Remove $ and space from start of each line
.join('\n')
.trim();
try {
await navigator.clipboard.writeText(code);
// Visual feedback
const originalBg = codeBlock.style.background;
codeBlock.style.background = 'rgba(16, 185, 129, 0.1)';
codeBlock.style.transition = 'background 0.3s ease';
setTimeout(() => {
codeBlock.style.background = originalBg;
}, 300);
} catch (err) {
console.error('Failed to copy:', err);
}
});
});
// ===== Copy button functionality =====
document.querySelectorAll('.code-copy-btn').forEach(copyBtn => {
copyBtn.addEventListener('click', async () => {
const codeBlock = copyBtn.closest('.hero-code, .step-code')?.querySelector('.code-content, .step-code code, code');
let code = codeBlock?.textContent || codeBlock?.innerText || '';
if (!code) return;
// Remove $ prompt symbols
code = code
.split('\n')
.map(line => line.replace(/^\$\s*/, ''))
.join('\n')
.trim();
try {
await navigator.clipboard.writeText(code);
// Visual feedback
copyBtn.classList.add('copied');
copyBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>';
setTimeout(() => {
copyBtn.classList.remove('copied');
copyBtn.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
}
});
});
// ===== FAQ accordion (optional enhancement) =====
document.querySelectorAll('.faq-item h3').forEach(question => {
question.style.cursor = 'pointer';
question.style.position = 'relative';
question.style.paddingRight = '40px';
// Create wrapper for original content to preserve i18n
const contentSpan = document.createElement('span');
contentSpan.className = 'faq-question-text';
while (question.firstChild) {
contentSpan.appendChild(question.firstChild);
}
question.appendChild(contentSpan);
// Add indicator
const indicator = document.createElement('span');
indicator.className = 'faq-indicator';
indicator.textContent = '+';
indicator.style.cssText = 'position: absolute; right: 0; top: 50%; transform: translateY(-50%); transition: transform 0.3s ease; pointer-events: none;';
question.appendChild(indicator);
question.addEventListener('click', () => {
const answer = question.nextElementSibling;
const isOpened = answer.style.display === 'none' || answer.style.display === '';
// Close all other FAQs
document.querySelectorAll('.faq-item p').forEach(p => {
p.style.display = 'none';
});
document.querySelectorAll('.faq-indicator').forEach(ind => {
ind.textContent = '+';
ind.style.transform = 'translateY(-50%)';
});
// Toggle current
if (isOpened) {
answer.style.display = 'block';
indicator.textContent = '−';
indicator.style.transform = 'translateY(-50%) rotate(180deg)';
}
});
// Initially hide all answers
const answer = question.nextElementSibling;
if (answer && answer.tagName === 'P') {
answer.style.display = 'none';
}
});
// ===== Performance optimization: Lazy load images =====
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
imageObserver.observe(img);
});
}
// ===== Console welcome message =====
console.log('%c🚀 jzero', 'font-size: 24px; font-weight: bold; color: #00d9ff;');
console.log('%cAI-Friendly Go Microservices Framework', 'font-size: 14px; color: #a1a1aa;');
console.log('%chttps://github.com/jzero-io/jzero', 'font-size: 12px; color: #6366f1;');
// ===== GitHub Star Count =====
async function fetchGitHubStars() {
const starCountEl = document.getElementById('githubStarCount');
if (!starCountEl) return;
const starNumberEl = starCountEl.querySelector('.star-number');
if (!starNumberEl) return;
try {
// Try to fetch from GitHub API
const response = await fetch('https://api.github.com/repos/jzero-io/jzero', {
headers: {
'Accept': 'application/vnd.github.v3+json',
}
});
if (response.ok) {
const data = await response.json();
const stars = data.stargazers_count;
// Format the number (e.g., 1234 -> 1.2k)
if (stars >= 1000) {
starNumberEl.textContent = (stars / 1000).toFixed(1) + 'k';
} else {
starNumberEl.textContent = stars.toString();
}
} else {
throw new Error('API request failed');
}
} catch (error) {
console.log('Could not fetch GitHub stars:', error);
starNumberEl.textContent = '★';
}
}
// Fetch stars when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fetchGitHubStars);
} else {
fetchGitHubStars();
}
// ===== Typewriter effect for install command =====
// Disabled - using static code display instead