Skip to content
This repository was archived by the owner on Jul 2, 2018. It is now read-only.

Added "decorateResults" option #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/jquery.autocomplete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/jquery.autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
selectFirst: false,
selectOnly: false,
showResult: null,
decorateResults: null,
preventDefaultReturn: true,
preventDefaultTab: false,
autoFill: false,
Expand Down Expand Up @@ -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);
};

/**
Expand All @@ -792,7 +792,7 @@
$.Autocompleter.prototype.showResults = function(results, filter) {
var numResults = results.length;
var self = this;
var $ul = $('<ul></ul>');
var $ul = this.dom.$list = $('<ul></ul>');
var i, result, $li, autoWidth, first = false, $first = false;

if (numResults) {
Expand All @@ -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);
Expand Down