diff options
Diffstat (limited to 'public/javascripts/admin_search.js')
| -rw-r--r-- | public/javascripts/admin_search.js | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index d645cca..ba52bb5 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js | |||
| @@ -1,28 +1,40 @@ | |||
| 1 | admin_search = { | 1 | admin_search = { |
| 2 | 2 | ||
| 3 | initialize : function() { | 3 | display_toggle : function() { |
| 4 | $("#search_term").bind("keyup", function() { | 4 | if ($('#search_widget').css("display") != "none") { |
| 5 | if ($(this).attr("value")) { | 5 | $('#search_widget').fadeOut(); |
| 6 | $.ajax({ | ||
| 7 | type: "GET", | ||
| 8 | url: "/admin/search", | ||
| 9 | data: "search_term=" + $(this).attr("value"), | ||
| 10 | dataType: "json", | ||
| 11 | success : function(results) { | ||
| 12 | admin_search.show_results(results); | ||
| 13 | } | ||
| 14 | }); | ||
| 15 | } | ||
| 16 | else { | ||
| 17 | $('#results').empty(); | ||
| 18 | } | ||
| 19 | }); | ||
| 20 | }, | ||
| 21 | |||
| 22 | show_results : function(results) { | ||
| 23 | $('#results').empty(); | ||
| 24 | for (result in results) { | ||
| 25 | $('#results').append("<p>" + results[result].title + "</p>"); | ||
| 26 | } | 6 | } |
| 27 | } | 7 | else { |
| 28 | } \ No newline at end of file | 8 | $('#search_widget').fadeIn(); |
| 9 | $('#search_term').attr("value", ""); | ||
| 10 | $('#search_term').focus(); | ||
| 11 | } | ||
| 12 | |||
| 13 | $("#search_term").bind("keyup", function() { | ||
| 14 | if ($(this).attr("value")) { | ||
| 15 | $.ajax({ | ||
| 16 | type: "GET", | ||
| 17 | url: "/admin/search", | ||
| 18 | data: "search_term=" + $(this).attr("value"), | ||
| 19 | dataType: "json", | ||
| 20 | success : function(results) { | ||
| 21 | admin_search.show_results(results); | ||
| 22 | } | ||
| 23 | }); | ||
| 24 | } | ||
| 25 | else { | ||
| 26 | $('#search_results').slideUp(); | ||
| 27 | $('#search_results').empty(); | ||
| 28 | } | ||
| 29 | }); | ||
| 30 | }, | ||
| 31 | |||
| 32 | show_results : function(results) { | ||
| 33 | $('#search_results').empty(); | ||
| 34 | for (result in results) { | ||
| 35 | $('#search_results').append("<p><a href='"+ results[result].edit_path + "'>" + results[result].title + "</a></p>"); | ||
| 36 | } | ||
| 37 | $('#search_results').slideDown(); | ||
| 38 | } | ||
| 39 | |||
| 40 | } \ No newline at end of file | ||
