1/** 2 * Override pagination link with ajax call 3 * 4 * @url https://rudrastyh.com/wordpress/load-more-posts-ajax.html 5 */ 6jQuery(document).ready(function($) { 7 var container = document.querySelector('#paginationcontainer'); 8 var button = document.querySelector('nav.pagination a'); 9 10 if (button) { 11 /** 12 * Grab request data from global object set via wp_localize_script. 13 */ 14 var requestData = ajaxDataNextPage; 15 var buttonContent = button.innerHTML; 16 button.addEventListener("click", function (e) { 17 e.preventDefault(); 18 button.style.width = $(button).outerWidth() + 'px'; 19 button.classList.add('disabled'); 20 button.innerHTML = "<div class='loading'></div>"; 21 22 var data = { 23 'action': 'load_next_page', 24 'query': requestData.posts, 25 'page': requestData.currentPage 26 }; 27 jQuery.post(requestData.ajaxUrl, data) 28 .done(function (response) { 29 var tmpContainer = document.createElement('div'); 30 tmpContainer.innerHTML = response; 31 while (tmpContainer.firstChild) { 32 container.appendChild(tmpContainer.firstChild); 33 } 34 requestData.currentPage++; 35 if (requestData.currentPage === requestData.maxPage) { 36 button.remove(); 37 } 38 }) 39 .fail(function() { 40 console.error('Ajax pagination request failed'); 41 }) 42 .always(function() { 43 button.innerHTML = buttonContent; 44 button.style.width = 'auto'; 45 button.classList.remove('disabled'); 46 }); 47 }); 48 } 49});
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.