26 lines
815 B
JavaScript
26 lines
815 B
JavaScript
import './styles/app.scss';
|
|
import htmx from 'htmx.org';
|
|
|
|
window.htmx = htmx;
|
|
|
|
document.addEventListener('click', (event) => {
|
|
const button = event.target.closest('[data-weather-location]');
|
|
if (!button || !navigator.geolocation) return;
|
|
|
|
navigator.geolocation.getCurrentPosition(async ({coords}) => {
|
|
const payload = new URLSearchParams({
|
|
_token: button.dataset.locationToken,
|
|
latitude: String(coords.latitude),
|
|
longitude: String(coords.longitude),
|
|
});
|
|
const response = await fetch(button.dataset.locationUrl, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
body: payload,
|
|
});
|
|
if (response.ok) {
|
|
window.location.reload();
|
|
}
|
|
});
|
|
});
|