]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Refactor
[rails.git] / app / assets / javascripts / index.js
index 4a9abc4dc0f78fe5fbb602f3d938a4cf2ff9b737..3d063189fb0db6e6e3b0706a8a79cb9ee1b5d982 100644 (file)
@@ -5,6 +5,7 @@
 //= require leaflet.key
 //= require leaflet.note
 //= require leaflet.share
+//= require leaflet.polyline
 //= require index/search
 //= require index/browse
 //= require index/export
@@ -12,6 +13,7 @@
 //= require index/history
 //= require index/note
 //= require index/new_note
+//= require index/directions
 //= require router
 
 (function() {
@@ -151,7 +153,7 @@ $(document).ready(function () {
       map._object);
 
     $.removeCookie("_osm_location");
-    $.cookie("_osm_location", cookieContent(map), { expires: expiry, path: "/" });
+    $.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" });
   });
 
   if ($.cookie('_osm_welcome') == 'hide') {
@@ -279,6 +281,7 @@ $(document).ready(function () {
     return page;
   };
 
+  var directions = OSM.Directions(map);
   var history = OSM.History(map);
 
   OSM.router = OSM.Router(map, {
@@ -322,12 +325,18 @@ $(document).ready(function () {
 
   $(".search_form").on("submit", function(e) {
     e.preventDefault();
-    $("header").addClass("closed");
-    var query = $(this).find("input[name=query]").val();
-    if (query) {
-      OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
+    if ($(".query_wrapper.routing").is(":visible")) {
+      // Directions
+      directions.requestRoute(true, true);
     } else {
-      OSM.router.route("/" + OSM.formatHash(map));
+      // Search
+      $("header").addClass("closed");
+      var query = $(this).find("input[name=query]").val();
+      if (query) {
+        OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
+      } else {
+        OSM.router.route("/" + OSM.formatHash(map));
+      }
     }
   });