1(function ($) { 2 window["cozyBlockPopularPostsInit"] = (e) => { 3 const n = e.replace(/-/gi, "_"); 4 const blockOptions = window[`cozyBlock_${n}`]; 5 const blockID = `#cozyBlock_${n}`; 6 7 if (blockOptions.display === "ticker") { 8 const tickerAttr = { 9 init: true, 10 direction: "vertical", 11 loop: blockOptions.sliderOptions.loop, 12 autoplay: blockOptions.sliderOptions.autoplay, 13 speed: blockOptions.sliderOptions.speed, 14 slidesPerView: blockOptions.sliderOptions.slidesPerView, 15 spaceBetween: blockOptions.sliderOptions.spaceBetween, 16 navigation: { 17 nextEl: `${blockID} .swiper-button-next`, 18 prevEl: `${blockID} .swiper-button-prev`, 19 }, 20 }; 21 22 if (blockOptions.sliderOptions.autoplay.status) { 23 tickerAttr.autoplay = { ...blockOptions.sliderOptions.autoplay }; 24 } else { 25 delete tickerAttr.autoplay; 26 } 27 28 new Swiper(blockID, tickerAttr); 29 } 30 31 if (blockOptions.display === "carousel") { 32 const carouselAttr = { 33 init: true, 34 loop: blockOptions?.carouselOptions?.loop, 35 autoplay: blockOptions?.carouselOptions?.autoplay, 36 speed: blockOptions?.carouselOptions?.speed, 37 slidesPerView: blockOptions?.carouselOptions?.slidesPerView, 38 spaceBetween: blockOptions?.carouselOptions?.spaceBetween, 39 navigation: { 40 nextEl: `${blockID} .swiper-button-next`, 41 prevEl: `${blockID} .swiper-button-prev`, 42 }, 43 pagination: { 44 el: `${blockID} .swiper-pagination`, 45 clickable: true, 46 }, 47 effect: blockOptions?.carouselOptions?.effect, 48 breakpoints: { 49 100: { 50 slidesPerView: 1, 51 }, 52 767: { 53 slidesPerView: 54 blockOptions.carouselOptions.slidesPerView <= 2 55 ? blockOptions.carouselOptions.slidesPerView 56 : 2, 57 }, 58 1024: { 59 slidesPerView: 60 blockOptions.carouselOptions.slidesPerView <= 3 61 ? blockOptions.carouselOptions.slidesPerView 62 : 3, 63 }, 64 1180: { 65 slidesPerView: blockOptions.carouselOptions.slidesPerView, 66 }, 67 }, 68 }; 69 70 if (blockOptions?.carouselOptions?.autoplay?.status) { 71 carouselAttr.autoplay = { 72 ...blockOptions?.carouselOptions?.autoplay, 73 }; 74 } else { 75 delete carouselAttr.autoplay; 76 } 77 78 new Swiper(blockID, carouselAttr); 79 } 80 81 if ( 82 (blockOptions.display === "grid" || blockOptions.display === "list") && 83 blockOptions?.ajaxLoader?.enabled 84 ) { 85 if (blockOptions?.ajaxLoader?.type === "default") { 86 let offset = 0; 87 $(blockID + " .cozy-block-popular-posts__ajax-loader").click( 88 function () { 89 var button = $(this); 90 button.addClass("show-spinner"); 91 $.ajax({ 92 url: blockOptions.ajaxUrl, 93 method: "POST", 94 data: { 95 action: "cozy_block_popular_posts_loader", 96 nonce: blockOptions.nonce, 97 offset: offset, 98 attributes: JSON.stringify(blockOptions), 99 }, 100 success: function (response) { 101 if (!response.success) { 102 button.addClass("display-none"); 103 return; 104 } 105 106 if (response.success && response.data) { 107 var $newPosts = $(response.data.render).hide(); // Hide new posts initially 108 109 if (blockOptions.display === "grid") { 110 $( 111 blockID + " .cozy-block-popular-posts__grid-wrapper" 112 ).append($newPosts); 113 } 114 115 if (blockOptions.display === "list") { 116 $( 117 blockID + " .cozy-block-popular-posts__list-wrapper" 118 ).append($newPosts); 119 } 120 121 // Fade in the new posts with animation 122 $newPosts.fadeIn(600); // Adjust duration as needed 123 button.removeClass("show-spinner"); 124 125 offset += blockOptions.ajaxLoader.content; 126 127 if (parseInt(response.data.next_chunk_count) <= 0) { 128 button.addClass("display-none"); 129 } 130 } 131 }, 132 error: function (error) { 133 console.log("Unable to load data..."); 134 }, 135 }); 136 } 137 ); 138 } 139 140 if (blockOptions?.ajaxLoader?.type === "scroll") { 141 const element = document.querySelector( 142 blockID + ".has-infinite-scroll" 143 ); 144 let isFetching = false; // Flag to prevent multiple AJAX requests 145 let offset = 0; // Initialize offset 146 let hasNextChunk = true; 147 148 function isContainerNearingEnd(el) { 149 var rect = el.getBoundingClientRect(); 150 var buffer = 200; // Adjust the buffer value as needed 151 return ( 152 rect.bottom - buffer <= 153 (window.innerHeight || document.documentElement.clientHeight) 154 ); 155 } 156 157 function fetchNewContent() { 158 if (isFetching) return; // Exit if an AJAX request is already in progress 159 160 isFetching = true; // Set the fetching flag to true 161 $(".scroll-spinner").removeClass("display-none"); 162 $.ajax({ 163 url: blockOptions.ajaxUrl, 164 method: "POST", 165 data: { 166 action: "cozy_block_popular_posts_loader", 167 nonce: blockOptions.nonce, 168 offset: offset, 169 attributes: JSON.stringify(blockOptions), 170 }, 171 success: function (response) { 172 if (!response.success) { 173 $(".scroll-spinner").addClass("display-none"); 174 } 175 if (response.success && response.data) { 176 var $newPosts = $(response.data.render).hide(); // Hide new posts initially 177 178 if (blockOptions.display === "grid") { 179 $( 180 blockID + " .cozy-block-popular-posts__grid-wrapper" 181 ).append($newPosts); 182 } 183 184 if (blockOptions.display === "list") { 185 $( 186 blockID + " .cozy-block-popular-posts__list-wrapper" 187 ).append($newPosts); 188 } 189 190 // Fade in the new posts with animation 191 $newPosts.fadeIn(600); // Adjust duration as needed 192 193 offset += blockOptions.ajaxLoader.content; 194 if (parseInt(response.data.next_chunk_count) <= 0) { 195 $(".scroll-spinner").addClass("display-none"); 196 hasNextChunk = false;
197 } 198 } 199 }, 200 error: function (error) { 201 console.log("Unable to load data..."); 202 }, 203 complete: function () { 204 isFetching = false; // Reset the fetching flag 205 $(".scroll-spinner").addClass("display-none"); 206 }, 207 }); 208 } 209 210 function debounce(func, wait) { 211 let timeout; 212 return function () { 213 clearTimeout(timeout); 214 timeout = setTimeout(() => func.apply(this, arguments), wait); 215 }; 216 } 217 218 const handleScroll = debounce(function () { 219 if (isContainerNearingEnd(element) && hasNextChunk) { 220 fetchNewContent(); 221 } 222 }, 200); // Adjust the debounce delay as needed 223 224 window.addEventListener("scroll", handleScroll); 225 } 226 } 227 }; 228})(jQuery);
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.