Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/theyoungdesigners_com/modules/googleAddress/static/ |
Upload File : |
var $ = jQuery.noConflict();
function GoogleAddress() {
let _this = this;
this.fillInAddress = function(e) {
const place = this.autocomplete.getPlace();
let address1 = '';
let postcode = '';
for (const component of place.address_components) {
const componentType = component.types[0];
switch (componentType) {
case "street_number": {
address1 = `${component.long_name} ${address1}`;
break;
}
case "route": {
address1 += component.short_name;
break;
}
case "postal_code": {
postcode = `${component.long_name}${postcode}`;
break;
}
case "postal_code_suffix": {
postcode = `${postcode}-${component.long_name}`;
break;
}
case "locality":
$(this.x_fields[1]).val(component.long_name); // town
break;
case "administrative_area_level_1": {
$(this.x_fields[2]).val(component.short_name); // state
break;
}
case "country":
if (this.x_format == 'short') {
$(this.x_fields[4]).val(component.short_name);
} else {
$(this.x_fields[4]).val(component.long_name);
}
break;
}
}
$(this.x_fields[0]).val(address1);
$(this.x_fields[3]).val(postcode);
if (this.x_next) {
let address2Field = document.querySelector(this.x_next);
address2Field.focus();
}
};
// can't have word 'Address' in the field label
$(document).on('loaded.template', function(e, jsondata, $container) {
$('.bind-address', $container).each(function() {
let param = this.dataset.address;
this.x_fields = param.split(',');
this.x_format = this.dataset.format || 'long';
this.x_next = this.dataset.next || false;
let address1Field = document.querySelector(this.x_fields[0]);
// Create the autocomplete object, restricting the search predictions to
// addresses in the US and Canada.
this.autocomplete = new google.maps.places.Autocomplete(address1Field, {
componentRestrictions: { country: ['us', 'ca'] },
fields: ['address_components'],
types: ['address'],
});
// address1Field.focus();
// When the user selects an address from the drop-down, populate the
// address fields in the form.
this.autocomplete.addListener('place_changed', _this.fillInAddress.bind(this));
});
});
}
new GoogleAddress();