diff --git a/.gitignore b/.gitignore index 6227a0dc..e61adca4 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ node_modules ._* .Spotlight-V100 .Trashes +.idea diff --git a/assets/js/shortcodes/gallery.js b/assets/js/shortcodes/gallery.js new file mode 100644 index 00000000..bc61fadb --- /dev/null +++ b/assets/js/shortcodes/gallery.js @@ -0,0 +1,24 @@ +function _getDefaultPackeryOptions() { + return { + percentPosition: true, + gutter: 5, + resize: true + }; +} + +(function init() { + window.addEventListener("DOMContentLoaded", (event) => { + console.groupCollapsed('[DEBUG] Gallery feature enable'); + let packeries = []; + let nodeGalleries = document.querySelectorAll('.gallery'); + + nodeGalleries.forEach(nodeGallery => { + // TODO : implement a reader of Packery configuration _getPackeryOptions; for example by reading data-attribute + let packery = new Packery(nodeGallery, _getDefaultPackeryOptions()); + packeries.push(packery); + }); + + console.log("Galleries founded and initialized with packery", packeries); + console.groupEnd(); + }); +})(); \ No newline at end of file diff --git a/layouts/partials/vendor.html b/layouts/partials/vendor.html index 2171288b..9e9a1076 100644 --- a/layouts/partials/vendor.html +++ b/layouts/partials/vendor.html @@ -48,8 +48,12 @@ {{/* Packery */}} {{ if .Page.HasShortcode "gallery" }} -{{ $packeryLib := resources.Get "lib/packery/packery.pkgd.min.js" }} - + {{ $packeryLib := resources.Get "lib/packery/packery.pkgd.min.js" }} + + + {{ $jsShortcodeGallery := resources.Get "js/shortcodes/gallery.js" }} + {{ $jsShortcodeGallery = $jsShortcodeGallery | resources.Minify | resources.Fingerprint "sha512" }} + {{ end }} {{/* tw-elements */}} diff --git a/layouts/shortcodes/gallery.html b/layouts/shortcodes/gallery.html index f03d709d..0aa82415 100644 --- a/layouts/shortcodes/gallery.html +++ b/layouts/shortcodes/gallery.html @@ -1,15 +1,6 @@ -{{ $id := delimit (slice "gallery" .Ordinal now.UnixNano) "-" }} +{{ $random := delimit (shuffle (seq 1 9)) "" }} +{{ $id := delimit (slice "gallery" $random now.UnixNano) "-" }} -