]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Load pluralizers
[rails.git] / app / assets / javascripts / index.js
index 6e3e3cea2feb1b6bcb2b8f652158324454c4dcc8..c5bddbaec058a714d2f01ded486cee431a3a1955 100644 (file)
@@ -24,7 +24,7 @@
 //= require index/home
 //= require router
 
-$(document).ready(function () {
+$(function () {
   const map = new L.OSM.Map("map", {
     zoomControl: false,
     layerControl: false,
@@ -236,20 +236,20 @@ $(document).ready(function () {
           });
 
     if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes
-    sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query, function () {
-      if (object && object.type === "note") {
-        const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) });
-        sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery);
-      }
-    }, function () {
-      // eslint-disable-next-line no-alert
-      alert(I18n.t("site.index.remote_failed"));
-    });
+    sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query)
+      .then(() => {
+        if (object && object.type === "note") {
+          const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) });
+          sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery);
+        }
+      })
+      .catch(() => {
+        // eslint-disable-next-line no-alert
+        alert(I18n.t("site.index.remote_failed"));
+      });
 
-    function sendRemoteEditCommand(url, callback, errorCallback) {
-      fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) })
-        .then(callback)
-        .catch(errorCallback);
+    function sendRemoteEditCommand(url) {
+      return fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) });
     }
 
     return false;
@@ -311,7 +311,7 @@ $(document).ready(function () {
     };
 
     function addObject(type, id, version, center) {
-      const hashParams = OSM.parseHash(window.location.hash);
+      const hashParams = OSM.parseHash(location.hash);
       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))) {
@@ -363,7 +363,7 @@ $(document).ready(function () {
     "/account/home": OSM.Home(map)
   });
 
-  if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
+  if (OSM.preferred_editor === "remote" && location.pathname === "/edit") {
     remoteEditHandler(map.getBounds(), params.object);
     OSM.router.setCurrentPath("/");
   }