From 878f3a52a9e0625f218b8b9a655ceb1d648d21cd Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Fri, 18 Jun 2021 16:35:48 +0200 Subject: [PATCH] Editor section to request location --- original-assets/styles/styles.scss | 2 +- templates/assets/css/styles.css | 2 +- templates/assets/js/geohelper.js | 26 ++++++++++++++++++++++++++ templates/editor.gohtml | 18 ++++++++++++------ templates/strings/de.yaml | 4 ++++ templates/strings/default.yaml | 4 ++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 templates/assets/js/geohelper.js diff --git a/original-assets/styles/styles.scss b/original-assets/styles/styles.scss index 5528124..a00cbf9 100644 --- a/original-assets/styles/styles.scss +++ b/original-assets/styles/styles.scss @@ -118,7 +118,7 @@ form { .fw-form { @extend .fw; - input:not([type]), input[type="text"], input[type="email"], input[type="url"], input[type="password"], textarea { + input:not([type]), input[type="submit"], input[type="button"], input[type="text"], input[type="email"], input[type="url"], input[type="password"], textarea { @extend .fw; } } diff --git a/templates/assets/css/styles.css b/templates/assets/css/styles.css index 18b07aa..3917a72 100644 --- a/templates/assets/css/styles.css +++ b/templates/assets/css/styles.css @@ -163,7 +163,7 @@ footer * { display: inline; } -.fw, .fw-form, .fw-form input:not([type]), .fw-form input[type=text], .fw-form input[type=email], .fw-form input[type=url], .fw-form input[type=password], .fw-form textarea { +.fw, .fw-form, .fw-form input:not([type]), .fw-form input[type=submit], .fw-form input[type=button], .fw-form input[type=text], .fw-form input[type=email], .fw-form input[type=url], .fw-form input[type=password], .fw-form textarea { width: 100%; } diff --git a/templates/assets/js/geohelper.js b/templates/assets/js/geohelper.js new file mode 100644 index 0000000..214c642 --- /dev/null +++ b/templates/assets/js/geohelper.js @@ -0,0 +1,26 @@ +(function () { + let geoBtn = document.querySelector('#geobtn') + function geo() { + let status = document.querySelector('#geostatus') + status.classList.add('hide') + status.value = '' + + function success(position) { + let latitude = position.coords.latitude + let longitude = position.coords.longitude + status.value = `geo:${latitude},${longitude}` + status.classList.remove('hide') + } + + function error() { + alert(geoBtn.dataset.failed) + } + + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(success, error) + } else { + alert(geoBtn.dataset.notsupported) + } + } + geoBtn.addEventListener('click', geo) +})() \ No newline at end of file diff --git a/templates/editor.gohtml b/templates/editor.gohtml index aff3fd3..6ee8366 100644 --- a/templates/editor.gohtml +++ b/templates/editor.gohtml @@ -18,7 +18,7 @@ tags: - --- - +

{{ string .Blog.Lang "update" }}

@@ -30,25 +30,25 @@ tags: {{ end }} - +

{{ string .Blog.Lang "delete" }}

{{ if .Data.DeleteURL }} - + {{ else }} - + {{ end }}

{{ string .Blog.Lang "upload" }}

- +

{{ string .Blog.Lang "drafts" }}

@@ -58,8 +58,14 @@ tags: {{ end }} - +
+

{{ string .Blog.Lang "location" }}

+
+ + +
+ {{ end }} diff --git a/templates/strings/de.yaml b/templates/strings/de.yaml index a94e877..584bf2d 100644 --- a/templates/strings/de.yaml +++ b/templates/strings/de.yaml @@ -15,6 +15,10 @@ interactions: "Interaktionen & Kommentare" interactionslabel: "Hast du eine Antwort hierzu veröffentlicht? Füge hier die URL ein." likeof: "Gefällt mir von" loading: "Laden..." +location: "Standort" +locationfailed: "Abfragen des Standorts fehlgeschlagen" +locationget: "Standort abfragen" +locationnotsupported: "Die Standort-API wird von diesem Browser nicht unterstützt" next: "Weiter" noposts: "Hier sind keine Posts." oldcontent: "⚠️ Dieser Eintrag ist bereits über ein Jahr alt. Er ist möglicherweise nicht mehr aktuell. Meinungen können sich geändert haben." diff --git a/templates/strings/default.yaml b/templates/strings/default.yaml index 0575c2d..66dd52d 100644 --- a/templates/strings/default.yaml +++ b/templates/strings/default.yaml @@ -22,6 +22,10 @@ interactions: "Interactions & Comments" interactionslabel: "Have you published a response to this? Paste the URL here." likeof: "Like of" loading: "Loading..." +location: "Location" +locationfailed: "Failed to request the location" +locationget: "Request location" +locationnotsupported: "The location API is not supported by this browser" login: "Login" logout: "Logout" nameopt: "Name (optional)"