Compare commits

...

6 Commits

6 changed files with 141 additions and 74 deletions

View File

@@ -1,20 +1,36 @@
.snap-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
gap: 10px;
$gap: var(--gap);
.snap-gallery-wrapper, .snap-slideshow-wrapper {
margin-bottom: $gap;
/* Create equal columns in flexbox */
.snap-image {
cursor: pointer;
/* Column amount and width are configurable by style variables */
width: calc(100% / var(--columns) - #{$gap});
min-width: var(--min-width);
img {
aspect-ratio: 16/10;
width: 100%;
object-fit: cover;
}
}
}
/* Create equal columns in flexbox */
.snap-image {
// TODO: Make this configurable with variables
width: calc(100% / 4 - 10px);
min-width: 200px;
.snap-gallery-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: $gap;
}
img {
aspect-ratio: 16/10;
width: 100%;
object-fit: cover;
.snap-slideshow-wrapper {
// Hide all contained images except the first
.snap-image:not(:first-child) {
display: none;
}
}
@@ -108,6 +124,7 @@
height: 100%;
text-align: center;
top: 0;
cursor: pointer;
.snap-lightbox-arrow {
display: inline-block;

View File

@@ -0,0 +1,9 @@
{{ $imgs := .imgs }}
{{ $galno := .galno }}
<div class="snap-gallery-wrapper" style="--columns:{{ default 4 .columns }};--min-width:{{ default 200 .minwidth }};--gap:10px;">
{{ range $i, $img := $imgs }}
<div class="snap-image">
<img src="{{ $img }}" onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});">
</div>
{{ end }}
</div>

View File

@@ -0,0 +1,21 @@
{{ $imgs := .imgs }}
{{ $galno := .galno }}
<div class="snap-lightbox" id="snap-lightbox-{{ $galno }}">
{{ range $i, $img := $imgs }}
<div class="snap-lightbox-inner">
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
<img src="{{ $img }}" style="width:100%">
</div>
{{ end }}
<!-- Close and Next/previous controls -->
<span class="snap-close" onclick="closeLightbox({{ $galno }})">&times;</span>
<a class="snap-lightbox-prev" onclick="moveLightboxItem({{ $galno }}, -1)"><i class="snap-lightbox-arrow"></i></a>
<a class="snap-lightbox-next" onclick="moveLightboxItem({{ $galno }}, 1)"><i class="snap-lightbox-arrow"></i></a>
{{/* <!-- Caption text -->
<div class="caption-container">
<p id="caption"></p>
</div> */}}
</div>

View File

@@ -0,0 +1,12 @@
{{ $imgs := .imgs }}
{{ $galno := .galno }}
<div class="snap-slideshow-wrapper" id="snap-slideshow-{{ $galno }}" style="--columns:1;--min-width:0px;--gap:0px;">
{{ range $i, $img := $imgs }}
<div class="snap-image">
<img src="{{ $img }}" onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});">
</div>
{{ end }}
</div>
<a onclick="moveSlideshowItem({{ $galno }}, -1)">prev</a>
<a onclick="moveSlideshowItem({{ $galno }}, 1)">next</a>

View File

