diff --git a/app/public/web.js b/app/public/web.js index 6da7060..b961bc5 100644 --- a/app/public/web.js +++ b/app/public/web.js @@ -1,58 +1,76 @@ -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: - */ - licenseKey: '8FFA6495-676C4D30-8BFC54B6-4D0A6CEC' - /* - Please do not take it and use it for other projects, as it was provided - specifically for Immich Public Proxy. +class LGallery { + items + lightGallery + element + index = 0 - For your own projects you can use the default license key of - 0000-0000-000-0000 as per their docs: + init (params = {}) { + // Create the lightGallery instance + this.element = document.getElementById('lightgallery') + this.lightGallery = lightGallery(this.element, Object.assign({ + plugins: [lgZoom, lgThumbnail, lgVideo, lgFullscreen], + speed: 500, + /* + This license key was graciously provided by LightGallery under their + GPLv3 open-source project license: + */ + licenseKey: '8FFA6495-676C4D30-8BFC54B6-4D0A6CEC' + /* + Please do not take it and use it for other projects, as it was provided + specifically for Immich Public Proxy. - https://www.lightgalleryjs.com/docs/settings/#licenseKey - */ - }, params.lgConfig)) + For your own projects you can use the default license key of + 0000-0000-000-0000 as per their docs: - // repeat the array for testing - let items = [] - for (let i = 0; i < 50; i++) { - items = items.concat(params.items) + https://www.lightgalleryjs.com/docs/settings/#licenseKey + */ + }, params.lgConfig)) + + // repeat the array for testing + let items = [] + for (let i = 0; i < 50; i++) { + items = items.concat(params.items) + } + this.items = items + + let timeout + window.addEventListener('scroll', () => { + if (timeout) clearTimeout(timeout) + timeout = setTimeout(lgallery.handleScroll, 100) + }) + lgallery.handleScroll() } - // Append thumbnails - items.forEach(item => { - if (item.video) { - lgEl.insertAdjacentHTML('beforeend', ` { + if (item.video) { + this.element.insertAdjacentHTML('beforeend', `
`) - } else { - lgEl.insertAdjacentHTML('beforeend', ` `) + } + }) + this.lightGallery.refresh() + this.index += numberOfItems } - }) - 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() } } +const lgallery = new LGallery() diff --git a/app/views/gallery.ejs b/app/views/gallery.ejs index 28d94ab..9d0b31c 100644 --- a/app/views/gallery.ejs +++ b/app/views/gallery.ejs @@ -32,8 +32,8 @@