From af957c015033c6a3ae3b4d017d7be917cd08a2f0 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 2 Apr 2023 19:45:23 -0700 Subject: [PATCH] Pull carousels array out into a variable and bail early if there are no carousels --- assets/scripts/photo_carousel.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/scripts/photo_carousel.js b/assets/scripts/photo_carousel.js index d7ae0b2..1b6cc3a 100644 --- a/assets/scripts/photo_carousel.js +++ b/assets/scripts/photo_carousel.js @@ -171,6 +171,16 @@ class PhotoParametersTable { } document.addEventListener("DOMContentLoaded", (event) => { + let allCarousels = Array.from(document.querySelectorAll("figure.carousel")).sort((a, b) => { + const aRect = a.getBoundingClientRect(); + const bRect = a.getBoundingClientRect(); + return aRect.top - bRect.top; + }); + + if (allCarousels.length === 0) { + return; + } + let photoParams = null; const photoParamsTableElement = document.querySelector(".photo-params table"); @@ -178,7 +188,7 @@ document.addEventListener("DOMContentLoaded", (event) => { photoParams = new PhotoParametersTable(photoParamsTableElement); } - document.querySelectorAll("figure.carousel").forEach(carouselElement => { + allCarousels.forEach(carouselElement => { class CarouselItem { element = null; relativeX = 0;