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], [data.maxLat, data.maxLon]]);
35 map.setView(center, data.zoom);
38 // Let clicks to object browser links propagate.
39 if (data.type && data.id) return;
41 marker.setLatLng(center).addTo(map);
47 var marker = L.marker([0, 0], {icon: getUserIcon()});
51 page.pushstate = page.popstate = function(path) {
52 var params = querystring.parse(path.substring(path.indexOf('?') + 1));
53 $(".search_form input[name=query]").val(params.query);
54 OSM.loadSidebarContent(path, page.load);
57 page.load = function() {
58 $(".search_results_entry").each(function() {
61 url: entry.data("href"),
65 minlon: map.getBounds().getWest(),
66 minlat: map.getBounds().getSouth(),
67 maxlon: map.getBounds().getEast(),
68 maxlat: map.getBounds().getNorth()
70 success: function(html) {
76 return map.getState();
79 page.unload = function() {
80 map.removeLayer(marker);
82 $(".search_form input[name=query]").val("");