@@ -2,6 +2,17 @@
{{- $.Page.Scratch.Add "gallerycount" 1 -}}
{{ $galno := $.Page.Scratch.Get "gallerycount" }}
{{/* Load CSS/JS and make sure it is only loaded once */}}
{{- if eq ($.Page.Scratch.Get "gallerycount") 1 }}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{- end }}
<script src="/js/snap-gallery.js"></script>
{{ end }}
{{/* Initialise index of this gallery */}}
<script>imageIndex[{{ $galno }}] = 1;</script>
{{/* Initialise variables holding image paths */}}
{{ $imgs := slice }}
@@ -19,41 +30,17 @@
{{ end }}
{{ end }}
{{/* Visible images */}}
<div class="snap-wrapper">
{{ range $i, $img := $imgs }}
<div class="snap-image">
<img src="{{ $img }}" onclick="openModal({{ $galno }});currentSlide({{ $galno }}, {{ add $i 1 }});" class="hover-shadow">
</div>
{{/* Visible images in separate modes */}}
{{ $mode := default "gallery" .Params.mode }}
{{/* Gallery mode */}}
{{ if eq $mode "gallery" }}
{{ partial "gallery" (dict "columns" .Params.columns "minwidth" .Params.minwidth "imgs" $imgs "galno" $galno) }}
{{/* Slideshow mode */}}
{{ else if eq $mode "slideshow" }}
{{ partial "slideshow" (dict "imgs" $imgs "galno" $galno) }}
{{/* Set autorotate timer for slideshow */}}
<script>setInterval(moveSlideshowItem, 5000, {{ $galno }}, 1);</script>
{{ end }}
</div>
{{/* The Modal/Lightbox */}}
<div class="snap-lightbox" id="snap-lightbox-{{ $galno }}">
{{ range $i, $img := $imgs }}
<div class="snap-lightbox-inner">
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
<img src="{{ $img }}" style="width:100%">
</div>
{{ end }}
<!-- Close and Next/previous controls -->
<span class="snap-close" onclick="closeModal({{ $galno }})">&times;</span>
<a class="snap-lightbox-prev" onclick="plusSlides({{ $galno }}, -1)"><i class="snap-lightbox-arrow"></i></a>
<a class="snap-lightbox-next" onclick="plusSlides({{ $galno }}, 1)"><i class="snap-lightbox-arrow"></i></a>
{{/* <!-- Caption text -->
<div class="caption-container">
<p id="caption"></p>
</div> */}}
</div>
{{/* Load CSS/JS and make sure it is only loaded once */}}
{{- if eq ($.Page.Scratch.Get "gallerycount") 1 }}
{{- with resources.Get "scss/snap-gallery.scss" | toCSS }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{- end }}
<script src="/js/snap-gallery.js"></script>
{{ end }}
{{ partial "lightbox" (dict "galno" $galno "imgs" $imgs) }}

View File

@@ -1,36 +1,57 @@
// Open the Modal
function openModal(id) {
document.getElementById(baseid + id).style.display = "block";
// Variables
var lightbox_baseid = "snap-lightbox-";
var slideshow_baseid = "snap-slideshow-";
//var imageIndex = {1: 1, 2: 1, 3: 1};
var imageIndex = {}
// Open the Lightbox
function openLightbox(id) {
document.getElementById(lightbox_baseid + id).style.display = "block";
}
// Close the Modal
function closeModal(id) {
document.getElementById(baseid + id).style.display = "none";
// Close the Lightbox
function closeLightbox(id) {
document.getElementById(lightbox_baseid + id).style.display = "none";
}
var baseid = "snap-lightbox-";
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(id, n) {
showSlides(id, slideIndex += n);
// Next/previous controls for lightbox
function moveLightboxItem(id, n) {
showLightboxItem(id, imageIndex[id] += n);
}
// Thumbnail image controls
function currentSlide(id, n) {
showSlides(id, slideIndex = n);
// Next/previous controls for slideshow
function moveSlideshowItem(id, n) {
showSlideshowItem(id, imageIndex[id] += n);
}
function showSlides(id, n) {
// Move lightbox to the specified item
function openLightboxItem(id, n) {
showLightboxItem(id, imageIndex[id] = n);
}
// TODO: Unify these functions
// In the lightbox, make a specific image visible, make others hidden
function showLightboxItem(id, n) {
var i;
var lightbox = document.getElementById(baseid + id);
var slides = lightbox.querySelectorAll(".snap-lightbox-inner");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
var lightbox = document.getElementById(lightbox_baseid + id);
var images = lightbox.querySelectorAll(".snap-lightbox-inner");
if (n > images.length) { imageIndex[id] = 1 }
if (n < 1) { imageIndex[id] = images.length }
for (i = 0; i < images.length; i++) {
images[i].style.display = "none";
}
slides[slideIndex - 1].style.display = "inline-block";
images[imageIndex[id] - 1].style.display = "inline-block";
}
// In the slideshow, make a specific image visible, make others hidden
function showSlideshowItem(id, n) {
var i;
var slideshow = document.getElementById(slideshow_baseid + id);
var images = slideshow.querySelectorAll(".snap-image");
if (n > images.length) { imageIndex[id] = 1 }
if (n < 1) { imageIndex[id] = images.length }
for (i = 0; i < images.length; i++) {
images[i].style.display = "none";
}
images[imageIndex[id] - 1].style.display = "block";
}