Simplify logic for project modals

This commit is contained in:
Hanzei 2018-06-27 11:22:46 +02:00
parent 7f8d87bad7
commit db4f7e5d7a
No known key found for this signature in database
GPG key ID: 69A2DEFD98937BA0

View file

@ -9,14 +9,13 @@
<div class="columns is-multiline"> <div class="columns is-multiline">
{{ $totalProjects := (len .Pages) }} {{ $totalProjects := (len .Pages) }}
{{ $numberOfProjectsToShow := .Site.Params.numberOfProjectsToShow | default $totalProjects }} {{ $numberOfProjectsToShow := .Site.Params.numberOfProjectsToShow | default $totalProjects }}
{{ range .Pages | first $numberOfProjectsToShow }} {{ range $index, $element := .Pages | first $numberOfProjectsToShow }}
{{ if eq (mod $numberOfProjectsToShow 2) 0 }} {{ if eq (mod $numberOfProjectsToShow 2) 0 }}
<div class="column is-half"> <div class="column is-half">
{{ else }} {{ else }}
<div class="column is-one-third"> <div class="column is-one-third">
{{ end }} {{ end }}
<div {{ if not .Params.external_link }} id="project{{ $card := .Title | urlize }}{{ replace $card "%" " "}}" {{ end }} <div id="project-{{ $index }}" class="card">
class="card">
<div class="card-image"> <div class="card-image">
<figure class="image is-3by2"> <figure class="image is-3by2">
<a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}> <a {{ if .Params.external_link }} href="{{ .Params.external_link }}" {{ end }}>
@ -34,7 +33,6 @@
{{ end }} {{ end }}
</div> </div>
</div> </div>
</div>
{{ if lt $numberOfProjectsToShow $totalProjects }} {{ if lt $numberOfProjectsToShow $totalProjects }}
<div class="container has-text-centered top-pad"> <div class="container has-text-centered top-pad">
<a href="{{ .RelPermalink }}">{{ i18n "index_projects_allProjects" . }}</a> <a href="{{ .RelPermalink }}">{{ i18n "index_projects_allProjects" . }}</a>
@ -43,8 +41,8 @@
</div> </div>
<!-- End Projects container --> <!-- End Projects container -->
<!-- Projects modals --> <!-- Projects modals -->
{{ range .Pages | first $numberOfProjectsToShow }} {{ if not .Params.external_link }} {{ range $index, $element := .Pages | first $numberOfProjectsToShow }} {{ if not .Params.external_link }}
<div class="modal" id="modal{{ $card := .Title | urlize }}{{ replace $card "%" " "}}"> <div class="modal" id="modal-{{ $index }}">
<div class="modal-background"></div> <div class="modal-background"></div>
<div class="modal-card"> <div class="modal-card">
{{ with .Title }} {{ with .Title }}
@ -61,14 +59,14 @@
</section> </section>
{{ end }} {{ end }}
</div> </div>
<button class="modal-close is-large" aria-label="close" id="close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}"></button> <button class="modal-close is-large" aria-label="close" id="close-{{ $index }}"></button>
</div> </div>
<script> <script>
$('#project{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function () { $('#project-{{ $index }}').click(function () {
$('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').addClass('is-active'); $('#modal-{{ $index }}').addClass('is-active');
}); });
$('#close{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').click(function () { $('#close-{{ $index }}').click(function () {
$('#modal{{ $card := .Title | urlize }}{{ replace $card "%" ""}}').removeClass('is-active'); $('#modal-{{ $index }}').removeClass('is-active');
}); });
</script> </script>
{{ end }} {{ end }} {{ end }} {{ end }}