rename JS functions to make them more clear
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<div class="snap-gallery-wrapper" style="--columns:{{ default 4 .columns }};--min-width:{{ default 200 .minwidth }};">
|
||||
{{ range $i, $img := $imgs }}
|
||||
<div class="snap-image">
|
||||
<img src="{{ $img }}" onclick="openModal({{ $galno }});currentSlide({{ $galno }}, {{ add $i 1 }});">
|
||||
<img src="{{ $img }}" onclick="openLightbox({{ $galno }});openLightboxItem({{ $galno }}, {{ add $i 1 }});">
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
{{ end }}
|
||||
|
||||
<!-- Close and Next/previous controls -->
|
||||
<span class="snap-close" onclick="closeModal({{ $galno }})">×</span>
|
||||
<span class="snap-close" onclick="closeLightbox({{ $galno }})">×</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>
|
||||
<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">
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
// Open the Modal
|
||||
function openModal(id) {
|
||||
// Variables
|
||||
var baseid = "snap-lightbox-";
|
||||
var imageIndex = 1;
|
||||
|
||||
// Open the Lightbox
|
||||
function openLightbox(id) {
|
||||
document.getElementById(baseid + id).style.display = "block";
|
||||
}
|
||||
|
||||
// Close the Modal
|
||||
function closeModal(id) {
|
||||
// Close the Lightbox
|
||||
function closeLightbox(id) {
|
||||
document.getElementById(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);
|
||||
function moveLightboxItem(id, n) {
|
||||
showLightboxItem(id, imageIndex += n);
|
||||
}
|
||||
|
||||
// Thumbnail image controls
|
||||
function currentSlide(id, n) {
|
||||
showSlides(id, slideIndex = n);
|
||||
// Move lightbox to the specified item
|
||||
function openLightboxItem(id, n) {
|
||||
showLightboxItem(id, imageIndex = n);
|
||||
}
|
||||
|
||||
function showSlides(id, n) {
|
||||
// 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 images = lightbox.querySelectorAll(".snap-lightbox-inner");
|
||||
if (n > images.length) { imageIndex = 1 }
|
||||
if (n < 1) { imageIndex = images.length }
|
||||
for (i = 0; i < images.length; i++) {
|
||||
images[i].style.display = "none";
|
||||
}
|
||||
slides[slideIndex - 1].style.display = "inline-block";
|
||||
images[imageIndex - 1].style.display = "inline-block";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user