Skip to content

Commit

Permalink
Add photoswipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jgthms committed Jun 11, 2024
1 parent 6cebea9 commit b84d168
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 12 additions & 1 deletion docs/assets/javascript/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,22 @@ document.addEventListener("DOMContentLoaded", () => {

if (images) {
images.forEach(img => {
const $figure = El("shop-product-image image is-square", "figure");
const $figure = El("shop-product-image image is-square", "a");
$figure.href = img.url;
$figure.dataset.pswpHeight = img.height;
$figure.dataset.pswpWidth = img.width;
$figure.target = "_blank";
const $img = document.createElement("img");
$img.src = img.url;
$figure.appendChild($img);
$carousel.appendChild($figure);

const lightbox = new window.PhotoSwipeLightbox({
gallery: '.shop-product-image',
pswpModule: window.PhotoSwipe
});

lightbox.init();
});

$images.appendChild($carousel);
Expand Down
9 changes: 7 additions & 2 deletions docs/shop.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- shop
---

<link rel="stylesheet" type="text/css" href="https://unpkg.com/[email protected]/dist/photoswipe.css">

<style type="text/css">
:root {
--shop-duration: 500ms;
Expand Down Expand Up @@ -287,8 +289,9 @@

.shop-product-image {
flex-shrink: 0;
cursor: pointer;
cursor: zoom-in;
overflow: hidden;
outline: none !important;
}

.shop-product-image img {
Expand All @@ -298,7 +301,7 @@
}

.shop-product-images:hover img {
transform: scale(1.1);
transform: scale(1.04);
}

.shop-product-heading {
Expand Down Expand Up @@ -496,4 +499,6 @@ <h2 class="bd-hero-subtitle algolia-lvl1">
</div>

<script src="https://unpkg.com/@shopify/[email protected]/dist/umd/storefront-api-client.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/umd/photoswipe.umd.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/umd/photoswipe-lightbox.umd.min.js"></script>
<script type="text/javascript" src="{{ site.url }}/assets/javascript/shop.js"></script>

0 comments on commit b84d168

Please sign in to comment.