diff options
author | Martin Fischer <martin@push-f.com> | 2025-03-14 08:22:25 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-03-14 08:35:51 +0100 |
commit | ddbab65241d2dcc6cd3c12866fc88e9a8d357014 (patch) | |
tree | 2ea496021a5d11a6db064275fa8c8e464f3bf665 /script.js | |
parent | abc9c9b3f48b6eae4c44c44589f91a490ae9bb72 (diff) |
feat: implement sharing UI
Diffstat (limited to 'script.js')
-rw-r--r-- | script.js | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -28,7 +28,32 @@ function route() { if (!latLon) { document.title = 'Share a location'; - content.append(createEl('h1', {}, ['not yet implemented'])); + content.append(createEl('h1', {}, [document.title])); + const input = createEl('input'); + const button = createEl('button', {}, ['Share']); + const inputGroup = createEl('div', { class: 'input-group' }, [input, button]); + const errorDiv = createEl('div', { class: 'error' }); + content.append(createEl('label', {}, ['Latitude, longitude', inputGroup])); + content.append(errorDiv); + function share() { + if (!input.value.trim()) { + return; + } + try { + let [lat, lon] = parseLatLon(input.value); + // TODO: use navigator.share if supported + window.location = `#${lat},${lon}`; + } catch (error) { + errorDiv.textContent = error; + } + } + input.addEventListener('keydown', (e) => { + if (e.key == 'Enter') { + share(); + } + }); + button.addEventListener('click', share); + // TODO: provide a button to share the current position via navigator.geolocation.getCurrentPosition if supported } else { document.title = 'Open location'; |