X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ae60b2a3949e96357477cc04f90fd0873cee8a92..3fceb197b7f492cf5cfcb4034b6e045638f128d4:/src/wolnelektury/static/js/search.js?ds=sidebyside diff --git a/src/wolnelektury/static/js/search.js b/src/wolnelektury/static/js/search.js index 4d001e0c0..34c63f3c9 100644 --- a/src/wolnelektury/static/js/search.js +++ b/src/wolnelektury/static/js/search.js @@ -5,45 +5,46 @@ var __bind = function (self, fn) { (function($){ $.widget("wl.search", { - options: { - minLength: 0, - dataType: "json", - host: '', + options: { + minLength: 0, + dataType: "json", + host: '' + }, + + _create: function() { + var opts = { + minLength: this.options.minLength, + select: __bind(this, this.enter), + focus: function() { return false; }, + source: this.element.data('source') + }; + + this.element.autocomplete($.extend(opts, this.options)) + .data("autocomplete")._renderItem = __bind(this, this.render_item); }, - _create: function() { - var opts = { - minLength: this.options.minLength, - select: __bind(this, this.enter), - focus: function() { return false; }, - source: this.element.data('source'), - }; - - this.element.autocomplete($.extend(opts, this.options)) - .data("autocomplete")._renderItem = __bind(this, this.render_item); - }, - - enter: function(event, ui) { - if (ui.item.url != undefined) { - location.href = this.options.host+ui.item.url; - } else { - this.element.closest('form').submit(); - } - }, - - render_item: function (ul, item) { - return $("
").data('item.autocomplete', item) - .append(''+item.label+''+ - ''+item.category+'') - .appendTo(ul); - }, - - destroy: function() { - - }, - + enter: function(event, ui) { + if (ui.item.url !== undefined) { + location.href = this.options.host+ui.item.url; + } else { + this.element.closest('form').submit(); + } + }, - }); + render_item: function (ul, item) { + var label; + if (item['author']) { + label = '' + item.label + ', ' + item['author']; + } else { + label = item.label; + } + return $("").data('item.autocomplete', item) + .append(''+label+'') + .appendTo(ul); + }, + destroy: function() { + } + }); })(jQuery);