1const initBannerBlock = function() { 2 const carousel1 = document.getElementsByClassName('c-carousel__slides'); 3 const carousel2 = document.getElementsByClassName('c-carousel__content-slides'); 4 const navButtons = document.getElementsByClassName('c-carousel__nav--button') 5 let flkty1; 6 let flkty2; 7 8 function buildCarousel() { 9 const carouselOption1 = JSON.parse(carousel1[0].dataset.flickdata); 10 const carouselOption2 = JSON.parse(carousel2[0].dataset.flickdata); 11 flkty1 = new Flickity(carousel1[0], carouselOption1); 12 flkty2 = new Flickity(carousel2[0], carouselOption2); 13 } 14 15 function Timer(callback, delay) { 16 let timerId, start, remaining = delay; 17 18 this.pause = function() { 19 window.clearTimeout(timerId); 20 remaining -= new Date() - start; 21 }; 22 23 this.resume = function() { 24 start = new Date(); 25 window.clearTimeout(timerId); 26 timerId = window.setTimeout(callback, remaining); 27 }; 28 29 this.resume(); 30 } 31 32 const timer = new Timer(function() { 33 flkty2.playPlayer(); 34 timer.pause(); 35 console.log('timer'); 36 }, 4000); 37 38 timer.pause(); 39 40 // Check we have carousels 41 if ( carousel1.length && carousel2.length) { 42 buildCarousel(); 43 // Add the navigation 44 if ( navButtons.length) { 45 for (let i = 0; i < navButtons.length; i++) { 46 navButtons[i].addEventListener('click', function(event) { 47 event.preventDefault(); 48 const direction = this.dataset.carouselNav; 49 flkty2.stopPlayer(); 50 timer.resume(); 51 if (direction === 'previous') flkty2.previous(true); 52 if (direction === 'next') flkty2.next(true); 53 }); 54 } 55 } 56 } 57}; 58 59//Initialize dynamic block preview (editor). 60if (window.acf) { 61 window.acf.addAction( 62 "render_block_preview/type=carousel", 63 initBannerBlock 64 ); 65}
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.