summaryrefslogtreecommitdiff
path: root/public/javascripts/admin_search.js
blob: ba52bb5bca81dda62edf76211c4b9e65de7a1492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
admin_search = {
  
  display_toggle : function() {
    if ($('#search_widget').css("display") != "none") {
      $('#search_widget').fadeOut();
    }
    else {
      $('#search_widget').fadeIn();
      $('#search_term').attr("value", "");
      $('#search_term').focus();
    }
    
    $("#search_term").bind("keyup", function() {
        if ($(this).attr("value")) {
          $.ajax({
            type: "GET",
            url: "/admin/search",
            data: "search_term=" + $(this).attr("value"),
            dataType: "json",
            success : function(results) {
              admin_search.show_results(results);
            }
          });
        }
        else {
          $('#search_results').slideUp();
          $('#search_results').empty(); 
        }
      });
    },
    
    show_results : function(results) {
       $('#search_results').empty();
       for (result in results) {
         $('#search_results').append("<p><a href='"+ results[result].edit_path + "'>" + results[result].title + "</a></p>");
       }
       $('#search_results').slideDown();
     }
     
  }