| 1 |
(function ($) { |
| 2 |
function SpPostShowCarouselInit() { |
| 3 |
if ($('.pcp-carousel-wrapper').length > 0) { |
| 4 |
function swiperSlide(selector, options) { |
| 5 |
if (1 === parseInt(pcp_vars.swiperEnqueue)) { |
| 6 |
return new PCPSwiper(selector, options); |
| 7 |
} else { |
| 8 |
return new Swiper(selector, options); |
| 9 |
} |
| 10 |
} |
| 11 |
$('.pcp-carousel-wrapper').each(function () { |
| 12 |
var pcp_container = $(this), |
| 13 |
pcp_container_id = pcp_container.attr('id'), |
| 14 |
pcpCarousel = $('#' + pcp_container_id + ' .sp-pcp-carousel:not(.swiper-initialized)'), |
| 15 |
pcpCarouselData = pcpCarousel.data('carousel'); |
| 16 |
if (pcpCarousel.length > 0) { |
| 17 |
// Carousel Swiper for Standard mode. |
| 18 |
var pcpSwiper = swiperSlide('#' + pcp_container_id + ' .sp-pcp-carousel', { |
| 19 |
speed: pcpCarouselData.speed, |
| 20 |
slidesPerView: pcpCarouselData.slidesPerView.mobile, |
| 21 |
spaceBetween: pcpCarouselData.spaceBetween, |
| 22 |
loop: pcpCarouselData.loop, |
| 23 |
loopFillGroupWithBlank: true, |
| 24 |
autoHeight: pcpCarouselData.autoHeight, |
| 25 |
simulateTouch: pcpCarouselData.simulateTouch, |
| 26 |
freeMode: pcpCarouselData.freeMode, |
| 27 |
allowTouchMove: pcpCarouselData.allowTouchMove, |
| 28 |
centeredSlides: pcpCarouselData.center_mode, |
| 29 |
mousewheel: pcpCarouselData.slider_mouse_wheel, |
| 30 |
lazy: pcpCarouselData.lazy, |
| 31 |
//grabCursor: true, |
| 32 |
pagination: |
| 33 |
pcpCarouselData.pagination == true |
| 34 |
? { |
| 35 |
el: '.swiper-pagination', |
| 36 |
clickable: true, |
| 37 |
dynamicBullets: pcpCarouselData.dynamicBullets, |
| 38 |
renderBullet: function (index, className) { |
| 39 |
if (pcpCarouselData.bullet_types == 'number') { |
| 40 |
return ( |
| 41 |
'<span class="' + |
| 42 |
className + |
| 43 |
'">' + |
| 44 |
(index + 1) + |
| 45 |
'</span>' |
| 46 |
) |
| 47 |
} else { |
| 48 |
return '<span class="' + className + '"></span>' |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
: false, |
| 53 |
autoplay: { |
| 54 |
delay: pcpCarouselData.autoplay_speed |
| 55 |
}, |
| 56 |
navigation: |
| 57 |
pcpCarouselData.navigation == true |
| 58 |
? { |
| 59 |
nextEl: '.pcp-button-next', |
| 60 |
prevEl: '.pcp-button-prev' |
| 61 |
} |
| 62 |
: false, |
| 63 |
breakpoints: { |
| 64 |
576: { |
| 65 |
slidesPerView: pcpCarouselData.slidesPerView.mobile_landscape, |
| 66 |
navigation: |
| 67 |
pcpCarouselData.navigation_mobile == true |
| 68 |
? { |
| 69 |
nextEl: '.pcp-button-next', |
| 70 |
prevEl: '.pcp-button-prev' |
| 71 |
} |
| 72 |
: false, |
| 73 |
pagination: |
| 74 |
pcpCarouselData.pagination_mobile == true |
| 75 |
? { |
| 76 |
el: '.swiper-pagination', |
| 77 |
clickable: true, |
| 78 |
dynamicBullets: pcpCarouselData.dynamicBullets, |
| 79 |
renderBullet: function (index, className) { |
| 80 |
if (pcpCarouselData.bullet_types == 'number') { |
| 81 |
return ( |
| 82 |
'<span class="' + |
| 83 |
className + |
| 84 |
'">' + |
| 85 |
(index + 1) + |
| 86 |
'</span>' |
| 87 |
) |
| 88 |
} else { |
| 89 |
return '<span class="' + className + '"></span>' |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
: false |
| 94 |
}, |
| 95 |
768: { |
| 96 |
slidesPerView: pcpCarouselData.slidesPerView.tablet, |
| 97 |
}, |
| 98 |
992: { |
| 99 |
slidesPerView: pcpCarouselData.slidesPerView.desktop, |
| 100 |
}, |
| 101 |
1200: { |
| 102 |
slidesPerView: pcpCarouselData.slidesPerView.lg_desktop, |
| 103 |
}, |
| 104 |
}, |
| 105 |
fadeEffect: { |
| 106 |
crossFade: true |
| 107 |
}, |
| 108 |
ally: { |
| 109 |
enabled: pcpCarouselData.enabled, |
| 110 |
prevSlideMessage: pcpCarouselData.prevSlideMessage, |
| 111 |
nextSlideMessage: pcpCarouselData.nextSlideMessage, |
| 112 |
firstSlideMessage: pcpCarouselData.firstSlideMessage, |
| 113 |
lastSlideMessage: pcpCarouselData.lastSlideMessage, |
| 114 |
paginationBulletMessage: pcpCarouselData.paginationBulletMessage |
| 115 |
}, |
| 116 |
keyboard: { |
| 117 |
enabled: pcpCarouselData.keyboard === "true" ? true : false, |
| 118 |
} |
| 119 |
}) |
| 120 |
if (pcpCarouselData.autoplay === false) { |
| 121 |
pcpSwiper.autoplay.stop() |
| 122 |
} |
| 123 |
if (pcpCarouselData.stop_onHover && pcpCarouselData.autoplay) { |
| 124 |
$(pcpCarousel).on({ |
| 125 |
mouseenter: function () { |
| 126 |
pcpSwiper.autoplay.stop(); |
| 127 |
}, |
| 128 |
mouseleave: function () { |
| 129 |
pcpSwiper.autoplay.start(); |
| 130 |
} |
| 131 |
}); |
| 132 |
} |
| 133 |
$(window).on('resize', function () { |
| 134 |
pcpSwiper.update() |
| 135 |
}) |
| 136 |
$(window).trigger("resize") |
| 137 |
} |
| 138 |
}) |
| 139 |
} |
| 140 |
|
| 141 |
/* Preloader js */ |
| 142 |
$('.sp-pcp-section').each(function () { |
| 143 |
var pcp_container = $(this).attr('id'); |
| 144 |
var PCP_Wrapper_ID = '#' + pcp_container; |
| 145 |
$(".pcp-preloader", PCP_Wrapper_ID).css({ "backgroundImage": "none", "visibility": "hidden" }); |
| 146 |
}) |
| 147 |
|
| 148 |
// Add class for gutenberg block. |
| 149 |
$('.sp-pcp-section').addClass('sp-pcp-section-loaded'); |
| 150 |
}; |
| 151 |
|
| 152 |
// Initialize the carousel when the document is ready |
| 153 |
$(document).ready(function () { |
| 154 |
SpPostShowCarouselInit(); |
| 155 |
}); |
| 156 |
|
| 157 |
// Register the handler with Elementor's frontend event. |
| 158 |
$(window).on('elementor/frontend/init', function () { |
| 159 |
// For general widget |
| 160 |
elementorFrontend.hooks.addAction('frontend/element_ready/smart_post_show_pro_shortcode.default', SpPostShowCarouselInit); |
| 161 |
// For deprecated widget. |
| 162 |
elementorFrontend.hooks.addAction('frontend/element_ready/sp_smart_post_show_free_shortcode.default', SpPostShowCarouselInit); |
| 163 |
}); |
| 164 |
})(jQuery); |