-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
815 lines (739 loc) · 29 KB
/
script.js
File metadata and controls
815 lines (739 loc) · 29 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
(function () {
'use strict';
/* ============================================
REDUCED MOTION CHECK
============================================ */
var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
/* ============================================
LENIS SMOOTH SCROLL
============================================ */
var lenis = null;
if (!prefersReducedMotion && typeof Lenis !== 'undefined') {
lenis = new Lenis({
duration: 1.2,
easing: function (t) { return Math.min(1, 1.001 - Math.pow(2, -10 * t)); },
orientation: 'vertical',
smoothWheel: true
});
function raf(time) {
lenis.raf(time);
requestAnimationFrame(raf);
}
requestAnimationFrame(raf);
// Connect Lenis to GSAP ScrollTrigger
if (typeof gsap !== 'undefined' && gsap.registerPlugin) {
lenis.on('scroll', function () {
ScrollTrigger.update();
});
gsap.ticker.add(function (time) {
lenis.raf(time * 1000);
});
gsap.ticker.lagSmoothing(0);
}
}
/* ============================================
GSAP + SCROLLTRIGGER SETUP
============================================ */
if (typeof gsap !== 'undefined' && typeof ScrollTrigger !== 'undefined') {
gsap.registerPlugin(ScrollTrigger);
}
/* ============================================
CUSTOM CURSOR
============================================ */
var cursor = document.getElementById('custom-cursor');
var cursorOuter = document.getElementById('custom-cursor-outer');
var mouseX = 0, mouseY = 0;
var outerX = 0, outerY = 0;
if (cursor && cursorOuter && window.matchMedia('(pointer: fine)').matches && !prefersReducedMotion) {
document.addEventListener('mousemove', function (e) {
mouseX = e.clientX;
mouseY = e.clientY;
cursor.style.transform = 'translate(' + mouseX + 'px, ' + mouseY + 'px) translate(-50%, -50%)';
});
// Smooth follow for outer cursor with trailing effect (slower follow = trail)
function animateCursor() {
outerX += (mouseX - outerX) * 0.08;
outerY += (mouseY - outerY) * 0.08;
cursorOuter.style.transform = 'translate(' + outerX + 'px, ' + outerY + 'px) translate(-50%, -50%)';
requestAnimationFrame(animateCursor);
}
animateCursor();
// Enhanced cursor behavior for different interactive elements
var btnEls = '.btn-primary, .btn-ghost, .nav-cta, button';
var linkEls = 'a, .footer-col a, .about-link, .nav-links a';
var interactiveEls = 'a, button, .btn-primary, .btn-ghost, .nav-cta, .hs-item, .mod, .feature-card, .about-card, .platform-card, input';
document.addEventListener('mouseover', function (e) {
var target = e.target.closest(interactiveEls);
if (!target) return;
cursor.classList.add('hover');
cursor.classList.add('hover-green');
cursorOuter.classList.add('hover');
// Buttons get larger ring with green border
if (e.target.closest(btnEls)) {
cursorOuter.classList.add('hover-btn');
}
// Links get medium ring
else if (e.target.closest(linkEls)) {
cursorOuter.classList.add('hover-link');
}
});
document.addEventListener('mouseout', function (e) {
var target = e.target.closest(interactiveEls);
if (!target) return;
cursor.classList.remove('hover');
cursor.classList.remove('hover-green');
cursorOuter.classList.remove('hover');
cursorOuter.classList.remove('hover-btn');
cursorOuter.classList.remove('hover-link');
});
} else {
// Remove cursor elements on touch devices
if (cursor) cursor.style.display = 'none';
if (cursorOuter) cursorOuter.style.display = 'none';
}
/* ============================================
LEAF PARTICLES (Canvas)
============================================ */
var leafCanvas = document.getElementById('leaf-particles');
if (leafCanvas && !prefersReducedMotion) {
var ctx = leafCanvas.getContext('2d');
var particles = [];
var particleCount = 25;
function resizeCanvas() {
leafCanvas.width = window.innerWidth;
leafCanvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
function createParticle() {
return {
x: Math.random() * leafCanvas.width,
y: Math.random() * leafCanvas.height - leafCanvas.height,
size: Math.random() * 8 + 4,
speedY: Math.random() * 0.5 + 0.2,
speedX: Math.random() * 0.3 - 0.15,
rotation: Math.random() * Math.PI * 2,
rotationSpeed: (Math.random() - 0.5) * 0.02,
opacity: Math.random() * 0.3 + 0.1,
wobble: Math.random() * Math.PI * 2,
wobbleSpeed: Math.random() * 0.02 + 0.01
};
}
for (var i = 0; i < particleCount; i++) {
var p = createParticle();
p.y = Math.random() * leafCanvas.height;
particles.push(p);
}
function drawLeaf(x, y, size, rotation, opacity) {
ctx.save();
ctx.translate(x, y);
ctx.rotate(rotation);
ctx.globalAlpha = opacity;
ctx.fillStyle = '#2ecc71';
ctx.beginPath();
// Simple leaf shape
ctx.moveTo(0, -size);
ctx.bezierCurveTo(size * 0.6, -size * 0.6, size * 0.6, size * 0.3, 0, size);
ctx.bezierCurveTo(-size * 0.6, size * 0.3, -size * 0.6, -size * 0.6, 0, -size);
ctx.fill();
// Leaf vein
ctx.strokeStyle = 'rgba(255,255,255,0.15)';
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(0, -size * 0.8);
ctx.lineTo(0, size * 0.8);
ctx.stroke();
ctx.restore();
}
function animateParticles() {
ctx.clearRect(0, 0, leafCanvas.width, leafCanvas.height);
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
p.y += p.speedY;
p.wobble += p.wobbleSpeed;
p.x += p.speedX + Math.sin(p.wobble) * 0.3;
p.rotation += p.rotationSpeed;
if (p.y > leafCanvas.height + 20) {
particles[i] = createParticle();
}
drawLeaf(p.x, p.y, p.size, p.rotation, p.opacity);
}
requestAnimationFrame(animateParticles);
}
animateParticles();
} else if (leafCanvas) {
leafCanvas.style.display = 'none';
}
/* ============================================
NAVIGATION
============================================ */
var nav = document.getElementById('nav');
if (nav) {
var onScroll = function () {
nav.classList.toggle('scrolled', window.scrollY > 30);
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
/* Nav indicator (sliding underline) */
var navAnchors = document.querySelectorAll('.nav-links a[href^="#"]');
var navIndicator = document.getElementById('nav-indicator');
function moveIndicator(el) {
if (!navIndicator || !el) return;
var rect = el.getBoundingClientRect();
var parentRect = el.parentElement.getBoundingClientRect();
navIndicator.style.left = (rect.left - parentRect.left) + 'px';
navIndicator.style.width = rect.width + 'px';
navIndicator.classList.add('visible');
}
if (navAnchors.length > 0 && 'IntersectionObserver' in window) {
var sectionObserver = new IntersectionObserver(function (entries) {
for (var i = 0; i < entries.length; i++) {
if (entries[i].isIntersecting) {
var id = entries[i].target.id;
for (var a = 0; a < navAnchors.length; a++) {
var href = navAnchors[a].getAttribute('href');
if (href === '#' + id) {
navAnchors[a].classList.add('active');
moveIndicator(navAnchors[a]);
} else {
navAnchors[a].classList.remove('active');
}
}
}
}
}, {
threshold: 0.15,
rootMargin: '-60px 0px -50% 0px'
});
for (var si = 0; si < navAnchors.length; si++) {
var href = navAnchors[si].getAttribute('href');
if (href && href !== '#') {
var sec = document.querySelector(href);
if (sec) sectionObserver.observe(sec);
}
}
}
/* Mobile toggle */
var toggle = document.getElementById('nav-toggle');
var navLinks = document.getElementById('nav-links');
if (toggle && navLinks) {
toggle.addEventListener('click', function () {
toggle.classList.toggle('open');
navLinks.classList.toggle('open');
});
}
/* Smooth scroll for anchors */
var anchors = document.querySelectorAll('a[href^="#"]');
for (var a = 0; a < anchors.length; a++) {
anchors[a].addEventListener('click', function (e) {
var id = this.getAttribute('href');
if (!id || id === '#') return;
var section = document.querySelector(id);
if (!section) return;
e.preventDefault();
if (toggle) toggle.classList.remove('open');
if (navLinks) navLinks.classList.remove('open');
var y = section.getBoundingClientRect().top + window.pageYOffset - 68;
if (lenis) {
lenis.scrollTo(y, { duration: 1.2 });
} else {
window.scrollTo({ top: y, behavior: 'smooth' });
}
});
}
/* ============================================
PAGE TRANSITIONS
============================================ */
var transitionLinks = document.querySelectorAll('a[href$=".html"]:not([target])');
for (var tl = 0; tl < transitionLinks.length; tl++) {
transitionLinks[tl].addEventListener('click', function (e) {
var href = this.getAttribute('href');
if (!href) return;
e.preventDefault();
// Create overlay
var overlay = document.createElement('div');
overlay.className = 'page-transition';
document.body.appendChild(overlay);
// Force reflow
void overlay.offsetWidth;
overlay.classList.add('active');
setTimeout(function () {
window.location.href = href;
}, 350);
});
}
/* ============================================
HERO ANIMATIONS (GSAP)
============================================ */
if (typeof gsap !== 'undefined') {
var heroTl = gsap.timeline({ defaults: { ease: 'power3.out' } });
// Badge pulse in
heroTl.to('.hero-badge', {
opacity: 1,
y: 0,
scale: 1,
duration: 0.8,
delay: 0.3
});
// Word-by-word staggered text reveal
heroTl.to('.hero-h1 .word', {
opacity: 1,
y: 0,
rotateX: 0,
duration: 0.9,
stagger: 0.15,
ease: 'power4.out'
}, '-=0.3');
// Paragraph
heroTl.to('.hero-p', {
opacity: 1,
y: 0,
duration: 0.7
}, '-=0.4');
// Actions
heroTl.to('.hero-actions', {
opacity: 1,
y: 0,
duration: 0.7
}, '-=0.3');
// Showcase with 3D feel
heroTl.to('.hero-showcase', {
opacity: 1,
y: 0,
duration: 1.2,
ease: 'power2.out'
}, '-=0.5');
/* Counter animation in hero */
var modCountEl = document.querySelector('.mod-count');
if (modCountEl) {
var target = parseInt(modCountEl.getAttribute('data-count'), 10) || 20;
heroTl.to(modCountEl, {
innerText: target,
duration: 1.5,
snap: { innerText: 1 },
ease: 'power2.out'
}, '-=1');
}
}
/* ============================================
3D TILT EFFECT ON HERO IMAGE
============================================ */
var heroTilt = document.getElementById('hero-tilt');
var heroShowcase = document.getElementById('hero-showcase');
if (heroTilt && heroShowcase && window.matchMedia('(min-width: 700px)').matches && !prefersReducedMotion) {
heroShowcase.addEventListener('mousemove', function (e) {
var rect = heroShowcase.getBoundingClientRect();
var x = (e.clientX - rect.left) / rect.width - 0.5;
var y = (e.clientY - rect.top) / rect.height - 0.5;
var rotateY = x * 4; // max ~2 degrees
var rotateX = -y * 3; // max ~1.5 degrees
gsap.to(heroTilt, {
rotateX: rotateX,
rotateY: rotateY,
duration: 0.5,
ease: 'power2.out',
transformPerspective: 1000
});
});
heroShowcase.addEventListener('mouseleave', function () {
gsap.to(heroTilt, {
rotateX: 0,
rotateY: 0,
duration: 0.7,
ease: 'elastic.out(1, 0.5)',
transformPerspective: 1000
});
});
}
/* ============================================
MAGNETIC BUTTONS (applied to all buttons + nav links)
============================================ */
/* Magnetic hover effect REMOVED — caused buttons to drift/move on all pages */
/* ============================================
GSAP SCROLL ANIMATIONS
============================================ */
if (typeof gsap !== 'undefined' && typeof ScrollTrigger !== 'undefined' && !prefersReducedMotion) {
/* --- Section headers --- */
gsap.utils.toArray('.section-header').forEach(function (header) {
gsap.from(header, {
scrollTrigger: {
trigger: header,
start: 'top 85%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 40,
duration: 0.9,
ease: 'power3.out'
});
});
/* --- Feature cards scale up + glow on scroll --- */
gsap.utils.toArray('.feature-card').forEach(function (card, i) {
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 88%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 50,
scale: 0.92,
duration: 0.8,
delay: i * 0.12,
ease: 'power3.out'
});
});
/* --- Counter animation for "20+" --- */
gsap.utils.toArray('.counter').forEach(function (counter) {
var targetVal = parseInt(counter.getAttribute('data-target'), 10) || 0;
ScrollTrigger.create({
trigger: counter,
start: 'top 85%',
once: true,
onEnter: function () {
gsap.to(counter, {
innerText: targetVal,
duration: 1.5,
snap: { innerText: 1 },
ease: 'power2.out'
});
}
});
});
/* --- Mods wave animation --- */
var modsWrap = document.querySelector('.mods-wrap');
if (modsWrap) {
var mods = modsWrap.querySelectorAll('.mod');
ScrollTrigger.create({
trigger: modsWrap,
start: 'top 80%',
once: true,
onEnter: function () {
gsap.to(mods, {
opacity: 1,
y: 0,
duration: 0.5,
stagger: 0.04,
ease: 'power2.out',
onComplete: function () {
// Add class for hover styles
mods.forEach(function (m) { m.classList.add('revealed'); });
}
});
}
});
}
/* --- Horizontal scroll gallery --- */
var hsWrapper = document.getElementById('horizontal-gallery');
var hsTrack = hsWrapper ? hsWrapper.querySelector('.horizontal-scroll-track') : null;
if (hsWrapper && hsTrack && window.matchMedia('(min-width: 700px)').matches) {
// Calculate total scroll distance
function getScrollDistance() {
return hsTrack.scrollWidth - hsWrapper.offsetWidth;
}
gsap.to(hsTrack, {
x: function () { return -getScrollDistance(); },
ease: 'none',
scrollTrigger: {
trigger: hsWrapper,
start: 'top 15%',
end: function () { return '+=' + getScrollDistance(); },
pin: true,
scrub: 1,
invalidateOnRefresh: true,
anticipatePin: 1
}
});
// Parallax depth on each item
gsap.utils.toArray('.hs-item img').forEach(function (img) {
gsap.to(img, {
x: -30,
ease: 'none',
scrollTrigger: {
trigger: hsWrapper,
start: 'top top',
end: 'bottom top',
scrub: 1
}
});
});
}
// 3D tilt on gallery items — DISABLED (causes stretching at edges)
// Cards use CSS-only :hover transitions instead
/* --- Cards use CSS-only hover (no JS tilt — causes stretching at edges) --- */
/* Feature cards and about cards rely on CSS :hover { transform: translateY(-8px) } */
// About cards use CSS-only :hover transitions
/* --- Comparison table rows staggered slide-up --- */
var compareRows = gsap.utils.toArray('.ctr:not(.ctr-head)');
compareRows.forEach(function (row, i) {
gsap.from(row, {
scrollTrigger: {
trigger: row,
start: 'top 90%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 30,
duration: 0.6,
delay: i * 0.08,
ease: 'power3.out'
});
// Animate checkmarks with spring
var checks = row.querySelectorAll('.ci-yes');
checks.forEach(function (check, ci) {
gsap.from(check, {
scrollTrigger: {
trigger: row,
start: 'top 90%',
toggleActions: 'play none none none'
},
scale: 0,
opacity: 0,
duration: 0.5,
delay: i * 0.08 + ci * 0.05 + 0.3,
ease: 'back.out(2)'
});
});
// Animate X marks with red flash
var xMarks = row.querySelectorAll('.ci-no');
xMarks.forEach(function (xm, xi) {
gsap.from(xm, {
scrollTrigger: {
trigger: row,
start: 'top 90%',
toggleActions: 'play none none none'
},
scale: 0,
opacity: 0,
duration: 0.4,
delay: i * 0.08 + xi * 0.05 + 0.3,
ease: 'power2.out',
onComplete: function () {
// Brief red flash
gsap.to(xm, { color: '#ff4444', duration: 0.15, yoyo: true, repeat: 1 });
}
});
});
});
/* --- About cards slide from alternating sides --- */
gsap.utils.toArray('.about-card').forEach(function (card) {
var direction = card.getAttribute('data-direction');
var xStart = direction === 'right' ? 80 : -80;
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 85%',
toggleActions: 'play none none none'
},
opacity: 0,
x: xStart,
duration: 0.9,
ease: 'power3.out'
});
});
/* About nums parallax */
gsap.utils.toArray('.about-num').forEach(function (num, i) {
var speed = [0.3, 0.5, 0.2][i] || 0.3;
gsap.to(num, {
y: -80 * speed,
ease: 'none',
scrollTrigger: {
trigger: num.closest('.about-card'),
start: 'top bottom',
end: 'bottom top',
scrub: 1
}
});
});
/* --- CTA section --- */
var ctaHeading = document.querySelector('.cta-heading');
if (ctaHeading) {
gsap.from(ctaHeading, {
scrollTrigger: {
trigger: '.cta',
start: 'top 80%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 30,
duration: 0.8,
ease: 'power3.out'
});
}
var ctaText = document.querySelector('.cta-text');
if (ctaText) {
gsap.from(ctaText, {
scrollTrigger: {
trigger: '.cta',
start: 'top 75%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 20,
duration: 0.7,
delay: 0.2,
ease: 'power3.out'
});
}
var ctaButtons = document.querySelector('.cta-buttons');
if (ctaButtons) {
gsap.from(ctaButtons, {
scrollTrigger: {
trigger: '.cta',
start: 'top 70%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 20,
duration: 0.7,
delay: 0.35,
ease: 'power3.out'
});
}
/* --- Footer links staggered fade in --- */
gsap.utils.toArray('.footer-col a').forEach(function (link, i) {
gsap.from(link, {
scrollTrigger: {
trigger: '.footer',
start: 'top 90%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 15,
duration: 0.5,
delay: i * 0.05,
ease: 'power2.out'
});
});
/* --- Download page cards --- */
gsap.utils.toArray('.platform-card').forEach(function (card, i) {
gsap.from(card, {
scrollTrigger: {
trigger: card,
start: 'top 90%',
toggleActions: 'play none none none'
},
opacity: 0,
y: 40,
scale: 0.95,
duration: 0.7,
delay: i * 0.12,
ease: 'power3.out'
});
});
}
/* ============================================
LIGHTBOX
============================================ */
var lightbox = document.getElementById('lightbox');
var lbImg = document.getElementById('lightbox-img');
var lbClose = document.getElementById('lightbox-close');
if (lightbox && lbImg) {
var galleryItems = document.querySelectorAll('.hs-item');
for (var b = 0; b < galleryItems.length; b++) {
galleryItems[b].addEventListener('click', function () {
var img = this.querySelector('img');
if (!img) return;
lbImg.src = img.src;
lbImg.alt = this.dataset.caption || '';
lightbox.classList.add('active');
lightbox.setAttribute('aria-hidden', 'false');
});
}
var closeLb = function () {
lightbox.classList.remove('active');
lightbox.setAttribute('aria-hidden', 'true');
};
if (lbClose) lbClose.addEventListener('click', closeLb);
lightbox.addEventListener('click', function (e) {
if (e.target === lightbox) closeLb();
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && lightbox.classList.contains('active')) closeLb();
});
}
/* ============================================
DOWNLOAD LOGIC
============================================ */
var heroDlBtn = document.getElementById('hero-download-btn');
var defaultUrl = 'https://github.com/LeafClientMC/LeafClient/raw/refs/heads/main/latestexe/LeafClient.zip';
if (heroDlBtn) {
heroDlBtn.addEventListener('click', function (e) {
e.preventDefault();
window.location.href = defaultUrl;
});
}
var verEl = document.getElementById('version-text');
var dlBtn = document.getElementById('download-btn');
if (verEl) {
setTimeout(function () {
try {
fetch('https://api.github.com/repos/LeafClientMC/LeafClient/releases/latest')
.then(function (r) { return r.ok ? r.json() : Promise.reject(); })
.then(function (d) {
if (d && d.tag_name) verEl.textContent = 'Latest: ' + d.tag_name;
})
.catch(function () { verEl.textContent = 'Latest Release'; });
} catch (e) { verEl.textContent = 'Latest Release'; }
}, 200);
}
if (dlBtn) {
dlBtn.addEventListener('click', function (e) {
e.preventDefault();
var modal = document.getElementById('download-modal');
if (!modal) { window.location.href = defaultUrl; return; }
modal.style.display = 'flex';
var cdEl = document.getElementById('countdown');
var fLink = document.getElementById('force-download-link');
var secs = 5;
if (cdEl) cdEl.textContent = secs;
var iv = setInterval(function () {
secs--;
if (cdEl) cdEl.textContent = secs;
if (secs <= 0) {
clearInterval(iv);
window.location.href = defaultUrl;
if (fLink) { fLink.classList.remove('hidden'); fLink.href = defaultUrl; }
}
}, 1000);
var closeModal = document.getElementById('close-modal');
if (closeModal) {
closeModal.addEventListener('click', function () {
modal.style.display = 'none';
clearInterval(iv);
}, { once: true });
}
});
}
/* ============================================
RIPPLE EFFECT ON BUTTON CLICK
============================================ */
if (!prefersReducedMotion) {
var rippleTargets = document.querySelectorAll('.btn-primary, .btn-ghost, .nav-cta');
rippleTargets.forEach(function (btn) {
btn.addEventListener('click', function (e) {
var rect = btn.getBoundingClientRect();
var ripple = document.createElement('span');
ripple.className = 'btn-ripple';
ripple.style.left = (e.clientX - rect.left) + 'px';
ripple.style.top = (e.clientY - rect.top) + 'px';
btn.appendChild(ripple);
ripple.addEventListener('animationend', function () {
ripple.remove();
});
});
});
}
/* ============================================
FALLBACK: Make mods visible if no GSAP
============================================ */
if (typeof gsap === 'undefined' || prefersReducedMotion) {
var allMods = document.querySelectorAll('.mod');
allMods.forEach(function (m) {
m.style.opacity = '1';
m.style.transform = 'none';
m.classList.add('revealed');
});
}
})();