1jQuery(document).ready(function ($) { 2 let page = 1; 3 let currentCategory = "all"; 4 5 function loadPosts(reset = false) { 6 $.ajax({ 7 url: ajax_object.ajaxurl, 8 type: "POST", 9 data: { 10 action: "load_blog_posts", 11 page: page, 12 category: currentCategory, 13 nonce: ajax_object.nonce, 14 }, 15 beforeSend: function () { 16 $("#load-more-btn").text("Loading..."); 17 $("#blog-posts-container").addClass("loader"); 18 }, 19 success: function (response) { 20 if (reset) { 21 $("#blog-posts-container").html(response.html); 22 $("#blog-posts-container").removeClass("loader"); 23 } else { 24 $("#blog-posts-container").append(response.html); 25 $("#blog-posts-container").removeClass("loader"); 26 } 27 28 $("#load-more-btn").text("Load More"); 29 if (response.current_page >= response.max_pages) { 30 $("#load-more-btn").hide(); 31 } else { 32 $("#load-more-btn").show(); 33 } 34 if ($.trim(response.html) === "<p>No posts found.</p>") { 35 $("#load-more-btn").hide(); 36 } 37 }, 38 error: function (xhr) { 39 console.log(xhr.responseText); 40 }, 41 }); 42 } 43 44 if (document.querySelector(".blog-listing")) { 45 loadPosts(true); 46 } 47 48 $(document).on("click", ".blog-filter__wrap li a", function (e) { 49 e.preventDefault(); 50 51 $(".blog-filter__wrap li").removeClass("active"); 52 $(this).parent().addClass("active"); 53 54 currentCategory = $(this).data("category"); 55 page = 1; 56 57 loadPosts(true); 58 }); 59 60 $(document).on("click", "#load-more-btn", function (e) { 61 e.preventDefault(); 62 page++; 63 loadPosts(); 64 }); 65 function loadFAQs(reset = false) { 66 $.ajax({ 67 url: ajax_object.ajaxurl, 68 type: "POST", 69 data: { 70 action: "load_faq_posts", 71 page: page, 72 category: currentCategory, 73 nonce: ajax_object.nonce, 74 }, 75 beforeSend: function () { 76 // $("#post-loader").html('<span class="loading">Loading...</span>'); 77 $("#faq-posts-wrapper").addClass("loader"); 78 }, 79 success: function (response) { 80 if (reset) { 81 $("#faq-posts-wrapper").html(response.html); 82 $("#faq-posts-wrapper").removeClass("loader"); 83 } else { 84 $("#faq-posts-wrapper").append(response.html); 85 $("#faq-posts-wrapper").removeClass("loader"); 86 } 87 // $("#post-loader").hide(""); 88 89 // Render pagination numbers 90 renderPagination(response.max_pages, response.current_page); 91 92 // Hide "No FAQs" message 93 if ($.trim(response.html) === "<p>No FAQs found.</p>") { 94 // $("#faq-pagination").hide(); 95 $("#faq-posts-wrapper").removeClass("loader"); 96 } else { 97 $("#faq-pagination").show(); 98 } 99 100 // Hide all answers except active ones 101 $(".faq_section__item").each(function () { 102 var $item = $(this); 103 var $answer = $item.find(".faq_section__answerWrap"); 104 105 if ($item.hasClass("faq_section__item--active")) { 106 $answer.show(); 107 } else { 108 $answer.hide(); 109 } 110 }); 111 }, 112 error: function (xhr) { 113 console.log(xhr.responseText); 114 }, 115 }); 116 } 117 118 function renderPagination(totalPages, currentPage) { 119 let paginationHtml = ""; 120 121 if (totalPages > 1) { 122 paginationHtml += `<ul class="faq-pagination pagination">`; 123 124 // Prev button 125 if (currentPage > 1) { 126 paginationHtml += `<li><a href="#" class="page-link prev-page prev" data-page="${ 127 currentPage - 1 128 }"><span class="prev_arrow">Prev</span></a></li>`; 129 } 130 131 // Page numbers 132 for (let i = 1; i <= totalPages; i++) { 133 const activeClass = i === currentPage ? "active" : ""; 134 paginationHtml += `<li><a href="#" class="page-link ${activeClass}" data-page="${i}">${i}</a></li>`; 135 } 136 137 // Next button 138 if (currentPage < totalPages) { 139 paginationHtml += `<li><a href="#" class="page-link next-page next" data-page="${ 140 currentPage + 1 141 }"><span class="next_arrow">Next</span></a></li>`; 142 } 143 144 paginationHtml += `</ul>`; 145 } 146 147 $("#faq-pagination").html(paginationHtml); 148 } 149 150 // Initial load 151 // loadFAQs(true); 152 153 // Category filter click 154 $(document).on("click", ".faq-filters__wrap li a", function (e) { 155 e.preventDefault(); 156 157 $(".faq-filters__wrap li").removeClass("active"); 158 $(this).parent().addClass("active"); 159 160 currentCategory = $(this).data("category"); 161 page = 1; 162 // $("#post-loader").show().html('<span class="loading">Loading...</span>'); 163 loadFAQs(true); 164 }); 165 166 // Pagination click 167 $(document).on("click", ".page-link", function (e) { 168 e.preventDefault(); 169 page = parseInt($(this).data("page")); 170 // $("#post-loader").show().html('<span class="loading">Loading...</span>'); 171 loadFAQs(true); 172 $("html, body").animate( 173 { 174 scrollTop: $(".faq-filters").offset().top - 150, 175 }, 176 500 177 ); 178 }); 179 180 // FAQ accordion toggle 181 $(document).on("click", ".faq_section__question", function () { 182 var $item = $(this).closest(".faq_section__item"); 183 var $wrapper = $item.closest(".faq__wrapper"); 184 185 if ($item.hasClass("faq_section__item--active")) { 186 $item.removeClass("faq_section__item--active"); 187 $item.find(".faq_section__answerWrap").stop(true, true).slide
187Up(300); 188 } else { 189 $wrapper 190 .find(".faq_section__item--active") 191 .removeClass("faq_section__item--active") 192 .find(".faq_section__answerWrap") 193 .stop(true, true) 194 .slideUp(300); 195 196 $item.addClass("faq_section__item--active"); 197 $item.find(".faq_section__answerWrap").stop(true, true).slideDown(300); 198 } 199 }); 200});
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.