-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
354 lines (308 loc) · 10.4 KB
/
main.js
File metadata and controls
354 lines (308 loc) · 10.4 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
/**
* Python Ankara — pythonankara.com
*
* Three independent modules:
* 1. PhotoStack — desktop spread + drag, mobile tap-through deck
* 2. FooterLogo — alternating logo swap every 10 s / on hover
* 3. ContactPop — delayed-open/close popover with copy-to-clipboard
*/
const MOBILE_BP = 600;
const isMobile = () => window.innerWidth <= MOBILE_BP;
/* ================================================================== */
/* 1. PHOTO STACK */
/* ================================================================== */
(() => {
const stack = document.getElementById("stack");
if (!stack) return;
const cards = [...stack.querySelectorAll(".stack-card")];
const n = cards.length;
// Shared position state for each card (used by desktop drag)
const positions = new Map();
cards.forEach((c, i) => {
positions.set(c, { x: 0, y: 0, tilt: 0 });
c.style.zIndex = i + 1;
});
let topZ = n + 1;
/* ---- DESKTOP: responsive spread ---- */
// Fractional offsets calibrated to match the reference layout at 1200 px
const SPREAD = [
{ xf: -0.69, yf: 0.03, r: -8 },
{ xf: -0.43, yf: 0.10, r: 5 },
{ xf: 0.43, yf: 0.03, r: -5 },
{ xf: 0.69, yf: 0.09, r: 7 },
{ xf: -0.55, yf: 0.14, r: 4 },
{ xf: 0.55, yf: 0.13, r: -6 },
{ xf: -0.28, yf: 0.16, r: -3 },
{ xf: 0.28, yf: 0.14, r: 4 },
{ xf: 0, yf: 0, r: 0 },
];
const REF_W = 1200;
function computeSpreads() {
const boxW = stack.offsetWidth;
const rect = stack.getBoundingClientRect();
const vw = window.innerWidth;
const gutter = 16;
const spaceL = rect.left - gutter;
const spaceR = vw - rect.right - gutter;
const squeeze = Math.min(vw / REF_W, 1);
return SPREAD.map((s) => {
const side = s.xf < 0 ? spaceL : spaceR;
const abs = Math.abs(s.xf);
// Power curve: inner cards compress faster on narrow viewports
const exp = 1 + (1 - squeeze) * 1.5;
const curved = Math.pow(abs, exp);
const sign = s.xf < 0 ? -1 : 1;
return { x: sign * curved * side, y: s.yf * boxW, r: s.r };
});
}
function applySpreads(animate) {
if (isMobile()) return;
const spreads = computeSpreads();
cards.forEach((c, i) => {
const s = spreads[i % spreads.length];
const p = positions.get(c);
p.x = s.x;
p.y = s.y;
p.tilt = s.r;
c.style.transition = animate
? "transform 0.8s cubic-bezier(0.34,1.56,0.64,1)"
: "transform 0.3s ease";
c.style.transform = `translate(${s.x}px,${s.y}px) rotate(${s.r}deg)`;
});
// Pin z-order by data-pin attributes
cards.forEach((c) => {
if (c.dataset.pin === "front") c.style.zIndex = 90;
if (c.dataset.pin === "top") c.style.zIndex = 100;
});
topZ = 101;
}
function initDesktopDrag() {
cards.forEach((card) => {
let dragging = false;
let startX, startY;
const pos = positions.get(card);
card.addEventListener("pointerdown", (e) => {
if (isMobile()) return;
dragging = true;
startX = e.clientX - pos.x;
startY = e.clientY - pos.y;
card.style.transition = "none";
card.style.zIndex = ++topZ;
card.setPointerCapture(e.pointerId);
});
card.addEventListener("pointermove", (e) => {
if (!dragging) return;
pos.x = e.clientX - startX;
pos.y = e.clientY - startY;
card.style.transform =
`translate(${pos.x}px,${pos.y}px) rotate(${pos.tilt + pos.x * 0.02}deg)`;
});
const up = () => {
if (!dragging) return;
dragging = false;
card.style.transition = "box-shadow 0.2s";
};
card.addEventListener("pointerup", up);
card.addEventListener("pointercancel", up);
});
}
/* ---- MOBILE: stacked deck with peek ---- */
let deckOrder = [];
const MAX_PEEK = 4;
const logoIdx = cards.findIndex((c) => c.dataset.pin === "top");
function buildDeckOrder() {
deckOrder = cards.map((_, i) => i).filter((i) => i !== logoIdx);
deckOrder.push(logoIdx);
}
function sizeDeckContainer() {
requestAnimationFrame(() => {
const h = cards[0].offsetHeight;
stack.style.height = h + Math.min(n - 1, MAX_PEEK) * 6 + "px";
});
}
function enterMobileMode() {
if (deckOrder.length === 0) buildDeckOrder();
layoutDeck(false);
sizeDeckContainer();
updateCounter();
}
function layoutDeck(animate) {
deckOrder.forEach((idx, pos) => {
const card = cards[idx];
const depth = n - 1 - pos; // 0 = top card
card.style.zIndex = pos + 1;
if (depth < MAX_PEEK) {
const y = depth * 6;
const s = 1 - depth * 0.03;
const r = depth === 0 ? 0 : (depth % 2 === 0 ? -0.6 : 0.6) * depth;
card.style.transform = `translateY(${y}px) scale(${s}) rotate(${r}deg)`;
card.style.opacity = "1";
} else {
card.style.transform = `translateY(${MAX_PEEK * 6}px) scale(${1 - MAX_PEEK * 0.03})`;
card.style.opacity = "0";
}
card.style.transition = animate
? "transform 0.4s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s ease"
: "none";
});
}
function cycleDeck() {
const topIdx = deckOrder.pop();
const top = cards[topIdx];
top.style.transition = "transform 0.3s ease, opacity 0.25s ease";
top.style.transform = "translateY(-30px) scale(0.95) rotate(-4deg)";
top.style.opacity = "0.3";
setTimeout(() => {
deckOrder.unshift(topIdx);
layoutDeck(true);
updateCounter();
}, 250);
}
function updateCounter() {
const el = document.getElementById("stackCounter");
if (!el || deckOrder.length === 0) return;
const topIdx = deckOrder[deckOrder.length - 1];
el.textContent = cards[topIdx].querySelector(".card-label").textContent;
}
/* ---- Mode switching ---- */
let currentMode = null; // "desktop" | "mobile"
function enterDesktopMode(animate) {
stack.style.height = "";
cards.forEach((c) => { c.style.opacity = ""; });
applySpreads(animate);
}
function resetCardsForModeSwitch() {
cards.forEach((c) => {
c.style.transform = "";
c.style.transition = "";
c.style.opacity = "";
c.style.zIndex = "";
});
}
function setMode(mode, animate) {
if (mode === currentMode) return false; // no change
resetCardsForModeSwitch();
currentMode = mode;
if (mode === "desktop") {
enterDesktopMode(animate);
} else {
enterMobileMode();
}
return true;
}
// Bind interaction listeners once (they check isMobile() at runtime)
initDesktopDrag();
stack.addEventListener("click", () => { if (isMobile()) cycleDeck(); });
let touchY = 0;
stack.addEventListener("touchstart", (e) => {
if (!isMobile()) return;
touchY = e.touches[0].clientY;
}, { passive: true });
stack.addEventListener("touchend", (e) => {
if (!isMobile()) return;
if (touchY - e.changedTouches[0].clientY > 40) cycleDeck();
}, { passive: true });
// Initial mode
const initialMode = isMobile() ? "mobile" : "desktop";
currentMode = initialMode;
if (initialMode === "desktop") {
setTimeout(() => applySpreads(true), 200);
} else {
enterMobileMode();
}
// Resize: switch mode or re-layout within same mode
let resizeTimer;
window.addEventListener("resize", () => {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(() => {
const newMode = isMobile() ? "mobile" : "desktop";
if (!setMode(newMode, false)) {
// Same mode — just re-layout
if (newMode === "desktop") {
applySpreads(false);
} else {
layoutDeck(false);
sizeDeckContainer();
}
}
}, 150);
});
})();
/* ================================================================== */
/* 2. FOOTER LOGO SWAP */
/* ================================================================== */
(() => {
const wrap = document.getElementById("footLogo");
if (!wrap) return;
let timer = setInterval(() => wrap.classList.toggle("show-python"), 10_000);
wrap.addEventListener("mouseenter", () => {
wrap.classList.toggle("show-python");
clearInterval(timer);
timer = setInterval(() => wrap.classList.toggle("show-python"), 10_000);
});
})();
/* ================================================================== */
/* 3. CONTACT POPOVER */
/* ================================================================== */
document.querySelectorAll(".contact-wrap").forEach((wrap) => {
let openT = null;
let closeT = null;
function show() {
clearTimeout(closeT);
openT = setTimeout(() => wrap.classList.add("is-open"), 350);
}
function hide() {
clearTimeout(openT);
closeT = setTimeout(() => wrap.classList.remove("is-open"), 400);
}
wrap.addEventListener("mouseenter", show);
wrap.addEventListener("mouseleave", hide);
// Toggle on click/tap (for mobile or direct clicks)
wrap.querySelector(".contact-trigger").addEventListener("click", (e) => {
e.preventDefault();
clearTimeout(openT);
clearTimeout(closeT);
wrap.classList.toggle("is-open");
});
// Close on outside click
document.addEventListener("click", (e) => {
if (!wrap.contains(e.target)) {
clearTimeout(openT);
wrap.classList.remove("is-open");
}
});
});
/* Copy to clipboard */
document.querySelectorAll(".contact-copy").forEach((btn) => {
btn.addEventListener("click", async (e) => {
e.preventDefault();
e.stopPropagation();
const email = btn.dataset.email;
const icoCopy = btn.querySelector(".ico-copy");
const icoCheck = btn.querySelector(".ico-check");
const label = btn.querySelector(".copy-label");
try {
await navigator.clipboard.writeText(email);
} catch {
// Fallback for insecure contexts
const ta = Object.assign(document.createElement("textarea"), {
value: email,
style: "position:fixed;opacity:0",
});
document.body.appendChild(ta);
ta.select();
try { document.execCommand("copy"); } catch { /* noop */ }
document.body.removeChild(ta);
}
btn.classList.add("copied");
icoCopy.style.display = "none";
icoCheck.style.display = "inline";
label.textContent = "Kopyalandı";
setTimeout(() => {
btn.classList.remove("copied");
icoCopy.style.display = "inline";
icoCheck.style.display = "none";
label.textContent = "Kopyala";
}, 1800);
});
});