PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.0
Easy Elements for Elementor – Addons & Website Templates v1.5.0
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / gallery / js / simple-gallery.js

simple-gallery.js in Easy Elements for Elementor – Addons & Website Templates 1.5.0, at widgets/gallery/js/simple-gallery.js

67 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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);