]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Allow searching users by IP subnet
[rails.git] / app / assets / javascripts / index.js
index ad34479d32f93b46a739e898f081e7c3cffc65ed..c3ee1e3bc9b47729faab64ad478d6a7818cbabb4 100644 (file)
@@ -38,30 +38,21 @@ $(document).ready(function () {
 
     $("#sidebar_loader").show().addClass("delayed-fade-in");
 
-    // IE<10 doesn't respect Vary: X-Requested-With header, so
-    // prevent caching the XHR response as a full-page URL.
-    if (content_path.indexOf("?") >= 0) {
-      content_path += "&xhr=1";
-    } else {
-      content_path += "?xhr=1";
-    }
-
     $("#sidebar_content")
       .empty();
 
-    $.ajax({
-      url: content_path,
-      dataType: "html",
-      complete: function (xhr) {
+    fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } })
+      .then(response => {
         $("#flash").empty();
         $("#sidebar_loader").removeClass("delayed-fade-in").hide();
 
-        var content = $(xhr.responseText);
+        const title = response.headers.get("X-Page-Title");
+        if (title) document.title = decodeURIComponent(title);
 
-        if (xhr.getResponseHeader("X-Page-Title")) {
-          var title = xhr.getResponseHeader("X-Page-Title");
-          document.title = decodeURIComponent(title);
-        }
+        return response.text();
+      })
+      .then(html => {
+        const content = $(html);
 
         $("head")
           .find("link[type=\"application/atom+xml\"]")
@@ -75,8 +66,7 @@ $(document).ready(function () {
         if (callback) {
           callback();
         }
-      }
-    });
+      });
   };
 
   var params = OSM.mapParams();
@@ -97,9 +87,7 @@ $(document).ready(function () {
   var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
   function addControlGroup(controls) {
-    controls.forEach(function (control) {
-      control.addTo(map);
-    });
+    for (const control of controls) control.addTo(map);
 
     var firstContainer = controls[0].getContainer();
     $(firstContainer).find(".control-button").first()
@@ -257,6 +245,7 @@ $(document).ready(function () {
       fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) })
         .then(callback)
         .catch(function () {
+          // eslint-disable-next-line no-alert
           alert(I18n.t("site.index.remote_failed"));
         });
     }