- Map links (/map.php?karte=…&x=…&y=…&zoom=…&ort=…) open the region at that spot with a pin
- "Share location" button on the map: click a spot, optional name, copy the link
- Calendar entries: "Pick location on the map" opens the map in a window, "Use this location" stores the meeting point
- Map links in comments, captions and descriptions render as "📍 Region – Location" and do not count as external links for moderation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
64 lines
2.5 KiB
JavaScript
64 lines
2.5 KiB
JavaScript
/**
|
|
* Kalender: Treffpunkt eines Termins auf der Karte auswaehlen. Die Karte laeuft im Fenster
|
|
* (assets/map/index.html?pick=1) und schickt den gewaehlten Ort per postMessage zurueck.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var modal = document.getElementById('map-pick-modal');
|
|
if (!modal) return;
|
|
var frame = modal.querySelector('[data-map-frame]');
|
|
var field = null; // Feld des Formulars, fuer das gerade ausgewaehlt wird
|
|
|
|
function open(target) {
|
|
field = target;
|
|
var current = field.querySelector('input[name="location"]').value;
|
|
// Schon ein Ort gewaehlt? Dann die Karte dort oeffnen.
|
|
var query = current.indexOf('?') !== -1 ? current.slice(current.indexOf('?') + 1) + '&' : '';
|
|
frame.src = '/assets/map/index.html?' + query + 'pick=1';
|
|
modal.hidden = false;
|
|
document.body.style.overflow = 'hidden';
|
|
}
|
|
|
|
function close() {
|
|
modal.hidden = true;
|
|
document.body.style.overflow = '';
|
|
frame.src = 'about:blank';
|
|
}
|
|
|
|
function setLocation(target, url, label) {
|
|
target.querySelector('input[name="location"]').value = url;
|
|
var text = target.querySelector('[data-location-label]');
|
|
text.textContent = url ? '📍 ' + label : 'Kein Ort gewählt';
|
|
text.classList.toggle('is-set', !!url);
|
|
target.querySelector('[data-clear-location]').hidden = !url;
|
|
}
|
|
|
|
document.addEventListener('click', function (event) {
|
|
var pick = event.target.closest('[data-pick-location]');
|
|
if (pick) {
|
|
open(pick.closest('[data-location-field]'));
|
|
return;
|
|
}
|
|
var clear = event.target.closest('[data-clear-location]');
|
|
if (clear) {
|
|
setLocation(clear.closest('[data-location-field]'), '', '');
|
|
return;
|
|
}
|
|
if (event.target.closest('[data-close-map-pick]') || event.target === modal) {
|
|
close();
|
|
}
|
|
});
|
|
|
|
document.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Escape' && !modal.hidden) close();
|
|
});
|
|
|
|
// Antwort der Karte: nur von unserer eigenen Seite annehmen
|
|
window.addEventListener('message', function (event) {
|
|
if (event.origin !== window.location.origin || !event.data || event.data.type !== 'lumina-map-pick' || !field) return;
|
|
if (typeof event.data.url !== 'string' || event.data.url.indexOf('/map.php?') !== 0) return;
|
|
setLocation(field, event.data.url, String(event.data.label || ''));
|
|
close();
|
|
});
|
|
})();
|