Skip to content

Commit 761e47e

Browse files
committed
Update templates-listing block
1 parent acce916 commit 761e47e

File tree

2 files changed

+105
-14
lines changed

2 files changed

+105
-14
lines changed

blocks/templates-listing/templates-listing.css

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
transform-style: preserve-3d;
7272
transition: transform 0.6s ease-in-out;
7373
border-radius: 10px;
74-
/* overflow: hidden; */
7574
}
7675

7776
.templates-listing .cards-card-image-flip .flip-inner.flipped {
@@ -106,7 +105,7 @@
106105

107106
/* === Back side of the image (resources) === */
108107
.templates-listing .cards-card-image-flip .flip-back {
109-
background-color: #333333; /* <- Dark background fix */
108+
background-color: #333333;
110109
transform: rotateY(180deg);
111110
display: flex;
112111
justify-content: center;
@@ -123,7 +122,7 @@
123122
height: 100%;
124123
gap: 10px;
125124
color: #fff;
126-
padding: 1rem;
125+
padding: 1.5em;
127126
}
128127

129128
.templates-listing .cards-card-image-flip .flip-back .resources .tags {
@@ -158,7 +157,7 @@
158157
.templates-listing .cards-card-image-flip .flip-back .resources img {
159158
width: 60px;
160159
height: auto;
161-
filter: brightness(0) invert(1); /* makes the icon pop on dark background */
160+
filter: brightness(0) invert(1);
162161
}
163162

164163
/* === Hide legacy resources section === */
@@ -177,3 +176,56 @@
177176
height: 475px;
178177
}
179178
}
179+
180+
/* === Modal Styles === */
181+
.tag-modal {
182+
display: none;
183+
position: fixed;
184+
z-index: 9999;
185+
left: 0; top: 0; right: 0; bottom: 0;
186+
background-color: rgba(0, 0, 0, 0.7);
187+
justify-content: center;
188+
align-items: center;
189+
}
190+
191+
.tag-modal.show {
192+
display: flex;
193+
}
194+
195+
.tag-modal-content {
196+
background: white;
197+
padding: 2em;
198+
border-radius: 8px;
199+
max-width: 600px;
200+
width: 90%;
201+
position: relative;
202+
box-shadow: 0 0 25px rgba(0, 0, 0, 0.3);
203+
max-height: 90vh;
204+
overflow-y: auto;
205+
}
206+
207+
.tag-modal-close {
208+
position: absolute;
209+
top: 0.5em;
210+
right: 1em;
211+
font-size: 1.5em;
212+
font-weight: bold;
213+
cursor: pointer;
214+
color: #999;
215+
}
216+
217+
.tag-modal-close:hover {
218+
color: #000;
219+
}
220+
221+
.tag-modal-body img {
222+
margin-top: 1em;
223+
max-width: 100%;
224+
border-radius: 6px;
225+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
226+
}
227+
228+
.tag-modal-body a {
229+
word-break: break-all;
230+
font-size: 0.9rem;
231+
}

blocks/templates-listing/templates-listing.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1+
/* eslint-disable */
12
import { createOptimizedPicture } from '../../scripts/aem.js';
23

