1jQuery(document).ready(function ($) { 2 var allowLoadMore = true; // Boolean flag to control the "Load More" button 3 4 // Function to handle the AJAX request 5 function handleAjaxFetch(container, append = false) { 6 if (!allowLoadMore) { 7 console.log("Load More action blocked"); 8 return; // Exit if not allowed to load more 9 } 10 11 allowLoadMore = false; // Disable further "Load More" actions 12 13 var selectedFilters; 14 if ($('.md_filter_accordeon').length > 0) { 15 selectedFilters = {}; 16 $('.md_filter_accordeon').each(function () { 17 var taxonomy = $(this).data('taxonomy'); 18 // If the "Voir tout" option is checked in this group, skip filtering for this taxonomy. 19 if ($(this).find('.aaa_filter_checkbox.voir-tout:checked').length > 0) { 20 // Do nothing for this taxonomy group. 21 } else { 22 var terms = $(this).find('.aaa_filter_checkbox:checked').map(function () { 23 return $(this).data('term-id'); 24 }).get(); 25 if (terms.length > 0) { 26 selectedFilters[taxonomy] = terms; 27 } 28 } 29 }); 30 } else { 31 selectedFilters = $('.aaa_filter_checkbox:checked').map(function () { 32 return $(this).data('term-id'); 33 }).get(); 34 if ($('.aaa_filter_checkbox.voir-tout:checked').length > 0) { 35 selectedFilters = []; 36 } 37 } 38 39 // Retrieve all necessary data attributes from the container or hidden input 40 var resultsPerLoad = container.data('results') || $('.aaa-archive-attributes').data('results'); 41 var cpt = container.data('cpt') || $('.aaa-archive-attributes').data('cpt'); 42 var taxonomy = container.data('taxonomy') || $('.aaa-archive-attributes').data('taxonomy'); 43 var template = container.data('template') || $('.aaa-archive-attributes').data('template'); 44 var filterRelation = container.data('filter-relation') || $('.aaa-archive-attributes').data('filter-relation'); 45 // Modified offset: use container.find() and add 1 to avoid duplicating the last post. 46 // var offset = append ? container.find('.aaa_post').length + 1 : 0; 47 var offset = append ? container.find('.aaa_post').length : 0; 48 // Retrieve pre-filter data attributes 49 var preTaxonomy = container.data('pre-taxonomy'); 50 var preTerm = container.data('pre-term'); 51 52 // Retrieve the search query from the search input field 53 var searchQuery = $('.aaa_search_input').val() || ''; 54 55 console.log("Fetching Posts for CPT: ", cpt); 56 console.log("Using Taxonomy: ", taxonomy); 57 console.log("With Template: ", template); 58 console.log("Filter Relation: ", filterRelation); 59 console.log("Selected Filters: ", selectedFilters); 60 console.log("Offset: ", offset); 61 console.log("Pre-filtering by: ", preTaxonomy, preTerm); 62 console.log("Search Query: ", searchQuery); 63 64 if (cpt && taxonomy && template && resultsPerLoad !== undefined) { 65 $.ajax({ 66 url: aaa_ajax_object.ajax_url, 67 type: 'POST', 68 data: { 69 action: 'aaa_get_posts', 70 filters: selectedFilters, 71 cpt: cpt, 72 results: resultsPerLoad, 73 taxonomy: taxonomy, 74 filter_relation: filterRelation, 75 template: template, 76 offset: offset, 77 pre_taxonomy: preTaxonomy, 78 pre_term: preTerm, 79 search: searchQuery, 80 articles_relies: container.data('articles-relies'), 81 show_ressources: container.data('show-ressources'), 82 action_id: container.data('action-id') 83 }, 84 beforeSend: function () { 85 // Disable the Load More button 86 $('.load-more').attr('disabled', true); 87 console.log("Load More button disabled"); 88 }, 89 success: function (response) { 90 console.log("AJAX request successful"); 91 console.log("Initial number of posts: ", response.total); 92 console.log("Displayed posts: ", response.displayed); 93 console.log("Remaining posts: ", response.remaining); 94 95 if (append) { 96 container.append(response.html); 97 } else { 98 container.html(response.html); 99 } 100 101 // Manage the visibility of the Load More button 102 if (response.remaining > 0) { 103 $('.load-more').show(); 104 } else { 105 $('.load-more').hide(); 106 } 107 108 console.log("Update successful, posts loaded."); 109 }, 110 error: function (xhr, status, error) { 111 console.log("AJAX error: ", error); 112 }, 113 complete: function () { 114 // Re-enable the Load More button 115 $('.load-more').attr('disabled', false); 116 allowLoadMore = true; 117 console.log("Load More button enabled"); 118 } 119 }); 120 } else { 121 console.log("Error: Missing data attributes."); 122 } 123 } 124 125 // Event binding for filter changes 126 $(document).on('change', '.aaa_filter_checkbox', function () { 127 var group = $(this).closest('.md_filter_accordeon'); 128 if ($(this).hasClass('voir-tout')) { 129 // In its own taxonomy group, uncheck other filters 130 group.find('.aaa_filter_checkbox').not(this).prop('checked', false); 131 } else { 132 // Uncheck voir-tout for its taxonomy group 133 group.find('.aaa_filter_checkbox.voir-tout').prop('checked', false); 134 } 135 136 var container = $('.posts-container'); // Use the posts container class 137 handleAjaxFetch(container, false); // Replace posts on filter change 138 }); 139 140 // Event binding for "Load More" functionality 141 $(document).on('click', '.load-more', function () { 142 console.log("LOAD MORE BUTTON CLICKED"); 143 var container = $('.posts-container'); // Always target the posts-container class directly 144 handleAjaxFetch(container, true); // Append posts on load more 145 }); 146 147 // Event binding for search input: trigger on Enter key press 148 $(document).on('keypress', '.aaa_search_input', function (e) { 149 if (e.which == 13) { // Enter key pressed 150 e.preventDefault(); 151 var container = $('.posts-container'); 152 handleAjaxFetch(container, false); // Update posts based on search query 153 } 154 }); 155});
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.