2 var __bind = function (self, fn) {
3 return function() { return fn.apply(self, arguments); };
7 $.widget("wl.search", {
16 minLength: this.options.minLength,
17 select: __bind(this, this.enter),
18 focus: function() { return false; },
19 source: this.element.data('source')
22 this.element.autocomplete($.extend(opts, this.options));
23 if (this.element.autocomplete('instance') !== undefined) this.element.autocomplete('instance')._renderItem = __bind(this, this.render_item_2022);
24 if (this.element.data('autocomplete') !== undefined) this.element.data('autocomplete')._renderItem = __bind(this, this.render_item);;
27 enter: function(event, ui) {
28 if (ui.item.url !== undefined) {
29 location.href = this.options.host+ui.item.url;
31 this.element.closest('form').submit();
35 render_item: function (ul, item) {
38 label = '<cite>' + item.label + '</cite>, ' + item['author'];
42 return $("<li></li>").data('item.autocomplete', item)
43 .append('<a href="'+this.options.host+item.url+'"><span class="search-hint-label">'+label+'</span>')
47 render_item_2022: function (ul, item) {
49 var $label = $("<li><a><div></div><span></span></a></li>");
51 $('div', $label).append($('<img>').attr('src', item.img));
54 label = '<cite>' + item.label + '</cite>, ' + item['author'];
58 $('span', $label).html(label);
59 $label.addClass('type-' + item.type);