1jQuery(document).ready(function($) { 2 let awpcf7alsTimer = null; 3 const awpcf7alsDelay = 300; // milisegundos 4 5 $(document).on('keyup', '.alzabara-cf7-api-select', function(e) { 6 const uuid = $(this).data('uuid'); 7 const $results = $('span[data-uuid="' + uuid + '"].alzabara-cf7-api-results'); 8 $('input[data-uuid="' + uuid + '"].alzabara-cf7-api-value').val(''); 9 10 if (e.keyCode === 27) { // ESC 11 $results.hide().empty(); 12 return; 13 } 14 15 const $input = $(this); 16 17 // limpiamos cualquier petición pendiente 18 if (awpcf7alsTimer) { 19 clearTimeout(awpcf7alsTimer); 20 } 21 22 awpcf7alsTimer = setTimeout(function() { 23 const query = $input.val().trim(); 24 const minChars = parseInt($input.data('min-chars')) || 2; 25 26 if (query.length < minChars) { 27 $results.hide().empty(); 28 return; 29 } 30 31 const fieldName = $input.data('field-name'); 32 const formId = $input.data('form-id'); 33 $results.innerHTML = '<div class="loading"><img src="' + AWPCF7ALSjs.loading + '" /></div>'; 34 $results.show(); 35 $.ajax({ 36 url: AWPCF7ALSjs.ajax, 37 method: 'POST', 38 dataType: 'json', 39 data: { 40 action: AWPCF7ALSjs.action, 41 nonce: AWPCF7ALSjs.nonce, 42 q: query, 43 form_id: formId, 44 field_name: fieldName, 45 label_key: $input.data('label-key'), 46 value_key: $input.data('value-key') 47 }, 48 success: function(response) { 49 $results.empty(); 50 51 if (!response || !response.success || !response.data || !response.data.options) { 52 $results.hide(); 53 return; 54 } 55 56 const options = response.data.options; 57 58 if (!options.length) { 59 $results.hide(); 60 return; 61 } 62 63 options.forEach(function(item) { 64 if (!item || !item.label || !item.value) { 65 return; 66 } 67 68 const $row = $('<span/>', { 69 'class': 'api-option', 70 'text': item.label 71 }); 72 73 $row.attr('data-value', item.value); 74 $results.append($row); 75 }); 76 77 $results.show(); 78 }, 79 error: function(xhr, status, error) { 80 console.error(error); 81 $results.hide().empty(); 82 } 83 }); 84 }, awpcf7alsDelay); 85 }); 86 87 $(document).on('click', '.api-option', function(e) { 88 e.preventDefault(); 89 e.stopPropagation(); 90 const uuid = $(this).parent().data('uuid'); 91 92 $('input[data-uuid="' + uuid + '"].alzabara-cf7-api-select').val($(this).text()); 93 $('input[data-uuid="' + uuid + '"].alzabara-cf7-api-value').val($(this).data('value')); 94 $('input[data-uuid="' + uuid + '"].alzabara-cf7-api-label').val($(this).text()); 95 $(this).parent().hide(); 96 }); 97 98 $(document).on('click', function(e) { 99 if (!$(e.target).closest('.alzabara-cf7-api-select, .alzabara-cf7-api-results').length) { 100 $('.alzabara-cf7-api-results').hide(); 101 } 102 }); 103 104 $(document).on('focus', 'input.alzabara-cf7-api-select', function(e) { 105 const uuid = $(this).data('uuid'); 106 if ($('span[data-uuid="' + uuid + '"].alzabara-cf7-api-results').children().length > 0) { 107 $('span[data-uuid="' + uuid + '"].alzabara-cf7-api-results').show(); 108 } 109 }); 110 111 $(document).on('wpcf7mailsent', function(event) { 112 const redirectUrl = $('input#alzabara-cf7-redirect').val(); 113 if (redirectUrl && redirectUrl.trim() !== '') { 114 window.location.href = redirectUrl; 115 } 116 }); 117});
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.