| 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); |