summaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'script.js')
-rw-r--r--script.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/script.js b/script.js
index 54bea94..9ca453c 100644
--- a/script.js
+++ b/script.js
@@ -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';