-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
379 lines (336 loc) · 12.1 KB
/
script.js
File metadata and controls
379 lines (336 loc) · 12.1 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/**
* DataStack Pro — Storefront JavaScript
* No external dependencies. Vanilla JS only.
*/
(function () {
'use strict';
// =========================================================================
// Dark / Light Mode Toggle
// =========================================================================
const ThemeManager = {
STORAGE_KEY: 'datastack-theme',
init() {
const saved = localStorage.getItem(this.STORAGE_KEY);
// Default to dark if nothing saved
const theme = saved || 'dark';
this.apply(theme);
document.querySelectorAll('.theme-toggle').forEach((btn) => {
btn.addEventListener('click', () => this.toggle());
});
},
apply(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem(this.STORAGE_KEY, theme);
},
toggle() {
const current = document.documentElement.getAttribute('data-theme');
this.apply(current === 'dark' ? 'light' : 'dark');
},
};
// =========================================================================
// Mobile Navigation Toggle
// =========================================================================
const MobileNav = {
init() {
const btn = document.getElementById('mobile-menu-btn');
const nav = document.getElementById('mobile-nav');
if (!btn || !nav) return;
btn.addEventListener('click', () => {
const isOpen = nav.classList.toggle('active');
btn.setAttribute('aria-expanded', isOpen);
// Prevent body scroll when menu is open
document.body.style.overflow = isOpen ? 'hidden' : '';
});
// Close on link click
nav.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', () => {
nav.classList.remove('active');
btn.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
});
});
},
};
// =========================================================================
// Smooth Scroll for Anchor Links
// =========================================================================
const SmoothScroll = {
init() {
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', (e) => {
const targetId = anchor.getAttribute('href');
if (targetId === '#') return;
const target = document.querySelector(targetId);
if (!target) return;
e.preventDefault();
const headerOffset = 80;
const elementPosition = target.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.scrollY - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth',
});
// Update URL without jumping
history.pushState(null, null, targetId);
});
});
},
};
// =========================================================================
// Scroll Reveal Animations (IntersectionObserver)
// =========================================================================
const ScrollReveal = {
init() {
// Respect reduced motion preference
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{
threshold: 0.1,
rootMargin: '0px 0px -50px 0px',
}
);
document.querySelectorAll('.reveal').forEach((el) => {
observer.observe(el);
});
},
};
// =========================================================================
// Animated Counters
// =========================================================================
const AnimatedCounters = {
init() {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
// Just show final values
document.querySelectorAll('[data-count]').forEach((el) => {
el.textContent = el.getAttribute('data-count');
});
return;
}
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.animate(entry.target);
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.5 }
);
document.querySelectorAll('[data-count]').forEach((el) => {
observer.observe(el);
});
},
animate(el) {
const target = parseInt(el.getAttribute('data-count'), 10);
const suffix = el.getAttribute('data-count-suffix') || '';
const duration = 1500;
const start = performance.now();
const step = (now) => {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
// Ease out cubic
const eased = 1 - Math.pow(1 - progress, 3);
const current = Math.floor(eased * target);
el.textContent = current.toLocaleString() + suffix;
if (progress < 1) {
requestAnimationFrame(step);
}
};
requestAnimationFrame(step);
},
};
// =========================================================================
// FAQ Accordion
// =========================================================================
const FaqAccordion = {
init() {
document.querySelectorAll('.faq-item').forEach((item) => {
const question = item.querySelector('.faq-question');
const answer = item.querySelector('.faq-answer');
if (!question || !answer) return;
question.addEventListener('click', () => {
const isOpen = item.classList.contains('active');
// Close all others
document.querySelectorAll('.faq-item.active').forEach((other) => {
if (other !== item) {
other.classList.remove('active');
const otherAnswer = other.querySelector('.faq-answer');
if (otherAnswer) otherAnswer.style.maxHeight = '0';
other
.querySelector('.faq-question')
?.setAttribute('aria-expanded', 'false');
}
});
// Toggle current
if (isOpen) {
item.classList.remove('active');
answer.style.maxHeight = '0';
question.setAttribute('aria-expanded', 'false');
} else {
item.classList.add('active');
answer.style.maxHeight = answer.scrollHeight + 'px';
question.setAttribute('aria-expanded', 'true');
}
});
});
},
};
// =========================================================================
// Code Snippet Tab Switching
// =========================================================================
const CodeTabs = {
init() {
document.querySelectorAll('.code-tabs').forEach((tabGroup) => {
const tabs = tabGroup.querySelectorAll('.code-tab');
const container = tabGroup.closest('.featured-code');
if (!container) return;
const panels = container.querySelectorAll('.code-panel');
tabs.forEach((tab) => {
tab.addEventListener('click', () => {
const target = tab.getAttribute('data-tab');
// Deactivate all
tabs.forEach((t) => {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
});
panels.forEach((p) => p.classList.remove('active'));
// Activate clicked
tab.classList.add('active');
tab.setAttribute('aria-selected', 'true');
const targetPanel = container.querySelector(
`[data-panel="${target}"]`
);
if (targetPanel) targetPanel.classList.add('active');
});
});
});
},
};
// =========================================================================
// Copy to Clipboard
// =========================================================================
const CopyClipboard = {
init() {
document.querySelectorAll('.copy-btn').forEach((btn) => {
btn.addEventListener('click', () => {
const codeBlock = btn.closest('.code-block');
if (!codeBlock) return;
const code = codeBlock.querySelector('code');
if (!code) return;
const text = code.textContent;
navigator.clipboard
.writeText(text)
.then(() => {
const original = btn.textContent;
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(() => {
btn.textContent = original;
btn.classList.remove('copied');
}, 2000);
})
.catch(() => {
// Fallback for older browsers
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
const original = btn.textContent;
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(() => {
btn.textContent = original;
btn.classList.remove('copied');
}, 2000);
} catch (_) {
btn.textContent = 'Failed';
setTimeout(() => {
btn.textContent = 'Copy';
}, 2000);
}
document.body.removeChild(textarea);
});
});
});
},
};
// =========================================================================
// Bundle Savings Calculator
// =========================================================================
const BundleCalculator = {
init() {
const el = document.getElementById('bundle-savings-amount');
if (!el) return;
// Prices in cents from config
const prices = {
'databricks-starter-kit': 3900,
'pyspark-utils-library': 2900,
'databricks-audit-toolkit': 4900,
'medallion-architecture-guide': 1900,
'unity-catalog-governance-pack': 3900,
'spark-performance-masterclass': 5900,
};
const total = Object.values(prices).reduce((a, b) => a + b, 0);
const discountPercent = 30;
const bundlePrice = Math.round(total * (1 - discountPercent / 100));
const savings = total - bundlePrice;
el.textContent = '$' + (savings / 100).toFixed(0);
},
};
// =========================================================================
// Header scroll effect
// =========================================================================
const HeaderScroll = {
init() {
const header = document.querySelector('.site-header');
if (!header) return;
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(() => {
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
ticking = false;
});
ticking = true;
}
});
},
};
// =========================================================================
// Initialize All Modules
// =========================================================================
function init() {
ThemeManager.init();
MobileNav.init();
SmoothScroll.init();
ScrollReveal.init();
AnimatedCounters.init();
FaqAccordion.init();
CodeTabs.init();
CopyClipboard.init();
BundleCalculator.init();
HeaderScroll.init();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();