From d065f88b1a565d1b9c784d27993159bc64c926ec Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 10 Aug 2024 05:53:59 +0300 Subject: [PATCH] Remove references to global variables from endpoint drag listener This causes visible input value updates even when the route is not recalculated. The upside is that it lets endpoints not know about the route and its update state. --- app/assets/javascripts/index/directions.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index ae01cb566..4e2c4a895 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -21,9 +21,11 @@ OSM.Directions = function (map) { }); var endpointDragCallback = function (dragging) { - if (map.hasLayer(polyline)) { - getRoute(false, !dragging); - } + if (!map.hasLayer(polyline)) return; + if (dragging && !chosenEngine.draggable) return; + if (dragging && awaitingRoute) return; + + getRoute(false, !dragging); }; var endpointGeocodeCallback = function () { getRoute(true, true); @@ -68,11 +70,8 @@ OSM.Directions = function (map) { }); endpoint.marker.on("drag dragend", function (e) { - var dragging = (e.type === "drag"); - if (dragging && !chosenEngine.draggable) return; - if (dragging && awaitingRoute) return; endpoint.setLatLng(e.target.getLatLng()); - dragCallback(dragging); + dragCallback(e.type === "drag"); }); input.on("keydown", function () { -- 2.39.5