Skip to content

Commit ef9cd4c

Browse files
committed
image expando
1 parent f1aa494 commit ef9cd4c

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

assets/script.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ document.querySelectorAll('.js-more-info').forEach(elem => {
9090
.then(response => response.text())
9191
.then(data => {
9292
infoContainer.innerHTML = data;
93+
// Add event listeners to any new expandable images
94+
addExpandableImageListeners(infoContainer);
9395
})
9496
.catch(error => {
9597
infoContainer.innerHTML = '<div class="error">Failed to load info</div>';
@@ -101,3 +103,47 @@ document.querySelectorAll('.js-more-info').forEach(elem => {
101103
}
102104
});
103105
});
106+
107+
// Function to add expandable image listeners to elements
108+
function addExpandableImageListeners(container = document) {
109+
container.querySelectorAll('.expandable-image').forEach(img => {
110+
// Only add listener if not already added
111+
if (!img.hasAttribute('data-expandable-listener')) {
112+
img.setAttribute('data-expandable-listener', 'true');
113+
img.addEventListener('click', function() {
114+
// Create overlay if it doesn't exist
115+
let overlay = document.querySelector('.image-overlay');
116+
if (!overlay) {
117+
overlay = document.createElement('div');
118+
overlay.className = 'image-overlay';
119+
document.body.appendChild(overlay);
120+
121+
// Add click event to close overlay
122+
overlay.addEventListener('click', function() {
123+
this.classList.remove('expanded');
124+
});
125+
}
126+
127+
// Create and add the expanded image
128+
const expandedImg = document.createElement('img');
129+
expandedImg.src = this.src;
130+
expandedImg.alt = this.alt || 'Expanded image';
131+
132+
// Clear previous content and add new image
133+
overlay.innerHTML = '';
134+
overlay.appendChild(expandedImg);
135+
136+
// Show the overlay
137+
overlay.classList.add('expanded');
138+
139+
// Prevent event bubbling
140+
expandedImg.addEventListener('click', function(e) {
141+
e.stopPropagation();
142+
});
143+
});
144+
}
145+
});
146+
}
147+
148+
// Initial setup for expandable images
149+
addExpandableImageListeners();

assets/style.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,39 @@ table {
225225
box-shadow: 0 2.5em 0 0;
226226
}
227227
}
228+
229+
/* Image expansion styles */
230+
.expandable-image {
231+
cursor: pointer;
232+
transition: transform 0.2s ease;
233+
}
234+
235+
.expandable-image:hover {
236+
transform: scale(1.02);
237+
}
238+
239+
.image-overlay {
240+
position: fixed;
241+
top: 0;
242+
left: 0;
243+
width: 100%;
244+
height: 100%;
245+
background-color: rgba(0, 0, 0, 0.9);
246+
display: none;
247+
justify-content: center;
248+
align-items: center;
249+
z-index: 1000;
250+
cursor: pointer;
251+
}
252+
253+
.image-overlay.expanded {
254+
display: flex;
255+
}
256+
257+
.image-overlay img {
258+
max-width: 90%;
259+
max-height: 90%;
260+
object-fit: contain;
261+
border-radius: 8px;
262+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
263+
}

templates/artist.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% block body %}
33
<div class="row">
44
<div class="three columns">
5-
<img src="{{ results.image }}" width='100%'/>
5+
<img src="{{ results.image }}" width='100%' class="expandable-image"/>
66
</div>
77
<div class="nine columns">
88
<div class="artist-desc js-artist-desc">

templates/group_info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="row">
22
<div class="three columns">
3-
<img src="{{ group_info.wikiImage }}" width='100%'>
3+
<img src="{{ group_info.wikiImage }}" width='100%' class="expandable-image">
44
</div>
55
<div class="six columns">
66
{{ group_info.wikiBody | safe}}

0 commit comments

Comments
 (0)