From d357ec0ff86d13dc56cc2522b246e56bd5d0d6ec Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 28 Apr 2025 04:31:23 +0300 Subject: [PATCH] Enable endpoint listeners before sidebar finishes loading It's possible to move the endpoint while the sidebar loads. In this case we need the listeners to update the coordinates of the scheduled route request. --- app/assets/javascripts/index/directions.js | 25 ++++++++-------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 5f7386518..61c646c59 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -222,25 +222,18 @@ OSM.Directions = function (map) { const page = {}; page.pushstate = page.popstate = function () { - if ($("#directions_content").length) { - page.load(); - } else { - initializeFromParams(); + page.load(); - $(".search_form").hide(); - $(".directions_form").show(); + if ($("#directions_content").length) return; - OSM.loadSidebarContent("/directions", () => { - enableListeners(); - - if (scheduledRouteArguments) { - getScheduledRoute(...scheduledRouteArguments); - scheduledRouteArguments = null; - } - }); + OSM.loadSidebarContent("/directions", () => { + if (scheduledRouteArguments) { + getScheduledRoute(...scheduledRouteArguments); + scheduledRouteArguments = null; + } + }); - map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng); - } + map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng); }; page.load = function () { -- 2.39.5