1class TolstoySlider extends HTMLElement{connectedCallback(){this._ready||customElements.whenDefined("splide-carousel").then(()=>{this.waitForSliders()})}waitForSliders(attempts=0){if(this.initCarousel=this.querySelector(".tolstoy__init-slider"),this.mainCarousel=this.querySelector(".tolstoy__main-slider"),this.overlay=this.querySelector(".tolstoy__overlay"),this.initSplide=this.initCarousel?.slider,this.mainSplide=this.mainCarousel?.slider,this.initSplide&&this.mainSplide){this.init();return}attempts<20&&requestAnimationFrame(()=>this.waitForSliders(attempts+1))}init(){this._ready||(this._ready=!0,this.muted=!1,this.isOpen=!1,this.syncMutedState(),this.getVideos().forEach(video=>{video.playsInline=!0,video.setAttribute("playsinline",""),video.setAttribute("webkit-playsinline","")}),this.bindInitOpens(),this.bindInitArrows(),this.bindMainNav(),this.bindSoundButtons(),this.bindOverlayDismiss(),this.bindAddToCart(),this.bindViewportObserver(),this.syncInitProgress(),this.mainSplide.on("moved",()=>{this.isOpen&&!this._isOpening&&requestAnimationFrame(()=>{this.playSlide(),this.updateMainNavState()})}),this.initSplide.on("move",()=>this.syncInitProgress()),this.initSplide.on("moved",()=>{this.syncInitProgress(),this.updateInitNavState()}),this.initSplide.on("mounted",()=>{this.syncInitProgress(),this.updateInitNavState()}))}bindInitOpens(){this.querySelectorAll("[data-tolstoy-open]").forEach(button=>{button.addEventListener("click",()=>{this.openMain(Number(button.dataset.tolstoyOpen))})})}bindInitArrows(){this.querySelectorAll("[data-init-prev]").forEach(button=>{button.addEventListener("click",()=>this.initSplide.go("<"))}),this.querySelectorAll("[data-init-next]").forEach(button=>{button.addEventListener("click",()=>this.initSplide.go(">"))})}bindMainNav(){this.overlay?.addEventListener("click",event=>{event.target.closest("[data-main-prev]")&&(event.stopPropagation(),this.mainSplide.go("<")),event.target.closest("[data-main-next]")&&(event.stopPropagation(),this.mainSplide.go(">")),event.target.closest("[data-tolstoy-close]")&&(event.stopPropagation(),this.closeMain())})}bindSoundButtons(){this.overlay?.addEventListener("click",event=>{event.target.closest("[data-sound]")&&(event.preventDefault(),event.stopPropagation(),this.toggleSound())})}bindOverlayDismiss(){this.overlay?.addEventListener("click",event=>{if(!event.target.closest(".tolstoy__main-panel")){if(this.isMobileOverlay()){event.target===this.overlay&&this.closeMain();return}this.closeMain()}}),this._onKeydown=event=>{event.key==="Escape"&&this.isOpen&&this.closeMain()},document.addEventListener("keydown",this._onKeydown)}bindViewportObserver(){"IntersectionObserver"in window&&(this._viewportObserver=new IntersectionObserver(entries=>{entries.forEach(entry=>{entry.isIntersecting||this.handleLeftViewport()})},{threshold:0}),this._viewportObserver.observe(this))}handleLeftViewport(){this.isOpen&&this.closeMain()}bindAddToCart(){this._atcResetTimers=new Map,this._checkmarkTemplate=this.querySelector("[data-tolstoy-atc-check-template]"),this.querySelectorAll("product-form[data-tolstoy-atc]").forEach(form=>{form.addEventListener("tolstoy:added",()=>{this.showAddedState(form)})})}showAddedState(productForm){const button=productForm.querySelector("[data-tolstoy-atc-button]"),label=productForm.querySelector("[data-tolstoy-atc-label]"),icon=productForm.querySelector("[data-tolstoy-atc-icon]");if(!button||!label||!icon)return;const existingTimer=this._atcResetTimers.get(button);existingTimer&&clearTimeout(existingTimer),button.dataset.tolstoyOriginalLabel||(button.dataset.tolstoyOriginalLabel=label.textContent.trim(),button.dataset.tolstoyOriginalIcon=icon.innerHTML),button.setAttribute("aria-disabled","true"),button.disabled=!0,button.classList.add("tolstoy-atc--added"),label.textContent=this.dataset.addedLabel||"Added to cart",icon.innerHTML="";const checkmark=this._checkmarkTemplate?.content?.firstElementChild?.cloneNode(!0);checkmark&&icon.appendChild(checkmark);const resetTimer=setTimeout(()=>{this.resetAddedState(button,label,icon),this._atcResetTimers.delete(button)},5e3);this._atcResetTimers.set(button,resetTimer)}resetAddedState(button,label,icon){button.removeAttribute("aria-disabled"),button.disabled=!1,button.classList.remove("tolstoy-atc--added"),label.textContent=button.dataset.tolstoyOriginalLabel||this.dataset.buyLabel||"",icon.innerHTML=button.dataset.tolstoyOriginalIcon||""}syncInitProgress(){const progressBar=this.querySelector(".tolstoy__init-progress-bar");if(!progressBar||!this.initSplide)return;const end=this.initSplide.Components.Controller.getEnd()+1,index=this.initSplide.index,progress=end>1?index/(end-1):1;
1progressBar.style.width=`${Math.min(progress,1)*100}%`}getVideos(){return[...this.mainCarousel.querySelectorAll("video")]}getActiveSlide(){return this.mainCarousel&&(this.mainCarousel.querySelector(".splide__slide.is-visible")||this.mainCarousel.querySelector('.splide__slide.is-active:not([aria-hidden="true"])'))||null}getSlideVideo(slide){if(!slide)return null;const video=slide.querySelector("video");if(!video)return null;if(this.getVideoSourceUrl(video))return video;const logicalIndex=slide.dataset.tolstoySlide;if(logicalIndex==null)return video;const sourceVideo=this.mainCarousel.querySelector(`.splide__slide[data-tolstoy-slide="${logicalIndex}"]:not(.splide__slide--clone)`)?.querySelector("video");if(!sourceVideo||!this.getVideoSourceUrl(sourceVideo))return video;const sources=sourceVideo.querySelectorAll("source");return sources.length?video.replaceChildren(...[...sources].map(item=>item.cloneNode(!0))):sourceVideo.src&&(video.src=sourceVideo.src),sourceVideo.poster&&(video.poster=sourceVideo.poster),video.load(),video}getVideoSourceUrl(video){return video&&(video.currentSrc||video.querySelector("source")?.getAttribute("src")||video.getAttribute("src"))||""}getVideoPovs(){return[...this.mainCarousel.querySelectorAll(".tolstoy__video-pov")]}getSoundButtons(){return[...this.mainCarousel.querySelectorAll("[data-sound]")]}setVideoMuted(video,muted){video.muted=muted,muted?video.setAttribute("muted",""):video.removeAttribute("muted")}syncMutedState(){this.getVideos().forEach(video=>{this.setVideoMuted(video,this.muted)}),this.getSoundButtons().forEach(button=>{button.classList.toggle("sound-off",this.muted)})}goToSlide(index,animate=!0){const splide=this.mainSplide;if(animate){splide.go(index);return}const{Controller,Move,Transition,Slides}=splide.Components,{speed,waitForTransition}=splide.options;Transition.cancel(),splide.options.speed=0,splide.options.waitForTransition=!1,Controller.setIndex(index),Move.jump(index),Slides.update(),splide.options.speed=speed,splide.options.waitForTransition=waitForTransition}pauseAll(){this.getVideoPovs().forEach(videoPov=>{videoPov.classList.remove("playing")}),this.getVideos().forEach(video=>{video.pause(),video.currentTime=0})}playSlide(){this.pauseAll();const slide=this.getActiveSlide(),video=this.getSlideVideo(slide);if(!video)return;const startPlayback=()=>{this.getActiveSlide()===slide&&(this.setVideoMuted(video,this.muted),slide.querySelector(".tolstoy__video-pov")?.classList.add("playing"),video.play().catch(()=>{}))};if(video.readyState>=HTMLMediaElement.HAVE_FUTURE_DATA){startPlayback();return}video.addEventListener("canplay",startPlayback,{once:!0}),video.networkState===HTMLMediaElement.NETWORK_EMPTY&&video.load()}toggleSound(){this.muted=!this.muted,this.syncMutedState()}getContentColumn(){const mainProduct=this.closest(".main-product");return mainProduct?mainProduct.querySelector(".main-product__column--content")||mainProduct.querySelector(".main-product__column--content-basic"):null}isMobileOverlay(){return window.matchMedia("(max-width: 920px)").matches}mountOverlay(){if(this._overlayMode=this.isMobileOverlay()?"mobile":"desktop",this._overlayMode==="mobile"){this.overlay.parentElement!==document.body&&document.body.appendChild(this.overlay),this.resetOverlayPosition();return}const column=this.getContentColumn();column&&(this.overlay.parentElement!==column&&column.appendChild(this.overlay),column.classList.add("tolstoy-column--open"),this.positionOverlay())}unmountOverlay(){const column=this.getContentColumn();this._overlayMode==="mobile"?this.overlay.parentElement===document.body&&this.appendChild(this.overlay):(column?.classList.remove("tolstoy-column--open"),this.overlay.parentElement!==this&&this.appendChild(this.overlay)),this.resetOverlayPosition(),this._overlayMode=null}positionOverlay(){if(!this.overlay)return;if(this.isMobileOverlay()){this.resetOverlayPosition();return}const column=this.getContentColumn();if(!column)return;const columnRect=column.getBoundingClientRect();this.overlay.style.top="0",this.overlay.style.right="auto",this.overlay.style.bottom="0",this.overlay.style.left=`${columnRect.left}px`,this.overlay.style.width=`${columnRect.width}px`,this.overlay.style.height="100vh",this.overlay.style.height="100dvh"}resetOverlayPosition(){this.overlay.style.top="",this.overlay.style.right="",this.overlay.style.bottom="",this.overlay.style.left="",this.overlay.style.width="",this.overlay.style.height=""}bindOverlayListeners(){this._onReposition=()=>{this.isOpen&&this.positionOverlay()},window.addEventListener("resize",this._onReposition),window.addEventListener("scroll",this._onReposition,{passive:!0})}unbindOverlayListeners(){this._onReposition&&(window.removeEventListener("resize",this._onReposition),window.removeEventListener("scroll",this._onReposition))}openMain(index){this.isOpen=!0,this._isOpening=!0,this.mountOverlay(),this.bindOverlayListeners(),this.overlay.classList.add("tolstoy__overlay--open"),this.overlay.setAttribute("aria-hidden","false"),this.classList.add("tolstoy--open"),document.body.classList.add("tolstoy-slider-open"),requestAnimationFrame(()=>{this.mainSplide.refresh(),this.goToSlide(index,!1),requestAnimationFrame(()=>{this._isOpening=!1,this.playSlide(),this.updateMainNavState()})})}closeMain(){this.isOpen=!1,this.pauseAll(),this.muted=!1,this.syncMutedState(),this.unbindOverlayListeners(),this.overlay.classList.remove("tolstoy__overlay--open"),this.overlay.setAttribute("aria-hidden","true"),this.classList.remove("tolstoy--open"),document.body.classList.remove("tolstoy-slider-open"),this.unmountOverlay(),this.goToSlide(0,!1)}updateMainNavState(){const prev=this.overlay?.querySelector("[data-main-prev]"),next=this.overlay?.querySelector("[data-main-next]");!prev||!next||(prev.disabled=!1,next.disabled=!1)}updateInitNavState(){const atStart=this.initSplide.index===0,atEnd=this.initSplide.index>=this.initSplide.length-1;this.querySelectorAll("[data-init-prev]").forEach(button=>{button.disabled=atStart}),this.querySelectorAll("[data-init-next]").forEach(button=>{button.disabled=atEnd})}disconnectedCallback(){document.removeEventListener("keydown",this._onKeydown),this.unbindOverlayListeners?.(),this._viewportObserver?.disconnect(),this._atcResetTimers?.forEach(timer=>clearTimeout(timer)),this._atcResetTimers?.clear(),this.isOpen&&(this.getContentColumn()?.classList.remove("tolstoy-column--open"),this.unmountOverlay()),document.body.classList.remove("tolstoy-slider-open")}}customElements.define("tolstoy-slider",TolstoySlider); 2//# sourceMappingURL=/cdn/shop/t/68/assets/tolstoy-slider.js.map?v=170833974143626800051784634458
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.