-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
166 lines (137 loc) · 4.58 KB
/
Copy pathscript.js
File metadata and controls
166 lines (137 loc) · 4.58 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
const faders = document.querySelectorAll(".fade-in-on-scroll");
const observerOptions = {
threshold: 0.2,
};
const onIntersection = (entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("is-visible");
observer.unobserve(entry.target);
}
});
};
const observer = new IntersectionObserver(onIntersection, observerOptions);
faders.forEach((el) => observer.observe(el));
const siteHeader = document.querySelector(".site-header");
const updateHeaderSize = () => {
if (!siteHeader) return;
siteHeader.classList.toggle("is-scrolled", window.scrollY > 24);
};
updateHeaderSize();
window.addEventListener("scroll", updateHeaderSize, { passive: true });
// ABOUT SECTION INTERACTION
const aboutTabs = document.querySelectorAll(".about-tab");
const aboutPanels = {
hobbies: document.getElementById("about-hobbies"),
interests: document.getElementById("about-interests"),
aspirations: document.getElementById("about-aspirations"),
"language-strengths": document.getElementById("about-language-strengths"),
"school-projects": document.getElementById("about-school-projects"),
};
const aboutSound = document.getElementById("about-sound");
aboutTabs.forEach((tab) => {
tab.addEventListener("click", () => {
const topic = tab.dataset.topic;
// play click sound (if loaded)
if (aboutSound) {
aboutSound.currentTime = 0;
aboutSound.play().catch(() => {
// ignore autoplay errors if browser blocks sound
});
}
// activate clicked tab
aboutTabs.forEach((t) => t.classList.remove("active"));
tab.classList.add("active");
// show matching panel
Object.values(aboutPanels).forEach((panel) =>
panel.classList.remove("active")
);
const activePanel = aboutPanels[topic];
if (activePanel) {
activePanel.classList.add("active");
}
});
});
const galleries = {
"cowboy-standoff": {
title: "Cowboy Standoff",
src: "demos/unity/stickman-shooter-unity.mp4",
},
"bri-hoops": {
title: "Bri Hoops",
src: "demos/unity/bri-hoops-final-demo-unity.mp4",
},
"backyard-cinema": {
title: "Backyard Cinema",
src: "demos/websites/BackyardCinemaDemo.mp4",
},
"polaroid-print": {
title: "Polaroid Prints",
src: "demos/websites/polaroid-print-personal-project.mp4",
},
"nearby-memories": {
title: "NearbyMemories App",
src: "nearbyMemories.mp4",
},
};
const modal = document.getElementById("slideshow-modal");
const modalTitle = document.getElementById("modal-title");
const modalMedia = document.getElementById("modal-media");
const modalCounter = document.getElementById("modal-counter");
const modalDots = document.getElementById("modal-dots");
const modalStage = document.querySelector(".modal-stage");
const galleryButtons = document.querySelectorAll("[data-gallery]");
let activeGallery = null;
const renderGalleryItem = () => {
if (!activeGallery) return;
modalTitle.textContent = activeGallery.title;
modalMedia.innerHTML = "";
const video = document.createElement("video");
video.src = activeGallery.src;
video.controls = true;
video.autoplay = true;
video.muted = true;
video.playsInline = true;
modalMedia.appendChild(video);
modalCounter.textContent = "Demo preview";
modalDots.innerHTML = "";
};
const openGallery = (galleryKey) => {
activeGallery = galleries[galleryKey];
if (!activeGallery || !modal) return;
modal.classList.add("is-open");
modal.setAttribute("aria-hidden", "false");
document.body.classList.add("modal-open");
renderGalleryItem();
};
const closeGallery = () => {
if (!modal) return;
modal.classList.remove("is-open");
modal.setAttribute("aria-hidden", "true");
document.body.classList.remove("modal-open");
modalMedia.innerHTML = "";
activeGallery = null;
};
galleryButtons.forEach((button) => {
button.addEventListener("click", () => openGallery(button.dataset.gallery));
button.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
openGallery(button.dataset.gallery);
}
});
});
document
.querySelector("[data-modal-prev]")
?.addEventListener("click", closeGallery);
document
.querySelector("[data-modal-next]")
?.addEventListener("click", closeGallery);
document.querySelectorAll("[data-close-modal]").forEach((button) => {
button.addEventListener("click", closeGallery);
});
document.addEventListener("keydown", (event) => {
if (!activeGallery) return;
if (event.key === "Escape") closeGallery();
if (event.key === "ArrowLeft" || event.key === "ArrowRight") closeGallery();
});