From 85636af26a6f5c266107e2f26f697bc9de0bb69d Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 5 May 2019 12:30:34 +0200 Subject: do not perform useless geolocation lookups (#10) --- public/static/js/geolocation.js | 10 ++++++---- public/static/js/geolocation.min.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'public') diff --git a/public/static/js/geolocation.js b/public/static/js/geolocation.js index 9cde56d..ccc8c3a 100644 --- a/public/static/js/geolocation.js +++ b/public/static/js/geolocation.js @@ -56,9 +56,11 @@ $(document).ready(function() { } }; - if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(processLocation, processError); - } else { - showError('Standortanfragen werden von diesem Browser nicht unterstützt', '', null); + if ($('div.geolocation').length) { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(processLocation, processError); + } else { + showError('Standortanfragen werden von diesem Browser nicht unterstützt', '', null); + } } }); diff --git a/public/static/js/geolocation.min.js b/public/static/js/geolocation.min.js index 11b5464..7862b5b 100644 --- a/public/static/js/geolocation.min.js +++ b/public/static/js/geolocation.min.js @@ -1 +1 @@ -$(document).ready(function(){var e=$("p.geolocationhint"),t=$("div.geolocation div.progress"),n=function(n,r,o){e.remove(),t.remove();var a=$(document.createElement("div"));a.attr("class","error"),a.text(r);var i=$(document.createElement("strong"));i.text(n),a.prepend(i),$("div.geolocation").append(a)},r=function(e){e.error?n("Backend-Fehler:",e.error):0==e.candidates.length?n("Keine Bahnhöfe in 70km Umkreis gefunden",""):(resultTable=$("
"),resultBody=resultTable.children(),$.each(e.candidates,function(e,t){var n=t.ds100,r=t.name,o=t.distance;o=o.toFixed(1);var a=$(document.createElement("a"));a.attr("href",n),a.text(r),resultBody.append(''+r+"")}),t.replaceWith(resultTable))},o=function(e){$.post("/geolocation",{lon:e.coords.longitude,lat:e.coords.latitude},r)},a=function(e){e.code==e.PERMISSION_DENIED?n("Standortanfrage nicht möglich.","Vermutlich fehlen die Rechte im Browser oder der Android Location Service ist deaktiviert."):e.code==e.POSITION_UNAVAILABLE?n("Standort konnte nicht ermittelt werden","(Service nicht verfügbar)"):e.code==e.TIMEOUT?n("Standort konnte nicht ermittelt werden","(Timeout)"):n("Standort konnte nicht ermittelt werden","(unbekannter Fehler)")};navigator.geolocation?navigator.geolocation.getCurrentPosition(o,a):n("Standortanfragen werden von diesem Browser nicht unterstützt","")}); +$(document).ready(function(){var e=$("p.geolocationhint"),t=$("div.geolocation div.progress"),n=function(n,r,o){e.remove(),t.remove();var a=$(document.createElement("div"));a.attr("class","error"),a.text(r);var i=$(document.createElement("strong"));i.text(n),a.prepend(i),$("div.geolocation").append(a)},r=function(e){e.error?n("Backend-Fehler:",e.error):0==e.candidates.length?n("Keine Bahnhöfe in 70km Umkreis gefunden",""):(resultTable=$("
"),resultBody=resultTable.children(),$.each(e.candidates,function(e,t){var n=t.ds100,r=t.name,o=t.distance;o=o.toFixed(1);var a=$(document.createElement("a"));a.attr("href",n),a.text(r),resultBody.append(''+r+"")}),t.replaceWith(resultTable))},o=function(e){$.post("/geolocation",{lon:e.coords.longitude,lat:e.coords.latitude},r)},a=function(e){e.code==e.PERMISSION_DENIED?n("Standortanfrage nicht möglich.","Vermutlich fehlen die Rechte im Browser oder der Android Location Service ist deaktiviert."):e.code==e.POSITION_UNAVAILABLE?n("Standort konnte nicht ermittelt werden","(Service nicht verfügbar)"):e.code==e.TIMEOUT?n("Standort konnte nicht ermittelt werden","(Timeout)"):n("Standort konnte nicht ermittelt werden","(unbekannter Fehler)")};$("div.geolocation").length&&(navigator.geolocation?navigator.geolocation.getCurrentPosition(o,a):n("Standortanfragen werden von diesem Browser nicht unterstützt",""))}); -- cgit v1.2.3