X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=share%2Fcollection.js;h=75391b9a8343015f2bed538cb9c8531cc633999c;hb=3628015ea9312e6a896ad6872659ee54f3a53df1;hp=1afd64c1fcc54a6c80acdd22a2925da8be450ad2;hpb=d83e2903e3ab90e605fee0b24e48b7cb8548e6ea;p=collection4.git diff --git a/share/collection.js b/share/collection.js index 1afd64c..75391b9 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,60 @@ 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() + { + window.setTimeout (function () + { + $("#search-suggest").hide (); + }, 500); + }); + + $("#search-input").focus (function() { var term = $("#search-input").val (); - $.getJSON ("collection.fcgi", - { "action": "list_graphs", "format": "json", "search": 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 (); }); });