🐛 : Shortcodes gallery (non-unique id, multiple loading <script> tag)

This commit is contained in:
v20100v
2023-12-18 14:37:47 +01:00
parent b6744efbf2
commit c790396863
5 changed files with 37 additions and 17 deletions
+6 -2
View File
@@ -48,8 +48,12 @@
{{/* Packery */}}
{{ if .Page.HasShortcode "gallery" }}
{{ $packeryLib := resources.Get "lib/packery/packery.pkgd.min.js" }}
<script defer src="{{ $packeryLib.RelPermalink }}" integrity="{{ $packeryLib.Data.Integrity }}"></script>
{{ $packeryLib := resources.Get "lib/packery/packery.pkgd.min.js" }}
<script defer src="{{ $packeryLib.RelPermalink }}" integrity="{{ $packeryLib.Data.Integrity }}"></script>
{{ $jsShortcodeGallery := resources.Get "js/shortcodes/gallery.js" }}
{{ $jsShortcodeGallery = $jsShortcodeGallery | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsShortcodeGallery.RelPermalink }}" integrity="{{ $jsShortcodeGallery.Data.Integrity }}"></script>
{{ end }}
{{/* tw-elements */}}
+4 -13
View File
@@ -1,15 +1,6 @@
{{ $id := delimit (slice "gallery" .Ordinal now.UnixNano) "-" }}
{{ $random := delimit (shuffle (seq 1 9)) "" }}
{{ $id := delimit (slice "gallery" $random now.UnixNano) "-" }}
<div id="{{ $id }}">
<div id="{{ $id }}" class="gallery">
{{ .Inner }}
</div>
<script>
$(window).on("load", function () {
$('#{{ $id }}').packery({
percentPosition: true,
gutter: 5,
resize: true
});
})
</script>
</div>