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);
53 $("#sidebar_content").load(path, function(a, b, xhr) {
54 if (xhr.getResponseHeader('X-Page-Title')) {
55 document.title = xhr.getResponseHeader('X-Page-Title');
61 page.load = function() {
62 $(".search_results_entry").each(function() {
65 url: entry.data("href"),
69 minlon: map.getBounds().getWest(),
70 minlat: map.getBounds().getSouth(),
71 maxlon: map.getBounds().getEast(),
72 maxlat: map.getBounds().getNorth()
74 success: function(html) {
81 page.unload = function() {
82 map.removeLayer(marker);
84 $(".search_form input[name=query]").val("");