1jQuery(function($) { 2 var isLoading = false; // Flag to track if an AJAX request is in progress 3 var $button = $('#load-more-posts'); 4 var post_type = $button.data('post_type'); 5 var post_category = $button.data('post_category'); 6 var offset = $button.data('offset'); // Get offset from data attribute 7 var posts_per_page = $button.data('posts_per_page'); 8 var template = $button.data('template'); 9 /*console.log('post_type: ', post_type); 10 console.log('post_category: ', post_category); 11 console.log('offset: ', offset); 12 console.log('posts_per_page: ', posts_per_page); 13 console.log('template: ', template);*/ 14 15 $.ajax({ 16 type: 'POST', 17 url: ajax_params.ajax_url, 18 data: { 19 'action': 'check_more_posts', 20 'post_type': post_type, 21 'post_category': post_category, 22 'offset': offset, 23 'posts_per_page': posts_per_page, 24 'template': template, 25 }, 26 dataType: 'json', // Explicitly expect JSON response from the server 27 success: function(response) { 28 /*console.log('Initial AJAX response from check_more_posts'); 29 console.log(response);*/ 30 if(response.morePostsAvailable) { 31 $button.show(); // Show the Load More button if additional posts are available 32 $button.attr('aria-hidden','false'); 33 } 34 }, 35 error: function() { 36 //console.log('Initial AJAX error'); 37 } 38 }); 39 40 $($button).on('click', function(e) { 41 e.preventDefault(); 42 43 if (isLoading) { 44 return; 45 } 46 isLoading = true; 47 48 $button.addClass('loading'); 49 $button.prop('disabled', true); 50 51 $.ajax({ 52 type: 'POST', 53 url: ajax_params.ajax_url, 54 data: { 55 'action': 'load_more_posts', 56 'post_type': post_type, 57 'post_category': post_category, 58 'offset': offset, 59 'posts_per_page': posts_per_page, 60 'template': template, 61 }, 62 dataType: 'json', // Explicitly expect JSON response from the server 63 success: function(response){ 64 if(!response.morePostsAvailable){ 65 $('#load-more-posts-container').append(response.html);// Append the final set of posts 66 $button.hide(); // Hide the Load More button 67 $button.attr('aria-hidden','true'); 68 }else{ 69 $('#load-more-posts-container').append(response.html); // Append the new posts 70 offset += posts_per_page; // Update the global offset variable 71 $button.data('offset', offset); // Update the offset data attribute 72 } 73 74 // Set equal element heights on the newly loaded posts 75 window.interscan.equalHeightElements(); 76 77 // Refresh first/last classes 78 window.interscan.adjustPostsPerRow(); 79 }, 80 error: function() { 81 // console.log('AJAX error'); 82 }, 83 complete: function() { 84 isLoading = false; 85 $button.removeClass('loading'); 86 $button.prop('disabled', false); 87 } 88 }); 89 }); 90});
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.