1// Get relevant fields 2const streetInput = document.querySelector('.asa-address-street input[type=text]'); 3const cityInput = document.querySelector('.asa-address-city input[type=text]'); 4const stateInput = document.querySelector('.asa-address-state select'); 5const zipInput = document.querySelector('.asa-address-zip input[type=text]'); 6const countryInput = document.querySelector('.asa-address-country select'); 7 8// Normalize the zip code 9function normalizeZipCode() { 10 if ( zipInput == null ) { 11 return; 12 } 13 14 zipInput.value = zipInput.value.replace(/\D/g,''); 15} 16 17document.addEventListener('DOMContentLoaded', normalizeZipCode); 18 19if ( zipInput != null ) { 20 zipInput.setAttribute('maxlength', '5'); 21 zipInput.addEventListener('input', normalizeZipCode); 22} 23 24// Add autocomplete to street address field 25let autocomplete; 26let autocompleteOptions = { 27 componentRestrictions: { 28 country: 'us' 29 }, 30 fields: ['address_components', 'geometry'], 31 strictBounds: true 32}; 33 34// Add bounds to autocomplete for inputs with 'asa-district-only' CSS class 35const bounds = { 36 north: 28.84829495319701, 37 south: 28.32553701848643, 38 west: -81.72220576896636, 39 east: -80.8209603430068 40} 41const districtOnlyField = document.querySelector('.asa-address-street.asa-district-only'); 42if ( districtOnlyField && districtOnlyField.contains(streetInput) ) { 43 autocompleteOptions['bounds'] = bounds; 44} 45 46function initMap() { 47 if ( streetInput == null ) { 48 return; 49 } 50 51 autocomplete = new google.maps.places.Autocomplete(streetInput, autocompleteOptions); 52 autocomplete.addListener('place_changed', onPlaceChanged); 53 54 // Prevent autocomplete selection from submitting form 55 google.maps.event.addDomListener(streetInput, 'keydown', function(e) { 56 if (e.keyCode == 13) { 57 e.preventDefault(); 58 } 59 }); 60} 61 62function onPlaceChanged() { 63 const place = autocomplete.getPlace(); 64 65 if(place.geometry){ 66 const addressPartsArr = place.address_components.map(component => { 67 const type = component.types[0]; 68 let value = component.long_name; 69 if ( type === "administrative_area_level_1" ) { 70 value = component.short_name; 71 } 72 return [type, value]; 73 }); 74 const addressParts = Object.fromEntries(addressPartsArr); 75 76 // Set street address 77 if ( streetInput ) { 78 streetInput.value = addressParts['street_number'] + ' ' + addressParts['route']; 79 } 80 81 // Set city 82 if ( cityInput ) { 83 cityInput.value = addressParts['locality']; 84 } 85 86 // Set state 87 if ( stateInput ) { 88 stateInput.value = addressParts['administrative_area_level_1']; 89 } 90 91 // Set zip 92 if ( zipInput ) { 93 zipInput.value = addressParts['postal_code']; 94 } 95 96 // Set country 97 if ( countryInput ) { 98 countryInput.value = addressParts['country']; 99 } 100 101 } 102}
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.