1jQuery(function() { 2 jQuery(window).load(function() { 3 //jQuery(document).ready(function () { 4 initAutocomplete(); 5 6 jQuery(document).bind('gform_post_render', function() { 7 initAutocomplete(); 8 }); 9 if (jQuery(".reverse").length) { 10 var el = jQuery(".reverse").val(); 11 var il = el.split(" "); 12 var val = il.reverse(); 13 var e = val.toString(); 14 jQuery(".reverse").val(e); 15 } 16 }); 17}); 18 19let marker; 20const infowindow = new google.maps.InfoWindow(); 21const infowindowContent = document.getElementById("infowindow-content"); 22 23function toggleBounce() { 24 if (marker.getAnimation() !== null) { 25 marker.setAnimation(null); 26 } else { 27 marker.setAnimation(google.maps.Animation.BOUNCE); 28 } 29} 30 31 32 33 34 35function addYourLocationButton(map, marker, geocoder) { 36 var controlDiv = document.createElement('div'); 37 38 var firstChild = document.createElement('button'); 39 firstChild.setAttribute('type', 'button'); 40 firstChild.style.backgroundColor = '#fff'; 41 firstChild.style.border = 'none'; 42 firstChild.style.outline = 'none'; 43 firstChild.style.width = '40px'; 44 firstChild.style.height = '40px'; 45 firstChild.style.borderRadius = '2px'; 46 firstChild.style.boxShadow = '0 1px 4px rgba(0,0,0,0.3)'; 47 firstChild.style.cursor = 'pointer'; 48 firstChild.style.marginRight = '10px'; 49 firstChild.style.padding = '0px'; 50 firstChild.title = 'Your Location'; 51 controlDiv.appendChild(firstChild); 52 53 var secondChild = document.createElement('div'); 54 secondChild.style.margin = '11px'; 55 secondChild.style.width = '18px'; 56 secondChild.style.height = '18px'; 57 secondChild.style.backgroundImage = 'url(https://maps.gstatic.com/tactile/mylocation/mylocation-sprite-1x.png)'; 58 secondChild.style.backgroundSize = ''; 59 secondChild.style.backgroundPosition = '0px 0px'; 60 secondChild.style.backgroundRepeat = 'no-repeat'; 61 secondChild.id = 'you_location_img'; 62 firstChild.appendChild(secondChild); 63 64 65 firstChild.addEventListener('click', function() { 66 var animationInterval = setInterval(function() { 67 if (imgX == '-18') 68 imgX = '0'; 69 else 70 imgX = '-18'; 71 }, 500); 72 if (navigator.geolocation) { 73 navigator.geolocation.getCurrentPosition(function(position) { 74 var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 75 marker.setPosition(latlng); 76 map.setZoom(18); 77 map.setCenter(latlng); 78 clearInterval(animationInterval); 79 geocoder.geocode({ 'latLng': latlng }, function(results, status) { 80 // validate 81 if (status != google.maps.GeocoderStatus.OK) { 82 console.log('Geocoder failed due to: ' + status); 83 return; 84 } 85 if (!results[0]) { 86 console.log('No results found'); 87 return; 88 } 89 }) 90 }); 91 92 } else { 93 clearInterval(animationInterval); 94 jQuery('#you_location_img').css('background-position', '0px 0px'); 95 } 96 clearInterval(animationInterval); 97 }); 98 99 100 controlDiv.index = 1; 101 map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv); 102} 103 104function initAutocomplete() { 105 106 if (jQuery('li.gf_state_2_digit').length > 0) { 107 var gf_state_code = 'short_name'; 108 } else { 109 var gf_state_code = 'long_name'; 110 } 111 112 var componentForm = { 113 route: 'long_name', 114 street_number: 'short_name', 115 sublocality_level_1: 'long_name', 116 locality: 'long_name', 117 administrative_area_level_1: gf_state_code, 118 country: 'long_name', 119 postal_code: 'short_name' 120 }; 121 122 jQuery('.gfac_autocomplete_addr').each(function() { 123 // Create the autocomplete object, restricting the search to geographical 124 // location types. 125 //check if address filed 126 var addr = jQuery(this);
127 if (addr.find('div.ginput_container_address').length > 0) 128 var v = addr.find('div.ginput_container_address').attr('id'); 129 else 130 var v = addr.find('input').attr('id'); 131 132 133 var v_array = v.split("_"); 134 var field_id = v_array[2]; 135 136 if (jQuery('div#' + v).length > 0 && jQuery('input#' + v + '_1').length > 0) { 137 var autocomplete = new google.maps.places.Autocomplete( 138 /** @type {!HTMLInputElement} */ 139 (document.getElementById(v + '_1')), { types: ['geocode'] }); 140 // console.log(jQuery('.gfac_autocomplete_addr').attr('class').split('_')); //add lenght condition with it 141 // autocomplete.setComponentRestrictions({ 'country': [jQuery('.gfac_autocomplete_addr').attr('class').split('_')[18]] }); 142 143 // if ((jQuery('div#' + v).closest('li[class*="gfac_autocomplete_country_"]').length > 0) || (jQuery('div#' + v).closest('div[class*="gfac_autocomplete_country_"]').length > 0)) { 144 if ((jQuery('.gfac_autocomplete_addr').attr('class').split('_').length > 0)) { 145 // Set initial restrict to the greater list of countries. 146 if((jQuery('.gfac_autocomplete_addr').attr('class').split('_').length > 0)) { 147 var clslist = jQuery('.gfac_autocomplete_addr').attr('class').split('_')[18]; 148 } else { 149 var clslist = jQuery('div#' + v).closest('div[class*="gfac_autocomplete_country"]')[0].className; 150 } 151 152 // var clslist = jQuery('.gfac_autocomplete_addr').attr('class').split('_')[18]; 153 var country = jQuery('fieldset.gfac_autocomplete_addr').attr('class').split('_'); 154 console.log('COUNTRY: ' + country[country.length - 1]); 155 autocomplete.setComponentRestrictions({ 'country': [country[country.length - 1]] }); 156 // console.log(country); 157 158 } 159 160 autocomplete.addListener('place_changed', function() { 161 var place = autocomplete.getPlace(); 162 163 // Get each component of the address from the place details 164 // and fill the corresponding field on the form. 165 var address1 = ''; 166 for (var i = 0; i < place.address_components.length; i++) { 167 168 var addressType = place.address_components[i].types[0]; 169 if (componentForm[addressType]) { 170 var val = place.address_components[i][componentForm[addressType]]; 171 172 //address line 1 173 if (addressType == 'street_number') { 174 address1 = val; 175 } 176 if (addressType == 'route') { 177 address1 = (jQuery(".gf_street_formatting").length) ? val + ' ' + address1 : address1 + ' ' + val; 178 } 179 jQuery('#' + v + '_1').val(address1); 180 181 //address line 2 182 if (addressType == 'sublocality_level_1') { 183 jQuery('#' + v + ' .address_line_2 input[type="text"]').val(val); 184 } 185 186 //city 187 if (addressType == 'locality') { 188 if (jQuery(".gfac_city_custom").length) { 189 jQuery(".gfac_city_custom div input").val(val); 190 } else { 191 jQuery('#' + v + ' .address_city input[type="text"]').val(val); 192 } 193 } 194 195 //state 196 if (addressType == 'administrative_area_level_1') { 197 jQuery('#' + v + ' .address_state input[type="text"]').val(val); 198 //us state 199 jQuery('#' + v + ' .address_state select').val(val); 200 } 201 202 //postal code 203 if (addressType == 'postal_code') { 204 if (jQuery(".gfac_postalcode_custom").length) { 205 jQuery(".gfac_postalcode_custom div input").val(val); 206 } else { 207 jQuery('#' + v + ' .address_zip input[type="text"]').val(val); 208 } 209 } 210 211 //country 212 if (addressType == 'country') { 213 if (jQuery(".gfac_country_custom").length) { 214 jQuery(".gfac_country_custom div span select").val(val); 215 } else { 216 jQuery('#' + v + ' .address_country select').val(val); 217 } 218 } 219 } 220 } 221 222 }); 223 224 if (jQuery(".gfac_address_map_enabled_" + field_id).length) { 225 let latLong = {}; 226 let marker = {}; 227 if (country == 'US') { 228 latLong = { lat: 36.241384, lng: -113.7547193 }; 229 marker_latLong = { lat: 40.6976701, lng: -74.259875 }; 230 } else if (country == 'CA') { 231 latLong = { lat: 50.8500661, lng: -130.2241653 }; 232 } else { 233 latLong = { lat: 40.749933, lng: -73.98633 }; 234 } 235 const map = new google.maps.Map(document.getElementById("gfacMap_container_" + field_id), { 236 center: latLong, 237 zoom: 4, 238 mapTypeId: 'roadmap', 239 streetViewControl: false, 240 mapTypeControl: false 241 }); 242 243 marker = new google.maps.Marker({ 244 position: { lat: 40.6976701, lng: -74.259875 }, 245 map, 246 draggable: true, 247 anchorPoint: new google.maps.Point(0, -29), 248 }); 249 geocoder = new google.maps.Geocoder(); 250 addYourLocationButton(map, marker, geocoder); 251 google.maps.event.addListener(marker, 'dragend', function() { 252 toggleBounce(); 253 geocoder.geocode({ 254 latLng: marker.getPosition() 255 }, function(responses) { 256 var map_address1 = ''; 257 for (var i = 0; i < responses.length; i++) { 258 for (var j = 0; j < responses[i].address_components.length; j++) { 259 const gfac_output = responses[i].address_components[j].long_name; 260 const gfac_type = responses[i].address_components[j].types[0]; 261 console.log(gfac_type + " = " + gfac_output); 262 263 jQuery('#' + v + '_1').val(responses[0].formatted_address); 264 265 //address line 2 266 if (gfac_type == 'neighborhood') { 267 jQuery('#' + v + ' .address_line_2 input[type="text"]').val(gfac_output); 268 } 269 270 //city 271 if (gfac_type == 'locality') { 272 jQuery('#' + v + ' .address_city input[type="text"]').val(gfac_output); 273 } 274 275 //state 276 if (gfac_type == 'administrative_area_level_1') { 277 jQuery('#' + v + ' .address_state input[type="text"]').val(gfac_output); 278 //us state 279 jQuery('#' + v + ' .address_state select').val(gfac_output); 280 } 281 282 //postal code 283 if (gfac_type == 'postal_code') { 284 jQuery('#' + v + ' .address_zip input[type="text"]').val(gfac_output); 285 } 286 287 //country 288 if (gfac_type == 'country') { 289 jQuery('#' + v + ' .address_country select').val(gfac_output); 290 } 291 292 } 293 } 294 if (responses && responses.length > 0) { 295 marker.formatted_address = responses[0].formatted_address; 296 } else { 297 marker.formatted_address = 'Cannot determine address at this location.'; 298 } 299 infowindow.setContent(marker.formatted_address); 300 infowindow.open(map, marker); 301 jQuery('#' + v).val(marker.formatted_address); 302 }); 303 }); 304 marker.addListener("click", toggleBounce); 305 autocomplete.bindTo("bounds", map); 306 307 infowindow.setContent(infowindowContent); 308 309 autocomplete.addListener("place_changed", () => { 310 infowindow.close(); 311 marker.setVisible(false); 312 const place = autocomplete.getPlace(); 313 314 if (place.geometry.viewport) { 315 map.fitBounds(place.geometry.viewport); 316 } else { 317 map.setCenter(place.geometry.location); 318 map.setZoom(17); 319 } 320 marker.setPosition(place.geometry.location); 321 marker.setVisible(true); 322 infowindowContent.children["place-name"].textContent = place.name; 323 infowindowContent.children["place-address"].textContent = 324 place.formatted_address; 325 infowindow.open(map, marker); 326 }); 327 } 328 329 } else if (jQuery('input#' + v).length > 0) { 330 //text field 331 var autocomplete = new google.maps.places.Autocomplete(
332 /** @type {!HTMLInputElement} */ 333 (document.getElementById(v)), { 334 types: ['geocode'] 335 }); 336 if ((jQuery('input#' + v).closest('li[class*="gfac_autocomplete_country_"]').length > 0) || (jQuery('input#' + v).closest('div[class*="gfac_autocomplete_country_"]').length > 0)) { 337 // Set initial restrict to the greater list of countries. 338 if((jQuery('input#' + v).closest('li[class*="gfac_autocomplete_country_"]').length > 0)) { 339 var clslist = jQuery('input#' + v).closest('li[class*="gfac_autocomplete_country"]')[0].className; 340 } else { 341 var clslist = jQuery('input#' + v).closest('div[class*="gfac_autocomplete_country"]')[0].className; 342 } 343 344 var country = clslist.substring(clslist.lastIndexOf("gfac_autocomplete_country_") + 26, clslist.lastIndexOf("gfac_autocomplete_country_") + 28); 345 autocomplete.setComponentRestrictions({ 'country': [country] }); 346 } 347 autocomplete.addListener('place_changed', function() { 348 var place = autocomplete.getPlace(); 349 if ((jQuery('input#' + v).closest('li[class*="gfac_autocomplete_addr_format"]').length > 0) || (jQuery('input#' + v).closest('div[class*="gfac_autocomplete_addr_format"]').length > 0)){ 350 jQuery('#' + v).val(place.formatted_address); 351 } 352 var address = ''; 353 if (place.address_components) { 354 address = [ 355 (place.address_components[0] && place.address_components[0].short_name || ''), 356 (place.address_components[1] && place.address_components[1].short_name || ''), 357 (place.address_components[2] && place.address_components[2].short_name || '') 358 ].join(' '); 359 } 360 }); 361 if (jQuery(".gfacMap_enabled_" + field_id).length) { 362 // map scripts 363 const map = new google.maps.Map(document.getElementById("gfacMap_container_" + field_id), { 364 center: { lat: 40.749933, lng: -73.98633 }, 365 zoom: 4, 366 mapTypeId: 'roadmap', 367 streetViewControl: false, 368 mapTypeControl: false 369 }); 370 371 marker = new google.maps.Marker({ 372 map, 373 draggable: true, 374 position: { lat: 40.6976701, lng: -74.259875 }, 375 anchorPoint: new google.maps.Point(0, -29), 376 }); 377 geocoder = new google.maps.Geocoder(); 378 addYourLocationButton(map, marker, geocoder); 379 380 google.maps.event.addListener(marker, 'dragend', function() { 381 // 382 toggleBounce(); 383 geocoder.geocode({ 384 latLng: marker.getPosition() 385 }, function(responses) { 386 if (responses && responses.length > 0) { 387 marker.formatted_address = responses[0].formatted_address; 388 } else { 389 marker.formatted_address = 'Cannot determine address at this location.'; 390 } 391 infowindow.setContent(marker.formatted_address); 392 infowindow.open(map, marker); 393 jQuery('#' + v).val(marker.formatted_address); 394 }); 395 }); 396 marker.addListener("click", toggleBounce); 397 autocomplete.bindTo("bounds", map); 398 399 infowindow.setContent(infowindowContent); 400 401 autocomplete.addListener("place_changed", () => { 402 infowindow.close(); 403 marker.setVisible(false); 404 const place = autocomplete.getPlace(); 405 406 if (place.geometry.viewport) { 407 map.fitBounds(place.geometry.viewport); 408 } else { 409 map.setCenter(place.geometry.location); 410 map.setZoom(17); 411 } 412 marker.setPosition(place.geometry.location); 413 marker.setVisible(true); 414 infowindowContent.children["place-name"].textContent = place.name; 415 infowindowContent.children["place-address"].textContent = 416 place.formatted_address; 417 infowindow.open(map, marker); 418 }); 419 } 420 } 421 }); 422}
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.