Skip to content

Commit

Permalink
Add photoswipe lightbox for images in blog articles.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenchio committed Dec 19, 2024
1 parent 4d7589d commit a2dfe2c
Show file tree
Hide file tree
Showing 5 changed files with 449 additions and 0 deletions.
4 changes: 4 additions & 0 deletions layouts/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<script type="module">
import '/js/prettify.js';
</script>
<script src="/vendor/photoswipe-lightbox.umd.min.js"></script>
<script src="/vendor/photoswipe.umd.min.js"></script>
<link rel="stylesheet" href="/vendor/photoswipe.css">
<script src="/js/lightbox.js"></script>
<div class="page article">
<div class="article--back">
<a class="article--back-link" href="/blog/">
Expand Down
15 changes: 15 additions & 0 deletions static/js/lightbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
window.addEventListener("load", function () {
document.querySelectorAll('img').forEach(function (img) {
if (img.parentNode.tagName === "A") {
img.parentNode.setAttribute("data-pswp-width", img.naturalWidth);
img.parentNode.setAttribute("data-pswp-height", img.naturalHeight);
}
});

const options = {
gallery: '.narrow-container a',
pswpModule: PhotoSwipe
};
const lightbox = new PhotoSwipeLightbox(options);
lightbox.init();
});
5 changes: 5 additions & 0 deletions static/vendor/photoswipe-lightbox.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a2dfe2c

Please sign in to comment.