{% set numberElement = images_collection|length %}
<div class="package-img-group mb-50">
<div class="row align-items-center g-3">
<div class="col-lg-6">
<div class="gallery-img-wrap thumb">
<img src="{{ main_picture_path }}" alt="{{ main_picture_name }}" class="thumbnail"> <a href="#" class=" handleEye"><i
class="bi bi-eye handleEye"></i></a>
</div>
</div>
<div class="col-lg-6 h-100">
<div class="row g-3 h-100">
{% set compt = 1 %}
{% for image in images_collection %}
{% if compt <= 3 %}
<div class="col-3 col-lg-6">
<div class="gallery-img-wrap handleEye">
<img src="{{ image.url }}" alt="{{ image.alt }}" class="thumbnail">
<a href="#" class=" handleEye"><i class="bi bi-eye handleEye"></i></a>
</div>
</div>
{% elseif(compt == 4) %}
<div class="col-3 col-lg-6">
<div class="gallery-img-wrap handleEye active">
<img src="{{ main_picture_path }}" alt="">
<button class="StartSlideShowFirstImage "><i
class="bi bi-plus-lg handleEye"></i> {{ numberElement - 3 }} {{ 'Pages.Common.Messages.OtherImages'|trans({}, 'messages_front') }}
</button>
</div>
</div>
{% endif %}
{% set compt = compt + 1 %}
{% endfor %}
</div>
</div>
</div>
</div>
<div id="modal-gallery" class="modal-gallery">
<span class="close">×</span>
<img class="modal-content" id="modal-image">
<div id="caption"></div>
<!-- Navigation buttons grouped at the top right -->
<div class="nav-buttons">
<span class="prev">❮ Prev</span>
<span class="next">Next ❯</span>
</div>
</div>
<style>
/* Modal styling */
.modal-gallery {
display: none; /* Hidden by default */
position: absolute;
border-radius: 10px;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.9); /* Black background with opacity */
}
.modal-content {
margin: auto;
display: block;
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
}
.close {
position: absolute;
top: 20px;
right: 35px;
color: #ffffff;
font-size: 30px;
font-weight: bold;
transition: 0.3s;
z-index: 1;
padding: 0px 9px;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 5px;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
/* Navigation buttons styling for bottom-right corner */
.nav-buttons {
position: absolute;
bottom: 20px;
right: 20px;
display: flex;
gap: 10px;
}
.prev, .next {
cursor: pointer;
color: white;
font-size: 18px;
padding: 8px 16px;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 5px;
user-select: none;
transition: background-color 0.3s, color 0.3s;
}
.prev:hover, .next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: #bbb;
}
</style>
<script>
// Select all thumbnail images
const modal = document.getElementById('modal-gallery');
const modalImg = document.getElementById('modal-image');
const captionText = document.getElementById('caption');
const closeBtn = document.querySelector('.close');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
//const galleryImages = document.querySelectorAll('.thumbnail');
const galleryImages = [
{% for image in images_collection %}
{
src: "{{ image.url }}",
alt: "{{ image.alt }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
];
const handleEyes = document.querySelectorAll('.handleEye');
let currentIndex = 0;
// Function to open modal and display the clicked image
function openModal(event) {
const icon = event.target; // The clicked eye icon
const parentDiv = icon.closest('.gallery-img-wrap'); // Find the closest div containing the image
const image = parentDiv.querySelector('img'); // Get the image inside the same gallery-img-wrap div
if (image) {
modal.style.display = 'block'; // Show the modal
modalImg.src = image.src; // Set the modal image to the clicked image's src
captionText.innerHTML = image.alt; // Set the caption to the alt text of the image
currentIndex = Array.from(galleryImages).indexOf(image); // Set the current index of the clicked image
}
}
// Function to close the modal
function closeModal() {
modal.style.display = 'none';
}
/*
modal.style.display = 'block';
modalImg.src = event.target.src;
*/
// Function to show the next image
function showNextImage() {
currentIndex = (currentIndex + 1) % galleryImages.length;
modalImg.src = galleryImages[currentIndex].src;
captionText.innerHTML = galleryImages[currentIndex].alt;
}
// Function to show the previous image
function showPrevImage() {
currentIndex = (currentIndex - 1 + galleryImages.length) % galleryImages.length;
modalImg.src = galleryImages[currentIndex].src;
captionText.innerHTML = galleryImages[currentIndex].alt;
}
handleEyes.forEach(eye => {
eye.addEventListener('click', openModal);
});
// Attach click event to each gallery image
// Attach click event to close button
closeBtn.addEventListener('click', closeModal);
// Attach click events to navigation buttons
nextBtn.addEventListener('click', showNextImage);
prevBtn.addEventListener('click', showPrevImage);
// Close the modal when clicking outside the image
window.addEventListener('click', (event) => {
if (event.target === modal) {
closeModal();
}
});
</script>