]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Introduce drag event callback for route endpoints
[rails.git] / app / assets / javascripts / index / directions.js
index f07aa7f072fdb9e0b2f03bf17f6feba763884000..8d9263323e44c154f60a77ede80f1eb8425da3df 100644 (file)
@@ -20,9 +20,15 @@ OSM.Directions = function (map) {
     weight: 12
   });
 
+  var endpointDragCallback = function (dragging) {
+    if (map.hasLayer(polyline)) {
+      getRoute(false, !dragging);
+    }
+  };
+
   var endpoints = [
-    Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN),
-    Endpoint($("input[name='route_to']"), OSM.MARKER_RED)
+    Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback),
+    Endpoint($("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback)
   ];
 
   var expiry = new Date();
@@ -42,7 +48,7 @@ OSM.Directions = function (map) {
     select.append("<option value='" + i + "'>" + I18n.t("javascripts.directions.engines." + engine.id) + "</option>");
   });
 
-  function Endpoint(input, iconUrl) {
+  function Endpoint(input, iconUrl, dragCallback) {
     var endpoint = {};
 
     endpoint.marker = L.marker([0, 0], {
@@ -63,13 +69,11 @@ OSM.Directions = function (map) {
       if (dragging && !chosenEngine.draggable) return;
       if (dragging && awaitingRoute) return;
       endpoint.setLatLng(e.target.getLatLng());
-      if (map.hasLayer(polyline)) {
-        getRoute(false, !dragging);
-      }
+      dragCallback(dragging);
     });
 
     input.on("keydown", function () {
-      input.removeClass("error");
+      input.removeClass("is-invalid");
     });
 
     input.on("change", function (e) {
@@ -81,7 +85,7 @@ OSM.Directions = function (map) {
     endpoint.setValue = function (value, latlng) {
       endpoint.value = value;
       delete endpoint.latlng;
-      input.removeClass("error");
+      input.removeClass("is-invalid");
       input.val(value);
 
       if (latlng) {
@@ -106,7 +110,7 @@ OSM.Directions = function (map) {
         endpoint.awaitingGeocode = false;
         endpoint.hasGeocode = true;
         if (json.length === 0) {
-          input.addClass("error");
+          input.addClass("is-invalid");
           alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value }));
           return;
         }