From b9d6c5349961b1c68d35bd8f0f8818879656b25a Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Fri, 27 Dec 2024 14:04:10 +1300 Subject: [PATCH] WIP --- app/public/web.js | 45 ++++++++++++++++++++++++++++++++++++++++--- app/views/gallery.ejs | 27 +++----------------------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/app/public/web.js b/app/public/web.js index a517cbf..6da7060 100644 --- a/app/public/web.js +++ b/app/public/web.js @@ -1,6 +1,9 @@ -function initLightGallery (config = {}) { - lightGallery(document.getElementById('lightgallery'), Object.assign({ +function initLightGallery (params = {}) { + // Create the lightGallery instance + const lgEl = document.getElementById('lightgallery') + const lg = lightGallery(lgEl, Object.assign({ plugins: [lgZoom, lgThumbnail, lgVideo, lgFullscreen], + speed: 500, /* This license key was graciously provided by LightGallery under their GPLv3 open-source project license: @@ -15,5 +18,41 @@ function initLightGallery (config = {}) { https://www.lightgalleryjs.com/docs/settings/#licenseKey */ - }, config)) + }, params.lgConfig)) + + // repeat the array for testing + let items = [] + for (let i = 0; i < 50; i++) { + items = items.concat(params.items) + } + + // Append thumbnails + items.forEach(item => { + if (item.video) { + lgEl.insertAdjacentHTML('beforeend', ` +
`) + } else { + lgEl.insertAdjacentHTML('beforeend', ` + `) + } + }) + lg.refresh() + + let timeout + window.addEventListener('scroll', () => { + if (timeout) clearTimeout(timeout) + timeout = setTimeout(handleScroll, 100) + }) +} + +function handleScroll () { + const scrollPosition = window.innerHeight + window.scrollY + const pageHeight = document.documentElement.scrollHeight + const buffer = 100 // pixels before bottom to trigger load + + if (pageHeight - scrollPosition <= buffer) { + loadMoreItems() + } } diff --git a/app/views/gallery.ejs b/app/views/gallery.ejs index 208f023..28d94ab 100644 --- a/app/views/gallery.ejs +++ b/app/views/gallery.ejs @@ -24,28 +24,7 @@ <% } %> -
- <% items.forEach(item => { - if (item.video) { %> - - data-download-url="<%- item.downloadUrl %>" - <% } %> - > - -
-
- <% } else { %> - - data-download-url="<%- item.downloadUrl %>" - <% } %> - > - - - <% } - }) %> -
+
@@ -53,8 +32,8 @@