-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
835 lines (674 loc) · 21.5 KB
/
index.html
File metadata and controls
835 lines (674 loc) · 21.5 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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" href="op1.png" type="image/png" sizes="16x16"/>
<title>Opinion Trends, now you can track belief shifts early. </title>
<meta name="description" content="Opinion Trends surfaces early belief shifts using live prediction market data." />
<link rel="stylesheet" href="trends.css" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@500;600&display=swap" rel="stylesheet">
<title>Opinion Trends.</title>
</head>
<body>
<div class="ambient-gradient"></div>
<nav class="navbar">
<div class="nav-left">
<img src="op1.png" alt="logo">
</div>
<div class="nav-center">
Opinion Trends
</div>
<div class="nav-right">
<button id="themeToggle" class="theme-toggle" type="button" aria-label="Toggle theme">
<!-- Sun -->
<svg class="icon sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
<path d="M12 18a6 6 0 1 0 0-12 6 6 0 0 0 0 12Z" stroke="currentColor"/>
<path d="M12 2v2" stroke="currentColor"/>
<path d="M12 20v2" stroke="currentColor"/>
<path d="M4.93 4.93l1.41 1.41" stroke="currentColor"/>
<path d="M17.66 17.66l1.41 1.41" stroke="currentColor"/>
<path d="M2 12h2" stroke="currentColor"/>
<path d="M20 12h2" stroke="currentColor"/>
<path d="M4.93 19.07l1.41-1.41" stroke="currentColor"/>
<path d="M17.66 6.34l1.41-1.41" stroke="currentColor"/>
</svg>
<!-- Moon (THIS ONE is balanced + same stroke style) -->
<svg class="icon moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
<path
d="M21 13.4A8 8 0 0 1 10.6 3a6.5 6.5 0 1 0 10.4 10.4Z"
stroke="currentColor"
/>
</svg>
</button>
</div>
</nav>
<main>
<section class="hero">
<h1>Explore what people are forming opinions on right now</h1>
<p>Based on activity across prediction markets.</p>
</section>
<section class="explore-box">
<div class="explore">
<input id="searchInput" placeholder="What’s trending?" />
<button>Explore</button>
</div>
</section>
<section class="cards hidden" id="cardsSection">
<h2>Trending now</h2>
<div class="card-grid" id="cardGrid"></div>
</section>
<section class="dive">
<p>
These signals represent collective belief movements before
they surface in headlines.
</p>
<a href="#">Explore deeper insights →</a>
</section>
</main>
<div id="detailPanel" class="detail-panel">
<div class="detail-header"></div>
<div id="detailContent" class="detail-content"></div>
<div class="detail-close" onclick="closePanel()" aria-label="Close panel">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<line x1="6" y1="6" x2="18" y2="18"/>
<line x1="6" y1="18" x2="18" y2="6"/>
</svg>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", async () => {
/* =========================
THEME TOGGLE
========================= */
function applyTheme(theme) {
document.documentElement.setAttribute("data-theme", theme);
}
function getPreferredTheme() {
const saved = localStorage.getItem("theme");
if (saved === "light" || saved === "dark") return saved;
// fallback to system preference
const prefersDark = window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
return prefersDark ? "dark" : "light";
}
// set initial theme immediately
applyTheme(getPreferredTheme());
// attach toggle listener
const themeBtn = document.getElementById("themeToggle");
themeBtn?.addEventListener("click", () => {
const current = document.documentElement.getAttribute("data-theme") || "light";
const next = current === "dark" ? "light" : "dark";
localStorage.setItem("theme", next);
applyTheme(next);
});
document.documentElement.setAttribute("data-theme", "light");
/* =========================
ELEMENTS
========================= */
const section = document.getElementById("cardsSection");
const container = document.getElementById("cardGrid");
const panel = document.getElementById("detailPanel");
const panelContent = document.getElementById("detailContent");
if (!section || !container || !panel || !panelContent) return;
section.classList.add("hidden");
container.innerHTML = "";
let markets = [];
let filteredMarkets = [];
let searchQuery = "";
const BRAND = "Opinion Trends";
const LIMIT = 30;
const REFRESH_MS = 60000;
const searchInput = document.getElementById("searchInput");
searchInput?.addEventListener("input", debounce((e) => {
searchQuery = e.target.value || "";
filteredMarkets = markets.filter(m => {
const title = normalize(m.marketTitle || "");
return title.includes(normalize(searchQuery));
});
renderMarkets();
}, 180));
/* =========================
FETCH
========================= */
async function fetchMarkets() {
const res = await fetch("/api/opinion", {
headers: { Accept: "application/json" }
});
if (!res.ok) throw new Error("API failed");
const json = await res.json();
return Array.isArray(json?.result?.list) ? json.result.list : [];
}
const shareCardCache = new WeakMap();
async function prepareShareCard(m, signal, v24) {
if (shareCardCache.has(m)) {
return shareCardCache.get(m);
}
const blob = await generateShareCard(m, signal, v24);
shareCardCache.set(m, blob);
return blob;
}
/* =========================
HELPERS
========================= */
function num(x) {
const n = Number(x);
return Number.isFinite(n) ? n : 0;
}
function money(n) {
return `$${Math.round(n).toLocaleString()}`;
}
function safeText(x, fallback = "") {
const t = (x ?? "").toString();
return t.trim().length ? t : fallback;
}
function getRules(m) {
return safeText(m.rules || m.resolveRules || m.resolutionRules || m.resolve_rules || m.resolution_rules, "");
}
function normalize(str) {
return (str || "")
.toString()
.toLowerCase()
.replace(/\s+/g, " ")
.trim();
}
function debounce(fn, delay = 200) {
let t;
return (...args) => {
clearTimeout(t);
t = setTimeout(() => fn(...args), delay);
};
}
function isActiveByCutoff(m) {
const cutoff = num(m.cutoffAt) * 1000;
if (!cutoff) return true; // if API doesn't provide cutoff, don't block
return cutoff > Date.now(); // only future markets
}
function getMarketUrl(m) {
if (m.url) return m.url;
const topicId =
m.topicId ||
m.topicID ||
m.marketTopicId ||
m.id ||
m.marketId;
if (!topicId) return "https://app.opinion.trade";
return `https://app.opinion.trade/detail?topicId=${topicId}`;
}
function getSignalTheme(signal) {
switch (signal) {
case "Exploding":
return {
bg: "#0A0E17",
glow: "rgba(255,120,0,0.55)",
badgeBg: "rgba(255,120,0,0.22)",
accent: "#FF7A00"
};
case "Accelerating":
return {
bg: "#0B0F19",
glow: "rgba(255,200,90,0.32)",
badgeBg: "rgba(255,200,90,0.18)",
accent: "#FBBF24"
};
case "Early":
return {
bg: "#0B0F19",
glow: "rgba(74,222,128,0.28)",
badgeBg: "rgba(74,222,128,0.16)",
accent: "#4ADE80"
};
case "Cooling":
return {
bg: "#0B0F19",
glow: "rgba(96,165,250,0.32)",
badgeBg: "rgba(96,165,250,0.18)",
accent: "#60A5FA"
};
default:
return {
bg: "#0B0F19",
glow: "rgba(255,255,255,0.12)",
badgeBg: "rgba(255,255,255,0.10)",
accent: "#E5E7EB"
};
}
}
async function generateShareCard(m, signal, v24) {
const W = 1080;
const H = 1080;
const theme = getSignalTheme(signal);
const canvas = document.createElement("canvas");
canvas.width = W;
canvas.height = H;
const ctx = canvas.getContext("2d");
/* =========================
BACKGROUND
========================= */
ctx.fillStyle = theme.bg;
ctx.fillRect(0, 0, W, H);
const glow = ctx.createRadialGradient(
W * 0.25,
H * 0.25,
40,
W * 0.25,
H * 0.25,
900
);
glow.addColorStop(0, theme.glow);
glow.addColorStop(1, "rgba(0,0,0,0)");
ctx.fillStyle = glow;
ctx.fillRect(0, 0, W, H);
/* =========================
CARD CONTAINER
========================= */
ctx.fillStyle = "rgba(255,255,255,0.06)";
roundRect(ctx, 90, 160, 900, 760, 44, true, false);
ctx.strokeStyle = "rgba(255,255,255,0.08)";
ctx.lineWidth = 1;
roundRect(ctx, 90, 160, 900, 760, 44, false, true);
/* =========================
BRAND
========================= */
ctx.fillStyle = "rgba(255,255,255,0.7)";
ctx.font = "600 32px Inter, sans-serif";
ctx.fillText("Opinion Trends", 130, 240);
/* =========================
SIGNAL BADGE
========================= */
ctx.fillStyle = theme.badgeBg;
roundRect(ctx, 130, 270, 240, 66, 999, true, false);
ctx.fillStyle = theme.accent;
ctx.font = "700 28px Inter, sans-serif";
ctx.fillText(signal.toUpperCase(), 165, 315);
/* =========================
TITLE
========================= */
ctx.fillStyle = "#FFFFFF";
ctx.font = "700 52px Manrope, sans-serif";
wrapText(ctx, m.marketTitle || "Untitled market", 130, 420, 820, 72, 3);
/* =========================
METRIC
========================= */
ctx.fillStyle = "rgba(255,255,255,0.78)";
ctx.font = "600 34px Inter, sans-serif";
ctx.fillText(`24h Volume: $${Math.round(v24).toLocaleString()}`, 130, 760);
/* =========================
FOOTER
========================= */
ctx.fillStyle = "rgba(255,255,255,0.14)";
ctx.fillRect(130, 810, 820, 2);
ctx.fillStyle = "rgba(255,255,255,0.6)";
ctx.font = "500 28px Inter, sans-serif";
ctx.fillText("Track belief shifts early.", 130, 870);
return new Promise((resolve) => {
canvas.toBlob(resolve, "image/jpeg", 0.92);
});
}
function roundRect(ctx, x, y, w, h, r, fill, stroke) {
if (typeof r === "number") r = { tl: r, tr: r, br: r, bl: r };
ctx.beginPath();
ctx.moveTo(x + r.tl, y);
ctx.lineTo(x + w - r.tr, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r.tr);
ctx.lineTo(x + w, y + h - r.br);
ctx.quadraticCurveTo(x + w, y + h, x + w - r.br, y + h);
ctx.lineTo(x + r.bl, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r.bl);
ctx.lineTo(x, y + r.tl);
ctx.quadraticCurveTo(x, y, x + r.tl, y);
ctx.closePath();
if (fill) ctx.fill();
if (stroke) ctx.stroke();
}
function wrapText(ctx, text, x, y, maxWidth, lineHeight, maxLines = 3) {
const words = (text || "").split(" ");
let line = "";
let lines = 0;
for (let i = 0; i < words.length; i++) {
const testLine = line + words[i] + " ";
const metrics = ctx.measureText(testLine);
if (metrics.width > maxWidth && i > 0) {
ctx.fillText(line.trim(), x, y);
line = words[i] + " ";
y += lineHeight;
lines++;
if (lines >= maxLines - 1) break;
} else {
line = testLine;
}
}
// last line
ctx.fillText(line.trim(), x, y);
}
/* =========================
SIGNAL (REAL, NOT MOCK)
Uses accel vs baseline, but DOES NOT affect ranking.
========================= */
function analyzeMarket(m) {
const v24 = num(m.volume24h);
const v7d = num(m.volume7d);
if (!v24) {
return { signal: "Quiet", accel: 0, deltaPct: 0, avg24: 0 };
}
if (!v7d) {
return { signal: "Active", accel: 0, deltaPct: 0, avg24: 0 };
}
const avg24 = v7d / 7;
const accel = avg24 ? (v24 - avg24) / avg24 : 0;
const deltaPct = avg24 ? ((v24 - avg24) / avg24) * 100 : 0;
let signal = "Quiet";
if (accel > 1.5) signal = "Exploding";
else if (accel > 0.6) signal = "Accelerating";
else if (accel > 0.2) signal = "Early";
else if (accel < -0.25) signal = "Cooling";
return { signal, accel, deltaPct, avg24 };
}
/* =========================
DETAIL PANEL (UPGRADED)
========================= */
function openDetailPanel(m) {
const v24 = num(m.volume24h);
const v7d = num(m.volume7d);
const vTotal = num(m.volume);
const { signal, deltaPct, avg24 } = analyzeMarket(m);
let why = "Steady attention with no unusual deviation from baseline.";
if (deltaPct > 80) why = "Attention is surging far above weekly baseline likely catalyst or narrative breakout.";
else if (deltaPct > 35) why = "Activity is meaningfully above baseline traders are re-pricing probability.";
else if (deltaPct < -35) why = "Attention is cooling the market may be reverting after a prior peak.";
const rawRules = getRules(m).trim();
const rulesSnippet = rawRules
? rawRules.slice(0, 520) + (rawRules.length > 520 ? "…" : "")
: "Resolution rules were not provided by the API for this market.";
const closesText = num(m.cutoffAt)
? new Date(num(m.cutoffAt) * 1000).toUTCString()
: "N/A";
const statusText = safeText(m.statusEnum || m.status, "Active");
const title = safeText(m.marketTitle, "Untitled market");
panelContent.innerHTML = `
<h3>${title}</h3>
<p class="why">
<strong>${signal}</strong> attention signal detected in the last 24 hours.
</p>
<div class="detail-metrics">
<div>
<span>24h volume</span>
<strong>${money(v24)}</strong>
</div>
<div>
<span>7d volume</span>
<strong>${money(v7d)}</strong>
</div>
<div>
<span>Total volume</span>
<strong>${money(vTotal)}</strong>
</div>
</div>
<p class="impact">
Why this matters: ${why}
</p>
<div class="detail-meta">
<strong>24h vs baseline:</strong>
${avg24 ? `${deltaPct > 0 ? "+" : ""}${Math.round(deltaPct)}%` : "N/A"}<br/>
<strong>Status:</strong> ${statusText}<br/>
<strong>Closes:</strong> ${closesText}
</div>
<div class="detail-meta">
<strong>How this market resolves</strong>
<p style="margin-top:10px; line-height:1.6;">
${rulesSnippet}
</p>
</div>
${
m.url
? `<a class="detail-link" href="${m.url}" target="_blank" rel="noopener">View market →</a>`
: ""
}
`;
panel.classList.add("active");
}
/* =========================
RENDER CARD
========================= */
function renderCard(m) {
const v24 = num(m.volume24h);
const { signal } = analyzeMarket(m);
const marketUrl = getMarketUrl(m);
const card = document.createElement("div");
card.dataset.signal = signal;
card.className = "trend-card";
card.setAttribute("role", "button");
card.setAttribute("tabindex", "0");
card.innerHTML = `
<div class="trend-tag">${signal}</div>
<div class="trend-title">${m.marketTitle || "Untitled market"}</div>
<div class="signal-row">
<span class="badge flat">24h Vol: ${money(v24)}</span>
<span class="source">${BRAND}</span>
</div>
<div class="card-actions">
<a class="action-link" href="${marketUrl}" target="_blank" rel="noopener">
Open market →
</a>
<button class="action-btn share-btn" type="button">Share</button>
<button class="action-btn dl-btn" type="button">Download</button>
</div>
`;
const shareBtn = card.querySelector(".share-btn");
const dlBtn = card.querySelector(".dl-btn");
const warmUp = () => {
// fire-and-forget
prepareShareCard(m, signal, v24).catch(() => {});
};
// Desktop
card.addEventListener("mouseenter", warmUp, { once: true });
// Keyboard / accessibility
card.addEventListener("focus", warmUp, { once: true });
// Mobile (first touch)
card.addEventListener("touchstart", warmUp, {
once: true,
passive: true
});
dlBtn?.addEventListener("click", async (e) => {
e.stopPropagation();
if (dlBtn.dataset.loading === "true") return;
dlBtn.dataset.loading = "true";
const originalText = dlBtn.textContent;
dlBtn.textContent = "Downloading…";
try {
const blob = await prepareShareCard(m, signal, v24);
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "opinion-trends.jpg";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 1500);
} catch (err) {
console.error("Download failed", err);
} finally {
dlBtn.dataset.loading = "false";
dlBtn.textContent = originalText;
}
});
// OPEN PANEL on card click
const open = () => openDetailPanel(m);
card.addEventListener("click", (e) => {
if (
e.target.closest(".share-btn") ||
e.target.closest(".dl-btn") ||
e.target.closest(".action-link")
) return;
open();
});
card.addEventListener("keydown", (e) => {
if (e.key === "Enter" || e.key === " ") open();
});
card.addEventListener("keypress", (e) => {
if (e.key === "Enter" || e.key === " ") open();
});
// SHARE logic
shareBtn?.addEventListener("click", async (e) => {
e.stopPropagation();
try {
const blob = await generateShareCard(m, signal, v24);
const file = new File([blob], "opinion-trends.jpg", { type: "image/jpeg" });
if (navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
text: `${m.marketTitle} — 24h Vol: ${money(v24)} (via Opinion Trends)`,
});
return;
}
// fallback: download
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "opinion-trends.jpg";
a.click();
URL.revokeObjectURL(url);
} catch (err) {
await navigator.clipboard.writeText(`${m.marketTitle}\n${marketUrl}`);
shareBtn.textContent = "Copied";
setTimeout(() => (shareBtn.textContent = "Share"), 1200);
}
});
// THIS WAS MISSING (critical)
container.appendChild(card);
}
/* =========================
RENDER MARKETS
- Filters past markets using cutoffAt
- Ranks by 24h volume only
========================= */
function renderMarkets() {
// animation should happen *every time renderMarkets runs*
container.classList.add("is-filtering");
container.innerHTML = "";
const q = normalize(searchQuery);
// Premium title behavior
const titleText = q ? `Results for “${q}”` : "Trending now";
const title = section.querySelector("h2");
if (title) title.textContent = titleText;
// IMPORTANT: choose list source correctly
const listToRender = q ? filteredMarkets : markets;
const ranked = [...listToRender]
.map(m => ({
market: m,
v24: num(m.volume24h)
}))
.filter(x => x.v24 > 0)
.filter(x => isActiveByCutoff(x.market))
.sort((a, b) => b.v24 - a.v24)
.slice(0, LIMIT);
if (!ranked.length) {
container.innerHTML = `
<p style="color:#64748B;margin-top:10px;">
No results found.
</p>
`;
// remove filter animation even if nothing renders
requestAnimationFrame(() => {
container.classList.remove("is-filtering");
});
return;
}
ranked.forEach(x => renderCard(x.market));
// remove filter class after rendering
requestAnimationFrame(() => {
container.classList.remove("is-filtering");
});
}
/* =========================
INIT
========================= */
async function load() {
try {
markets = await fetchMarkets();
filteredMarkets = markets;
renderMarkets();
if (!markets.length) {
section.innerHTML = `
<h2>Trending now</h2>
<p style="color:#64748B">No active markets available right now.</p>
`;
section.classList.remove("hidden");
return;
}
renderMarkets();
section.classList.remove("hidden");
} catch (err) {
console.error(err);
section.innerHTML = `
<h2>Trending now</h2>
<p style="color:#B45309">Unable to load live market data right now.</p>
`;
section.classList.remove("hidden");
}
}
load();
// LIVE REFRESH
setInterval(async () => {
try {
markets = await fetchMarkets();
renderMarkets();
} catch (e) {
// silently skip refresh
}
}, REFRESH_MS);
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") closePanel();
});
/* =========================
PANEL SLIDE WITH SPRING EASING
========================= */
const panel = document.getElementById("detailPanel");
function openPanel() {
if (!panel) return;
panel.classList.add("active");
// subtle spring effect
panel.style.transform = "translateY(105%)"; // start slightly below
requestAnimationFrame(() => {
panel.style.transition = "transform 0.35s cubic-bezier(0.22, 1, 0.36, 1)";
panel.style.transform = "translateY(0)";
});
// reveal content
const content = panel.querySelector(".detail-content");
if (content) content.style.opacity = "1";
}
function closePanel() {
if (!panel) return;
panel.style.transition = "transform 0.35s cubic-bezier(0.22, 1, 0.36, 1)";
panel.style.transform = "translateY(105%)";
// hide content
const content = panel.querySelector(".detail-content");
if (content) content.style.opacity = "0";
// remove active class after animation
panel.addEventListener(
"transitionend",
() => {
panel.classList.remove("active");
panel.style.transition = "";
},
{ once: true }
);
}
/* =========================
ESCAPE KEY TO CLOSE
========================= */
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") closePanel();
});
/* =========================
CLOSE PANEL
========================= */
function closePanel() {
const panel = document.getElementById("detailPanel");
panel.classList.remove("active");
}
</script>
</body>
</html>