52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
(function($) {
|
|
"use strict";
|
|
|
|
if (typeof window.initGeneralAdSection === 'function') {
|
|
// return;
|
|
}
|
|
|
|
window.initGeneralAdSection = function(moduleId) {
|
|
const $module = $('#' + moduleId);
|
|
if (!$module.length) return;
|
|
|
|
$module.find('.general-ad-row').each(function() {
|
|
const $row = $(this);
|
|
const $swiperContainer = $row.find('.swiper-container');
|
|
|
|
const slidesPerView = parseInt($swiperContainer.data('slides-per-view'), 10) || 6;
|
|
const spaceBetween = parseInt($swiperContainer.data('space-between'), 10) || 10;
|
|
const totalSlides = $swiperContainer.find('.swiper-slide').length;
|
|
|
|
const loop = totalSlides > 1;
|
|
|
|
new Swiper($swiperContainer[0], {
|
|
slidesPerView: 2,
|
|
spaceBetween: spaceBetween,
|
|
loop: loop,
|
|
autoplay: {
|
|
delay: 3000,
|
|
disableOnInteraction: false,
|
|
},
|
|
navigation: {
|
|
nextEl: $row.find('.swiper-button-next')[0],
|
|
prevEl: $row.find('.swiper-button-prev')[0],
|
|
},
|
|
breakpoints: {
|
|
640: { slidesPerView: 3 },
|
|
768: { slidesPerView: 4 },
|
|
1024: {
|
|
slidesPerView: (totalSlides < slidesPerView) ? totalSlides : slidesPerView
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
$(function() {
|
|
$('.general-ad-section').each(function() {
|
|
window.initGeneralAdSection($(this).attr('id'));
|
|
});
|
|
});
|
|
|
|
})(jQuery);
|