first work into renewed gallery
This commit is contained in:
87
layouts/shortcodes/figure.bak.html
Normal file
87
layouts/shortcodes/figure.bak.html
Normal 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>
|
||||
@@ -1,87 +1,68 @@
|
||||
<!--
|
||||
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 -}}
|
||||
<!-- Images used to open the lightbox -->
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<img src="img1.jpg" onclick="openModal();currentSlide(1)" class="hover-shadow">
|
||||
</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()">×</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)">❮</a>
|
||||
<a class="next" onclick="plusSlides(1)">❯</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>
|
||||
|
||||
53
layouts/shortcodes/snap-gallery.html
Normal file
53
layouts/shortcodes/snap-gallery.html
Normal 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()">×</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)">❮</a>
|
||||
<a class="next" onclick="plusSlides(1)">❯</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>
|
||||
Reference in New Issue
Block a user