1jQuery(document).ready(function($) { 2 // Store offsets by unique target ID 3 const offsetsByTarget = {}; 4 5 $('.load-more-btn').each(function() { 6 const $btn = $(this); 7 const target = $btn.data('target'); 8 const offset = parseInt($btn.data('offset'), 10) || 0; 9 offsetsByTarget[target] = offset; 10 }); 11 12 $('.load-more-btn').on('click', function() { 13 const $btn = $(this); 14 const category = $btn.data('category'); 15 const perPage = parseInt($btn.data('per-page'), 10) || 4; 16 const target = $btn.data('target'); 17 18 const offset = offsetsByTarget[target] || 0; 19 20 $btn.prop('disabled', true).text('Loading...'); 21 22 $.ajax({ 23 url: my_ajax_object.ajax_url, 24 type: 'POST', 25 data: { 26 action: 'my_load_more_products', 27 category: category, 28 per_page: perPage, 29 offset: offset, 30 }, 31 success: function(response) { 32 const $container = $(target).find('ul.products'); 33 34 // Check if valid HTML was returned 35 if (response && response.html && response.html.trim() !== '') { 36 $container.append(response.html); 37 offsetsByTarget[target] = response.newOffset; 38 39 const itemsLoaded = $(response.html).filter('li.product').length; 40 41 // If fewer than perPage were returned or no more left, remove the button 42 if (!response.hasMore || itemsLoaded < perPage) { 43 $btn.remove(); 44 } else { 45 $btn.data('offset', response.newOffset); 46 $btn.prop('disabled', false).text('Load More'); 47 } 48 49 } else { 50 // No products returned â remove button 51 $btn.remove(); 52 } 53 }, 54 error: function() { 55 $btn.prop('disabled', false).text('Load More'); 56 } 57 }); 58 }); 59});
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.