WIP
This commit is contained in:
+42
-3
@@ -1,6 +1,9 @@
|
|||||||
function initLightGallery (config = {}) {
|
function initLightGallery (params = {}) {
|
||||||
lightGallery(document.getElementById('lightgallery'), Object.assign({
|
// Create the lightGallery instance
|
||||||
|
const lgEl = document.getElementById('lightgallery')
|
||||||
|
const lg = lightGallery(lgEl, Object.assign({
|
||||||
plugins: [lgZoom, lgThumbnail, lgVideo, lgFullscreen],
|
plugins: [lgZoom, lgThumbnail, lgVideo, lgFullscreen],
|
||||||
|
speed: 500,
|
||||||
/*
|
/*
|
||||||
This license key was graciously provided by LightGallery under their
|
This license key was graciously provided by LightGallery under their
|
||||||
GPLv3 open-source project license:
|
GPLv3 open-source project license:
|
||||||
@@ -15,5 +18,41 @@ function initLightGallery (config = {}) {
|
|||||||
|
|
||||||
https://www.lightgalleryjs.com/docs/settings/#licenseKey
|
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', `<a data-video='${item.video}'
|
||||||
|
${item.downloadUrl ? 'data-download-url="' + item.downloadUrl + '"' : ''}>
|
||||||
|
<img alt="" src="${item.thumbnailUrl}"/><div class="play-icon"></div></a>`)
|
||||||
|
} else {
|
||||||
|
lgEl.insertAdjacentHTML('beforeend', `<a href="${item.previewUrl}"
|
||||||
|
${item.downloadUrl ? 'data-download-url="' + item.downloadUrl + '"' : ''}>
|
||||||
|
<img alt="" src="${item.thumbnailUrl}"/></a>`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-24
@@ -24,28 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<div id="lightgallery">
|
<div id="lightgallery"></div>
|
||||||
<% items.forEach(item => {
|
|
||||||
if (item.video) { %>
|
|
||||||
<a data-video='<%- item.video %>'
|
|
||||||
<% if (item.downloadUrl) { %>
|
|
||||||
data-download-url="<%- item.downloadUrl %>"
|
|
||||||
<% } %>
|
|
||||||
>
|
|
||||||
<img alt="" src="<%- item.thumbnailUrl %>"/>
|
|
||||||
<div class="play-icon"></div>
|
|
||||||
</a>
|
|
||||||
<% } else { %>
|
|
||||||
<a href="<%- item.previewUrl %>"
|
|
||||||
<% if (item.downloadUrl) { %>
|
|
||||||
data-download-url="<%- item.downloadUrl %>"
|
|
||||||
<% } %>
|
|
||||||
>
|
|
||||||
<img alt="" src="<%- item.thumbnailUrl %>"/>
|
|
||||||
</a>
|
|
||||||
<% }
|
|
||||||
}) %>
|
|
||||||
</div>
|
|
||||||
<script src="/share/static/web.js"></script>
|
<script src="/share/static/web.js"></script>
|
||||||
<script src="/share/static/lg/lightgallery.min.js"></script>
|
<script src="/share/static/lg/lightgallery.min.js"></script>
|
||||||
<script src="/share/static/lg/lg-fullscreen.min.js"></script>
|
<script src="/share/static/lg/lg-fullscreen.min.js"></script>
|
||||||
@@ -53,8 +32,8 @@
|
|||||||
<script src="/share/static/lg/lg-video.min.js"></script>
|
<script src="/share/static/lg/lg-video.min.js"></script>
|
||||||
<script src="/share/static/lg/lg-zoom.min.js"></script>
|
<script src="/share/static/lg/lg-zoom.min.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
initLightGallery(<%- JSON.stringify(lgConfig) %>) // initLightGallery imported from web.js
|
initLightGallery(<%- JSON.stringify({lgConfig, items, openItem}) %>) // initLightGallery imported from web.js
|
||||||
<% if (openItem) { %>
|
<% if (false && openItem) { %>
|
||||||
const openItem = <%- openItem %>
|
const openItem = <%- openItem %>
|
||||||
const thumbs = document.querySelectorAll('#lightgallery a')
|
const thumbs = document.querySelectorAll('#lightgallery a')
|
||||||
if (thumbs.length >= openItem) {
|
if (thumbs.length >= openItem) {
|
||||||
|
|||||||
Reference in New Issue
Block a user