summaryrefslogtreecommitdiff
path: root/public/static/js/geolocation.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/static/js/geolocation.js')
-rw-r--r--public/static/js/geolocation.js63
1 files changed, 40 insertions, 23 deletions
diff --git a/public/static/js/geolocation.js b/public/static/js/geolocation.js
index 50801a5..03857a1 100644
--- a/public/static/js/geolocation.js
+++ b/public/static/js/geolocation.js
@@ -1,55 +1,71 @@
/*
- * Copyright (C) 2020 Daniel Friesel
+ * Copyright (C) 2020 Birte Kristina Friesel
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
$(document).ready(function() {
- function getPlaceholder() {
+ const getPlaceholder = function() {
return $('div.geolocation div.progress');
}
- var showError = function(header, message, code) {
- getPlaceholder().remove();
- var errnode = $(document.createElement('div'));
+ const showError = function(header, message, code) {
+ const errnode = $(document.createElement('div'));
errnode.attr('class', 'error');
errnode.text(message);
- var headnode = $(document.createElement('strong'));
- headnode.text(header);
+ const headnode = $(document.createElement('strong'));
+ headnode.text(header + ' ');
errnode.prepend(headnode);
$('div.geolocation').append(errnode);
+
+ const recent = $('div.geolocation').data('recent');
+ if (recent) {
+ const stops = recent.split('|');
+ const res = $(document.createElement('p'));
+ $.each(stops, function(i, stop) {
+ const parts = stop.split(';');
+ const node = $('<a class="tablerow" href="/s/' + parts[0] + '?hafas=' + parts[2] + '"><span><i class="material-icons" aria-hidden="true">' + (parseInt(parts[2]) ? 'directions' : 'train') + '</i>' + parts[1] + '</span></a>');
+ node.click(function() {
+ $('nav .preloader-wrapper').addClass('active');
+ });
+ res.append(node);
+ });
+ $('p.geolocationhint').text('Letzte Ziele:');
+ getPlaceholder().replaceWith(res);
+ } else {
+ getPlaceholder().remove();
+ }
};
- var processResult = function(data) {
+ const processResult = function(data) {
if (data.error) {
showError('Backend-Fehler:', data.error, null);
} else if (data.candidates.length == 0) {
showError('Keine Bahnhöfe in 70km Umkreis gefunden', '', null);
} else {
- resultTable = $('<table><tbody></tbody></table>')
- resultBody = resultTable.children();
+ const res = $(document.createElement('p'));
$.each(data.candidates, function(i, candidate) {
- var ds100 = candidate.ds100,
+ const eva = candidate.eva,
name = candidate.name,
- distance = candidate.distance;
- distance = distance.toFixed(1);
-
- var stationlink = $(document.createElement('a'));
- stationlink.attr('href', ds100);
- stationlink.text(name);
+ hafas = candidate.hafas,
+ distance = candidate.distance.toFixed(1);
- resultBody.append('<tr><td><a href="/s/' + ds100 + '">' + name + '</a></td></tr>');
+ const node = $('<a class="tablerow" href="/s/' + eva + '?hafas=' + hafas + '"><span><i class="material-icons" aria-hidden="true">' + (parseInt(hafas) ? 'directions' : 'train') + '</i>' + name + '</span></a>');
+ node.click(function() {
+ $('nav .preloader-wrapper').addClass('active');
+ });
+ res.append(node);
});
- getPlaceholder().replaceWith(resultTable);
+ getPlaceholder().replaceWith(res);
}
};
- var processLocation = function(loc) {
+ const processLocation = function(loc) {
$.post('/geolocation', {lon: loc.coords.longitude, lat: loc.coords.latitude}, processResult);
};
- var processError = function(error) {
+ const processError = function(error) {
if (error.code == error.PERMISSION_DENIED) {
showError('Standortanfrage nicht möglich.', 'Vermutlich fehlen die Rechte im Browser oder der Android Location Service ist deaktiviert.', 'geolocation.error.PERMISSION_DENIED');
} else if (error.code == error.POSITION_UNAVAILABLE) {
@@ -61,8 +77,9 @@ $(document).ready(function() {
}
};
- var geoLocationButton = $('div.geolocation > button');
- var getGeoLocation = function() {
+ const geoLocationButton = $('div.geolocation > button');
+ const recentStops = geoLocationButton.data('recent');
+ const getGeoLocation = function() {
geoLocationButton.replaceWith($('<p class="geolocationhint">Stationen in der Umgebung:</p><div class="progress"><div class="indeterminate"></div></div>'));
navigator.geolocation.getCurrentPosition(processLocation, processError);
}