Исправлены ошибки

This commit is contained in:
Valentin Silyutin
2025-11-12 20:10:40 +04:00
parent d257b13650
commit 1ab21ec6c7

View File

@@ -93,6 +93,7 @@ const playVideo = (slide) => {
clearInterval(checkInterval); clearInterval(checkInterval);
} }
}, 100); }, 100);
slide.checkInterval = checkInterval;
} }
}; };
@@ -118,9 +119,7 @@ const pauseVideo = (slide) => {
const setVideoSize = (gallery) => { const setVideoSize = (gallery) => {
const items = gallery.querySelectorAll('.advdominion-lg__video-wrapper'); const items = gallery.querySelectorAll('.advdominion-lg__video-wrapper');
items[0].style = ` items[0].style.cssText = '';
width: '';
`;
let height = (items[0].getBoundingClientRect().width * 9) / 16; let height = (items[0].getBoundingClientRect().width * 9) / 16;
let width = ''; let width = '';
if (height > items[0].getBoundingClientRect().height) { if (height > items[0].getBoundingClientRect().height) {
@@ -128,7 +127,7 @@ const setVideoSize = (gallery) => {
width = `${(height * 16) / 9}px`; width = `${(height * 16) / 9}px`;
} }
for (const item of items) { for (const item of items) {
item.style = ` item.style.cssText = `
height: ${height}px; height: ${height}px;
width: ${width}; width: ${width};
`; `;
@@ -143,10 +142,17 @@ const hide = async (duration = 500, easing = 'linear') => {
easing, easing,
}).finished; }).finished;
// Очищаем интервалы проверки для видео
for (const slide of gallery.querySelectorAll('.advdominion-lg__item_video')) {
if (slide.checkInterval) {
clearInterval(slide.checkInterval);
}
}
gallery.remove(); gallery.remove();
delete window.GalleryRTPlayer; delete window.GalleryRTPlayer;
document.body.style = ` document.body.style.cssText = `
overflow: ''; overflow: '';
margin-right: ''; margin-right: '';
`; `;
@@ -155,7 +161,7 @@ const hide = async (duration = 500, easing = 'linear') => {
const show = async (duration = 500, easing = 'linear') => { const show = async (duration = 500, easing = 'linear') => {
const gallery = document.body.querySelector('.advdominion-lg'); const gallery = document.body.querySelector('.advdominion-lg');
document.body.style = ` document.body.style.cssText = `
overflow: hidden; overflow: hidden;
margin-right: ${getScrollbarWidth()}px margin-right: ${getScrollbarWidth()}px
`; `;
@@ -328,7 +334,7 @@ const init = async (items = [], options = {}, index = 0) => {
const gallery = document.body.querySelector('.advdominion-lg'); const gallery = document.body.querySelector('.advdominion-lg');
gallery.querySelector('.advdominion-lg__container').style = ` gallery.querySelector('.advdominion-lg__container').style.cssText = `
visibility: hidden; visibility: hidden;
`; `;
@@ -340,7 +346,7 @@ const init = async (items = [], options = {}, index = 0) => {
); );
swiper.on('init', function () { swiper.on('init', function () {
gallery.querySelector('.advdominion-lg__container').style = ` gallery.querySelector('.advdominion-lg__container').style.cssText = `
visibility: ''; visibility: '';
`; `;
@@ -375,26 +381,25 @@ const init = async (items = [], options = {}, index = 0) => {
swiper.init(); swiper.init();
gallery.querySelector('.advdominion-lg__close').addEventListener('click', () => { const closeHandler = () => {
hide(options?.animation?.hide?.duration, options?.animation?.hide?.easing); hide(options?.animation?.hide?.duration, options?.animation?.hide?.easing);
}); };
document.querySelector('body').addEventListener( const keydownHandler = (e) => {
'keydown', if (e.key === 'Escape') {
(e) => { closeHandler();
if (e.key === 'Escape') { document.body.removeEventListener('keydown', keydownHandler);
hide(options?.animation?.hide?.duration, options?.animation?.hide?.easing); }
} };
},
{ gallery.querySelector('.advdominion-lg__close').addEventListener('click', closeHandler);
once: true, document.body.addEventListener('keydown', keydownHandler);
},
);
}; };
export const gallery = (container, options) => { export const gallery = (container, options) => {
const items = []; const items = [];
if (options.single) { if (options.single) {
const element = container.children[0];
items.push({ items.push({
url: element.href, url: element.href,
caption: document.querySelector(element.dataset.galleryCaption)?.textContent, caption: document.querySelector(element.dataset.galleryCaption)?.textContent,