From 4918bd4dcddc41bb8daa5005ff69b56b7960bbde Mon Sep 17 00:00:00 2001 From: evenfrost Date: Mon, 30 Jan 2017 19:55:07 +0300 Subject: [PATCH 1/2] Make possible to disable sorting --- awesomplete.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/awesomplete.js b/awesomplete.js index f8866f73..fc9d803c 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -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); @@ -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", { @@ -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)); From 7d408bccfeaeb5b9af52b79ec7e3ab8f127541f1 Mon Sep 17 00:00:00 2001 From: Aleksey Kislov Date: Mon, 30 Jan 2017 20:02:42 +0300 Subject: [PATCH 2/2] Update sort info --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index ec963e1b..85320fd9 100644 --- a/index.html +++ b/index.html @@ -238,7 +238,7 @@

Extend

sort Controls how list items are ordered. - Sort function (will be passed directly to Array.prototype.sort()) to sort the items after they have been filtered and before they are truncated and converted to HTML elements. + Sort function (will be passed directly to Array.prototype.sort()) to sort the items after they have been filtered and before they are truncated and converted to HTML elements. If value is false, sorting will be disabled. Sorted by length first, order second.