]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/search.js
Allow searching users by IP subnet
[rails.git] / app / assets / javascripts / index / search.js
index e54c5132c65ab4dca495aa72bfc9ed380718df7b..3c1af5056ad57b06b4d615c5788000ca9262d861 100644 (file)
@@ -10,22 +10,18 @@ OSM.Search = function (map) {
   $(".search_form a.btn.switch_link").on("click", function (e) {
     e.preventDefault();
     var query = $(this).closest("form").find("input[name=query]").val();
-    if (query) {
-      OSM.router.route("/directions?from=" + encodeURIComponent(query) + OSM.formatHash(map));
-    } else {
-      OSM.router.route("/directions" + OSM.formatHash(map));
-    }
+    let search = "";
+    if (query) search = "?" + new URLSearchParams({ from: query });
+    OSM.router.route("/directions" + search + OSM.formatHash(map));
   });
 
   $(".search_form").on("submit", function (e) {
     e.preventDefault();
     $("header").addClass("closed");
     var query = $(this).find("input[name=query]").val();
-    if (query) {
-      OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
-    } else {
-      OSM.router.route("/" + OSM.formatHash(map));
-    }
+    let search = "/";
+    if (query) search = "/search?" + new URLSearchParams({ query });
+    OSM.router.route(search + OSM.formatHash(map));
   });
 
   $(".describe_location").on("click", function (e) {
@@ -51,21 +47,19 @@ OSM.Search = function (map) {
     var div = $(this).parents(".search_more"),
         csrf_param = $("meta[name=csrf-param]").attr("content"),
         csrf_token = $("meta[name=csrf-token]").attr("content"),
-        params = {};
+        params = new URLSearchParams();
 
     $(this).hide();
     div.find(".loader").show();
 
-    params[csrf_param] = csrf_token;
+    params.set(csrf_param, csrf_token);
 
-    $.ajax({
-      url: $(this).attr("href"),
+    fetch($(this).attr("href"), {
       method: "POST",
-      data: params,
-      success: function (data) {
-        div.replaceWith(data);
-      }
-    });
+      body: params
+    })
+      .then(response => response.text())
+      .then(data => div.replaceWith(data));
   }
 
   function showSearchResult() {
@@ -129,19 +123,20 @@ OSM.Search = function (map) {
       var entry = $(this),
           csrf_param = $("meta[name=csrf-param]").attr("content"),
           csrf_token = $("meta[name=csrf-token]").attr("content"),
-          params = {
+          params = new URLSearchParams({
             zoom: map.getZoom(),
             minlon: map.getBounds().getWest(),
             minlat: map.getBounds().getSouth(),
             maxlon: map.getBounds().getEast(),
             maxlat: map.getBounds().getNorth()
-          };
-      params[csrf_param] = csrf_token;
-      $.ajax({
-        url: entry.data("href"),
+          });
+      params.set(csrf_param, csrf_token);
+      fetch(entry.data("href"), {
         method: "POST",
-        data: params,
-        success: function (html) {
+        body: params
+      })
+        .then(response => response.text())
+        .then(function (html) {
           entry.html(html);
           // go to first result of first geocoder
           if (index === 0) {
@@ -150,8 +145,7 @@ OSM.Search = function (map) {
               panToSearchResult(firstResult.data());
             }
           }
-        }
-      });
+        });
     });
 
     return map.getState();