|
| 1 | +<!-- Image Gallery Modal --> |
| 2 | +<div class="modal fade" id="imageModal" tabindex="-1" aria-labelledby="imageModalLabel" aria-hidden="true"> |
| 3 | + <div class="modal-dialog modal-fullscreen"> |
| 4 | + <div class="modal-content bg-dark"> |
| 5 | + <div class="modal-header border-0"> |
| 6 | + <h5 class="modal-title text-white" id="imageModalLabel">Image Gallery</h5> |
| 7 | + <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button> |
| 8 | + </div> |
| 9 | + <div class="modal-body d-flex align-items-center justify-content-center position-relative p-0"> |
| 10 | + <button type="button" class="btn btn-light position-absolute start-0 ms-3 rounded-circle" id="modal-prev-btn" style="z-index: 1050; width: 50px; height: 50px;"> |
| 11 | + <span class="material-symbols-outlined">chevron_left</span> |
| 12 | + </button> |
| 13 | + <img id="modal-image" src="" alt="" class="img-fluid" style="max-height: 90vh; max-width: 100%;"> |
| 14 | + <button type="button" class="btn btn-light position-absolute end-0 me-3 rounded-circle" id="modal-next-btn" style="z-index: 1050; width: 50px; height: 50px;"> |
| 15 | + <span class="material-symbols-outlined">chevron_right</span> |
| 16 | + </button> |
| 17 | + </div> |
| 18 | + <div class="modal-footer border-0 justify-content-center"> |
| 19 | + <span class="text-white" id="modal-counter">1 / 1</span> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | +</div> |
| 24 | + |
| 25 | +<script> |
| 26 | +// Image modal functionality |
| 27 | +(function() { |
| 28 | + let currentImages = []; |
| 29 | + let currentIndex = 0; |
| 30 | + |
| 31 | + const modal = document.getElementById('imageModal'); |
| 32 | + const modalImage = document.getElementById('modal-image'); |
| 33 | + const modalCounter = document.getElementById('modal-counter'); |
| 34 | + const prevBtn = document.getElementById('modal-prev-btn'); |
| 35 | + const nextBtn = document.getElementById('modal-next-btn'); |
| 36 | + |
| 37 | + function updateImage() { |
| 38 | + if (currentImages.length === 0) return; |
| 39 | + modalImage.src = currentImages[currentIndex]; |
| 40 | + modalCounter.textContent = `${currentIndex + 1} / ${currentImages.length}`; |
| 41 | + } |
| 42 | + |
| 43 | + function showPrev() { |
| 44 | + currentIndex = (currentIndex - 1 + currentImages.length) % currentImages.length; |
| 45 | + updateImage(); |
| 46 | + } |
| 47 | + |
| 48 | + function showNext() { |
| 49 | + currentIndex = (currentIndex + 1) % currentImages.length; |
| 50 | + updateImage(); |
| 51 | + } |
| 52 | + |
| 53 | + // Event listeners |
| 54 | + prevBtn.addEventListener('click', showPrev); |
| 55 | + nextBtn.addEventListener('click', showNext); |
| 56 | + |
| 57 | + // Keyboard navigation |
| 58 | + document.addEventListener('keydown', function(e) { |
| 59 | + if (modal.classList.contains('show')) { |
| 60 | + if (e.key === 'ArrowLeft') showPrev(); |
| 61 | + else if (e.key === 'ArrowRight') showNext(); |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + // Global function to open modal |
| 66 | + window.openImageModal = function(images, index) { |
| 67 | + currentImages = images; |
| 68 | + currentIndex = index; |
| 69 | + updateImage(); |
| 70 | + const bsModal = new bootstrap.Modal(modal); |
| 71 | + bsModal.show(); |
| 72 | + }; |
| 73 | +})(); |
| 74 | +</script> |
0 commit comments