-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
252 lines (194 loc) · 6.33 KB
/
script.js
File metadata and controls
252 lines (194 loc) · 6.33 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
let projects = [];
let activeProjectIndex = 0;
let activeImageIndex = 0;
const landing = document.getElementById("landing");
const enterButton = document.getElementById("enterButton");
const profileButton = document.getElementById("profileButton");
const headerContactButton = document.getElementById("headerContactButton");
const closeProfileButton = document.getElementById("closeProfileButton");
const profileOverlay = document.getElementById("profileOverlay");
const brandButton = document.getElementById("brandButton");
const heroImage = document.getElementById("heroImage");
const heroType = document.getElementById("heroType");
const heroYear = document.getElementById("heroYear");
const heroLocation = document.getElementById("heroLocation");
const projectTitle = document.getElementById("projectTitle");
const projectDesc = document.getElementById("projectDesc");
const sideTitle = document.getElementById("sideTitle");
const sideLocation = document.getElementById("sideLocation");
const sideYear = document.getElementById("sideYear");
const sideType = document.getElementById("sideType");
const sideDesc = document.getElementById("side-desc");
const thumbnails = document.getElementById("thumbnails");
const prevImageButton = document.getElementById("prevImage");
const nextImageButton = document.getElementById("nextImage");
const imageCurrent = document.getElementById("imageCurrent");
const imageTotal = document.getElementById("imageTotal");
function enterSite() {
landing.classList.add("hidden");
}
function openProfile() {
profileOverlay.style.display = "flex";
}
function closeProfile() {
profileOverlay.style.display = "none";
}
function updateHeroImage() {
const project = projects[activeProjectIndex];
if (!project || !project.images || project.images.length === 0) {
heroImage.src = "";
heroImage.alt = "";
imageCurrent.innerText = "0";
imageTotal.innerText = "0";
return;
}
heroImage.src = project.images[activeImageIndex];
heroImage.alt = `${project.title} ${activeImageIndex + 1}`;
imageCurrent.innerText = activeImageIndex + 1;
imageTotal.innerText = project.images.length;
}
function showProject(index) {
const p = projects[index];
if (!p) return;
activeProjectIndex = index;
activeImageIndex = 0;
updateHeroImage();
heroType.innerText = p.type || "";
heroYear.innerText = p.year || "";
heroLocation.innerText = p.location || "";
projectTitle.innerText = p.title || "";
projectDesc.innerText = p.desc || "";
sideTitle.innerText = p.title || "";
sideLocation.innerText = p.location || "";
sideYear.innerText = p.year || "";
sideType.innerText = p.type || "";
if (sideDesc) {
sideDesc.innerText = p.desc || "";
}
updateActiveThumbnail();
}
function showPrevImage() {
const project = projects[activeProjectIndex];
if (!project || !project.images || project.images.length <= 1) return;
activeImageIndex--;
if (activeImageIndex < 0) {
activeImageIndex = project.images.length - 1;
}
updateHeroImage();
}
function showNextImage() {
const project = projects[activeProjectIndex];
if (!project || !project.images || project.images.length <= 1) return;
activeImageIndex++;
if (activeImageIndex >= project.images.length) {
activeImageIndex = 0;
}
updateHeroImage();
}
function updateActiveThumbnail() {
const thumbElements = thumbnails.querySelectorAll(".thumb");
thumbElements.forEach((thumb, index) => {
if (index === activeProjectIndex) {
thumb.classList.add("active");
} else {
thumb.classList.remove("active");
}
});
}
function loadThumbnails() {
thumbnails.innerHTML = "";
projects.forEach((p, i) => {
const el = document.createElement("button");
el.className = "thumb";
el.type = "button";
const thumbImage = p.thumbnail || (p.images && p.images[0]) || "";
el.innerHTML = `
<img src="${thumbImage}" alt="${p.title}">
<div class="thumb-text">
<p class="thumb-year">${p.year || ""}</p>
<p class="thumb-title">${p.title || ""}</p>
<p class="thumb-location">${p.location || ""}</p>
</div>
`;
el.addEventListener("click", () => showProject(i));
thumbnails.appendChild(el);
});
updateActiveThumbnail();
}
async function loadProjects() {
try {
const res = await fetch("projects.json");
if (!res.ok) {
throw new Error("Failed to load projects.json");
}
projects = await res.json();
if (!Array.isArray(projects) || projects.length === 0) {
throw new Error("No project data found.");
}
// 연도 기준 내림차순 정렬
// 예: 2024 > 2023.02 > 2022 > 2019.10
projects.sort((a, b) => {
const yearA = String(a.year || "");
const yearB = String(b.year || "");
return yearB.localeCompare(yearA);
});
showProject(0);
loadThumbnails();
} catch (err) {
console.error(err);
projectTitle.innerText = "Project data could not be loaded.";
projectDesc.innerText = "Please check projects.json and file paths.";
imageCurrent.innerText = "0";
imageTotal.innerText = "0";
}
}
enterButton.addEventListener("click", enterSite);
if (profileButton) {
profileButton.addEventListener("click", openProfile);
}
if (headerContactButton) {
headerContactButton.addEventListener("click", openProfile);
}
if (closeProfileButton) {
closeProfileButton.addEventListener("click", closeProfile);
}
if (brandButton) {
brandButton.addEventListener("click", () => {
landing.classList.remove("hidden");
});
}
if (prevImageButton) {
prevImageButton.addEventListener("click", showPrevImage);
}
if (nextImageButton) {
nextImageButton.addEventListener("click", showNextImage);
}
window.addEventListener("wheel", (event) => {
if (event.deltaY > 20 && !landing.classList.contains("hidden")) {
enterSite();
}
});
window.addEventListener("keydown", (event) => {
if ((event.key === "Enter" || event.key === "ArrowDown") && !landing.classList.contains("hidden")) {
enterSite();
}
if (event.key === "Escape") {
closeProfile();
}
if (landing.classList.contains("hidden")) {
if (event.key === "ArrowLeft") {
showPrevImage();
}
if (event.key === "ArrowRight") {
showNextImage();
}
}
});
if (profileOverlay) {
profileOverlay.addEventListener("click", (event) => {
if (event.target === profileOverlay) {
closeProfile();
}
});
}
loadProjects();