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.type && data.id) return; // Browse link
37 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
38 map.fitBounds([[data.minLat, data.minLon],
39 [data.maxLat, data.maxLon]]);
41 map.setView(center, data.zoom);
45 var marker = L.marker([0, 0], {icon: getUserIcon()});
49 page.pushstate = page.popstate = function(path) {
50 var params = querystring.parse(path.substring(path.indexOf('?') + 1));
51 $(".search_form input[name=query]").val(params.query);
52 OSM.loadSidebarContent(path, page.load);
55 page.load = function() {
56 $(".search_results_entry").each(function() {
59 url: entry.data("href"),
63 minlon: map.getBounds().getWest(),
64 minlat: map.getBounds().getSouth(),
65 maxlon: map.getBounds().getEast(),
66 maxlat: map.getBounds().getNorth()
68 success: function(html) {
74 return map.getState();
77 page.unload = function() {
78 map.removeLayer(marker);
80 $(".search_form input[name=query]").val("");