summaryrefslogtreecommitdiff
path: root/public/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/admin_search.js60
1 files changed, 41 insertions, 19 deletions
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js
index 37c46cc..9bf878b 100644
--- a/public/javascripts/admin_search.js
+++ b/public/javascripts/admin_search.js
@@ -5,46 +5,68 @@ admin_search = {
5 admin_search.display_toggle(); 5 admin_search.display_toggle();
6 return false; 6 return false;
7 }); 7 });
8 },
9 8
10 display_toggle : function() { 9 $(document).bind("keydown", function(e) {
11 if ($('#search_widget').css("display") != "none") { 10 if (e.key === "Escape" && $('#search_widget').is(':visible')) {
12 $('#search_widget').fadeOut(); 11 $('#search_widget').fadeOut();
13 } 12 }
14 else { 13 });
15 $('#search_widget').fadeIn(); 14
16 $('#search_term').attr("value", ""); 15 $(document).bind("click", function(e) {
17 $('#search_term').focus(); 16 if ($('#search_widget').is(':visible') &&
18 } 17 !$(e.target).closest('#search_widget').length &&
18 !$(e.target).closest('a[onclick*="display_toggle"]').length) {
19 $('#search_widget').fadeOut();
20 }
21 });
19 22
20 $("#search_term").bind("keyup", function() { 23 $("#search_term").bind("input", function() {
24 if (!$('#search_widget').is(':visible')) return;
21 if ($(this).val()) { 25 if ($(this).val()) {
22 $.ajax({ 26 $.ajax({
23 type: "GET", 27 type: "GET",
24 url: ADMIN_SEARCH_URL, 28 url: ADMIN_SEARCH_URL,
25 data: "search_term=" + $(this).val(), 29 data: "search_term=" + $(this).val(),
26 dataType: "json", 30 dataType: "json",
27 success : function(results) { 31 success: function(results) {
28 admin_search.show_results(results); 32 admin_search.show_results(results);
29 }, 33 },
30 error: function(xhr, status, error) { 34 error: function(xhr, status, error) {
31 console.log("Ajax error:", status, error, xhr.status, xhr.responseText); 35 console.log("Ajax error:", status, error, xhr.status, xhr.responseText);
32 } 36 }
33 }); 37 });
34 } 38 } else {
35 else {
36 $('#search_results').slideUp(); 39 $('#search_results').slideUp();
37 $('#search_results').empty(); 40 $('#search_results').empty();
38 } 41 }
39 }); 42 });
40 }, 43 },
41 44
45 display_toggle : function() {
46 if ($('#search_widget').is(':visible')) {
47 $('#search_widget').fadeOut();
48 } else {
49 $('#search_widget').fadeIn();
50 $('#search_term').focus();
51 }
52 },
53
42 show_results : function(results) { 54 show_results : function(results) {
43 $('#search_results').empty(); 55 $('#search_results').empty();
44 for (result in results) { 56 if (results.length) {
45 $('#search_results').append("<p><a href='"+ results[result].edit_path + "'>" + results[result].title + "</a></p>"); 57 $('#search_results').append(
46 } 58 "<p class='search_more'>Press Enter to see all results ⏎</p>"
47 $('#search_results').slideDown(); 59 );
60 }
61 for (result in results) {
62 $('#search_results').append(
63 "<p><a href='" + results[result].node_path + "'>" +
64 results[result].title +
65 "<span class='result_path'>" + results[result].unique_name + "</span>" +
66 "</a></p>"
67 );
68 }
69 $('#search_results').slideDown();
48 } 70 }
49}; 71};
50 72