fixes #3242: Indent paragraphs
[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           dataType: "json",
11           host: '',
12         },
13
14         _create: function() {
15             var opts = { 
16                 minLength: this.options.minLength,
17                 select: __bind(this, this.enter),
18                 focus: function() { return false; },
19                 source: this.element.data('source'),
20             };
21
22             this.element.autocomplete($.extend(opts, this.options))
23                 .data("autocomplete")._renderItem = __bind(this, this.render_item);
24         },
25
26         enter: function(event, ui) {
27             if (ui.item.url != undefined) {
28                 location.href = this.options.host+ui.item.url;
29             } else {
30                 this.element.closest('form').submit();
31             }
32         },
33    
34         render_item: function (ul, item) {
35             return $("<li></li>").data('item.autocomplete', item)
36                 .append('<a href="'+this.options.host+item.url+'"><span class="search-hint-label">'+item.label+'</span>'+
37                         '<span class="search-hint-category mono">'+item.category+'</span></a>')
38                 .appendTo(ul);
39         }, 
40
41         destroy: function() {
42
43         },
44         
45
46     });
47
48
49 })(jQuery);