From: Anton Khorev Date: Mon, 3 Feb 2025 13:17:44 +0000 (+0300) Subject: Move directions params init code to its own function X-Git-Tag: live~11^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/0ba8ac49f6815db5a971776f4960f16549d18645 Move directions params init code to its own function --- diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 9d25e67a0..463023776 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -284,9 +284,21 @@ OSM.Directions = function (map) { map.once("startinglocation", startingLocationListener); }); + function initializeFromParams() { + const params = new URLSearchParams(location.search), + route = (params.get("route") || "").split(";"); + + if (params.has("engine")) setEngine(params.get("engine")); + + endpoints[0].setValue(params.get("from") || route[0] || lastLocation.join(", ")); + endpoints[1].setValue(params.get("to") || route[1] || ""); + } + const page = {}; page.pushstate = page.popstate = function () { + initializeFromParams(); + $(".search_form").hide(); $(".directions_form").show(); @@ -311,14 +323,6 @@ OSM.Directions = function (map) { endpoints[0].enableListeners(); endpoints[1].enableListeners(); - const params = new URLSearchParams(location.search), - route = (params.get("route") || "").split(";"); - - if (params.has("engine")) setEngine(params.get("engine")); - - endpoints[0].setValue(params.get("from") || route[0] || lastLocation.join(", ")); - endpoints[1].setValue(params.get("to") || route[1] || ""); - map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng); };