Merge branch 'custompdf'
[wolnelektury.git] / wolnelektury / static / js / search.js
1
2 var __bind = function (self, fn) {
3     return function() { fn.apply(self, arguments); };
4 };
5
6 (function($){
7     $.widget("wl.search", {
8         options: {
9           minLength: 0,
10         },
11
12         _create: function() {
13             var opts = { 
14                 minLength: this.options.minLength,
15                 select: __bind(this, this.enter),
16                 focus: function() { return false; },
17                 source: this.element.data('source'),
18             };
19             this.element.autocomplete(opts).data("autocomplete")._renderItem = __bind(this, this.render_item);
20         },
21
22         enter: function(event, ui) {
23             if (ui.item.url != undefined) {
24                 location.href = ui.item.url;
25             } else {
26                 this.element.closest('form').submit();
27             }
28         },
29    
30         render_item: function (ul, item) {
31             return $("<li></li>").data('item.autocomplete', item)
32                 .append('<a href="'+item.url+'"><span class="search-hint-label">'+item.label+'</span>'+
33                         '<span class="search-hint-category mono">'+item.category+'</span></a>')
34                 .appendTo(ul);
35         },
36
37         destroy: function() {
38
39         },
40         
41
42     });
43
44
45 })(jQuery);