1(function($) { 2 3 // Prevent Chrome autocomplete dropdown on the address line 1 fields 4 $(document).on('focus click tap', 'input#billing_address_1, input#shipping_address_1', function() { 5 $(this).attr("autocomplete", 'new-password'); 6 }); 7 8})(jQuery); 9 10var RpCheckoutAutocomplete = RpCheckoutAutocomplete || {}; 11var RpCheckoutAutocomplete_shipping = RpCheckoutAutocomplete_shipping || {}; 12RpCheckoutAutocomplete.event = {}; 13RpCheckoutAutocomplete_shipping.event = {}; 14RpCheckoutAutocomplete.method = { 15 placeSearch: "", 16 IdSeparator: "", 17 autocomplete : "", 18 streetNumber : "", 19 formFields : { 20 'billing_address_1': '', 21 'billing_address_2': '', 22 'billing_city': '', 23 'billing_state': '', 24 'billing_postcode': '', 25 'billing_country' : '' 26 }, 27 formFieldsValue : { 28 'billing_address_1': '', 29 'billing_address_2': '', 30 'billing_city': '', 31 'billing_state': '', 32 'billing_postcode': '', 33 'billing_country' : '' 34 }, 35 component_form : "", 36 37 initialize: function(){ 38 this.getIdSeparator(); 39 this.initFormFields(); 40 41 this.autocomplete = new google.maps.places.Autocomplete( 42 (document.getElementById('billing_address_1')), 43 { 44 types: ['address'] 45 }); 46 google.maps.event.addListener(this.autocomplete, 'place_changed', function( event ) { 47 RpCheckoutAutocomplete.method.fillInAddress() 48 }); 49 var billing_address = document.getElementById("billing_address_1"); 50 if(billing_address != null){ 51 billing_address.addEventListener("focus", function( event ) { 52 RpCheckoutAutocomplete.method.setAutocompleteCountry() 53 }, true); 54 } 55 56 var billing_country = document.getElementById("billing_country"); 57 if(billing_country != null){ 58 billing_country.addEventListener("change", function( event ) { 59 RpCheckoutAutocomplete.method.setAutocompleteCountry() 60 }, true); 61 } 62 63 64 }, 65 getIdSeparator : function() { 66 if (!document.getElementById('billing_address_1')) { 67 this.IdSeparator = "_"; 68 return "_"; 69 } 70 this.IdSeparator = ":"; 71 return ":"; 72 }, 73 initFormFields: function () 74 { 75 console.log('-------------'); 76 for (var field in this.formFields) { 77 this.formFields[field] = (field); 78 } 79 this.component_form = {}; 80 this.component_form_standard = 81 { 82 'country': ['billing_country', 'long_name'], 83 'street_number': ['billing_address_1', 'short_name'], 84 'route': ['billing_address_1', 'long_name'], 85 'locality': ['billing_city', 'long_name'], 86 'postal_town': ['billing_city', 'long_name'], 87 'sublocality_level_1': ['billing_city', 'long_name'], 88 'administrative_area_level_2': ['billing_city', 'long_name'], 89 'administrative_area_level_3': ['billing_city', 'long_name'], 90 'administrative_area_level_1': ['billing_state', 'short_name'], 91 'postal_code': ['billing_postcode', 'short_name'] 92 }; 93 this.component_form_alt = 94 { 95 'country': ['billing_country', 'long_name'], 96 'street_number': ['billing_address_1', 'short_name'], 97 'route': ['billing_address_1', 'long_name'], 98 'locality': ['billing_city', 'long_name'], 99 'postal_town': ['billing_city', 'long_name'], 100 'sublocality_level_1': ['billing_city', 'long_name'], 101 'administrative_area_level_2': ['billing_state', 'long_name'], 102 'postal_code': ['billing_postcode', 'short_name'] 103 }; 104 this.alt_countries = ['ES', 'GB']; 105 }, 106 107 fillInAddress : function () { 108 this.clearFormValues(); 109 var place = this.autocomplete.getPlace(); 110 this.resetForm(); 111 console.log(place.address_components); 112 var current_country = document.getElementById("billing_country").value; 113 if(this.alt_countries.includes(current_country)){ 114 this.component_form = this.component_form_alt; 115 }else{ 116 this.component_form = this.component_form_standard; 117 } 118 for (var f in this.component_form) { 119 loop1: 120 for (var field in place.address_components) { 121 var types = place.address_components[field].types; 122 for (var t in types) { 123 124 if(f == types[t]) { 125 var field_id = this.component_form[f][0]; 126 var prop = this.component_form[f][1]; 127 // If it's empty so far, then fill it 128 if(this.formFieldsValue[field_id] == '') { 129 if(place.address_components[field].hasOwnProperty(prop)){ 130 this.formFieldsValue[field_id] = place.address_components[field][prop]; 131 console.log(field_id + " = " + place.address_components[field][prop]); 132 break loop1; 133 } 134 } 135 } 136 137 } 138 } 139 } 140 this.streetNumber = place.name; 141 var street_addr_type = place.types.indexOf('street_address'); 142 if(street_addr_type == -1 && typeof precise_address_alert !== 'undefined' && precise_address_alert != 'disabled') { 143 alert(precise_address_alert); 144 } 145 146 this.appendStreetNumber(); 147 this.fillForm(); 148 149 //update checkout 150 jQuery("#billing_state").trigger("change"); 151 jQuery(document.body).trigger("update_checkout"); 152 if(typeof FireCheckout !== 'undefined') 153 { 154 checkout.update(checkout.urls.billing_address); 155 } 156 }, 157
158 clearFormValues: function () 159 { 160 for (var f in this.formFieldsValue) { 161 this.formFieldsValue[f] = ''; 162 } 163 }, 164 appendStreetNumber : function () 165 { 166 167 if(this.streetNumber != '') 168 { 169 this.formFieldsValue['billing_address_1'] = this.streetNumber 170 } 171 }, 172 fillForm : function() 173 { 174 for (var f in this.formFieldsValue) { 175 if(f == 'billing_country' ) 176 { 177 this.selectRegion( f,this.formFieldsValue[f]); 178 } 179 else 180 { 181 if(document.getElementById((f)) === null){ 182 continue; 183 } 184 else 185 { 186 var autoc_value = this.formFieldsValue[f]; 187 if(f == 'billing_state' && jQuery('select#' + f).length > 0 && jQuery('select#' + f + ' option[value="' + autoc_value +'"]').length == 0) { 188 // State dropdown without a matching value... try the text 189 autoc_value = jQuery('select#' + f + ' option').filter(function () { return jQuery(this).html() == autoc_value; }).val() 190 } 191 document.getElementById((f)).value = autoc_value; 192 jQuery('#'+f).trigger('input'); 193 } 194 195 } 196 } 197 }, 198 selectRegion:function (id,regionText) 199 { 200 if(document.getElementById((id)) == null){ 201 return false; 202 } 203 var el = document.getElementById((id)); 204 if(el.tagName == 'select') { 205 for(var i=0; i<el.options.length; i++) {
206 if ( el.options[i].text == regionText ) { 207 el.selectedIndex = i; 208 break; 209 } 210 } 211 } 212 }, 213 resetForm :function () 214 { 215 if(document.getElementById(('billing_address_2')) !== null){ 216 document.getElementById(('billing_address_2')).value = ''; 217 } 218 }, 219 220 221 setAutocompleteCountry : function () { 222 223 if(document.getElementById('billing_country') === null){ 224 country = 'US'; 225 } 226 else 227 { 228 var country = document.getElementById('billing_country').value; 229 } 230 this.autocomplete.setComponentRestrictions({ 231 'country': country 232 }); 233 } 234 235 236} 237 238 239RpCheckoutAutocomplete_shipping.method = { 240 placeSearch: "", 241 IdSeparator: "", 242 autocomplete : "", 243 streetNumber : "", 244 formFields : { 245 'shipping_address_1': '', 246 'shipping_address_2': '', 247 'shipping_city': '', 248 'shipping_state': '', 249 'shipping_postcode': '', 250 'shipping_country' : '' 251 }, 252 formFieldsValue : { 253 'shipping_address_1': '', 254 'shipping_address_2': '', 255 'shipping_city': '', 256 'shipping_state': '', 257 'shipping_postcode': '', 258 'shipping_country' : '' 259 }, 260 component_form : "", 261 262 initialize: function(){ 263 this.getIdSeparator(); 264 this.initFormFields(); 265 266 this.autocomplete = new google.maps.places.Autocomplete( 267 (document.getElementById('shipping_address_1')), 268 { 269 types: ['address'] 270 }); 271 google.maps.event.addListener(this.autocomplete, 'place_changed', function( event ) { 272 RpCheckoutAutocomplete_shipping.method.fillInAddress() 273 }); 274 var shipping_address = document.getElementById("shipping_address_1"); 275 if(shipping_address != null){ 276 shipping_address.addEventListener("focus", function( event ) { 277 RpCheckoutAutocomplete_shipping.method.setAutocompleteCountry() 278 }, true); 279 } 280 281 var shipping_country = document.getElementById("shipping_country"); 282 if(shipping_country != null){ 283 shipping_country.addEventListener("change", function( event ) { 284 RpCheckoutAutocomplete_shipping.method.setAutocompleteCountry() 285 }, true); 286 } 287 288 289 }, 290 getIdSeparator : function() { 291 if (!document.getElementById('shipping_address_1')) { 292 this.IdSeparator = "_"; 293 return "_"; 294 } 295 this.IdSeparator = ":"; 296 return ":"; 297 }, 298 initFormFields: function () 299 { 300 console.log('-------------'); 301 for (var field in this.formFields) { 302 this.formFields[field] = (field); 303 } 304 this.component_form = {}; 305 this.component_form_standard = 306 { 307 'country': ['shipping_country', 'long_name'], 308 'street_number': ['shipping_address_1', 'short_name'], 309 'route': ['shipping_address_1', 'long_name'], 310 'locality': ['shipping_city', 'long_name'], 311 'postal_town': ['shipping_city', 'long_name'], 312 'sublocality_level_1': ['shipping_city', 'long_name'], 313 'administrative_area_level_2': ['shipping_city', 'long_name'], 314 'administrative_area_level_3': ['shipping_city', 'long_name'], 315 'administrative_area_level_1': ['shipping_state', 'short_name'], 316 'postal_code': ['shipping_postcode', 'short_name'] 317 }; 318 this.component_form_alt = 319 { 320 'country': ['shipping_country', 'long_name'], 321 'street_number': ['shipping_address_1', 'short_name'], 322 'route': ['shipping_address_1', 'long_name'], 323 'locality': ['shipping_city', 'long_name'], 324 'postal_town': ['shipping_city', 'long_name'], 325 'sublocality_level_1': ['shipping_city', 'long_name'], 326 'administrative_area_level_2': ['shipping_state', 'long_name'], 327 'postal_code': ['billing_postcode', 'short_name'] 328 }; 329 this.alt_countries = ['ES', 'GB']; 330 }, 331 332 fillInAddress : function () {
333 this.clearFormValues(); 334 var place = this.autocomplete.getPlace(); 335 this.resetForm(); 336 console.log(place.address_components); 337 var current_country = document.getElementById("shipping_country").value; 338 if(this.alt_countries.includes(current_country)){ 339 this.component_form = this.component_form_alt; 340 }else{ 341 this.component_form = this.component_form_standard; 342 } 343 for (var f in this.component_form) { 344 loop1: 345 for (var field in place.address_components) { 346 var types = place.address_components[field].types; 347 for (var t in types) { 348 349 if(f == types[t]) { 350 var field_id = this.component_form[f][0]; 351 var prop = this.component_form[f][1]; 352 // If it's empty so far, then fill it 353 if(this.formFieldsValue[field_id] == '') { 354 if(place.address_components[field].hasOwnProperty(prop)){ 355 this.formFieldsValue[field_id] = place.address_components[field][prop]; 356 console.log(field_id + " = " + place.address_components[field][prop]); 357 break loop1; 358 } 359 } 360 } 361 362 } 363 } 364 } 365 this.streetNumber = place.name; 366 367 if(place.types.indexOf('street_address') == -1 && typeof precise_address_alert !== 'undefined' && precise_address_alert != 'disabled') { 368 alert(precise_address_alert); 369 } 370 371 this.appendStreetNumber(); 372 this.fillForm(); 373 374 375 //update checkout 376 jQuery("#shipping_state").trigger("change"); 377 jQuery(document.body).trigger("update_checkout"); 378 if(typeof FireCheckout !== 'undefined') 379 { 380 checkout.update(checkout.urls.shipping_address); 381 } 382 }, 383 384 clearFormValues: function () 385 { 386 for (var f in this.formFieldsValue) { 387 this.formFieldsValue[f] = ''; 388 } 389 }, 390 appendStreetNumber : function () 391 { 392 if(this.streetNumber != '') 393 { 394 this.formFieldsValue['shipping_address_1'] = this.streetNumber; 395 } 396 }, 397 fillForm : function() 398 { 399 for (var f in this.formFieldsValue) { 400 if(f == 'shipping_country' ) 401 { 402 this.selectRegion( f,this.formFieldsValue[f]); 403 } 404 else 405 { 406 if(document.getElementById((f)) === null){ 407 continue; 408 } 409 else 410 { 411 var autoc_value = this.formFieldsValue[f]; 412 if(f == 'shipping_state' && jQuery('select#' + f).length > 0 && jQuery('select#' + f + ' option[value="' + autoc_value +'"]').length == 0) { 413 // State dropdown without a matching value... try the text 414 autoc_value = jQuery('select#' + f + ' option').filter(function () { return jQuery(this).html() == autoc_value; }).val() 415 } 416 document.getElementById((f)).value = autoc_value; 417 jQuery('#'+f).trigger('input'); 418 } 419 420 } 421 } 422 }, 423 selectRegion:function (id,regionText) 424 { 425 if(document.getElementById((id)) == null){ 426 return false; 427 } 428 var el = document.getElementById((id)); 429 if(el.tagName == 'select') { 430 for(var i=0; i<el.options.length; i++) {
431 if ( el.options[i].text == regionText ) { 432 el.selectedIndex = i; 433 break; 434 } 435 } 436 } 437 }, 438 resetForm :function () 439 { 440 if(document.getElementById(('shipping_address_2')) !== null){ 441 document.getElementById(('shipping_address_2')).value = ''; 442 } 443 }, 444 445 446 setAutocompleteCountry : function () { 447 448 if(document.getElementById('shipping_country') === null){ 449 country = 'US'; 450 } 451 else 452 { 453 var country = document.getElementById('shipping_country').value; 454 } 455 this.autocomplete.setComponentRestrictions({ 456 'country': country 457 }); 458 } 459 460 461} 462 463 464window.addEventListener('load', function(){ 465 if(!(document.getElementById('billing_address_1') === null)) 466 RpCheckoutAutocomplete.method.initialize(); 467 if(!(document.getElementById('shipping_address_1') === null)) 468 RpCheckoutAutocomplete_shipping.method.initialize(); 469}); 470 471if(!(document.getElementById('billing_address_1') === null)){ 472 var billaddr = document.getElementById('billing_address_1'); 473 google.maps.event.addDomListener(billaddr, 'keydown', function(e) { 474 if (e.keyCode == 13) { 475 e.preventDefault(); 476 } 477 }); 478} 479 480if(!(document.getElementById('shipping_address_1') === null)){ 481 var shipaddr = document.getElementById('shipping_address_1'); 482 google.maps.event.addDomListener(shipaddr, 'keydown', function(e) { 483 if (e.keyCode == 13) { 484 e.preventDefault(); 485 } 486 }); 487}
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.