Skip to content

Commit eaa4420

Browse files
committed
Add PhotoSwipe initialization debugging and DOMContentLoaded check
1 parent 8cf11f6 commit eaa4420

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/components/PhotoGallery.astro

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,17 @@ try {
188188
// Initialize PhotoSwipe on all galleries
189189
function initializeGalleries() {
190190
const galleries = document.querySelectorAll(".photo-gallery-container");
191+
console.log("[PhotoGallery] Found containers:", galleries.length);
191192

192193
galleries.forEach((container) => {
193194
const gallery = container.querySelector(".gallery-grid");
194-
if (!gallery) return;
195+
if (!gallery) {
196+
console.warn("[PhotoGallery] No .gallery-grid found in container");
197+
return;
198+
}
195199

196200
const galleryId = gallery.getAttribute("id") || "photo-gallery";
201+
console.log("[PhotoGallery] Initializing gallery:", galleryId);
197202

198203
const lightbox = new PhotoSwipeLightbox({
199204
gallery: `#${galleryId}`,
@@ -209,11 +214,17 @@ try {
209214
});
210215

211216
lightbox.init();
217+
console.log("[PhotoGallery] Lightbox initialized for:", galleryId);
212218
});
213219
}
214220

215-
// Initialize on page load
216-
initializeGalleries();
221+
// Initialize when DOM is ready
222+
if (document.readyState === "loading") {
223+
document.addEventListener("DOMContentLoaded", initializeGalleries);
224+
} else {
225+
// DOM already loaded
226+
initializeGalleries();
227+
}
217228

218229
// Re-initialize after Astro View Transitions
219230
document.addEventListener("astro:after-swap", () => {

0 commit comments

Comments
 (0)