]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Add node version pages
[rails.git] / app / assets / javascripts / index.js
index 449c52038e59ffc859f25375d6a9025a68625555..621054caf6a01c312fc9b6ae3e6402671cb13b90 100644 (file)
@@ -175,8 +175,7 @@ $(document).ready(function () {
     }
   }
 
-  var placement = $("html").attr("dir") === "rtl" ? "right" : "left";
-  $(".leaflet-control .control-button").tooltip({ placement: placement, container: "body" });
+  $(".leaflet-control .control-button").tooltip({ placement: "left", container: "body" });
 
   var expiry = new Date();
   expiry.setYear(expiry.getFullYear() + 10);
@@ -192,11 +191,11 @@ $(document).ready(function () {
   });
 
   if (Cookies.get("_osm_welcome") !== "hide") {
-    $(".welcome").addClass("visible");
+    $(".welcome").removeAttr("hidden");
   }
 
   $(".welcome .btn-close").on("click", function () {
-    $(".welcome").removeClass("visible");
+    $(".welcome").hide();
     Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/", samesite: "lax" });
   });
 
@@ -245,8 +244,8 @@ $(document).ready(function () {
   });
 
   function remoteEditHandler(bbox, object) {
-    var loaded = false,
-        url,
+    var remoteEditHost = "http://127.0.0.1:8111",
+        osmHost = location.protocol + "//" + location.host,
         query = {
           left: bbox.getWest() - 0.0001,
           top: bbox.getNorth() + 0.0001,
@@ -254,25 +253,31 @@ $(document).ready(function () {
           bottom: bbox.getSouth() - 0.0001
         };
 
-    url = "http://127.0.0.1:8111/load_and_zoom?";
-
-    if (object) query.select = object.type + object.id;
-
-    var iframe = $("<iframe>")
-      .hide()
-      .appendTo("body")
-      .attr("src", url + Qs.stringify(query))
-      .on("load", function () {
-        $(this).remove();
-        loaded = true;
-      });
+    if (object && object.type !== "note") query.select = object.type + object.id; // can't select notes
+    sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + Qs.stringify(query), function () {
+      if (object && object.type === "note") {
+        var noteQuery = { url: osmHost + OSM.apiUrl(object) };
+        sendRemoteEditCommand(remoteEditHost + "/import?" + Qs.stringify(noteQuery));
+      }
+    });
 
-    setTimeout(function () {
-      if (!loaded) {
+    function sendRemoteEditCommand(url, callback) {
+      var iframe = $("<iframe>");
+      var timeoutId = setTimeout(function () {
         alert(I18n.t("site.index.remote_failed"));
         iframe.remove();
-      }
-    }, 1000);
+      }, 5000);
+
+      iframe
+        .hide()
+        .appendTo("body")
+        .attr("src", url)
+        .on("load", function () {
+          clearTimeout(timeoutId);
+          iframe.remove();
+          if (callback) callback();
+        });
+    }
 
     return false;
   }
@@ -341,10 +346,6 @@ $(document).ready(function () {
           });
         }
       });
-
-      $(".colour-preview-box").each(function () {
-        $(this).css("background-color", $(this).data("colour"));
-      });
     }
 
     page.unload = function () {
@@ -354,6 +355,16 @@ $(document).ready(function () {
     return page;
   };
 
+  OSM.OldBrowse = function () {
+    var page = {};
+
+    page.pushstate = page.popstate = function (path) {
+      OSM.loadSidebarContent(path);
+    };
+
+    return page;
+  };
+
   var history = OSM.History(map);
 
   OSM.router = OSM.Router(map, {
@@ -368,6 +379,7 @@ $(document).ready(function () {
     "/user/:display_name/history": history,
     "/note/:id": OSM.Note(map),
     "/node/:id(/history)": OSM.Browse(map, "node"),
+    "/node/:id/history/:version": OSM.OldBrowse(),
     "/way/:id(/history)": OSM.Browse(map, "way"),
     "/relation/:id(/history)": OSM.Browse(map, "relation"),
     "/changeset/:id": OSM.Changeset(map),
@@ -400,4 +412,8 @@ $(document).ready(function () {
       e.preventDefault();
     }
   });
+
+  $(document).on("click", "#sidebar_content .btn-close", function () {
+    OSM.router.route("/" + OSM.formatHash(map));
+  });
 });