Task 10121 | fix: поправили прайсы цен для карт, которые некорректно выводятся при заполнении из админки
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Небольшая задержка для корректной инициализации GLightbox
|
||||
setTimeout(() => {
|
||||
document.querySelectorAll('.simple-gallery-block').forEach(function (block) {
|
||||
const blockId = block.getAttribute('data-gallery-id');
|
||||
@@ -16,28 +15,32 @@ function initSimpleGallery(blockId) {
|
||||
let thumbnailSwiper;
|
||||
let lightbox;
|
||||
|
||||
// Проверяем, одно изображение или несколько
|
||||
const isSingleImage = container.querySelector('.single-image');
|
||||
const hasMultipleImages = container.querySelector('.gallery-swiper');
|
||||
|
||||
function initLightbox() {
|
||||
if (typeof GLightbox === 'undefined') {
|
||||
console.warn('GLightbox is not loaded');
|
||||
return;
|
||||
}
|
||||
// Ждем загрузки GLightbox
|
||||
const checkGLightbox = () => {
|
||||
if (typeof GLightbox !== 'undefined') {
|
||||
const selector = `#${blockId} .glightbox`;
|
||||
|
||||
const selector = `#${blockId} .glightbox`;
|
||||
if (lightbox) {
|
||||
lightbox.destroy();
|
||||
}
|
||||
|
||||
if (lightbox) {
|
||||
lightbox.destroy();
|
||||
}
|
||||
lightbox = GLightbox({
|
||||
selector: selector,
|
||||
preload: false,
|
||||
touchNavigation: true,
|
||||
loop: true
|
||||
});
|
||||
} else {
|
||||
// Пробуем еще раз через 100мс
|
||||
setTimeout(checkGLightbox, 100);
|
||||
}
|
||||
};
|
||||
|
||||
lightbox = GLightbox({
|
||||
selector: selector,
|
||||
preload: false,
|
||||
touchNavigation: true,
|
||||
loop: true
|
||||
});
|
||||
checkGLightbox();
|
||||
}
|
||||
|
||||
function updateThumbnails(activeIndex) {
|
||||
@@ -59,7 +62,7 @@ function initSimpleGallery(blockId) {
|
||||
}
|
||||
}
|
||||
|
||||
// Инициализация для одного изображения
|
||||
// Если одно изображение
|
||||
if (isSingleImage) {
|
||||
initLightbox();
|
||||
|
||||
@@ -69,9 +72,12 @@ function initSimpleGallery(blockId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Инициализация для множественных изображений
|
||||
// Если несколько изображений
|
||||
if (hasMultipleImages) {
|
||||
// Thumbnail swiper
|
||||
const slides = hasMultipleImages.querySelectorAll('.swiper-slide');
|
||||
const isSingleSlide = slides.length <= 1;
|
||||
|
||||
// Инициализируем свайпер для миниатюр
|
||||
thumbnailSwiper = new Swiper(`#${blockId} .thumbnail-swiper`, {
|
||||
slidesPerView: 'auto',
|
||||
spaceBetween: 6,
|
||||
@@ -80,8 +86,9 @@ function initSimpleGallery(blockId) {
|
||||
watchSlidesProgress: true,
|
||||
});
|
||||
|
||||
// Main swiper
|
||||
// Инициализируем основной свайпер
|
||||
mainSwiper = new Swiper(`#${blockId} .gallery-swiper`, {
|
||||
loop: true,
|
||||
slidesPerView: 'auto',
|
||||
spaceBetween: 0,
|
||||
grabCursor: true,
|
||||
@@ -90,6 +97,12 @@ function initSimpleGallery(blockId) {
|
||||
loadPrevNext: true,
|
||||
loadOnTransitionStart: true,
|
||||
},
|
||||
pagination: {
|
||||
el: `#${blockId} .simple-gallery-swiper-pagination`,
|
||||
type: 'bullets',
|
||||
clickable: true,
|
||||
bulletClass: 'swiper-pagination-bullet',
|
||||
},
|
||||
on: {
|
||||
slideChange: function () {
|
||||
updateThumbnails(this.realIndex);
|
||||
@@ -98,10 +111,23 @@ function initSimpleGallery(blockId) {
|
||||
}
|
||||
});
|
||||
|
||||
// Lightbox для множественных изображений
|
||||
// Скрываем элементы навигации при одном слайде
|
||||
if (isSingleSlide) {
|
||||
const pagination = container.querySelector('.simple-gallery-swiper-pagination');
|
||||
const thumbnailContainer = container.querySelector('.thumbnail-swiper').parentElement;
|
||||
|
||||
if (pagination) pagination.style.display = 'none';
|
||||
if (thumbnailContainer) thumbnailContainer.style.display = 'none';
|
||||
|
||||
if (mainSwiper.autoplay) {
|
||||
mainSwiper.autoplay.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// Инициализируем лайтбокс
|
||||
initLightbox();
|
||||
|
||||
// Обработчик клика по thumbnail
|
||||
// Обработчик кликов по миниатюрам
|
||||
container.addEventListener('click', (e) => {
|
||||
const thumbnail = e.target.closest('.thumbnail');
|
||||
if (!thumbnail) return;
|
||||
@@ -109,14 +135,14 @@ function initSimpleGallery(blockId) {
|
||||
const index = parseInt(thumbnail.getAttribute('data-index'));
|
||||
|
||||
if (mainSwiper) {
|
||||
mainSwiper.slideTo(index);
|
||||
mainSwiper.slideToLoop(index);
|
||||
}
|
||||
|
||||
updateThumbnails(index);
|
||||
centerThumbnail(index);
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
// Очистка ресурсов при выгрузке страницы
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (mainSwiper) mainSwiper.destroy();
|
||||
if (thumbnailSwiper) thumbnailSwiper.destroy();
|
||||
|
||||
Reference in New Issue
Block a user