1 OSM.Search = function(map) {
2 $(".search_form input[name=query]")
3 .on("focus", function() {
4 $(".describe_location").fadeOut(100);
6 .on("blur", function() {
7 $(".describe_location").fadeIn(100);
11 .on("click", ".search_more a", clickSearchMore)
12 .on("click", ".search_results_entry a.set_position", clickSearchResult);
14 function clickSearchMore(e) {
18 var div = $(this).parents(".search_more");
21 div.find(".loader").show();
23 $.get($(this).attr("href"), function(data) {
24 div.replaceWith(data);
28 function clickSearchResult(e) {
29 var data = $(this).data(),
30 center = L.latLng(data.lat, data.lon);
32 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
33 map.fitBounds([[data.minLat, data.minLon],
34 [data.maxLat, data.maxLon]]);
36 map.setView(center, data.zoom);
40 var marker = L.marker([0, 0], {icon: getUserIcon()});
44 page.pushstate = page.popstate = function(path) {
45 var params = querystring.parse(path.substring(path.indexOf('?') + 1));
46 $(".search_form input[name=query]").val(params.query);
47 OSM.loadSidebarContent(path, page.load);
50 page.load = function() {
51 $(".search_results_entry").each(function() {
54 url: entry.data("href"),
58 minlon: map.getBounds().getWest(),
59 minlat: map.getBounds().getSouth(),
60 maxlon: map.getBounds().getEast(),
61 maxlat: map.getBounds().getNorth()
63 success: function(html) {
69 return map.getState();
72 page.unload = function() {
73 map.removeLayer(marker);
75 $(".search_form input[name=query]").val("");