opds fix
[wolnelektury.git] / apps / wolnelektury_core / 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
20             this.element.autocomplete($.extend(opts, this.options))
21                 .data("autocomplete")._renderItem = __bind(this, this.render_item);
22         },
23
24         enter: function(event, ui) {
25             if (ui.item.url != undefined) {
26                 location.href = ui.item.url;
27             } else {
28                 this.element.closest('form').submit();
29             }
30         },
31    
32         render_item: function (ul, item) {
33             return $("<li></li>").data('item.autocomplete', item)
34                 .append('<a href="'+item.url+'"><span class="search-hint-label">'+item.label+'</span>'+
35                         '<span class="search-hint-category mono">'+item.category+'</span></a>')
36                 .appendTo(ul);
37         }, 
38
39         destroy: function() {
40
41         },
42         
43
44     });
45
46
47 })(jQuery);