1 OSM.Search = function(map) {
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 $("#query").val(params.query);
53 $("#sidebar_content").load(path, page.load);
56 page.load = function() {
57 $("#sidebar").removeClass("minimized");
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) {
77 page.unload = function() {
78 map.removeLayer(marker);