| 1 |
(function ($) { |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
// Elementor hook |
| 5 |
const initEelGalleryPopup = function ($scope) { |
| 6 |
const $gallery = $scope.find('.eel-gallery-grid.eel-popup-enabled'); |
| 7 |
if (!$gallery.length) return; |
| 8 |
|
| 9 |
let currentIndex = 0; |
| 10 |
const $lightbox = $scope.find('.eel-lightbox-gallery'); |
| 11 |
const $lightboxImg = $lightbox.find('.eel-lightbox-image'); |
| 12 |
const $galleryLinks = $gallery.find('.eel-popup-link'); |
| 13 |
|
| 14 |
function openLightbox(index) { |
| 15 |
currentIndex = index; |
| 16 |
const imgSrc = $galleryLinks.eq(currentIndex).attr('href'); |
| 17 |
$lightboxImg.attr('src', imgSrc); |
| 18 |
$lightbox.fadeIn(300).css('display', 'grid'); |
| 19 |
} |
| 20 |
|
| 21 |
function showNext() { |
| 22 |
currentIndex = (currentIndex + 1) % $galleryLinks.length; |
| 23 |
$lightboxImg.attr('src', $galleryLinks.eq(currentIndex).attr('href')); |
| 24 |
} |
| 25 |
|
| 26 |
function showPrev() { |
| 27 |
currentIndex = (currentIndex - 1 + $galleryLinks.length) % $galleryLinks.length; |
| 28 |
$lightboxImg.attr('src', $galleryLinks.eq(currentIndex).attr('href')); |
| 29 |
} |
| 30 |
|
| 31 |
$galleryLinks.off('click').on('click', function (e) { |
| 32 |
e.preventDefault(); |
| 33 |
const index = $(this).data('index'); |
| 34 |
openLightbox(index); |
| 35 |
}); |
| 36 |
|
| 37 |
$lightbox.find('.eel-next').off('click').on('click', showNext); |
| 38 |
$lightbox.find('.eel-prev').off('click').on('click', showPrev); |
| 39 |
$lightbox.find('.eel-close').off('click').on('click', function () { |
| 40 |
$lightbox.fadeOut(200); |
| 41 |
}); |
| 42 |
|
| 43 |
$lightbox.off('click').on('click', function (e) { |
| 44 |
if ($(e.target).is('.eel-lightbox-gallery, .eel-close')) { |
| 45 |
$lightbox.fadeOut(200); |
| 46 |
} |
| 47 |
}); |
| 48 |
|
| 49 |
$(document).off('keydown.eelLightbox').on('keydown.eelLightbox', function (e) { |
| 50 |
if ($lightbox.is(':visible')) { |
| 51 |
if (e.key === 'ArrowRight') showNext(); |
| 52 |
else if (e.key === 'ArrowLeft') showPrev(); |
| 53 |
else if (e.key === 'Escape') $lightbox.fadeOut(200); |
| 54 |
} |
| 55 |
}); |
| 56 |
}; |
| 57 |
|
| 58 |
// � |
| 59 |
Works on both frontend and Elementor editor |
| 60 |
$(window).on('elementor/frontend/init', function () { |
| 61 |
elementorFrontend.hooks.addAction( |
| 62 |
'frontend/element_ready/eel-gallery.default', |
| 63 |
initEelGalleryPopup |
| 64 |
); |
| 65 |
}); |
| 66 |
|
| 67 |
})(jQuery); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
(function ($) { |
| 72 |
"use strict"; |
| 73 |
|
| 74 |
const initEelCarouselPopup = function ($scope) { |
| 75 |
const $galleryLinks = $scope.find('.eel-popup-link-carousel'); |
| 76 |
const $lightbox = $scope.find('.eel-lightbox-carousel'); |
| 77 |
const $lightboxImg = $lightbox.find('.eel-lightbox-image-carousel'); |
| 78 |
let currentIndex = 0; |
| 79 |
|
| 80 |
if (!$galleryLinks.length) return; |
| 81 |
|
| 82 |
function updateLightboxImage(index) { |
| 83 |
currentIndex = index; |
| 84 |
const $targetLink = $galleryLinks.eq(currentIndex); |
| 85 |
const imgSrc = $targetLink.attr('href'); |
| 86 |
|
| 87 |
$lightboxImg.attr('src', imgSrc); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
$galleryLinks.off('click').on('click', function (e) { |
| 92 |
e.preventDefault(); |
| 93 |
|
| 94 |
const index = parseInt($(this).attr('data-index')) || 0; |
| 95 |
updateLightboxImage(index); |
| 96 |
$lightbox.fadeIn(300).css('display', 'grid'); |
| 97 |
}); |
| 98 |
|
| 99 |
// Next Button |
| 100 |
$lightbox.find('.eel-next').off('click').on('click', function (e) { |
| 101 |
e.stopPropagation(); |
| 102 |
let nextIndex = (currentIndex + 1) % $galleryLinks.length; |
| 103 |
updateLightboxImage(nextIndex); |
| 104 |
}); |
| 105 |
|
| 106 |
// Previous Button |
| 107 |
$lightbox.find('.eel-prev').off('click').on('click', function (e) { |
| 108 |
e.stopPropagation(); |
| 109 |
let prevIndex = (currentIndex - 1 + $galleryLinks.length) % $galleryLinks.length; |
| 110 |
updateLightboxImage(prevIndex); |
| 111 |
}); |
| 112 |
|
| 113 |
// Close Button |
| 114 |
$lightbox.find('.eel-close').off('click').on('click', function () { |
| 115 |
$lightbox.fadeOut(200); |
| 116 |
}); |
| 117 |
|
| 118 |
|
| 119 |
$(document).off('keydown.eelCarousel').on('keydown.eelCarousel', function (e) { |
| 120 |
if ($lightbox.is(':visible')) { |
| 121 |
if (e.key === "ArrowRight") $lightbox.find('.eel-next').click(); |
| 122 |
if (e.key === "ArrowLeft") $lightbox.find('.eel-prev').click(); |
| 123 |
if (e.key === "Escape") $lightbox.fadeOut(200); |
| 124 |
} |
| 125 |
}); |
| 126 |
}; |
| 127 |
|
| 128 |
$(window).on('elementor/frontend/init', function () { |
| 129 |
elementorFrontend.hooks.addAction( |
| 130 |
'frontend/element_ready/eel-image-carousel.default', |
| 131 |
initEelCarouselPopup |
| 132 |
); |
| 133 |
}); |
| 134 |
|
| 135 |
})(jQuery); |