]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Add history changesets layer module
[rails.git] / app / assets / javascripts / index.js
index c5bddbaec058a714d2f01ded486cee431a3a1955..7ff8a40d1474905b9d706968e75c35b90b22149f 100644 (file)
@@ -1,7 +1,6 @@
 //= require_self
 //= require leaflet.sidebar
 //= require leaflet.sidebar-pane
-//= require leaflet.locatecontrol/dist/L.Control.Locate.umd
 //= require leaflet.locate
 //= require leaflet.layers
 //= require leaflet.key
@@ -37,7 +36,7 @@ $(function () {
 
     map.setSidebarOverlaid(false);
 
-    $("#sidebar_loader").show().addClass("delayed-fade-in");
+    $("#sidebar_loader").prop("hidden", false).addClass("delayed-fade-in");
 
     // Prevent caching the XHR response as a full-page URL
     // https://github.com/openstreetmap/openstreetmap-website/issues/5663
@@ -53,7 +52,7 @@ $(function () {
     fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } })
       .then(response => {
         $("#flash").empty();
-        $("#sidebar_loader").removeClass("delayed-fade-in").hide();
+        $("#sidebar_loader").removeClass("delayed-fade-in").prop("hidden", true);
 
         const title = response.headers.get("X-Page-Title");
         if (title) document.title = decodeURIComponent(title);
@@ -111,39 +110,30 @@ $(function () {
   }
 
   addControlGroup([
-    L.OSM.zoom({ position: position }),
-    L.OSM.locate({ position: position })
+    L.OSM.zoom({ position }),
+    L.OSM.locate({ position })
   ]);
 
   addControlGroup([
     L.OSM.layers({
-      position: position,
-      layers: map.baseLayers,
-      sidebar: sidebar
-    }),
-    L.OSM.key({
-      position: position,
-      sidebar: sidebar
+      position,
+      sidebar,
+      layers: map.baseLayers
     }),
+    L.OSM.key({ position, sidebar }),
     L.OSM.share({
-      "position": position,
-      "sidebar": sidebar,
+      position,
+      sidebar,
       "short": true
     })
   ]);
 
   addControlGroup([
-    L.OSM.note({
-      position: position,
-      sidebar: sidebar
-    })
+    L.OSM.note({ position, sidebar })
   ]);
 
   addControlGroup([
-    L.OSM.query({
-      position: position,
-      sidebar: sidebar
-    })
+    L.OSM.query({ position, sidebar })
   ]);
 
   L.control.scale()
@@ -245,7 +235,7 @@ $(function () {
       })
       .catch(() => {
         // eslint-disable-next-line no-alert
-        alert(I18n.t("site.index.remote_failed"));
+        alert(OSM.i18n.t("site.index.remote_failed"));
       });
 
     function sendRemoteEditCommand(url) {
@@ -261,12 +251,12 @@ $(function () {
     e.preventDefault();
   });
 
-  if (OSM.params().edit_help) {
+  if (new URLSearchParams(location.search).get("edit_help")) {
     $("#editanchor")
       .removeAttr("title")
       .tooltip({
         placement: "bottom",
-        title: I18n.t("javascripts.edit_help")
+        title: OSM.i18n.t("javascripts.edit_help")
       })
       .tooltip("show");
 
@@ -280,7 +270,7 @@ $(function () {
 
     page.pushstate = page.popstate = function () {
       map.setSidebarOverlaid(true);
-      document.title = I18n.t("layouts.project_name.title");
+      document.title = OSM.i18n.t("layouts.project_name.title");
     };
 
     page.load = function () {
@@ -288,9 +278,6 @@ $(function () {
       if (params.has("query")) {
         $("#sidebar .search_form input[name=query]").value(params.get("query"));
       }
-      if (!("autofocus" in document.createElement("input"))) {
-        $("#sidebar .search_form input[name=query]").focus();
-      }
       return map.getState();
     };
 
@@ -311,7 +298,7 @@ $(function () {
     };
 
     function addObject(type, id, version, center) {
-      const hashParams = OSM.parseHash(location.hash);
+      const hashParams = OSM.parseHash();
       map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
         if (!hashParams.center && bounds.isValid() &&
             (center || !map.getBounds().contains(bounds))) {
@@ -380,6 +367,11 @@ $(function () {
       return;
     }
 
+    // Open local anchor links as normal.
+    if ($(this).attr("href")?.startsWith("#")) {
+      return;
+    }
+
     // Ignore cross-protocol and cross-origin links.
     if (location.protocol !== this.protocol || location.host !== this.host) {
       return;
@@ -393,7 +385,7 @@ $(function () {
     }
   });
 
-  $(document).on("click", "#sidebar_content .btn-close", function () {
+  $(document).on("click", "#sidebar .sidebar-close-controls button", function () {
     OSM.router.route("/" + OSM.formatHash(map));
   });
 });