diff --git a/index.html b/index.html
index da7e9c0..cf7c1c1 100644
--- a/index.html
+++ b/index.html
@@ -110,8 +110,8 @@
@@ -125,8 +125,8 @@
Reisezeit:
-
diff --git a/script/components/map/mapObjects.js b/script/components/map/mapObjects.js
index 735f8ea..f79cc32 100644
--- a/script/components/map/mapObjects.js
+++ b/script/components/map/mapObjects.js
@@ -96,26 +96,17 @@ class CityMenu {
}
#initMenuEntry(element, cityId, cityName) {
- const input = element.querySelector("input");
- const label = element.querySelector("label");
-
- // make unique across document by adding city to strings
- input.name = `city-menu-${cityId}`;
- input.id = `city-menu-${cityId}-${input.id}`;
- label.setAttribute(
- "for",
- `city-menu-${cityId}-${label.getAttribute("for")}`,
- );
+ const result = initInputAndLabel(element, cityId);
// needed for reacting when entry is chosen
- input.data = {
+ result.input.data = {
type: "city",
cityName: cityName,
cityId: cityId,
- entry: input.value,
+ entry: result.input.value,
};
- return input.value; // what is the "name" of this entry?
+ return result.input.value; // what is the "name" of this entry?
}
}
@@ -155,22 +146,16 @@ class JourneyMenu {
update(diff) {}
#initMenuEntry(element, id) {
- const input = element.querySelector("input");
- const label = element.querySelector("label");
-
- // make unique across document by adding id to strings
- input.name = `edge-menu-${id}`;
- input.id = `edge-menu-${id}-${input.id}`;
- label.setAttribute("for", `edge-menu-${id}-${label.getAttribute("for")}`);
+ const result = initInputAndLabel(element, id);
// needed for reacting when entry is chosen
- input.data = {
+ result.input.data = {
type: "edge",
id: id,
- entry: input.value,
+ entry: result.input.value,
};
- return input.value; // what is the "name" of this entry?
+ return result.input.value; // what is the "name" of this entry?
}
remove() {
diff --git a/script/util.js b/script/util.js
index e52b29e..a1a9b51 100644
--- a/script/util.js
+++ b/script/util.js
@@ -22,6 +22,17 @@ function updateElement(element, data) {
}
}
+function initInputAndLabel(container, idSuffix) {
+ const input = container.querySelector("input");
+ const label = container.querySelector("label");
+
+ input.name = `${input.name}-${idSuffix}`;
+ input.id = `${input.id}-${idSuffix}`;
+ label.setAttribute("for", input.id);
+
+ return { input: input, label: label };
+}
+
function* calculateDiffs(oldObjectOfObjects, newObjectOfObjects) {
for (let id in oldObjectOfObjects) {
// this id is not present in the new object