]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/edit/id.js.erb
Replace use of I18n in javascript with OSM.i18n
[rails.git] / app / assets / javascripts / edit / id.js.erb
index 7c907ed3a3496d2419179de705791c5f2182f740..7f111b41ec4bfcad8bf24a3385874b3b265fac16 100644 (file)
@@ -1,10 +1,10 @@
-$(document).ready(function () {
+$(function () {
   const id = $("#id-embed"),
         idData = id.data();
 
   if (!idData.configured) {
     // eslint-disable-next-line no-alert
-    alert(I18n.t("site.edit.id_not_configured"));
+    alert(OSM.i18n.t("site.edit.id_not_configured"));
     return;
   }
 
@@ -13,15 +13,18 @@ $(document).ready(function () {
   const hashArgs = OSM.parseHash(location.hash);
   const mapParams = OSM.mapParams();
   const params = new URLSearchParams();
-  let { zoom, lat, lon } = mapParams;
+  let zoom, lat, lon;
 
+  if (idData.lat && idData.lon) {
+    ({ zoom, lat, lon } = idData);
+  } else if (!mapParams.object) {
+    ({ zoom, lat, lon } = mapParams);
+  }
   if (mapParams.object) {
     params.set("id", mapParams.object.type + "/" + mapParams.object.id);
     if (hashArgs.center) ({ zoom, center: { lat, lng: lon } } = hashArgs);
-  } else if (idData.lat && idData.lon) {
-    ({ zoom, lat, lon } = { zoom: 16, ...idData });
   }
-  params.set("map", [zoom || 17, lat, lon].join("/"));
+  if (lat && lon) params.set("map", [zoom || 17, lat, lon].join("/"));
 
   const passThroughKeys = ["background", "comment", "disable_features", "gpx", "hashtags", "locale", "maprules", "notes", "offset", "photo", "photo_dates", "photo_overlay", "photo_username", "presets", "source", "validationDisable", "validationWarning", "validationError", "walkthrough"];
   for (const key of passThroughKeys) {
@@ -32,5 +35,5 @@ $(document).ready(function () {
 
   if (idData.gpx) params.set("gpx", idData.gpx);
 
-  id.attr("src", idData.url + "#" + params.toString().replace(/\+/g, "%20"));
+  id.attr("src", idData.url + "#" + params);
 });