1if (!customElements.get("f-slideshow")) { 2 class FSlideshow extends HTMLElement { 3 constructor() { 4 super(); 5 } 6 7 connectedCallback() { 8 this.autoplay = this.dataset.autoplay === "1"; 9 this.autoplaySpeed = parseInt(this.dataset.autoplaySpeed); 10 this.showArrows = this.dataset.enableArrows === "1"; 11 this.showDots = this.dataset.enableDots === "1"; 12 this.id = this.dataset.id; 13 this.sliderContainer = this.querySelector(".swiper-container"); 14 15 this.lastVideo = null; 16 this.lastActive = null; 17 this.timeout = null; 18 this.initSlider(); 19 } 20 21 initSlider() { 22 const swiperConfig = { 23 init: false, 24 autoplay: this.autoplay 25 ? { 26 delay: this.autoplaySpeed * 1000, 27 disableOnInteraction: false, // â æ¹ï¼ä¸è¦å ä¸ºç¨æ·äº¤äºææ 28 } 29 : false, 30 slidesPerView: 1, 31 slidesPerGroup: 1, 32 loop: true, 33 effect: "fade", 34 fadeEffect: { 35 crossFade: true, 36 }, 37 speed: 1000, 38 navigation: this.showArrows 39 ? { 40 nextEl: this.querySelector(".f-slider-controls__button-next"), 41 prevEl: this.querySelector(".f-slider-controls__button-prev"), 42 } 43 : false, 44 pagination: this.showDots 45 ? { 46 el: ".swiper-pagination", 47 clickable: true, 48 bulletClass: "f-dot", 49 bulletActiveClass: "f-dot--active", 50 } 51 : false, 52 breakpoints: { 53 992: { 54 threshold: 2, 55 }, 56 }, 57 on: { 58 init: () => { 59 // â åå§ååç«å³ææ¾é¦å±è§é¢ 60 setTimeout(() => { 61 this.playActiveVideo(); 62 window.dispatchEvent(new Event("resize")); 63 }, 150); 64 }, 65 slideChange: () => this.handleChange(), 66 }, 67 }; 68 69 this.slider = new Swiper(this.sliderContainer, swiperConfig); 70 this.slider.init(); 71 72 // â çªå£å°ºå¯¸åååéæ°ææ¾è§é¢ 73 window.addEventListener("resize", () => { 74 clearTimeout(this._resizeTimer); 75 this._resizeTimer = setTimeout(() => { 76 this.playActiveVideo(); 77 }, 300); 78 }); 79 } 80 81 handleChange() { 82 const { activeIndex, slides } = this.slider; 83 const activeSlide = slides[activeIndex]; 84 if (!activeSlide) return; 85 86 const slideType = activeSlide.dataset.slideType; 87 88 if (slideType === "video_slide") { 89 const video = activeSlide.querySelector("video"); 90 if (video) { 91 // æåä¸ä¸ä¸ªè§é¢ 92 if (this.lastVideo && this.lastVideo !== video) { 93 this.lastVideo.pause(); 94 } 95 96 // â èªå¨ææ¾å½åè§é¢ 97 const playPromise = video.play(); 98 if (playPromise !== undefined) { 99 playPromise 100 .then(() => { 101 this.lastVideo = video; 102 }) 103 .catch((err) => { 104 console.warn("Video play prevented:", err); 105 }); 106 } 107 } 108 } else { 109 // éè§é¢æ¶æåä¸ä¸ä¸ªè§é¢ 110 if (this.lastVideo) { 111 this.lastVideo.pause(); 112 this.lastVideo = null; 113 } 114 } 115 } 116 117 playActiveVideo() { 118 // â ä¸é¨ç¨äºåå§åæ resize æ¶è°ç¨ 119 if (!this.slider) return; 120 const { activeIndex, slides } = this.slider; 121 const activeSlide = slides[activeIndex]; 122 if (!activeSlide) return; 123 if (activeSlide.dataset.slideType !== "video_slide") return; 124 125 const video = activeSlide.querySelector("video"); 126 if (!video) return; 127 128 // è¥ loop 模å¼ä¸è§é¢è¢«å éï¼å¼ºå¶ææ¾çå®èç¹ 129 try { 130 video.currentTime = 0; 131 video.play(); 132 this.lastVideo = video; 133 } catch (err) { 134 console.warn("playActiveVideo failed:", err); 135 } 136 } 137 138 onBlockSelect(ev) { 139 const block = ev.target; 140 const index = Number(block.dataset.slide); 141 this.lastActive = index; 142 if (this.slider) { 143 this.slider.slideToLoop(index); 144 this.playActiveVideo(); // â ç«å³ææ¾ 145 } 146 } 147 } 148
149 customElements.define("f-slideshow", FSlideshow); 150}
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.