]> git.openstreetmap.org Git - rails.git/commitdiff
Pre-fill directions 'from' field with search query, if any.
authorMatt Amos <zerebubuth@gmail.com>
Mon, 26 Jan 2015 14:52:18 +0000 (14:52 +0000)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 26 Jan 2015 14:52:18 +0000 (14:52 +0000)
app/assets/javascripts/index/directions.js.erb
app/assets/javascripts/index/search.js

index 30b6349fde6ac0e7ea5c2add73a9f356350dfa79..b1f9e44b9be6dd1e346377cfe986fd08a45db9d4 100644 (file)
@@ -290,6 +290,10 @@ OSM.Directions = function (map) {
       setEngine(params.engine);
     }
 
+    if (params.from) {
+      $(".directions_form input[name='route_from']").val(params.from);
+    }
+
     var o = route[0] && L.latLng(route[0].split(',')),
         d = route[1] && L.latLng(route[1].split(','));
 
index 46f756f3bc017275fb0c1a51b112d54c65d0aea7..08d2dc96c92b178c7ee10e0d1640ff4b7347c083 100644 (file)
@@ -9,6 +9,16 @@ OSM.Search = function(map) {
     }
   });
 
+  $(".search_form a.button.switch_link").on("click", function(e) {
+    e.preventDefault();
+    var query = $(e.target).parent().parent().find("input[name=query]").val();
+    if (query) {
+      OSM.router.route("/directions?from=" + encodeURIComponent(query) + OSM.formatHash(map));
+    } else {
+      OSM.router.route("/directions" + OSM.formatHash(map));
+    }
+  });
+
   $(".search_form").on("submit", function(e) {
     e.preventDefault();
     $("header").addClass("closed");