1jQuery(function($){ 2 // Apply the select2 library on your select elements 3 if ($(".filter").length) { 4 $(".filter").select2({ 5 minimumResultsForSearch: Infinity, 6 }); 7 } 8 if ($(".filter-year").length) { 9 $(".filter-year").select2({ 10 minimumResultsForSearch: Infinity, 11 }); 12 } 13 14 function loadPosts(page = 1) { 15 var data = { 16 action: 'investor_filter', 17 page: page, 18 }; 19 if ($('#investor-category').length) { 20 data['investor-category'] = $('#investor-category').val(); 21 } 22 if ($('#date-investor').length) { 23 data['date-investor'] = $('#date-investor').val(); 24 } 25 26 $.ajax({ 27 url: wpApiSettingsInvestor.root + 'custom/v1/investor-filter/', 28 method: 'POST', 29 dataType: 'json', 30 data: data, 31 beforeSend: function (xhr) { 32 xhr.setRequestHeader('X-WP-Nonce', wpApiSettingsInvestor.nonce); 33 $('.loading').show(); 34 }, 35 success: function (response) { 36 if ($('#response-reports').length) { 37 $('#response-reports').html(response.content); 38 if(response.content.trim() != '<p>'+wpApiSettingsInvestor.no_posts_found+'</p>') { 39 generatePagination(response.pages, page); 40 } 41 } 42 $('.loading').hide(); 43 }, 44 error: function(jqXHR, textStatus, errorThrown) { 45 console.error('Error:', errorThrown); 46 console.error('Error status:', jqXHR.status); 47 console.error('Error status text:', jqXHR.statusText); 48 console.error('Error response:', jqXHR.responseText); 49 $('.loading').hide(); 50 } 51 }); 52 } 53 54 function generatePagination(pages, currentPage) { 55 var pagination = ''; 56 $('#pagination-reports').addClass("d-none"); 57 if ($('#pagination-reports').length) { 58 if(pages > 1 && $('#response-reports').html().trim() != '<p>'+wpApiSettingsInvestor.no_posts_found+'</p>') { 59 $('#pagination-reports').removeClass("d-none"); 60 61 // Determine if previous and next buttons should be disabled 62 var previousDisabled = currentPage === 1 ? 'disabled' : ''; 63 var nextDisabled = currentPage === pages ? 'disabled' : ''; 64 65 pagination += '<a class="order-2 order-md-1 ' + previousDisabled + '" href="#" data-page="' + Math.max(1, currentPage - 1) + '">'+wpApiSettingsInvestor.previous+'</a>'; 66 pagination += '<ul class="d-flex mb-0 order-1 order-md-2">'; 67 68 var firstPage = Math.max(1, currentPage - 2); 69 var lastPage = Math.min(pages, firstPage + 4); 70 71 // Ensure we always show 5 pages 72 if (lastPage - firstPage < 4){ 73 firstPage = Math.max(1, lastPage - 4); 74 } 75 76 // If first page is not 1, show ... 77 if(firstPage > 1) { 78 pagination += '<li><a href="#" data-page="1">1</a></li>'; 79 pagination += '<li><a href="#">...</a></li>'; 80 } 81 82 for (var i = firstPage; i <= lastPage; i++) { 83 if (i === currentPage) { 84 pagination += '<li><a href="#" class="active" data-page="' + i + '">' + i + '</a></li>'; 85 } else { 86 pagination += '<li><a href="#" data-page="' + i + '">' + i + '</a></li>'; 87 } 88 } 89 90 // If last page is not the actual last page, show ... 91 if(lastPage < pages) { 92 pagination += '<li><a href="#">...</a></li>'; 93 pagination += '<li><a href="#" data-page="' + pages + '">' + pages + '</a></li>'; 94 } 95 96 pagination += '</ul>'; 97 pagination += '<a class="order-3 ' + nextDisabled + '" href="#" data-page="' + Math.min(pages, currentPage + 1) + '">'+wpApiSettingsInvestor.next+'</a>'; 98 } 99 100 $('#pagination-reports').html(pagination); 101 bindPaginationLinks(); 102 } 103 } 104 105 function bindPaginationLinks() { 106 if ($('#pagination-reports a').length) { 107 $('#pagination-reports a').on('click', function (e) { 108 e.preventDefault(); 109 var page = $(this).data('page'); 110 loadPosts(page); 111 }); 112 } 113 } 114 115 // When the filter changes, load the first page 116 if ($('.filter').length || $('.filter-year').length) { 117 $('.filter, .filter-year').on('change', function () { 118 loadPosts(1); 119 }); 120 121 } 122 123 // Load the first page when the page loads 124 $(document).ready(function() { 125 if ($('#response-reports').length) { 126 loadPosts(1); 127 } 128 }); 129});
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.