From 6f4123cba9bbcf934f60b495fbdf66c93e1a7d7f Mon Sep 17 00:00:00 2001 From: Vyacheslav Bazhinov Date: Tue, 17 Apr 2012 18:48:59 +0700 Subject: [PATCH] Added "decorateResults" option which can be used to decorate ul itself with optional elements --- doc/jquery.autocomplete.txt | 7 +++++++ src/jquery.autocomplete.js | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/jquery.autocomplete.txt b/doc/jquery.autocomplete.txt index bdddd78..7b11bad 100644 --- a/doc/jquery.autocomplete.txt +++ b/doc/jquery.autocomplete.txt @@ -130,6 +130,13 @@ showResult (default value: null) this function will be called. The returned value will be displayed inside an LI element in the results list. Autocompleter will provide the value and the data. +decorateResults (default value: null) + A JavaScript function that can provide advanced markup for resulting list. This function will + be called for jquery "ul" element. The returned value will be displayed inside top-level div. + Autocompleter will provide jquery-wrapped "ul" element and expects function to return any item + that will contain that "ul" element. Function should not change "ul" element as there are event + handlers bound to it and some function relying on "ul" markup. + onItemSelect (default value: null) A JavaScript function that will be called when an item is selected. The autocompleter will specify a single argument, being the LI element selected. This LI element will have an diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 02fcdc2..7f85f40 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -65,6 +65,7 @@ selectFirst: false, selectOnly: false, showResult: null, + decorateResults: null, preventDefaultReturn: true, preventDefaultTab: false, autoFill: false, @@ -778,10 +779,9 @@ /** * Get all items from the results list - * @param result */ $.Autocompleter.prototype.getItems = function() { - return $('>ul>li', this.dom.$results); + return $('>li', this.dom.$list); }; /** @@ -792,7 +792,7 @@ $.Autocompleter.prototype.showResults = function(results, filter) { var numResults = results.length; var self = this; - var $ul = $(''); + var $ul = this.dom.$list = $(''); var i, result, $li, autoWidth, first = false, $first = false; if (numResults) { @@ -814,7 +814,13 @@ // input element location may have changed. this.position(); - this.dom.$results.html($ul).show(); + if (this.options.decorateResults) { + var newResults = this.options.decorateResults($ul); + } else { + var newResults = $ul; + } + + this.dom.$results.html(newResults).show(); if (this.options.autoWidth) { autoWidth = this.dom.$elem.outerWidth() - this.dom.$results.outerWidth() + this.dom.$results.width(); this.dom.$results.css(this.options.autoWidth, autoWidth);