summaryrefslogtreecommitdiff
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2025-08-27 01:37:04 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2025-08-27 01:37:04 +0700
commitea8c6da9b8bafa1d4e5fe5a77fb306006db7d6f6 (patch)
tree02377a21a94ded0a33315817d139f739c75a7013
parentb0ab2ed92870d8c651267db10d68eb695da2ec62 (diff)
downloadweb-ea8c6da9b8bafa1d4e5fe5a77fb306006db7d6f6.tar.gz
web-ea8c6da9b8bafa1d4e5fe5a77fb306006db7d6f6.zip
feat: update galleries on resize (with smooth animations this time)
-rw-r--r--internal/lightgallery/html_renderer.go47
-rw-r--r--views/pages/blog-page.html16
2 files changed, 39 insertions, 24 deletions
diff --git a/internal/lightgallery/html_renderer.go b/internal/lightgallery/html_renderer.go
index e20e9ec..17a6f2b 100644
--- a/internal/lightgallery/html_renderer.go
+++ b/internal/lightgallery/html_renderer.go
@@ -92,32 +92,35 @@ func (r *LightGalleryHTMLRenderer) renderLightGallery(w util.BufWriter, source [
w.WriteString(fmt.Sprintf(`
<script>
function createLightGallery%s() {
- const $lgContainer = document.getElementById('lg-%s');
- const inlineGallery = lightGallery($lgContainer, {
- container: $lgContainer,
- dynamic: true,
- dynamicEl: [%s],
- width: "100%%",
- height: "50vmin",
- hash: false,
- closable: false,
- showMaximizeIcon: true,
- appendSubHtmlTo: ".lg-sub-html",
- isMobile: () => false,
- slideDelay: 0,
- plugins: [lgZoom, lgThumbnail],
- thumbWidth: calculateVmin(10),
- thumbHeight: "10vmin",
- thumbMargin: 4
- });
+ const $lgContainer = document.getElementById('lg-%s');
+ const config = {
+ container: $lgContainer,
+ dynamic: true,
+ dynamicEl: [%s],
+ width: "100%%",
+ height: "50vmin",
+ hash: false,
+ closable: false,
+ showMaximizeIcon: true,
+ appendSubHtmlTo: ".lg-sub-html",
+ isMobile: () => false,
+ slideDelay: 0,
+ plugins: [lgZoom, lgThumbnail],
+ thumbWidth: calculateVmin(10),
+ thumbHeight: "10vmin",
+ thumbMargin: 4
+ };
+ const inlineGallery = lightGallery($lgContainer, config);
- setTimeout(() => {
- inlineGallery.openGallery();
- }, 200);
+ setTimeout(() => {
+ inlineGallery.openGallery();
+ }, 200);
+
+ galleryMap.set(inlineGallery, createLightGallery%s);
}
document.addEventListener('DOMContentLoaded', createLightGallery%s);
-</script>`, galleryID, galleryID, strings.Join(dynamicElements, ","), galleryID))
+</script>`, galleryID, galleryID, strings.Join(dynamicElements, ","), galleryID, galleryID))
}
return ast.WalkContinue, nil
diff --git a/views/pages/blog-page.html b/views/pages/blog-page.html
index 83860d7..d685fda 100644
--- a/views/pages/blog-page.html
+++ b/views/pages/blog-page.html
@@ -12,6 +12,10 @@
height: 100% !important;
}
</style>
+
+<script>
+ const galleryMap = new Map();
+</script>
{{ end }}
{{ define "body" }}
@@ -70,10 +74,18 @@
{{ .MapLocationAreaMeters }}
)});
+ let resizeTimeout;
window.addEventListener('resize', function() {
- setTimeout(() => {
+ clearTimeout(resizeTimeout);
+ resizeTimeout = setTimeout(() => {
map.invalidateSize();
- }, 100);
+ var oldGalleryMap = new Map(galleryMap);
+ oldGalleryMap.forEach((createFunc, g, map) => {
+ galleryMap.delete(g);
+ g.destroy();
+ createFunc();
+ });
+ }, 300);
});
</script>
{{- end }}