Complete rewrite #1

Merged
mxmehl merged 27 commits from refactoring into master 2024-02-07 22:17:50 +01:00
7 changed files with 347 additions and 343 deletions
Showing only changes of commit 33fbd81151 - Show all commits

View File

@@ -0,0 +1,87 @@
<!--
SPDX-FileCopyrightText: 2020 Max Mehl <mail@mehl.mx>
SPDX-License-Identifier: MIT
-->
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/snap-gallery.css" />{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 -}}
<!-- use src image -->
{{- $thumb := .Get "src" -}}
<!-- set unique ID depending on whether part of gallery or alone -->
{{- $figid := "" -}}
{{- $galid := "" -}}
{{- $id := "" -}}
{{- $previd := "" -}}
{{- $nextid := "" -}}
{{- if .Parent -}} <!-- gallery -->
{{- $galid = .Page.Scratch.Get "gallery" -}}
{{- if not $galid }}{{ $galid = 0 }}{{ end -}}
{{- $galid = add $galid 1 -}}
{{- $.Page.Scratch.Add "thisgalfig" 1 -}}
{{- $figid = .Page.Scratch.Get "thisgalfig" -}}
{{- else -}} <!-- standalone figure -->
{{- $.Page.Scratch.Add "nogalfig" 1 -}}
{{- $figid = .Page.Scratch.Get "nogalfig" -}}
{{- end -}}
{{- if $galid -}} <!-- gallery -->
{{- $id = print "gal" $galid "-" "fig" $figid -}}
{{- $previd = print "gal" $galid "-" "fig" (sub $figid 1) -}}
{{- $nextid = print "gal" $galid "-" "fig" (add $figid 1) -}}
{{- else -}} <!-- standalone figure -->
{{- $id = print "fig" $figid -}}
{{- end -}}
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
<div class="snap-wrapper">
{{ if (.Get "link") -}}
<a href="{{ .Get "link" }}"
{{- with .Get "target" }} target="{{ . }}"{{ end -}}
{{- with .Get "rel" }} rel="{{ . }}"{{ end -}}
>
{{ else -}}
{{ if not (eq (.Get "lightbox") "none") }}<a href="#{{ $id }}">{{ end }}
{{- end -}}
<!-- THUMBNAIL -->
<img src="{{ $thumb | relURL }}" class="snap-thumb"
{{- with .Get "alt" }} alt="{{ . }}"{{ end -}}
{{- with .Get "title" }} title="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
/>
{{- if or (.Get "caption") (.Get "attr")}}
<figcaption>
{{- .Get "caption" | markdownify -}}
{{- with .Get "attr" }} {{ . | markdownify}}{{ end -}}
</figcaption>
{{- end }}
</a>
<!-- FULL IMAGE; HIDDEN -->
{{- if not (eq (.Get "lightbox") "none") -}}
<div class="snap-lightbox" id="{{ $id }}">
<a href="#_" class="snap-lightbox-close"></a>
<div class="snap-lightbox-inner">
<img src="{{ .Get "src" }}" {{ with .Get "alt" }}alt="{{ . }}"{{ end }} />
<p>
{{- if or (.Get "caption") (.Get "attr") -}}
{{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" }} <a href="{{ . }}">{{- end -}}
{{- with .Get "attr" }} {{ . | markdownify}}{{ end -}}
{{- with .Get "attrlink" }}</a>{{- end -}}
{{- end }}
</p>
</div>
<a href="#_" class="snap-lightbox-close-button"><i class="snap-lightbox-x"></i></a>
{{- if .Parent -}}
{{- if not (eq $figid 1) -}}
<a href="#{{ $previd }}" class="snap-lightbox-prev"><i class="snap-lightbox-arrow"></i></a>
{{- else -}}
<span class="snap-lightbox-prev"><i class="snap-lightbox-arrow"></i></span>
{{- end -}}
<!-- TODO: Somehow try to identify whether this is the last element in the gallery -->
<a href="#{{ $nextid }}" class="snap-lightbox-next"><i class="snap-lightbox-arrow"></i></a>
{{- end }}
</div>
{{- end -}}
</div>
</figure>

View File

@@ -1,87 +1,68 @@
<!-- <!-- Images used to open the lightbox -->
SPDX-FileCopyrightText: 2020 Max Mehl <mail@mehl.mx> <div class="row">
SPDX-License-Identifier: MIT <div class="column">
--> <img src="img1.jpg" onclick="openModal();currentSlide(1)" class="hover-shadow">
<!-- count how many times we've called this shortcode; load the css if it's the first time -->
{{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/snap-gallery.css" />{{ end }}
{{- $.Page.Scratch.Add "figurecount" 1 -}}
<!-- use src image -->
{{- $thumb := .Get "src" -}}
<!-- set unique ID depending on whether part of gallery or alone -->
{{- $figid := "" -}}
{{- $galid := "" -}}
{{- $id := "" -}}
{{- $previd := "" -}}
{{- $nextid := "" -}}
{{- if .Parent -}} <!-- gallery -->
{{- $galid = .Page.Scratch.Get "gallery" -}}
{{- if not $galid }}{{ $galid = 0 }}{{ end -}}
{{- $galid = add $galid 1 -}}
{{- $.Page.Scratch.Add "thisgalfig" 1 -}}
{{- $figid = .Page.Scratch.Get "thisgalfig" -}}
{{- else -}} <!-- standalone figure -->
{{- $.Page.Scratch.Add "nogalfig" 1 -}}
{{- $figid = .Page.Scratch.Get "nogalfig" -}}
{{- end -}}
{{- if $galid -}} <!-- gallery -->
{{- $id = print "gal" $galid "-" "fig" $figid -}}
{{- $previd = print "gal" $galid "-" "fig" (sub $figid 1) -}}
{{- $nextid = print "gal" $galid "-" "fig" (add $figid 1) -}}
{{- else -}} <!-- standalone figure -->
{{- $id = print "fig" $figid -}}
{{- end -}}
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
<div class="snap-wrapper">
{{ if (.Get "link") -}}
<a href="{{ .Get "link" }}"
{{- with .Get "target" }} target="{{ . }}"{{ end -}}
{{- with .Get "rel" }} rel="{{ . }}"{{ end -}}
>
{{ else -}}
{{ if not (eq (.Get "lightbox") "none") }}<a href="#{{ $id }}">{{ end }}
{{- end -}}
<!-- THUMBNAIL -->
<img src="{{ $thumb | relURL }}" class="snap-thumb"
{{- with .Get "alt" }} alt="{{ . }}"{{ end -}}
{{- with .Get "title" }} title="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
/>
{{- if or (.Get "caption") (.Get "attr")}}
<figcaption>
{{- .Get "caption" | markdownify -}}
{{- with .Get "attr" }} {{ . | markdownify}}{{ end -}}
</figcaption>
{{- end }}
</a>
<!-- FULL IMAGE; HIDDEN -->
{{- if not (eq (.Get "lightbox") "none") -}}
<div class="snap-lightbox" id="{{ $id }}">
<a href="#_" class="snap-lightbox-close"></a>
<div class="snap-lightbox-inner">
<img src="{{ .Get "src" }}" {{ with .Get "alt" }}alt="{{ . }}"{{ end }} />
<p>
{{- if or (.Get "caption") (.Get "attr") -}}
{{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" }} <a href="{{ . }}">{{- end -}}
{{- with .Get "attr" }} {{ . | markdownify}}{{ end -}}
{{- with .Get "attrlink" }}</a>{{- end -}}
{{- end }}
</p>
</div>
<a href="#_" class="snap-lightbox-close-button"><i class="snap-lightbox-x"></i></a>
{{- if .Parent -}}
{{- if not (eq $figid 1) -}}
<a href="#{{ $previd }}" class="snap-lightbox-prev"><i class="snap-lightbox-arrow"></i></a>
{{- else -}}
<span class="snap-lightbox-prev"><i class="snap-lightbox-arrow"></i></span>
{{- end -}}
<!-- TODO: Somehow try to identify whether this is the last element in the gallery -->
<a href="#{{ $nextid }}" class="snap-lightbox-next"><i class="snap-lightbox-arrow"></i></a>
{{- end }}
</div>
{{- end -}}
</div> </div>
</figure> <div class="column">
<img src="img2.jpg" onclick="openModal();currentSlide(2)" class="hover-shadow">
</div>
<div class="column">
<img src="img3.jpg" onclick="openModal();currentSlide(3)" class="hover-shadow">
</div>
<div class="column">
<img src="img4.jpg" onclick="openModal();currentSlide(4)" class="hover-shadow">
</div>
</div>
<!-- The Modal/Lightbox -->
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">&times;</span>
<div class="modal-content">
<div class="mySlides">
<div class="numbertext">1 / 4</div>
<img src="img1.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">2 / 4</div>
<img src="img2.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">3 / 4</div>
<img src="img3.jpg" style="width:100%">
</div>
<div class="mySlides">
<div class="numbertext">4 / 4</div>
<img src="img4.jpg" style="width:100%">
</div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
<!-- Caption text -->
<div class="caption-container">
<p id="caption"></p>
</div>
<!-- Thumbnail image controls -->
<div class="column">
<img class="demo" src="img1.jpg" onclick="currentSlide(1)" alt="Nature">
</div>
<div class="column">
<img class="demo" src="img2.jpg" onclick="currentSlide(2)" alt="Snow">
</div>
<div class="column">
<img class="demo" src="img3.jpg" onclick="currentSlide(3)" alt="Mountains">
</div>
<div class="column">
<img class="demo" src="img4.jpg" onclick="currentSlide(4)" alt="Lights">
</div>
</div>
</div>

View File

@@ -0,0 +1,53 @@
<link rel="stylesheet" href="/css/snap-gallery.css" />
<script src="/js/snap-gallery.js"></script>
{{/* Initialise variables */}}
{{ $imgs := slice }}
{{ if .Params.isdir }}
{{/* Get images from folder, somehow put into map */}}
{{ else }}
{{ range (split .Params.src ",") }}
{{ $imgs = $imgs | append (trim . " ") }}
{{ end }}
{{ end }}
{{/* Visible images */}}
<div class="row">
{{ range $i, $img := $imgs }}
<div class="column">
<img src="{{ $img }}" onclick="openModal();currentSlide({{ add $i 1 }});" class="hover-shadow">
</div>
{{ end }}
</div>
{{/* The Modal/Lightbox */}}
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">&times;</span>
<div class="modal-content">
{{ range $i, $img := $imgs }}
<div class="mySlides">
<div class="numbertext">{{ add $i 1 }} / {{ len $imgs }}</div>
<img src="{{ $img }}" style="width:100%">
</div>
{{ end }}
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
<!-- Caption text -->
<div class="caption-container">
<p id="caption"></p>
</div>
<!-- Thumbnail image controls -->
{{ range $i, $img := $imgs }}
<div class="column">
<img class="demo" src="{{ $img }}" onclick="currentSlide({{ add $i 1 }})" alt="Nature">
</div>
{{ end }}
</div>
</div>

View File

@@ -1,282 +1,125 @@
/* .row > .column {
SPDX-FileCopyrightText: 2020 Max Mehl <mail@mehl.mx> padding: 0 8px;
SPDX-License-Identifier: MIT
*/
/** GENERAL FIGURE LAYOUT **/
figure {
max-width: 90%;
margin: 10px auto;
display: block;
text-align: center;
} }
/* make box with box-shadow only as large as image */ .row:after {
.snap-wrapper {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
display: inline-block;
}
figure a:hover {
text-decoration: none;
}
figure img {
max-width: 100%;
max-height: 100%;
}
figure.sm {
max-width: 30%;
}
figure.md {
max-width: 50%;
}
figure.lg {
max-width: 70%;
}
figure.pull-right {
padding: 10px 0 10px 10px;
}
figure.pull-left {
padding: 10px 10px 10px 0;
}
figure figcaption {
background-color: rgba(0, 0, 0, 0.5);
display: block;
font-size: .8em;
padding: 1px;
position: static;
text-align: center;
bottom: 0;
left: 0;
right: 0;
color: #FFF;
}
/* Extra classes for figures */
figure.no-border .snap-wrapper {
box-shadow: none;
}
/** GALLERY MARKUP **/
.snap-gallery {
margin: 10px;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
/* avoid sick effects of inline-block on gallery elements */
.snap-gallery .snap-wrapper {
display: block;
}
.snap-gallery figure {
position: relative;
width: 30%;
padding-bottom: 30%;
margin: 1%;
text-align: left;
box-shadow: 0 1px 2px 0 rgba(0,0,0,0.2),0 2px 4px 0 rgba(0,0,0,0.19);
}
.snap-gallery figcaption {
position: absolute;
}
.snap-gallery img.snap-thumb {
position: absolute;
object-fit: cover;
object-position: center;
height: 100%;
width: 100%;
}
.snap-gallery figure img.snap-thumb:hover {
transform: scale(1.02);
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
@media screen and (max-width: 767px) {
.snap-gallery figure {
width: 45%;
padding-bottom: 45%;
margin: 2%
}
}
@media screen and (max-width: 479px) {
.snap-gallery figure {
width: 90%;
padding-bottom: 90%;
margin: 3%;
}
}
/** LIGHTBOX MARKUP **/
.snap-lightbox {
/** Default lightbox to hidden */
display: none;
/** Position and style */
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
white-space: nowrap;
top: 0;
left: 0;
background: rgba(0,0,0,0.8);
}
/* effects when "activating" the figure */
.snap-lightbox:target {
/** Remove default browser outline */
outline: none;
/** Unhide lightbox **/
display: block;
}
/* Click on the complete background closes the lightbox */
/* Exception: arrow in gallery, they have higher z-index */
a.snap-lightbox-close {
position: fixed;
z-index: 800;
width: 100%;
height: 100%;
text-align: center;
white-space: nowrap;
top: 0;
left: 0;
}
/* keep lightbox in middle. TODO: hacky, and not realibly in middle */
.snap-lightbox::before {
content: ""; content: "";
display: inline-block; display: table;
vertical-align: middle; clear: both;
width: 0;
/* adjust for white space between pseudo element and next sibling */
margin-right: -.25em;
/* stretch line height */
height: 100%;
} }
/* Container for image */ /* Create four equal columns that floats next to eachother */
.snap-lightbox-inner { .column {
display: inline-block; float: left;
vertical-align: middle; width: 25%;
white-space: normal;
max-width: 90%;
max-height: 80%;
height: 100%;
} }
.snap-lightbox-inner p { /* The Modal (background) */
color: #fff; .modal {
z-index: 810; display: none;
position: relative;
}
/* prev/next arrows & close button */
.snap-lightbox-close-button {
position: fixed; position: fixed;
z-index: 950; z-index: 1;
width: 5%; padding-top: 100px;
height: calc(5vw); /* ~5% width */
right: 0;
top: 0;
}
.snap-lightbox-x::after {
content: "\00d7"; /* This will render the 'X' */
font-size: 3em;
font-style: normal;
font-weight: 700;
color: #000;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.snap-lightbox-close-button:hover .snap-lightbox-x::after {
color: #fff;
transition: all 0.25s ease;
}
.snap-lightbox-prev, .snap-lightbox-next {
position: fixed;
z-index: 800;
width: 5%;
height: 100%;
text-align: center;
top: 0;
}
.snap-lightbox-prev {
left: 0; left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
} }
.snap-lightbox-next { /* Modal Content */
right: 0; .modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
} }
.snap-lightbox-arrow { /* The Close Button */
display: inline-block; .close {
position: fixed; color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%; top: 50%;
z-index: 900; width: auto;
border: solid #000; padding: 16px;
border-width: 0 7px 7px 0; margin-top: -50px;
display: inline-block; color: white;
padding: 1%; font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
} }
span .snap-lightbox-arrow { /* Position the "next button" to the right */
border-color: #5e5e5e; .next {
right: 0;
border-radius: 3px 0 0 3px;
} }
.snap-lightbox-prev .snap-lightbox-arrow { /* On hover, add a black background color with a little bit see-through */
left: 2%; .prev:hover,
transform: rotate(135deg); .next:hover {
-webkit-transform: rotate(135deg); background-color: rgba(0, 0, 0, 0.8);
} }
.snap-lightbox-next .snap-lightbox-arrow { /* Number text (1/3 etc) */
right: 2%; .numbertext {
transform: rotate(-45deg); color: #f2f2f2;
-webkit-transform: rotate(-45deg); font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
} }
a.snap-lightbox-prev:hover > .snap-lightbox-arrow, /* Caption text */
a.snap-lightbox-next:hover > .snap-lightbox-arrow { .caption-container {
border-color: #fff; text-align: center;
transition: all 0.25s ease; background-color: black;
padding: 2px 16px;
color: white;
} }
@media screen and (max-width: 767px) { img.demo {
.snap-lightbox-inner { opacity: 0.6;
max-width: 80%; }
}
.snap-lightbox-prev, .snap-lightbox-next { .img-active,
width: 10%; .demo:hover {
} opacity: 1 !important;
.snap-lightbox-close-button { }
width: 10%;
height: calc(10vw); /* ~10% width */ img.hover-shadow {
} transition: 0.3s;
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
} }

40
static/js/snap-gallery.js Normal file
View File

@@ -0,0 +1,40 @@
// Open the Modal
function openModal() {
document.getElementById("myModal").style.display = "block";
}
// Close the Modal
function closeModal() {
document.getElementById("myModal").style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
var captionText = document.getElementById("caption");
if (n > slides.length) { slideIndex = 1 }
if (n < 1) { slideIndex = slides.length }
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" img-active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " img-active";
captionText.innerHTML = dots[slideIndex - 1].alt;
}