v5
This commit is contained in:
parent
1b9afa40ef
commit
2c6acf1c3f
@ -10,7 +10,7 @@ session_start();
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="main-nav">
|
||||
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
|
||||
<ul class="navbar-nav mx-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php#services">Servizi</a>
|
||||
</li>
|
||||
@ -21,7 +21,7 @@ session_start();
|
||||
<a class="nav-link" href="contact.php">Contattaci</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav ms-lg-3">
|
||||
<ul class="navbar-nav">
|
||||
<?php if (isset($_SESSION['user_id'])):
|
||||
?>
|
||||
<li class="nav-item dropdown">
|
||||
|
||||
@ -1 +1,53 @@
|
||||
// Main javascript file
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const locationInputs = document.querySelectorAll('input[name="location"]');
|
||||
if (locationInputs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const COMUNI_URL = 'https://raw.githubusercontent.com/matteocontrini/comuni-json/master/comuni.json';
|
||||
const IP_GEOLOCATION_URL = 'http://ip-api.com/json';
|
||||
|
||||
// Create a datalist for suggestions
|
||||
const datalist = document.createElement('datalist');
|
||||
datalist.id = 'comuni-list';
|
||||
document.body.appendChild(datalist);
|
||||
|
||||
// Attach the datalist to the input fields
|
||||
locationInputs.forEach(input => {
|
||||
input.setAttribute('list', datalist.id);
|
||||
input.setAttribute('autocomplete', 'off'); // Disable browser's own autocomplete
|
||||
});
|
||||
|
||||
// Fetch comuni and populate datalist
|
||||
fetch(COMUNI_URL)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
data.forEach(comune => {
|
||||
const option = document.createElement('option');
|
||||
option.value = comune.nome;
|
||||
datalist.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching Italian municipalities:', error);
|
||||
});
|
||||
|
||||
// Fetch IP-based geolocation and pre-fill the input
|
||||
fetch(IP_GEOLOCATION_URL)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data && data.city) {
|
||||
locationInputs.forEach(input => {
|
||||
// Only set the value if the input is currently empty
|
||||
if (input.value.trim() === '') {
|
||||
input.value = data.city;
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching IP geolocation:', error);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user