34
export default async function decorate(block) {
45
const spreadsheetLink = block.querySelector('a')?.href;
56
block.textContent = '';
67

8+
// Create and append a global modal to the body (once)
9+
const tagModal = document.createElement('div');
10+
tagModal.className = 'tag-modal';
11+
tagModal.innerHTML = `
12+
<div class="tag-modal-content">
13+
<span class="tag-modal-close">&times;</span>
14+
<div class="tag-modal-body">
15+
<p>Loading...</p>
16+
</div>
17+
</div>
18+
`;
19+
document.body.appendChild(tagModal);
20+
21+
// Close modal on clicking close button
22+
tagModal.querySelector('.tag-modal-close').addEventListener('click', () => {
23+
tagModal.classList.remove('show');
24+
tagModal.querySelector('.tag-modal-body').innerHTML = '<p>Loading...</p>';
25+
});
26+
727
async function fetchJson(link) {
828
const response = await fetch(link);
929
if (response.ok) {
@@ -19,17 +39,14 @@ export default async function decorate(block) {
1939
const displayAdAssets = [];
2040
const metaAdAssets = [];
2141

22-
// Email assets
2342
if (item.Email1Pod) emailAssets.push({ key: 'Email1Pod', value: item.Email1Pod });
2443
if (item.Email2Pod) emailAssets.push({ key: 'Email2Pod', value: item.Email2Pod });
2544
if (item.Email3Pod) emailAssets.push({ key: 'Email3Pod', value: item.Email3Pod });
2645

27-
// Display Ad assets
2846
if (item.DisplayAd300x600) displayAdAssets.push({ key: 'DisplayAd300x600', value: item.DisplayAd300x600 });
2947
if (item.DisplayAd300x250) displayAdAssets.push({ key: 'DisplayAd300x250', value: item.DisplayAd300x250 });
3048
if (item.DisplayAd970x250) displayAdAssets.push({ key: 'DisplayAd970x250', value: item.DisplayAd970x250 });
3149

32-
// Meta Ad assets
3350
if (item.MetaAd1x1) metaAdAssets.push({ key: 'MetaAd1x1', value: item.MetaAd1x1 });
3451
if (item.MetaAd4x5) metaAdAssets.push({ key: 'MetaAd4x5', value: item.MetaAd4x5 });
3552
if (item.MetaAd9x16) metaAdAssets.push({ key: 'MetaAd9x16', value: item.MetaAd9x16 });
@@ -46,8 +63,6 @@ export default async function decorate(block) {
4663
function createCards(data) {
4764
const ul = document.createElement('ul');
4865

49-
console.log("data: ", data);
50-
5166
data.forEach((item) => {
5267
const hasDisplayAd = item.DisplayAd === 'true';
5368
const hasEmail = item.Email === 'true';
@@ -83,7 +98,7 @@ export default async function decorate(block) {
8398
` : ''}
8499
85100
${item.displayAdAssets.length ? `
86-
<div template-type>
101+
<div class="template-type">
87102
Display Ad
88103
<div class="tags">
89104
${item.displayAdAssets.map((asset) => `<span class="tag tag-display" title="${asset.key}" data-src="${asset.value}">${asset.key}</span>`).join('')}
@@ -92,15 +107,14 @@ export default async function decorate(block) {
92107
` : ''}
93108
94109
${item.metaAdAssets.length ? `
95-
<div template-type>
110+
<div class="template-type">
96111
Meta Ad
97112
<div class="tags">
98113
${item.metaAdAssets.map((asset) => `<span class="tag tag-meta" title="${asset.key}" data-src="${asset.value}">${asset.key}</span>`).join('')}
99114
</div>
100115
</div>
101116
` : ''}
102117
</div>
103-
104118
</div>
105119
</div>
106120
</div>
@@ -115,20 +129,45 @@ export default async function decorate(block) {
115129
</div>
116130
`;
117131

132+
// Flip interaction
118133
li.addEventListener('click', () => {
119-
// Unflip any currently flipped cards
120134
const allFlipped = ul.querySelectorAll('.flip-inner.flipped');
121135
allFlipped.forEach((flipped) => {
122136
if (flipped !== li.querySelector('.flip-inner')) {
123137
flipped.classList.remove('flipped');
124138
}
125139
});
126140

127-
// Toggle flip on the current card
128141
const flipContainer = li.querySelector('.flip-inner');
129142
flipContainer.classList.toggle('flipped');
130143
});
131144

145+
// Modal tag interaction
146+
li.querySelectorAll('.tag').forEach((tagEl) => {
147+
tagEl.addEventListener('click', (e) => {
148+
e.stopPropagation();
149+
150+
const assetTitle = tagEl.getAttribute('title');
151+
const assetSrc = tagEl.getAttribute('data-src');
152+
153+
const modalBody = tagModal.querySelector('.tag-modal-body');
154+
modalBody.innerHTML = `
155+
<h3>${assetTitle}</h3>
156+
${
157+
assetSrc.match(/\.(jpg|jpeg|png|gif|webp)$/i)
158+
? `<img src="${assetSrc}"
159+
alt="${assetTitle}"
160+
loading="eager"
161+
decoding="async"
162+
style="max-width: 100%; margin-top: 1em;">`
163+
: `<p><em>Preview unavailable</em></p>`
164+
}
165+
`;
166+
167+
tagModal.classList.add('show');
168+
});
169+
});
170+
132171
ul.append(li);
133172
});
134173

0 commit comments

Comments
 (0)