From f9c4cf44d61daef0f1ad177209f513a8b4b4ffb7 Mon Sep 17 00:00:00 2001 From: NoahPeeters Date: Sat, 4 Jul 2020 00:09:48 +0200 Subject: [PATCH] Provide option to exclude img from photoswipe Hides all images with the attribute `photoswipe="false"`. --- layouts/partials/body/photoswipe.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/layouts/partials/body/photoswipe.html b/layouts/partials/body/photoswipe.html index fa94498..102c4a7 100644 --- a/layouts/partials/body/photoswipe.html +++ b/layouts/partials/body/photoswipe.html @@ -99,7 +99,6 @@ document.addEventListener('DOMContentLoaded', function () { var captionElem = document.querySelector('.modal__caption'); var pagingElem = document.querySelector('.modal__paging'); var itemsElem = document.querySelector('.modal__items'); - var imgTotalNum = null; var myFadeTimeout = null; var mySwipe = null; var keydownFunction = function (e) { @@ -114,13 +113,19 @@ document.addEventListener('DOMContentLoaded', function () { } } - if (galleryContainerElem) { - imgTotalNum = galleryContainerElem.querySelectorAll('img').length; - } else { + if (!galleryContainerElem) { galleryContainerElem = document.querySelector('.single__contents'); - imgTotalNum = galleryContainerElem.querySelectorAll('img').length; } + var allImages = []; + galleryContainerElem.querySelectorAll('img').forEach(function (elem) { + if (elem.getAttribute('photoswipe') != "false") { + allImages.push(elem); + } + }); + + var imgTotalNum = allImages.length; + MicroModal.init({ onClose: function () { if (mySwipe) { @@ -148,7 +153,7 @@ document.addEventListener('DOMContentLoaded', function () { }); } - galleryContainerElem.querySelectorAll('img').forEach(function (elem, idx) { + allImages.forEach(function (elem, idx) { elem.style.cursor = 'pointer'; var clonedElem = elem.cloneNode(true);