Skip to content

Commit 0ef9bc7

Browse files
committed
make gallery pics clickable to enlarge
1 parent f22ed50 commit 0ef9bc7

4 files changed

Lines changed: 82 additions & 7 deletions

File tree

_layout/head.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<meta name="google-site-verification" content="9CIsKebPd-hNdMScya0EZx2Z_GtQ9g3yDXmpbgs2mrU" />
76

87
{{insert basic/stylesheets.html}}
98

_libs/scripts/gallery-modal.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var modal = document.getElementById("galleryModal");
2+
var span = document.getElementsByClassName("close")[0];
3+
var images = document.querySelectorAll(".gallery-img img");
4+
var originalParent = null;
5+
var currentImage = null;
6+
7+
images.forEach(function (img) {
8+
img.style.cursor = "pointer";
9+
img.onclick = function (e) {
10+
e.preventDefault();
11+
modal.style.display = "block";
12+
// Move the image to the modal
13+
originalParent = img.parentNode;
14+
currentImage = img;
15+
modal.appendChild(img);
16+
};
17+
});
18+
19+
span.onclick = function () {
20+
modal.style.display = "none";
21+
// Move the image back to its original parent
22+
if (originalParent && currentImage) {
23+
originalParent.appendChild(currentImage);
24+
}
25+
};

_sass/gallery.scss

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,43 @@
4444
}
4545
}
4646

47+
.gallery-modal {
48+
display: none;
49+
position: fixed;
50+
z-index: 1;
51+
padding-top: 1%;
52+
left: 0;
53+
top: 0;
54+
width: 100%;
55+
height: 100%;
56+
overflow: auto;
57+
background-color: rgba(0, 0, 0, 0.9);
58+
59+
img {
60+
margin: auto;
61+
display: block;
62+
height: 95%;
63+
width: auto;
64+
}
65+
66+
.close {
67+
position: absolute;
68+
top: 15px;
69+
right: 35px;
70+
color: #f1f1f1;
71+
font-size: 40px;
72+
font-weight: bold;
73+
transition: 0.3s;
74+
}
75+
76+
.close:hover,
77+
.close:focus {
78+
color: #bbb;
79+
text-decoration: none;
80+
cursor: pointer;
81+
}
82+
}
83+
4784
/* Responsive columns */
4885
@media (max-width: 1024px) {
4986
.gallery-wrapper {
@@ -60,4 +97,13 @@
6097
.gallery-img img {
6198
height: 160px; /* slightly smaller on mobile */
6299
}
100+
101+
.gallery-modal {
102+
padding-top: 20%;
103+
104+
img {
105+
width: 80%;
106+
height: auto;
107+
}
108+
}
63109
}

utils/gallery.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ function add_gallery_item(io, obj::GalleryItem)
2222
)
2323
end
2424

25-
function parse_gallery_item(item)
26-
27-
28-
obj
29-
end
30-
3125
@lx function makeGallery(img_dir)
3226
io = IOBuffer()
3327

@@ -54,5 +48,16 @@ end
5448

5549
write(io, "</div>")
5650

51+
write(
52+
io,
53+
"""
54+
<div id="galleryModal" class="gallery-modal">
55+
<span class="close">&times;</span>
56+
</div>
57+
"""
58+
)
59+
60+
write(io, """<script src="/libs/scripts/gallery-modal.js"></script>""")
61+
5762
take!(io) |> String |> html
5863
end

0 commit comments

Comments
 (0)