Files
dnssash/theme/rd.dnssash/rb.custom/premium_ad_section/module.js
T
2026-06-11 18:47:38 +09:00

67 lines
2.5 KiB
JavaScript

(function($) {
"use strict";
if (typeof window.initPremiumAdSection === 'function') {
// return;
}
window.initPremiumAdSection = function(moduleId) {
const $module = $('#' + moduleId);
if (!$module.length) return;
$module.find('.premium-ad-row').each(function() {
const $row = $(this);
const $swiperContainer = $row.find('.swiper-container');
// 설정된 컬럼 수 (예: 6)
const configColumns = parseInt($swiperContainer.data('slides-per-view'), 10) || 6;
const spaceBetween = parseInt($swiperContainer.data('space-between'), 10) || 10;
// 실제 슬라이드 개수 (예: 3)
const totalSlides = $swiperContainer.find('.swiper-slide').length;
// 💡 [핵심 수정] 슬라이드 개수가 설정된 컬럼 수보다 적으면, 개수만큼만 보여줘서 꽉 채움
// 예: 6개 설정인데 3개만 있다면, 3개를 100% 너비로 꽉 채워서 보여줌
let slidesPerViewPC = configColumns;
if (totalSlides > 0 && totalSlides < configColumns) {
slidesPerViewPC = totalSlides;
}
// 슬라이드가 1개면 롤링 안 함, 2개 이상이면 무조건 롤링
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: (totalSlides < 3) ? totalSlides : 3
},
768: {
slidesPerView: (totalSlides < 4) ? totalSlides : 4
},
1024: {
// 💡 PC에서는 계산된 slidesPerViewPC 사용
slidesPerView: slidesPerViewPC
}
}
});
});
};
$(function() {
$('.premium-ad-section').each(function() {
window.initPremiumAdSection($(this).attr('id'));
});
});
})(jQuery);