1jQuery(function ($) { 2 3 /* ----------------------------- 4 FILTER STATE 5 ----------------------------- */ 6 7 let filters = { 8 product: null, 9 publisher: null, 10 category: null, 11 region: null 12 }; 13 14 let templateUrl = typeof window.template_url !== "undefined" ? window.template_url : ""; 15 16 let isLoading = false; 17 let isLastPage = false; 18 19 20 $(".dropdown_bar-item-box__item").click(function () { 21 let type = $(this).data("type"); 22 let id = $(this).data("id"); 23 let text = $(this).text().trim(); 24 let title = $(this).closest(".dropdown_bar").find(".dropdown_bar-item__title"); 25 26 if (title.text() === text) { 27 title.text(""); 28 filters[type] = null; 29 } else { 30 title.text(text); 31 filters[type] = id; 32 } 33 34 $(this).closest(".dropdown_bar-item-box-wrapper").removeClass("active"); 35 36 if (!$(this).closest(".modal").length) { 37 runFilter(); 38 } 39 }); 40 41 $(".dropdown_bar").click(function (event) { 42 if (!$(event.target).closest(".dropdown_bar-item-box-wrapper").length) { 43 let wrapper = $(this).find(".dropdown_bar-item-box-wrapper"); 44 45 $(".dropdown_bar-item-box-wrapper") 46 .not(wrapper) 47 .removeClass("active"); 48 49 wrapper.toggleClass("active"); 50 } 51 }); 52 53 $(".btn-apply-filter").click(function () { 54 runFilter(); 55 56 $(".overlay,.js-modal").removeClass("active"); 57 $("html, body").removeClass("scroll-disabled"); 58 }); 59 60 function runFilter(page = 1) { 61 if (isLoading) return; 62 63 isLoading = true; 64 65 if (page === 1) { 66 isLastPage = false; 67 } 68 69 let data = { 70 action: "filter_stories", 71 product: filters.product, 72 publisher: filters.publisher, 73 category: filters.category, 74 region: filters.region, 75 page: page, 76 nonce: cnk_loadmore_params.nonce 77 }; 78 79 $.ajax({ 80 url: cnk_loadmore_params.ajaxurl, 81 data: data, 82 type: "POST", 83 84 beforeSend: function () { 85 if (page === 1) { 86 $("#ajax_response").html( 87 '<div class="ajax-loader"><img style="width:auto;" src="' + 88 templateUrl + 89 '/assets/img/loading.png" /></div>' 90 ); 91 } else { 92 $(".cnk_loadmore").hide(); 93 $(".ajax-loader").removeClass("d-none"); 94 } 95 }, 96 97 success: function (response) { 98 isLoading = false; 99 100 let html = ""; 101 let lastPage = false; 102 103 if (typeof response === "string" && response.trim().startsWith("{")) { 104 try { 105 let parsed = JSON.parse(response); 106 html = parsed.content || ""; 107 lastPage = parsed.is_last_page || false; 108 109 if (lastPage) { 110 isLastPage = true; 111 } 112 } catch (error) { 113 html = response; 114 } 115 } else if (typeof response === "object" && response !== null) { 116 html = response.content || ""; 117 lastPage = response.is_last_page || false; 118 119 if (lastPage) { 120 isLastPage = true; 121 } 122 } else { 123 html = response; 124 } 125 126 if (html) { 127 if (page === 1) { 128 $("#ajax_response").html(html); 129 $(".no-results-message").hide(); 130 cnk_loadmore_params.current_page = 1; 131 } else { 132 $("#ajax_response").append(html); 133 cnk_loadmore_params.current_page++; 134 } 135 136 $(".cnk_loadmore").toggle(!isLastPage && !lastPage); 137 } else { 138 if (page === 1) { 139 $("#ajax_response").html(""); 140 $(".no-results-message").show(); 141 } 142 143 $(".cnk_loadmore").hide(); 144 } 145 }, 146 147 error: function (xhr, status, error) { 148 isLoading = false;
149 150 console.error("Ajax hatası:", error); 151 152 $(".ajax-loader").addClass("d-none"); 153 $(".cnk_loadmore").show(); 154 } 155 }); 156 } 157 158 $(".clear-filter-btn").click(function () { 159 filters = { 160 product: null, 161 publisher: null, 162 category: null, 163 region: null 164 }; 165 166 $(".dropdown_bar").each(function () { 167 let item = $(this).find('.dropdown_bar-item-box__item[data-id="all"]'); 168 let text = item.text().trim(); 169 170 $(this).find(".dropdown_bar-item__title").text(text); 171 }); 172 173 runFilter(); 174 175 $(".overlay, .js-modal").removeClass("active"); 176 $("html, body").removeClass("scroll-disabled"); 177 }); 178 179 /* ----------------------------- 180 GENERIC LOAD MORE 181 ----------------------------- */ 182 183 function loadMore(data, button) { 184 $.ajax({ 185 url: cnk_loadmore_params.ajaxurl, 186 type: "POST", 187 data: data, 188 189 beforeSend: function () { 190 button.addClass("disabled"); 191 $(".ajax-loader").removeClass("d-none"); 192 }, 193 194 success: function (response) { 195 if (!response) { 196 button.hide(); 197 return; 198 } 199 200 button.removeClass("disabled"); 201 $("#ajax_response").append(response); 202 $(".ajax-loader").addClass("d-none"); 203 204 cnk_loadmore_params.current_page++; 205 206 if (cnk_loadmore_params.current_page >= cnk_loadmore_params.max_page) { 207 button.hide(); 208 isLastPage = true; 209 } 210 }, 211 212 error: function (err) { 213 console.error("Ajax error:", err); 214 $(".ajax-loader").addClass("d-none"); 215 } 216 }); 217 } 218 219 /* ----------------------------- 220 LOAD MORE BUTTONS 221 ----------------------------- */ 222 223 $(".cnk_loadmore").on("click", function () { 224 let button = $(this); 225 226 if (isLastPage) return; 227 228 if (Object.values(filters).some(v => v !== null)) { 229 runFilter(cnk_loadmore_params.current_page + 1); 230 } else { 231 loadMore({ 232 action: "loadmore", 233 query: cnk_loadmore_params.posts, 234 page: cnk_loadmore_params.current_page, 235 nonce: cnk_loadmore_params.nonce 236 }, button); 237 } 238 }); 239 240 $(".cnk_loadmore_posts").on("click", function () { 241 let button = $(this); 242 243 loadMore({ 244 action: "loadmore_posts", 245 query: cnk_loadmore_params.posts, 246 page: cnk_loadmore_params.current_page, 247 nonce: cnk_loadmore_params.nonce 248 }, button); 249 }); 250 251 $(".cnk_loadmore_guides").on("click", function () { 252 let button = $(this); 253 254 loadMore({ 255 action: "loadmore_guides", 256 query: cnk_loadmore_params.posts, 257 page: cnk_loadmore_params.current_page, 258 nonce: cnk_loadmore_params.nonce 259 }, button); 260 }); 261 262 $(".cnk_loadmore_webinars").on("click", function () { 263 let button = $(this); 264 265 loadMore({ 266 action: "loadmore_webinars", 267 query: cnk_loadmore_params.posts, 268 page: cnk_loadmore_params.current_page, 269 nonce: cnk_loadmore_params.nonce 270 }, button); 271 }); 272 273 /* ----------------------------- 274 REPORTS LOAD MORE 275 ----------------------------- */ 276 277 let reportPage = 1; 278 let reportMaxPages = parseInt($(".cnk_loadmore_reports").data("max-pages")); 279 280 $(".cnk_loadmore_reports").on("click", function () { 281 let button = $(this); 282 283 if (reportPage >= reportMaxPages) { 284 button.hide(); 285 return; 286 } 287 288 $.ajax({ 289 url: cnk_loadmore_params.ajaxurl, 290 type: "POST", 291 data: { 292 action: "loadmore_reports", 293 query: cnk_loadmore_params.posts, 294 page: reportPage, 295 nonce: cnk_loadmore_params.nonce 296 }, 297 298 beforeSend: function () { 299 button.prop("disabled", true); 300 }, 301 302 success: function (response) { 303 if (!response) { 304 button.hide(); 305 return; 306 } 307 308 $("#ajax_response").append(response); 309 310 reportPage++; 311 312 if (reportPage >= reportMaxPages) { 313 button.hide(); 314 } else { 315 button.prop("disabled", false); 316 } 317 } 318 }); 319 }); 320 321});
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.