1 namespace('kivi', function(k){
3 k.QuickSearch = function($real, options) {
4 if ($real.data("quick_search"))
5 return $real.data("quick_search");
15 function send_query(action, term, id, success) {
16 var data = { module: o.module };
17 if (term !== undefined) data.term = term;
18 if (id !== undefined) data.id = id;
20 url: 'controller.pl?action=TopQuickSearch/' + action,
27 function submit_search(term) {
28 send_query('do_search', term, undefined, kivi.eval_json_result);
32 source: function(req, rsp) {
33 send_query('query_autocomplete', req.term, undefined, function (data){ rsp(data); });
35 select: function(event, ui) {
36 send_query('select_autocomplete', undefined, ui.item.id, kivi.eval_json_result);
39 $real.keypress(function(event){
40 if (event.which == KEY.ENTER) {
41 if ($real.val() !== '') {
42 submit_search($real.val());
47 $real.data('quick_search', {});
52 $('input[id^=top-quick-search]').each(function(_,e){
53 kivi.QuickSearch($(e), { module: $(e).attr('module') });