+ $(".directions_form").on("submit", function(e) {
+ e.preventDefault();
+ $("header").addClass("closed");
+ getRoute();
+ });
+
+ $(".routing_marker").on('dragstart', function (e) {
+ e.originalEvent.dataTransfer.effectAllowed = 'move';
+ e.originalEvent.dataTransfer.setData('id', this.id);
+ var xo = e.originalEvent.clientX - $(e.target).offset().left;
+ var yo = e.originalEvent.clientY - $(e.target).offset().top;
+ e.originalEvent.dataTransfer.setData('offsetX', e.originalEvent.target.width / 2 - xo);
+ e.originalEvent.dataTransfer.setData('offsetY', e.originalEvent.target.height - yo);
+ });
+
+ var page = {};
+
+ page.pushstate = page.popstate = function() {
+ $(".search_form").hide();
+ $(".directions_form").show();
+
+ $("#map").on('dragend dragover', function (e) {
+ e.preventDefault();
+ });
+
+ $("#map").on('drop', function (e) {
+ e.preventDefault();
+ var oe = e.originalEvent;
+ var id = oe.dataTransfer.getData('id');
+ var pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present
+ pt.x += Number(oe.dataTransfer.getData('offsetX'));
+ pt.y += Number(oe.dataTransfer.getData('offsetY'));
+ var ll = map.containerPointToLatLng(pt);
+ endpoints[id === 'marker_from' ? 0 : 1].setLatLng(ll);
+ getRoute();
+ });
+
+ var params = querystring.parse(location.search.substring(1)),
+ route = (params.route || '').split(';');
+
+ if (params.engine) {
+ setEngine(params.engine);
+ }
+
+ if (params.from) {
+ endpoints[0].setValue(params.from);
+ endpoints[1].setValue("");
+ } else {
+ endpoints[0].setValue("");
+ endpoints[1].setValue("");
+ }
+
+ var o = route[0] && L.latLng(route[0].split(',')),
+ d = route[1] && L.latLng(route[1].split(','));
+
+ if (o) endpoints[0].setLatLng(o);
+ if (d) endpoints[1].setLatLng(d);
+
+ map.setSidebarOverlaid(!o || !d);
+
+ getRoute();
+ };
+
+ page.load = function() {
+ page.pushstate();
+ };
+
+ page.unload = function() {
+ $(".search_form").show();
+ $(".directions_form").hide();
+ $("#map").off('dragend dragover drop');
+
+ map
+ .removeLayer(popup)
+ .removeLayer(polyline)
+ .removeLayer(endpoints[0].marker)
+ .removeLayer(endpoints[1].marker);
+ };
+
+ return page;
+};
+
+OSM.Directions.engines = [];
+
+OSM.Directions.addEngine = function (engine, supportsHTTPS) {
+ if (document.location.protocol == "http:" || supportsHTTPS) {
+ OSM.Directions.engines.push(engine);
+ }