1jQuery(document).ready(function($) { 2 3 console.log('CA YIMBY Endorsement Lookup script loaded'); 4 console.log('Form element:', $('#ca-yimby-form').length); 5 6 $('#ca-yimby-form').on('submit', function(e) { 7 e.preventDefault(); 8 9 console.log('Form submitted'); 10 11 var $form = $(this); 12 13 // Get form values using the form context 14 var address = $form.find('input[name="address"]').val(); 15 var city = $form.find('input[name="city"]').val(); 16 var zip = $form.find('input[name="zip"]').val(); 17 18 console.log('Form values:', {address: address, city: city, zip: zip}); 19 20 // Trim values 21 address = address ? address.trim() : ''; 22 city = city ? city.trim() : ''; 23 zip = zip ? zip.trim() : ''; 24 25 console.log('Trimmed values:', {address: address, city: city, zip: zip}); 26 27 // Validate 28 if (!address || !city || !zip) { 29 console.log('Validation failed - empty fields'); 30 showError('Please fill in all fields.'); 31 return false; 32 } 33 34 // Validate ZIP code 35 if (!/^\d{5}$/.test(zip)) { 36 console.log('Validation failed - invalid ZIP'); 37 showError('Please enter a valid 5-digit ZIP code.'); 38 return false; 39 } 40 41 console.log('Validation passed, making AJAX call'); 42 43 // Show loading, hide results and errors 44 $('#ca-yimby-loading').show(); 45 $('#ca-yimby-results').hide(); 46 $('#ca-yimby-error').hide(); 47 $('.ca-yimby-button').prop('disabled', true); 48 49 // Make AJAX request 50 $.ajax({ 51 url: caYimbyEndorsement.ajaxUrl, 52 type: 'POST', 53 data: { 54 action: 'lookup_endorsements', 55 nonce: caYimbyEndorsement.nonce, 56 address: address, 57 city: city, 58 zip: zip 59 }, 60 success: function(response) { 61 console.log('AJAX response received:', response); 62 63 $('#ca-yimby-loading').hide(); 64 $('.ca-yimby-button').prop('disabled', false); 65 66 if (response.success) { 67 displayResults(response.data.endorsements); 68 } else { 69 showError(response.data.message || 'An error occurred. Please try again.'); 70 } 71 }, 72 error: function(xhr, status, error) { 73 console.error('AJAX error:', status, error); 74 console.error('Response:', xhr.responseText); 75 76 $('#ca-yimby-loading').hide(); 77 $('.ca-yimby-button').prop('disabled', false); 78 showError('A network error occurred. Please check your connection and try again.'); 79 } 80 }); 81 82 return false; 83 }); 84 85 function displayResults(endorsements) { 86 var html = ''; 87 88 // Display Assembly endorsement 89 if (endorsements.assembly) { 90 html += createEndorsementCard(endorsements.assembly); 91 } 92 93 // Display Senate endorsement 94 if (endorsements.senate) { 95 html += createEndorsementCard(endorsements.senate); 96 } 97 98 $('#ca-results-content').html(html); 99 $('#ca-yimby-results').slideDown(); 100 } 101 102 function createEndorsementCard(endorsement) { 103 var html = '<div class="legislator-card">'; 104 html += '<div class="legislator-header">'; 105 106 // Add candidate photo 107 if (endorsement.image) { 108 html += '<img src="' + escapeHtml(endorsement.image) + '" alt="' + escapeHtml(endorsement.name) + '" class="endorsement-photo">'; 109 } 110 111 html += '<div class="legislator-title">'; 112 html += '<p class="office-title">' + escapeHtml(endorsement.district_label) + '</p>'; 113 114 // Make candidate name a clickable link 115 if (endorsement.url) { 116 html += '<h5><a href="' + escapeHtml(endorsement.url) + '" target="_blank" rel="noopener noreferrer">
116' + escapeHtml(endorsement.name) + '</a></h5>'; 117 } else { 118 html += '<h5>' + escapeHtml(endorsement.name) + '</h5>'; 119 } 120 121 html += '</div>'; 122 html += '</div>'; 123 html += '</div>'; 124 125 return html; 126 } 127 128 function showError(message) { 129 $('#ca-yimby-error').html(message).slideDown(); 130 $('#ca-yimby-results').hide(); 131 } 132 133 function escapeHtml(text) { 134 var map = { 135 '&': '&', 136 '<': '<', 137 '>': '>', 138 '"': '"', 139 "'": ''' 140 }; 141 return String(text).replace(/[&<>"']/g, function(m) { return map[m]; }); 142 } 143});
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.