From: Florian Forster Date: Mon, 21 Jun 2010 13:29:23 +0000 (+0200) Subject: share/collection.js: Improve the search suggestion behavior. X-Git-Tag: v4.0.0~205 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0b309b20095f91057133a0956343962ac4d54b19;p=collection4.git share/collection.js: Improve the search suggestion behavior. --- diff --git a/share/collection.js b/share/collection.js index 026d434..9968452 100644 --- a/share/collection.js +++ b/share/collection.js @@ -1,6 +1,8 @@ function format_instance(inst) { - return ("
  • " + inst.description + "
  • "); + return ("
  • " + inst.description + + "
  • "); } function format_instance_list(instances) @@ -24,22 +26,57 @@ function format_graph(graph) return ("
  • " + graph.title + format_instance_list (graph.instances) + "
  • "); } +function update_search_suggestions () +{ + var term = $("#search-input").val (); + if (term.length < 2) + { + $("#search-suggest").hide (); + return (true); + } + + $("#search-suggest").show (); + $.getJSON ("collection.fcgi", + { "action": "search_json", "q": term}, + function(data) + { + var i; + $("#search-suggest").html (""); + for (i = 0; i < data.length; i++) + { + var graph = data[i]; + $("#search-suggest").append (format_graph (graph)); + } + } + ); +} /* update_search_suggestions */ + $(document).ready(function() { - $("#search-input").keyup (function() + /* $("#layout-middle-right").html (""); */ + $("#search-form").append (""); + $("#search-suggest").hide (); + + $("#search-input").blur (function() + { + $("#search-suggest").hide (); + }); + + $("#search-input").focus (function() { var term = $("#search-input").val (); - $.getJSON ("collection.fcgi", - { "action": "search_json", "q": term}, - function(data) - { - var i; - $("#search-output").html (""); - for (i = 0; i < data.length; i++) - { - var graph = data[i]; - $("#search-output").append (format_graph (graph)); - } - }); + if (term.length < 2) + { + $("#search-suggest").hide (); + } + else + { + $("#search-suggest").show (); + } + }); + + $("#search-input").keyup (function() + { + update_search_suggestions (); }); }); diff --git a/share/style.css b/share/style.css index d5b1161..740ae33 100644 --- a/share/style.css +++ b/share/style.css @@ -35,13 +35,23 @@ body vertical-align: top; } -ul.graph_list +#search-form +{ + position: relative; +} + +#search-suggest +{ + position: absolute; +} + +#search-output ul.graph_list { margin: 0; padding: 1ex; } -li.graph +#search-output li.graph { display: block; border: 1px solid gray; @@ -50,7 +60,7 @@ li.graph background-color: rgb(245,245,255); } -ul.instance_list +#search-output ul.instance_list { margin: 0; padding: 1ex; @@ -59,7 +69,7 @@ ul.instance_list background-color: rgb(252,252,252); } -li.instance +#search-output li.instance { display: block;