Skip to content

Commit

Permalink
Fix lightbox initialization to not wrap images out of content.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenchio committed Dec 25, 2024
1 parent 29029be commit d2a23f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 4 additions & 2 deletions layouts/blog/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ <h1 class="article--title">{{ .Title }}</h1>

<div class="article--follow">
<div>Follow us:</div>
ку <a href="https://www.linkedin.com/company/ivelum/" target="_blank">
<a href="https://www.linkedin.com/company/ivelum/" target="_blank">
<img src="{{ (resources.Get "img/ico-linkedin.svg").RelPermalink }}" />
</a>
</div>
</div>
{{ .Content }}
<div class="article--content">
{{ .Content }}
</div>
{{/* partial "blog-subscribe-form.html" . */}}
</article>
{{ partial "blog-navigation.html" . }}
Expand Down
25 changes: 14 additions & 11 deletions static/js/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ window.addEventListener("load", function () {
document.head.appendChild(link);

link.href = '/vendor/photoswipe.css';
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);
document
.getElementsByClassName("article--content")[0]
.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 lightbox = new PhotoSwipeLightbox({
gallery: img.parentNode,
pswpModule: PhotoSwipe
});
lightbox.init();
}
});
const lightbox = new PhotoSwipeLightbox({
gallery: img.parentNode,
pswpModule: PhotoSwipe
});
lightbox.init();
}
});
});

0 comments on commit d2a23f4

Please sign in to comment.