Skip to content
Merged
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
14 changes: 9 additions & 5 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = function (input, o) {
autoFirst: false,
data: _.DATA,
filter: _.FILTER_CONTAINS,
sort: _.SORT_BYLENGTH,
sort: o.sort === false ? false : _.SORT_BYLENGTH,
item: _.ITEM,
replace: _.REPLACE
}, o);
Expand Down Expand Up @@ -197,7 +197,7 @@ _.prototype = {
lis[i].setAttribute("aria-selected", "true");
this.status.textContent = lis[i].textContent;

// scroll to highlighted element in case parent's height is fixed
// scroll to highlighted element in case parent's height is fixed
this.ul.scrollTop = lis[i].offsetTop - this.ul.clientHeight + lis[i].clientHeight;

$.fire(this.input, "awesomplete-highlight", {
Expand Down Expand Up @@ -246,9 +246,13 @@ _.prototype = {
})
.filter(function(item) {
return me.filter(item, value);
})
.sort(this.sort)
.slice(0, this.maxItems);
});

if (this.sort !== false) {
this.suggestions = this.suggestions.sort(this.sort);
}

this.suggestions = this.suggestions.slice(0, this.maxItems);

this.suggestions.forEach(function(text) {
me.ul.appendChild(me.item(text, value));
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ <h1>Extend</h1>
<tr>
<td><code>sort</code></td>
<td>Controls how list items are ordered.</td>
<td>Sort function (will be passed directly to <code>Array.prototype.sort()</code>) to sort the items after they have been filtered and before they are truncated and converted to HTML elements.</td>
<td>Sort function (will be passed directly to <code>Array.prototype.sort()</code>) to sort the items after they have been filtered and before they are truncated and converted to HTML elements. If value is <code>false</code>, sorting will be disabled.</td>
<td>Sorted by length first, order second.</td>
</tr>
<tr>
Expand Down