adasd
All checks were successful
Deploy / deploy (push) Successful in 52s

This commit is contained in:
2026-07-22 22:19:31 +02:00
parent 2e800d4839
commit cbecbef830
8 changed files with 450 additions and 194 deletions

View File

@@ -116,6 +116,7 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
</main>
<script>
(function(){
const body = document.body;
const locInput = document.getElementById('loc');
const latInput = document.getElementById('lat');
const lngInput = document.getElementById('lng');
@@ -125,8 +126,64 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
const btnMap = document.getElementById('btnMap');
const mapWrapper = document.getElementById('mapWrapper');
const mapContainer = document.getElementById('mapContainer');
const isLoggedIn = body?.dataset.auth === '1';
const profileLocationPreference = body?.dataset.locationPreference || 'prompt';
const locationStorageKey = 'pkt_user_location';
const locationSessionStorageKey = 'pkt_user_location_session';
let map, marker;
function effectiveLocationPreference() {
if (!isLoggedIn) {
try {
const guestPreference = window.localStorage.getItem('pkt_location_preference_guest');
if (guestPreference && ['disabled', 'prompt', 'enabled'].includes(guestPreference)) {
return guestPreference;
}
} catch (err) {
// ignore
}
}
return profileLocationPreference;
}
function getStoredLocation() {
const candidates = [];
try {
const sessionValue = window.sessionStorage.getItem(locationSessionStorageKey);
if (sessionValue) candidates.push(sessionValue);
} catch (err) {
// ignore
}
try {
const localValue = window.localStorage.getItem(locationStorageKey);
if (localValue) candidates.push(localValue);
} catch (err) {
// ignore
}
for (const value of candidates) {
try {
const parsed = JSON.parse(value);
if (parsed && Number.isFinite(parsed.lat) && Number.isFinite(parsed.lng)) {
return parsed;
}
} catch (err) {
// ignore
}
}
return null;
}
function applyLocation(lat, lng, label = 'Mein Standort') {
latInput.value = Number(lat).toFixed(6);
lngInput.value = Number(lng).toFixed(6);
if (locInput && !locInput.value.trim()) {
locInput.value = label;
}
toggleRadius(true);
}
function toggleRadius(show) {
if (!radiusWrap) return;
radiusWrap.hidden = !show;
@@ -198,17 +255,25 @@ if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
window.PKTConsent?.openPreferences?.();
return;
}
const preference = effectiveLocationPreference();
if (preference === 'disabled') {
alert('Die Standortverwendung ist in deinem Profil deaktiviert.');
return;
}
const storedLocation = getStoredLocation();
if (preference === 'enabled' && storedLocation) {
applyLocation(storedLocation.lat, storedLocation.lng, storedLocation.label || 'Mein Standort');
return;
}
if (!navigator.geolocation) {
alert('Geolocation wird nicht unterstützt.');
return;
}
navigator.geolocation.getCurrentPosition((pos) => {
const lat = pos.coords.latitude;
const lng = pos.coords.longitude;
latInput.value = lat.toFixed(6);
lngInput.value = lng.toFixed(6);
if (locInput && !locInput.value.trim()) locInput.value = 'Mein Standort';
toggleRadius(true);
applyLocation(pos.coords.latitude, pos.coords.longitude, 'Mein Standort');
}, () => alert('Standort konnte nicht ermittelt werden.'));
});