templates/front/gallery/index.html.twig line 1

Open in your IDE?
  1. {% set numberElement = images_collection|length %}
  2. <div class="package-img-group mb-50">
  3.     <div class="row align-items-center g-3">
  4.         <div class="col-lg-6">
  5.             <div class="gallery-img-wrap thumb">
  6.                 <img src="{{ main_picture_path }}" alt="{{ main_picture_name }}" class="thumbnail"> <a href="#" class=" handleEye"><i
  7.                             class="bi bi-eye handleEye"></i></a>
  8.             </div>
  9.         </div>
  10.         <div class="col-lg-6 h-100">
  11.             <div class="row g-3 h-100">
  12.                 {% set compt = 1 %}
  13.                 {% for image in images_collection %}
  14.                     {% if compt <= 3 %}
  15.                         <div class="col-3 col-lg-6">
  16.                             <div class="gallery-img-wrap  handleEye">
  17.                                 <img src="{{ image.url }}" alt="{{ image.alt }}" class="thumbnail">
  18.                                 <a href="#" class=" handleEye"><i class="bi bi-eye handleEye"></i></a>
  19.                             </div>
  20.                         </div>
  21.                     {% elseif(compt == 4) %}
  22.                         <div class="col-3 col-lg-6">
  23.                             <div class="gallery-img-wrap handleEye active">
  24.                                 <img src="{{ main_picture_path }}" alt="">
  25.                                 <button class="StartSlideShowFirstImage "><i
  26.                                             class="bi bi-plus-lg handleEye"></i> {{ numberElement - 3 }} {{ 'Pages.Common.Messages.OtherImages'|trans({}, 'messages_front') }}
  27.                                 </button>
  28.                             </div>
  29.                         </div>
  30.                     {% endif %}
  31.                     {% set compt = compt + 1 %}
  32.                 {% endfor %}
  33.             </div>
  34.         </div>
  35.     </div>
  36. </div>
  37. <div id="modal-gallery" class="modal-gallery">
  38.     <span class="close">&times;</span>
  39.     <img class="modal-content" id="modal-image">
  40.     <div id="caption"></div>
  41.     <!-- Navigation buttons grouped at the top right -->
  42.     <div class="nav-buttons">
  43.         <span class="prev">&#10094; Prev</span>
  44.         <span class="next">Next &#10095;</span>
  45.     </div>
  46. </div>
  47. <style>
  48.     /* Modal styling */
  49.     .modal-gallery {
  50.         display: none; /* Hidden by default */
  51.         position: absolute;
  52.         border-radius: 10px;
  53.         z-index: 1;
  54.         left: 0;
  55.         top: 0;
  56.         width: 100%;
  57.         height: 100%;
  58.         overflow: hidden;
  59.         background-color: rgba(0, 0, 0, 0.9); /* Black background with opacity */
  60.     }
  61.     .modal-content {
  62.         margin: auto;
  63.         display: block;
  64.         width: auto;
  65.         height: auto;
  66.         max-width: 100%;
  67.         max-height: 100%;
  68.     }
  69.     .close {
  70.         position: absolute;
  71.         top: 20px;
  72.         right: 35px;
  73.         color: #ffffff;
  74.         font-size: 30px;
  75.         font-weight: bold;
  76.         transition: 0.3s;
  77.         z-index: 1;
  78.         padding: 0px 9px;
  79.         background-color: rgba(0, 0, 0, 0.5);
  80.         border-radius: 5px;
  81.     }
  82.     .close:hover,
  83.     .close:focus {
  84.         color: #bbb;
  85.         text-decoration: none;
  86.         cursor: pointer;
  87.     }
  88.     /* Navigation buttons styling for bottom-right corner */
  89.     .nav-buttons {
  90.         position: absolute;
  91.         bottom: 20px;
  92.         right: 20px;
  93.         display: flex;
  94.         gap: 10px;
  95.     }
  96.     .prev, .next {
  97.         cursor: pointer;
  98.         color: white;
  99.         font-size: 18px;
  100.         padding: 8px 16px;
  101.         background-color: rgba(0, 0, 0, 0.5);
  102.         border-radius: 5px;
  103.         user-select: none;
  104.         transition: background-color 0.3s, color 0.3s;
  105.     }
  106.     .prev:hover, .next:hover {
  107.         background-color: rgba(0, 0, 0, 0.8);
  108.         color: #bbb;
  109.     }
  110. </style>
  111. <script>
  112.     // Select all thumbnail images
  113.     const modal = document.getElementById('modal-gallery');
  114.     const modalImg = document.getElementById('modal-image');
  115.     const captionText = document.getElementById('caption');
  116.     const closeBtn = document.querySelector('.close');
  117.     const prevBtn = document.querySelector('.prev');
  118.     const nextBtn = document.querySelector('.next');
  119.     //const galleryImages = document.querySelectorAll('.thumbnail');
  120.     const galleryImages = [
  121.         {% for image in images_collection %}
  122.         {
  123.             src: "{{ image.url }}",
  124.             alt: "{{ image.alt }}"
  125.         }{% if not loop.last %},{% endif %}
  126.         {% endfor %}
  127.     ];
  128.     const handleEyes = document.querySelectorAll('.handleEye');
  129.     let currentIndex = 0;
  130.     // Function to open modal and display the clicked image
  131.     function openModal(event) {
  132.         const icon = event.target; // The clicked eye icon
  133.         const parentDiv = icon.closest('.gallery-img-wrap'); // Find the closest div containing the image
  134.         const image = parentDiv.querySelector('img'); // Get the image inside the same gallery-img-wrap div
  135.         if (image) {
  136.             modal.style.display = 'block'; // Show the modal
  137.             modalImg.src = image.src; // Set the modal image to the clicked image's src
  138.             captionText.innerHTML = image.alt; // Set the caption to the alt text of the image
  139.             currentIndex = Array.from(galleryImages).indexOf(image); // Set the current index of the clicked image
  140.         }
  141.     }
  142.     // Function to close the modal
  143.     function closeModal() {
  144.         modal.style.display = 'none';
  145.     }
  146.     /*
  147.       modal.style.display = 'block';
  148.         modalImg.src = event.target.src;
  149.      */
  150.     // Function to show the next image
  151.     function showNextImage() {
  152.         currentIndex = (currentIndex + 1) % galleryImages.length;
  153.         modalImg.src = galleryImages[currentIndex].src;
  154.         captionText.innerHTML = galleryImages[currentIndex].alt;
  155.     }
  156.     // Function to show the previous image
  157.     function showPrevImage() {
  158.         currentIndex = (currentIndex - 1 + galleryImages.length) % galleryImages.length;
  159.         modalImg.src = galleryImages[currentIndex].src;
  160.         captionText.innerHTML = galleryImages[currentIndex].alt;
  161.     }
  162.     handleEyes.forEach(eye => {
  163.         eye.addEventListener('click', openModal);
  164.     });
  165.     // Attach click event to each gallery image
  166.     // Attach click event to close button
  167.     closeBtn.addEventListener('click', closeModal);
  168.     // Attach click events to navigation buttons
  169.     nextBtn.addEventListener('click', showNextImage);
  170.     prevBtn.addEventListener('click', showPrevImage);
  171.     // Close the modal when clicking outside the image
  172.     window.addEventListener('click', (event) => {
  173.         if (event.target === modal) {
  174.             closeModal();
  175.         }
  176.     });
  177. </script>