From 9995d316b23eaf3145da524de0b30313769a73ac Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Mon, 26 Jan 2015 14:52:18 +0000 Subject: [PATCH] Pre-fill directions 'from' field with search query, if any. --- app/assets/javascripts/index/directions.js.erb | 4 ++++ app/assets/javascripts/index/search.js | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/assets/javascripts/index/directions.js.erb b/app/assets/javascripts/index/directions.js.erb index 30b6349fd..b1f9e44b9 100644 --- a/app/assets/javascripts/index/directions.js.erb +++ b/app/assets/javascripts/index/directions.js.erb @@ -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(',')); diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index 46f756f3b..08d2dc96c 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -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"); -- 2.39.5