-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
247 lines (210 loc) · 7.47 KB
/
script.js
File metadata and controls
247 lines (210 loc) · 7.47 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
// Theme Management
const themeToggle = document.getElementById('themeToggle');
const html = document.documentElement;
// Check for saved theme preference or default to light
const savedTheme = localStorage.getItem('theme') || 'light';
html.setAttribute('data-theme', savedTheme);
// Toggle theme
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
// Code Tab Switching
const codeTabs = document.querySelectorAll('.code-tab');
const codeBlocks = document.querySelectorAll('.code-block');
codeTabs.forEach(tab => {
tab.addEventListener('click', () => {
const lang = tab.getAttribute('data-lang');
// Update active tab
codeTabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Update active code block
codeBlocks.forEach(block => {
if (block.getAttribute('data-lang') === lang) {
block.classList.add('active');
} else {
block.classList.remove('active');
}
});
});
});
// Smooth Scrolling for Navigation Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Account for fixed navbar
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Add scroll effect to navbar
const navbar = document.querySelector('.navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.boxShadow = 'var(--shadow-md)';
} else {
navbar.style.boxShadow = 'none';
}
lastScroll = currentScroll;
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Apply fade-in animation to sections
document.querySelectorAll('.feature-card, .sdk-card, .use-case-card, .benefit-card, .comparison-card').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Copy code functionality (optional enhancement)
function addCopyButtons() {
const codeBlocks = document.querySelectorAll('.code-block');
codeBlocks.forEach(block => {
const wrapper = document.createElement('div');
wrapper.style.position = 'relative';
const copyButton = document.createElement('button');
copyButton.textContent = 'Copy';
copyButton.style.cssText = `
position: absolute;
top: 1rem;
right: 1rem;
padding: 0.5rem 1rem;
background: var(--accent-primary);
color: white;
border: none;
border-radius: 6px;
font-size: 0.875rem;
cursor: pointer;
opacity: 0.8;
transition: opacity 0.3s ease;
`;
copyButton.addEventListener('mouseenter', () => {
copyButton.style.opacity = '1';
});
copyButton.addEventListener('mouseleave', () => {
copyButton.style.opacity = '0.8';
});
copyButton.addEventListener('click', async () => {
const code = block.querySelector('code').textContent;
try {
await navigator.clipboard.writeText(code);
copyButton.textContent = 'Copied!';
setTimeout(() => {
copyButton.textContent = 'Copy';
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
}
});
block.style.position = 'relative';
block.appendChild(copyButton);
});
}
// Initialize copy buttons when DOM is loaded
document.addEventListener('DOMContentLoaded', addCopyButtons);
// Mobile menu toggle (if needed in future)
function createMobileMenu() {
const navLinks = document.querySelector('.nav-links');
const mobileMenuButton = document.createElement('button');
mobileMenuButton.className = 'mobile-menu-toggle';
mobileMenuButton.innerHTML = `
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
`;
// Add mobile menu functionality here if needed
}
// Performance optimization: Debounce scroll events
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Apply debouncing to scroll handler
const debouncedScroll = debounce(() => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.boxShadow = 'var(--shadow-md)';
} else {
navbar.style.boxShadow = 'none';
}
}, 10);
window.addEventListener('scroll', debouncedScroll);
// Add interactive hover effects to graph animation nodes
document.querySelectorAll('.node').forEach(node => {
node.addEventListener('mouseenter', () => {
node.style.transform = 'scale(1.5)';
});
node.addEventListener('mouseleave', () => {
node.style.transform = 'scale(1)';
});
});
// Preload images for better performance
function preloadImages() {
const imageUrls = [
'https://github.com/jchristn/LiteGraph/blob/main/assets/favicon.png?raw=true'
];
imageUrls.forEach(url => {
const img = new Image();
img.src = url;
});
}
// Initialize on page load
window.addEventListener('load', () => {
preloadImages();
});
// Add keyboard navigation support
document.addEventListener('keydown', (e) => {
// Press 'T' to toggle theme
if (e.key === 't' && !e.ctrlKey && !e.metaKey && !e.altKey) {
const activeElement = document.activeElement;
if (activeElement.tagName !== 'INPUT' && activeElement.tagName !== 'TEXTAREA') {
themeToggle.click();
}
}
});
// Analytics placeholder (implement if needed)
function trackEvent(category, action, label) {
// Implement analytics tracking here if needed
console.log(`Analytics: ${category} - ${action} - ${label}`);
}
// Track important interactions
document.querySelectorAll('.btn-primary').forEach(btn => {
btn.addEventListener('click', () => {
trackEvent('CTA', 'click', 'Get Started');
});
});
document.querySelectorAll('.github-link').forEach(link => {
link.addEventListener('click', () => {
trackEvent('External', 'click', 'GitHub');
});
});