1const bannerSwiper = new Swiper(".udaivilas-banner", { 2 loop: true, 3 slidesPerView: 1, 4 speed: 700, 5 effect: "fade", 6 watchOverflow: true, 7 fadeEffect: { crossFade: true }, 8 9 autoplay: { 10 delay: 5000, 11 disableOnInteraction: false 12 }, 13 mousewheel: { 14 forceToAxis: true, 15 sensitivity: 0.5, 16 thresholdDelta: 20, 17 thresholdTime: 200, 18 releaseOnEdges: true 19 }, 20 21 navigation: { 22 nextEl: ".swiper-button-next", 23 prevEl: ".swiper-button-prev" 24 }, 25 26 on: { 27 init: function () { 28 // const swiper = this; 29 // const totalSlides = swiper.slides.length - swiper.loopedSlides * 2; 30 31 // if (totalSlides <= 1) { 32 // $(swiper.navigation.nextEl).css("display", "none"); 33 // $(swiper.navigation.prevEl).css("display", "none"); 34 // } 35 36 stopAutoplayIfVideo(this); 37 playVideoIfExists(this); 38 }, 39 40 slideChangeTransitionStart: function () { 41 pauseAllVideos(this); 42 // Reset mute button on slide change 43 const muteBtn = document.getElementById("muteToggleButton"); 44 if (muteBtn) muteBtn.classList.remove("mute"); 45 }, 46 47 slideChangeTransitionEnd: function () { 48 stopAutoplayIfVideo(this); 49 playVideoIfExists(this); 50 } 51 } 52}); 53 54 55// ------------------------ 56// UTILITY FUNCTIONS 57// ------------------------ 58 59function getActiveSlide(swiper) { 60 return [...swiper.slides].find( 61 (s) => s.dataset.swiperSlideIndex == swiper.realIndex 62 ); 63} 64 65function playVideoIfExists(swiper) { 66 const slide = getActiveSlide(swiper); 67 const video = slide?.querySelector(".slide-video"); 68 if (!video) { 69 swiper.autoplay.start(); // image slide 70 return; 71 } 72 73 swiper.autoplay.stop(); // video slide 74 75 video.muted = true; 76 video.currentTime = 0; 77 78 video.onended = () => { 79 swiper.slideNext(); 80 }; 81 82 video.play().catch(() => {}); 83} 84 85function stopAutoplayIfVideo(swiper) { 86 const slide = getActiveSlide(swiper); 87 const video = slide?.querySelector(".slide-video"); 88 if (video) swiper.autoplay.stop(); 89} 90 91function pauseAllVideos(swiper) { 92 swiper.slides.forEach((s) => { 93 const v = s.querySelector(".slide-video"); 94 if (v) v.pause(); 95 }); 96} 97 98 99// ------------------------ 100// MUTE BUTTON 101// ------------------------ 102const muteBtn = document.getElementById("muteToggleButton"); 103if (muteBtn) { 104 muteBtn.addEventListener("click", () => { 105 const activeVideo = document.querySelector(".swiper-slide-active .slide-video"); 106 if (activeVideo) { 107 activeVideo.muted = !activeVideo.muted; 108 muteBtn.classList.toggle("mute", activeVideo.muted === false); 109 } 110 }); 111}
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.