SHOW:
|
|
- or go back to the newest paste.
1 | var cache = {}, lastXhr; | |
2 | ||
3 | - | $("#hifind-find").autocomplete({ |
3 | + | $("#hifind-find").autocomplete({ |
4 | - | source: function(request, response) { |
4 | + | source: function(request, response) { |
5 | - | |
5 | + | |
6 | - | var term = request.term; |
6 | + | var term = request.term; |
7 | - | if (term in cache) { |
7 | + | if (term in cache) { |
8 | - | response(cache[term]); |
8 | + | response(cache[term]); |
9 | - | return; |
9 | + | return; |
10 | - | } |
10 | + | } |
11 | - | |
11 | + | |
12 | - | var posturl = '/hifind/jquery_ui/autocomplete/'+term; |
12 | + | var posturl = '/hifind/jquery_ui/autocomplete/'+term; |
13 | - | lastXhr = $.post(posturl, function(data, status, xhr) { |
13 | + | lastXhr = $.post(posturl, function(data, status, xhr) { |
14 | - | cache[term] = data; |
14 | + | cache[term] = data; |
15 | - | if (xhr === lastXhr) { |
15 | + | if (xhr === lastXhr) { |
16 | - | response(data); |
16 | + | response(data); |
17 | - | } |
17 | + | } |
18 | - | }, 'json'); |
18 | + | }, 'json'); |
19 | - | }, |
19 | + | }, |
20 | - | delay: 300, |
20 | + | delay: 300, |
21 | - | minLength: 2 |
21 | + | minLength: 2 |
22 | - | }); |
22 | + | }); |
23 | ||
24 | - | $("#hifind-find").bind('autocompleteselect', function(event, ui){ |
24 | + | $("#hifind-find").bind('autocompleteselect', function(event, ui){ |
25 | - | window.location = ui.item.dest; |
25 | + | window.location = ui.item.dest; |
26 | - | }); |
26 | + | }); |