Skip to content

Commit bf55433

Browse files
Copilotbrunoborges
andcommitted
Add expand/collapse all cards feature with toggle button
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent e414bdd commit bf55433

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

site/app.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@
211211
// Only handle touches on the card-code area
212212
if (!e.target.closest('.card-code')) return;
213213

214+
// Don't handle touch events when in expanded mode
215+
const tipsGrid = document.getElementById('tipsGrid');
216+
if (tipsGrid && tipsGrid.classList.contains('expanded')) {
217+
return;
218+
}
219+
214220
touchEndX = e.changedTouches[0].clientX;
215221
touchEndY = e.changedTouches[0].clientY;
216222

@@ -245,6 +251,11 @@
245251
// This is a safety net in case touch events trigger click as fallback
246252
card.addEventListener('click', (e) => {
247253
if (e.target.closest('.card-code')) {
254+
// Don't prevent navigation when in expanded mode
255+
const tipsGrid = document.getElementById('tipsGrid');
256+
if (tipsGrid && tipsGrid.classList.contains('expanded')) {
257+
return;
258+
}
248259
e.preventDefault();
249260
e.stopPropagation();
250261
}
@@ -470,6 +481,36 @@
470481
});
471482
};
472483

484+
/* ==========================================================
485+
6. View Toggle (Expand/Collapse All Cards)
486+
========================================================== */
487+
const initViewToggle = () => {
488+
const toggleBtn = document.getElementById('viewToggle');
489+
const tipsGrid = document.getElementById('tipsGrid');
490+
if (!toggleBtn || !tipsGrid) return;
491+
492+
let isExpanded = false;
493+
494+
toggleBtn.addEventListener('click', () => {
495+
isExpanded = !isExpanded;
496+
497+
if (isExpanded) {
498+
tipsGrid.classList.add('expanded');
499+
toggleBtn.querySelector('.view-toggle-icon').textContent = '⊞';
500+
toggleBtn.querySelector('.view-toggle-text').textContent = 'Collapse All';
501+
502+
// Remove toggled class from all cards when expanding
503+
document.querySelectorAll('.tip-card').forEach(card => {
504+
card.classList.remove('toggled');
505+
});
506+
} else {
507+
tipsGrid.classList.remove('expanded');
508+
toggleBtn.querySelector('.view-toggle-icon').textContent = '⊟';
509+
toggleBtn.querySelector('.view-toggle-text').textContent = 'Expand All';
510+
}
511+
});
512+
};
513+
473514
/* ==========================================================
474515
Utilities
475516
========================================================== */
@@ -488,6 +529,7 @@
488529
});
489530
initFilters();
490531
initCardToggle();
532+
initViewToggle();
491533
initCopyButtons();
492534
initSyntaxHighlighting();
493535
initNewsletter();

site/styles.css

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,81 @@ nav {
589589
gap: 8px;
590590
}
591591

592+
/* ---------- View Toggle Button ---------- */
593+
.view-toggle-wrap {
594+
display: flex;
595+
justify-content: center;
596+
margin: 16px 0;
597+
}
598+
599+
.view-toggle-btn {
600+
display: inline-flex;
601+
align-items: center;
602+
gap: 8px;
603+
padding: 10px 20px;
604+
font-size: 0.88rem;
605+
font-weight: 500;
606+
color: var(--text);
607+
background: var(--surface);
608+
border: 1px solid var(--border);
609+
border-radius: var(--radius-sm);
610+
cursor: pointer;
611+
transition: all 0.25s;
612+
}
613+
614+
.view-toggle-btn:hover {
615+
background: var(--surface-2);
616+
border-color: var(--border-light);
617+
transform: translateY(-2px);
618+
}
619+
620+
.view-toggle-icon {
621+
font-size: 1.1rem;
622+
line-height: 1;
623+
}
624+
625+
/* ---------- Expanded Mode ---------- */
626+
.tips-grid.expanded .tip-card {
627+
pointer-events: auto;
628+
}
629+
630+
.tips-grid.expanded .tip-card:hover {
631+
transform: none;
632+
box-shadow: none;
633+
}
634+
635+
.tips-grid.expanded .tip-card .card-code {
636+
display: flex;
637+
flex-direction: column;
638+
}
639+
640+
.tips-grid.expanded .tip-card .old-layer,
641+
.tips-grid.expanded .tip-card .modern-layer {
642+
position: static;
643+
opacity: 1;
644+
min-height: auto;
645+
border-top: 1px solid var(--border);
646+
}
647+
648+
.tips-grid.expanded .tip-card .old-layer {
649+
border-top: none;
650+
}
651+
652+
.tips-grid.expanded .tip-card .hover-hint {
653+
display: none;
654+
}
655+
656+
/* Disable hover effects in expanded mode */
657+
.tips-grid.expanded .tip-card:hover .old-layer,
658+
.tips-grid.expanded .tip-card.toggled .old-layer {
659+
opacity: 1;
660+
}
661+
662+
.tips-grid.expanded .tip-card:hover .modern-layer,
663+
.tips-grid.expanded .tip-card.toggled .modern-layer {
664+
opacity: 1;
665+
}
666+
592667
/* ---------- Stats Bar ---------- */
593668
.stats-bar {
594669
display: flex;

templates/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ <h2 class="section-title">All comparisons</h2>
240240
<button class="filter-pill" data-filter="security">Security</button>
241241
<button class="filter-pill" data-filter="tooling">Tooling</button>
242242
</div>
243+
<div class="view-toggle-wrap">
244+
<button class="view-toggle-btn" id="viewToggle" aria-label="Toggle view mode">
245+
<span class="view-toggle-icon"></span>
246+
<span class="view-toggle-text">Expand All</span>
247+
</button>
248+
</div>
243249
<div class="tips-grid" id="tipsGrid">
244250
{{tipCards}}
245251
</div>

0 commit comments

Comments
 (0)