2022-09-04 19:41:13 +00:00
|
|
|
function clearAddressFields() {
|
|
|
|
$('#address-components').hide();
|
|
|
|
$('#street-number').val('');
|
|
|
|
$('#street-number').prop('disabled', true);
|
|
|
|
$('#route').val('');
|
|
|
|
$('#locality').val('');
|
|
|
|
$('#postal-code').val('');
|
|
|
|
}
|
|
|
|
function getAddressFiedlValue(addressComponents, $field){
|
|
|
|
let field = addressComponents.find(obj => obj.types.indexOf($field) > -1);
|
|
|
|
return field != undefined?field.long_name:'';
|
|
|
|
}
|
|
|
|
function initialize() {
|
|
|
|
let input = document.getElementById('field_location');
|
|
|
|
let options = {
|
|
|
|
types: ['address'],
|
|
|
|
componentRestrictions: { country: "de" }
|
|
|
|
};
|
|
|
|
var autocomplete = new google.maps.places.Autocomplete(input, options);
|
|
|
|
autocomplete.addListener("place_changed", () => {
|
|
|
|
clearAddressFields();
|
|
|
|
const place = autocomplete.getPlace();
|
|
|
|
if (!place.geometry) return;
|
|
|
|
var componentMap = {
|
|
|
|
country: 'country',
|
|
|
|
locality: 'locality',
|
|
|
|
administrative_area_level_1 : 'administrative_area_level_1',
|
|
|
|
administrative_area_level_2 : 'administrative_area_level_2',
|
|
|
|
postal_code: 'postal_code',
|
|
|
|
route: 'route',
|
|
|
|
street_number : 'street_number',
|
|
|
|
};
|
|
|
|
$('#address-components').show();
|
|
|
|
let addressComponents = autocomplete.getPlace().address_components;
|
|
|
|
let streetNumber = getAddressFiedlValue(addressComponents, 'street_number');
|
|
|
|
if(streetNumber == '') {
|
|
|
|
$('#street-number').prop('disabled', false);
|
|
|
|
$('#street-number').focus();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#street-number').prop('disabled', true);
|
|
|
|
$('#street-number').val(streetNumber);
|
|
|
|
}
|
|
|
|
let country = getAddressFiedlValue(addressComponents, 'country');
|
|
|
|
let route = getAddressFiedlValue(addressComponents, 'route');
|
|
|
|
$('#route').val(route);
|
|
|
|
let locality = getAddressFiedlValue(addressComponents, 'locality');
|
|
|
|
$('#locality').val(locality);
|
|
|
|
let postalCode = getAddressFiedlValue(addressComponents, 'postal_code');
|
|
|
|
$('#postal-code').val(postalCode);
|
|
|
|
$('#street-number').blur(function(){
|
|
|
|
if($('#street-number').val() == '') $('#street-number').focus();
|
|
|
|
else{
|
|
|
|
$('#street-number').prop('disabled', true);
|
|
|
|
$('#field_location').val(route+' '+$('#street-number').val()+', '+locality+', '+country);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$(window).on('load', google.maps.event, initialize);
|
|
|
|
let input = document.querySelector("#ctelefon");
|
2022-09-05 14:58:04 +00:00
|
|
|
if(input != undefined){
|
|
|
|
let iti = window.intlTelInput(input, {
|
|
|
|
initialCountry: "de",
|
|
|
|
preferredCountries: ["de"],
|
|
|
|
geoIpLookup: function(callback) {
|
|
|
|
$.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
|
|
|
|
let countryCode = (resp && resp.country)?resp.country:"us";
|
|
|
|
callback(countryCode);
|
|
|
|
});
|
|
|
|
},
|
2022-09-07 08:51:17 +00:00
|
|
|
utilsScript: "/template/assets/libs/intl-tel-input/js/utils.min.js",
|
2022-09-05 14:58:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-04 19:41:13 +00:00
|
|
|
// iti.getNumber();
|
|
|
|
function updateProducts(){}
|
|
|
|
$(window).on('load', function(){
|
2022-09-05 14:58:04 +00:00
|
|
|
$("#successful-submitting-form").delay(4000).slideUp(200, function() { $(this).alert('close'); });
|
2022-09-04 19:41:13 +00:00
|
|
|
$('#anfrage').submit(function(){
|
|
|
|
objProducts = [];
|
|
|
|
localStorage.setItem("products", JSON.stringify(objProducts));
|
|
|
|
});
|
|
|
|
});
|