-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (142 loc) · 4.28 KB
/
Copy pathscript.js
File metadata and controls
167 lines (142 loc) · 4.28 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
// script.js
/**
* Initializes the vertical section navigation controls.
* Binds next/previous buttons and keeps their state synced with scroll position.
* @returns {void}
*/
function initSectionNavigation() {
const container = document.querySelector('.scroll-container');
const sections = Array.from(document.querySelectorAll('.scroll-container .section'));
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
if (!container || !sections.length || !prevBtn || !nextBtn) {
return;
}
let current = 0;
/**
* Updates previous/next button visibility according to the current section index.
* @returns {void}
*/
function updateButtons() {
prevBtn.classList.toggle('hidden', current === 0);
nextBtn.classList.toggle('hidden', current === sections.length - 1);
}
/**
* Scrolls to a target section by index and updates navigation state.
* @param {number} index - Target section index.
* @returns {void}
*/
function scrollTo(index) {
sections[index].scrollIntoView({ behavior: 'smooth' });
current = index;
updateButtons();
}
prevBtn.addEventListener('click', () => scrollTo(current - 1));
nextBtn.addEventListener('click', () => scrollTo(current + 1));
container.addEventListener('scroll', () => {
const scrollTop = container.scrollTop;
sections.forEach((section, index) => {
if (Math.abs(section.offsetTop - scrollTop) < section.clientHeight / 2) {
current = index;
}
});
updateButtons();
});
updateButtons();
}
/**
* Initializes the hero logo easter egg animation and keyboard/mouse triggers.
* @returns {void}
*/
function initLogoEasterEgg() {
const trigger = document.getElementById('trigger-logo');
const egg = document.getElementById('easter-egg');
if (!trigger || !egg) {
return;
}
const hLines = egg.querySelectorAll('.h-line');
const vLines = egg.querySelectorAll('.v-line');
const squares = egg.querySelectorAll('.square');
const letters = egg.querySelector('.letters');
if (!letters) {
return;
}
/**
* Replays all forward animation tracks from the initial state.
* @returns {void}
*/
function resetAnimations() {
hLines.forEach((line) => {
line.style.animation = 'none';
line.offsetHeight;
line.style.animation = 'draw-h 0.8s forwards';
});
vLines.forEach((line) => {
line.style.animation = 'none';
line.offsetHeight;
line.style.animation = 'draw-v 0.8s forwards';
});
squares.forEach((square, index) => {
square.style.animation = 'none';
square.offsetHeight;
square.style.animation = `pop 0.4s ${1.8 + index * 0.4}s forwards`;
});
letters.style.animation = 'none';
letters.offsetHeight;
letters.style.animation = 'rise 0.8s ease-out 2.6s forwards';
}
/**
* Plays reverse tracks to hide the easter egg sequence.
* @returns {void}
*/
function reverseAnimations() {
letters.style.animation = 'rise-reverse 0.5s forwards';
squares.forEach((square, index) => {
square.style.animation = `pop-reverse 0.3s ${0.2 + index * 0.2}s forwards`;
});
hLines.forEach((line) => {
line.style.animation = 'draw-h-reverse 0.4s 0.6s forwards';
});
vLines.forEach((line) => {
line.style.animation = 'draw-v-reverse 0.4s 0.6s forwards';
});
}
/**
* Runs a full easter egg cycle (forward then reverse).
* @returns {void}
*/
function playEasterEgg() {
resetAnimations();
egg.classList.add('visible');
setTimeout(() => {
reverseAnimations();
setTimeout(() => egg.classList.remove('visible'), 800);
}, 4200);
}
trigger.addEventListener('dblclick', playEasterEgg);
trigger.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
playEasterEgg();
}
});
}
let hasInitialized = false;
/**
* Bootstraps all page behaviors exactly once.
* @returns {void}
*/
function initSite() {
if (hasInitialized) {
return;
}
hasInitialized = true;
initSectionNavigation();
initLogoEasterEgg();
}
document.addEventListener('site:components-loaded', initSite);
document.addEventListener('DOMContentLoaded', () => {
if (!document.querySelector('[data-include]')) {
initSite();
}
});