if(document.querySelector("#gallery-load") !== null){
document.addEventListener("DOMContentLoaded", function () { const gallery = document.querySelector("#gallery-load") ; const items = gallery.querySelectorAll(".jet-images-layout__item") ; const loadMoreBtn = document.getElementById("loadMore");
if(gallery === null && items === null){ return; }
const itemsPerLoad = 6; // how many images per click let visibleCount = 0;
function showItems(n = itemsPerLoad) { const nextCount = visibleCount + n;
for (let i = visibleCount; i < nextCount && i < items.length; i++) { items[i].style.display = "block"; // reveal item } visibleCount = Math.min(nextCount, items.length); // hide button if no more items left if (visibleCount >= items.length) { loadMoreBtn.classList.add("hidden"); } }
// button click loadMoreBtn.addEventListener("click", function () { showItems(); ensureFullHeight(); });
// ensure page fills height function ensureFullHeight() { while ( document.body.scrollHeight <= window.innerHeight && visibleCount < items.length ) { showItems(); } } // initial setup: hide all items.forEach((item) => (item.style.display = "none"));
// first batch showItems(); ensureFullHeight(); }); }
