]> git.openstreetmap.org Git - rails.git/commitdiff
Move directions params init code to its own function
authorAnton Khorev <tony29@yandex.ru>
Mon, 3 Feb 2025 13:17:44 +0000 (16:17 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 6 Mar 2025 09:02:15 +0000 (12:02 +0300)
app/assets/javascripts/index/directions.js

index 9d25e67a0a9a4d1da4be1ebf1ae9fe4da264b15b..4630237760cc1507a2921e3e74cc957c8a4fa532 100644 (file)
@@ -284,9 +284,21 @@ OSM.Directions = function (map) {
     map.once("startinglocation", startingLocationListener);
   });
 
     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 () {
   const page = {};
 
   page.pushstate = page.popstate = function () {
+    initializeFromParams();
+
     $(".search_form").hide();
     $(".directions_form").show();
 
     $(".search_form").hide();
     $(".directions_form").show();
 
@@ -311,14 +323,6 @@ OSM.Directions = function (map) {
     endpoints[0].enableListeners();
     endpoints[1].enableListeners();
 
     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);
   };
 
     map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng);
   };