1. transport_mode depends on origin and 2. pickup timetable
Deploy PBT / deploy (push) Successful in 16s
Deploy PBT / deploy (push) Successful in 16s
This commit is contained in:
@@ -111,6 +111,9 @@
|
||||
if (!hidden) return;
|
||||
|
||||
function clearMatch() {
|
||||
delete hidden.dataset.stopType;
|
||||
delete hidden.dataset.stopLat;
|
||||
delete hidden.dataset.stopLon;
|
||||
if (!hidden.value) return;
|
||||
hidden.value = "";
|
||||
if (hint) { hint.textContent = ""; hint.classList.remove("matched"); }
|
||||
@@ -118,6 +121,9 @@
|
||||
}
|
||||
function markMatch(stop) {
|
||||
hidden.value = String(stop.id);
|
||||
hidden.dataset.stopType = stop.type;
|
||||
hidden.dataset.stopLat = stop.lat;
|
||||
hidden.dataset.stopLon = stop.lon;
|
||||
if (hint) {
|
||||
hint.textContent = "✓ " + stop.name +
|
||||
(stop.municipality ? ", " + stop.municipality : "");
|
||||
@@ -223,8 +229,88 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Which "Verkehrsmittel" options make sense for a given origin stop type.
|
||||
// Rail stops aren't narrowed further (OSM doesn't tell S-Bahn from Fernzug).
|
||||
var MODES_FOR_STOP_TYPE = {
|
||||
bus: ["Bus"],
|
||||
bus_station: ["Bus"],
|
||||
tram: ["Straßenbahn"],
|
||||
subway: ["U-Bahn"],
|
||||
train: ["S-Bahn", "Regionalzug", "Fernzug (ÖBB/Railjet/WESTbahn)"],
|
||||
};
|
||||
|
||||
function setupModeFilter(form) {
|
||||
var select = form.querySelector("#transport_mode");
|
||||
var originHidden = form.querySelector("#origin_stop_id");
|
||||
if (!select || !originHidden) return;
|
||||
var hint = form.querySelector("[data-mode-hint]");
|
||||
|
||||
function apply() {
|
||||
var allowed = MODES_FOR_STOP_TYPE[originHidden.dataset.stopType || ""] || null;
|
||||
var firstVisible = null;
|
||||
Array.prototype.forEach.call(select.options, function (opt) {
|
||||
var ok = !allowed || allowed.indexOf(opt.value) !== -1;
|
||||
opt.hidden = !ok;
|
||||
opt.disabled = !ok;
|
||||
if (ok && !firstVisible) firstVisible = opt;
|
||||
});
|
||||
if (allowed && firstVisible && allowed.indexOf(select.value) === -1) {
|
||||
select.value = firstVisible.value;
|
||||
}
|
||||
if (hint) {
|
||||
hint.textContent = allowed
|
||||
? "Eingeschränkt auf das Verkehrsmittel der gewählten Haltestelle."
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener("stopchange", apply);
|
||||
apply(); // e.g. an already-matched origin when editing a trip
|
||||
}
|
||||
|
||||
// "Fahrplan öffnen": opens Google Maps transit directions for the chosen
|
||||
// stops (exact coordinates when matched, else the typed name) so the user
|
||||
// can look up the real departure and copy it into the "Kurs" field.
|
||||
function setupTimetableLink(form) {
|
||||
var link = form.querySelector("[data-timetable-link]");
|
||||
var originText = form.querySelector("#origin");
|
||||
var destText = form.querySelector("#destination");
|
||||
var originHidden = form.querySelector("#origin_stop_id");
|
||||
var destHidden = form.querySelector("#destination_stop_id");
|
||||
if (!link || !originText || !destText || !originHidden || !destHidden) return;
|
||||
|
||||
function locationParam(textInput, hiddenInput) {
|
||||
var lat = hiddenInput.dataset.stopLat, lon = hiddenInput.dataset.stopLon;
|
||||
if (lat && lon) return lat + "," + lon;
|
||||
var name = textInput.value.trim();
|
||||
return name ? name + ", Österreich" : "";
|
||||
}
|
||||
|
||||
function apply() {
|
||||
var origin = locationParam(originText, originHidden);
|
||||
var destination = locationParam(destText, destHidden);
|
||||
if (!origin || !destination) {
|
||||
link.removeAttribute("href");
|
||||
link.setAttribute("aria-disabled", "true");
|
||||
return;
|
||||
}
|
||||
link.href = "https://www.google.com/maps/dir/?api=1" +
|
||||
"&origin=" + encodeURIComponent(origin) +
|
||||
"&destination=" + encodeURIComponent(destination) +
|
||||
"&travelmode=transit";
|
||||
link.removeAttribute("aria-disabled");
|
||||
}
|
||||
|
||||
form.addEventListener("stopchange", apply);
|
||||
originText.addEventListener("input", apply);
|
||||
destText.addEventListener("input", apply);
|
||||
apply();
|
||||
}
|
||||
|
||||
document.querySelectorAll("form").forEach(function (form) {
|
||||
form.querySelectorAll("[data-stop-input]").forEach(function (i) { setupStopCombo(i, form); });
|
||||
form.querySelectorAll("[data-line-input]").forEach(function (i) { setupLineCombo(i, form); });
|
||||
setupModeFilter(form);
|
||||
setupTimetableLink(form);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user