1/* Public JavaScript for Patrimonio Fichas */ 2 3(function($) { 4 'use strict'; 5 6 $(document).ready(function() { 7 initFilters(); 8 initSearch(); 9 initCategoryFilter(); 10 initDownloads(); 11 }); 12 13 function debounce(fn, wait) { 14 let t; 15 return function() { 16 const args = arguments; 17 const ctx = this; 18 clearTimeout(t); 19 t = setTimeout(function() { 20 fn.apply(ctx, args); 21 }, wait); 22 }; 23 } 24 25 /** 26 * Initialize recommendation badge filters 27 */ 28 function initFilters() { 29 $('.pf-filter-badge').on('click', function(e) { 30 e.preventDefault(); 31 $('.pf-filter-badge').removeClass('active'); 32 $(this).addClass('active'); 33 34 const activeFilter = $(this).data('filter') || 'all'; 35 const searchTerm = $('#pf-search').val() || ''; 36 const category = $('#pf-category-filter').length ? $('#pf-category-filter').val() : 'all'; 37 38 filterCards(activeFilter, searchTerm, category); 39 }); 40 } 41 42 /** 43 * Initialize search input with debounce 44 */ 45 function initSearch() { 46 const doSearch = debounce(function() { 47 const searchTerm = $('#pf-search').val() || ''; 48 const activeFilter = $('.pf-filter-badge.active').data('filter') || 'all'; 49 const category = $('#pf-category-filter').length ? $('#pf-category-filter').val() : 'all'; 50 51 filterCards(activeFilter, searchTerm, category); 52 }, 300); 53 54 $('#pf-search').on('input', doSearch); 55 } 56 57 /** 58 * Initialize category select filter 59 */ 60 function initCategoryFilter() { 61 $(document).on('change', '#pf-category-filter', function() { 62 const category = $(this).val() || 'all'; 63 const activeFilter = $('.pf-filter-badge.active').data('filter') || 'all'; 64 const searchTerm = $('#pf-search').val() || ''; 65 66 filterCards(activeFilter, searchTerm, category); 67 }); 68 } 69 70 /** 71 * Filter cards via AJAX 72 * @param {string} recommendation - 'all'|'excellent'|'good'|'caution' 73 * @param {string} search - search term 74 * @param {string} category - taxonomy slug or 'all' 75 */ 76 function filterCards(recommendation, search, category) { 77 // simple loading state 78 const $grid = $('#pf-fichas-grid'); 79 $grid.css('opacity', 0.6); 80 81 $.ajax({ 82 url: (typeof patrimonio_fichas_ajax !== 'undefined') ? patrimonio_fichas_ajax.ajax_url : '/wp-admin/admin-ajax.php', 83 type: 'POST', 84 data: { 85 action: 'pf_filter_fichas', 86 recommendation: recommendation || 'all', 87 search: search || '', 88 category: category || 'all', 89 nonce: (typeof patrimonio_fichas_ajax !== 'undefined') ? patrimonio_fichas_ajax.nonce : '' 90 }, 91 success: function(response) { 92 $grid.html(response); 93 }, 94 error: function(jqXHR, textStatus, errorThrown) { 95 console.error('pf_filter_fichas error:', textStatus, errorThrown); 96 // helpful debug info 97 if (jqXHR && jqXHR.responseText) { 98 console.log('Response text:', jqXHR.responseText); 99 } 100 }, 101 complete: function() { 102 $grid.css('opacity', ''); 103 } 104 }); 105 } 106 107 /** 108 * Initialize downloads (placeholder) 109 */ 110 function initDownloads() { 111 window.pfDownloadFiles = function(postId) { 112 console.log('Downloading files for post:', postId); 113 // aquà puedes implementar la lógica real 114 }; 115 } 116 117})(jQuery);
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.