State Variables
The gallery system maintains the following state:renderGallery
Initializes and renders the complete gallery system with main image, thumbnails, and navigation controls.Array of image URLs or paths. URLs starting with “http” are used as-is; others are prefixed with
images/. Falls back to placeholder if array is empty.Behavior
- Image resolution: Converts relative paths to
images/{filename}format - Fallback handling: Shows placeholder image when no images provided
- State initialization: Populates
lightboxImagesandgalleryImagesarrays - Responsive setup: Adjusts
galleryThumbsPerPagebased on viewport (4 for mobile, 8 for desktop) - Photo counter: Updates the photo count display element
- Event binding: Attaches click handlers for navigation, lightbox opening, and window resize
- Initial display: Renders thumbnails and activates first image
Side Effects
- Updates DOM elements:
#gallery-main-image,#gallery-thumbnails,#photo-count - Binds click handlers to
#thumb-prev,#thumb-next,#gallery-main-prev,#gallery-main-next - Makes main image clickable to open lightbox
- Registers resize listener to handle responsive thumbnail adjustments
- Controls visibility of 360° tour button (shown only on first image)
Example Usage
setActive
Changes the currently displayed image in the gallery.Zero-based index of the image to display
Behavior
- Updates
galleryCurrentIndexstate - Changes main image
srcandaltattributes - Calls
updateGalleryThumbHighlights()to update thumbnail styling - Shows 360° tour button only when
index === 0(first image)
renderGallery() at ~/workspace/source/app.js:261-272
updateGalleryThumbHighlights
Updates the visual styling of thumbnails to indicate the active image.Behavior
- Queries all
.thumbnail-itemelements - Calculates actual image index based on current pagination page
- Toggles CSS classes:
- Active:
ring-2 ring-primary opacity-100 - Inactive:
opacity-80
- Active:
renderGallery() at ~/workspace/source/app.js:274-286
renderThumbnails
Renders the current page of thumbnails with pagination controls.Behavior
- Clears thumbnail container
- Recalculates
galleryThumbsPerPagefor current viewport - Creates thumbnail DOM elements for visible page
- Binds click handlers:
- Single click: Calls
setActive(i) - Double click: Calls
openLightbox(i)
- Single click: Calls
- Updates navigation button disabled states
- Renders pagination dots with
renderPaginationDots()
DOM Structure
Each thumbnail has:- Classes:
thumbnail-item aspect-square rounded-md overflow-hidden bg-slate-100 dark:bg-slate-700 cursor-pointer transition - Active styling:
ring-2 ring-primary opacity-100 - Inactive styling:
opacity-80 hover:opacity-100
renderGallery() at ~/workspace/source/app.js:288-322
galleryNextImage
Navigates to the next image in the gallery, with wraparound.Behavior
- Increments index with modulo wraparound (last → first)
- Calls
setActive()to update display - Auto-advances thumbnail page if new image is on different page
renderGallery() at ~/workspace/source/app.js:324-333
galleryPrevImage
Navigates to the previous image in the gallery, with wraparound.Behavior
- Decrements index with modulo wraparound (first → last)
- Calls
setActive()to update display - Auto-advances thumbnail page if new image is on different page
renderGallery() at ~/workspace/source/app.js:335-344
thumbNextPage
Advances to the next page of thumbnails.Behavior
- Checks if next page exists
- Increments
galleryThumbPage - Calls
renderThumbnails()to update display
renderGallery() at ~/workspace/source/app.js:346-352
thumbPrevPage
Goes back to the previous page of thumbnails.Behavior
- Checks if previous page exists
- Decrements
galleryThumbPage - Calls
renderThumbnails()to update display
renderGallery() at ~/workspace/source/app.js:354-359
Integration
The gallery functions work together in this flow:renderGallery(images)initializes the systemrenderThumbnails()displays current page of thumbnailssetActive(index)changes the main imageupdateGalleryThumbHighlights()updates thumbnail styling- Navigation functions (
galleryNextImage,galleryPrevImage,thumbNextPage,thumbPrevPage) modify state and trigger re-renders
Event Handlers
- Thumbnail click:
setActive(i) - Thumbnail double-click:
openLightbox(i) - Main image click:
openLightbox(galleryCurrentIndex) - Window resize: Recalculates
galleryThumbsPerPageand re-renders - Navigation buttons: Bound to respective next/prev functions