const modalEvents = ['touchstart', 'touchmove', 'touchend', 'mousemove', 'click', 'zoom:open']; modalEvents.forEach(event => modal.addEventListener(event, hideByTimeout)); // Показываем UI, если переключаем слайды стрелками клавиатуры document.addEventListener('keydown', e => { const { isOpen } = t_getZoomState(); if (isOpen && ['ArrowLeft', 'ArrowRight'].includes(e.key)) hideByTimeout(); }); function hideByTimeout() { if (timerID) clearTimeout(timerID); updateControlsHiddenState('remove'); timerID = setTimeout(() => { const { isOpen } = t_getZoomState(); updateControlsHiddenState(isOpen ? 'add' : 'remove'); timerID = 0; }, 2000); } modal.addEventListener('zoom:close', () => { if (timerID) clearTimeout(timerID); updateControlsHiddenState('remove'); }); function updateControlsHiddenState(action) { const hideAnimationClass = 't-zoomer__hide-animation'; const uiElements = document.querySelectorAll('.t-zoomer__ui-item, .t-zoomer__comments'); uiElements.forEach(control => control.classList[action](hideAnimationClass)); }}/** * in case of count of zoom el not more one */function t_zoom__initSingleZoom() { const slidesCount = document.querySelectorAll('.t-carousel__zoomer__item').length; if (slidesCount === 1) { const controls = document.querySelectorAll('.t-carousel__zoomer__control'); controls.forEach(control => { control.style.display = 'none'; }); }}/** * get and set events on prev/next btns */function t_zoom__getEventOnBtn() { const navBtns = [ { name: 'right', direction: 'next', }, { name: 'left', direction: 'prev', }, ]; navBtns.forEach(({ name, direction }) => { const button = document.querySelector(`.t-carousel__zoomer__control_${name}`); button?.addEventListener('click', () => t_zoom__setEventOnBtn(direction)); });}/** * @param {'next' | 'prev'} direction */function t_zoom__setEventOnBtn(direction) { const slidesLength = document.querySelectorAll('.t-carousel__zoomer__item').length; if (slidesLength <= 1) return; const sliderTrack = document.querySelector('.t-carousel__zoomer__track'); const modal = document.querySelector('.t-zoomer__wrapper'); const sliderOnTransition = sliderTrack.getAttribute('data-on-transition'); const modalOnDrag = modal.getAttribute('data-on-drag'); if (sliderOnTransition === 'y' || modalOnDrag === 'y') return; t_zoom_unscale(); setTimeout(() => { t_zoom_showSlide(direction); });}/** * create slides for zoomer carousel: * from target element will find parent with all slides,