Skip to content

Commit

Permalink
Make possible to disable sorting (#17043)
Browse files Browse the repository at this point in the history
* Make possible to disable sorting

* Update sort info
  • Loading branch information
evenfrost authored and LeaVerou committed Jan 30, 2017
1 parent ba6a1fc commit 4f1c6e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit 4f1c6e9

Please sign in to comment.