summaryrefslogtreecommitdiffstats
path: root/awesomplete.js
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2016-02-05 11:32:44 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2016-02-05 11:32:44 +0300
commit332ca53fc73322fb06d8052d26fe2e59e12312e9 (patch)
treed5bc285c4cf0ba449bf930c0c6ba222771fb3922 /awesomplete.js
parente57253015a6e36c5ed887caf08fc3f5472edb80d (diff)
parent626baf50ca4854ca856e207b287d1b1509be970f (diff)
downloadawesomplete-332ca53fc73322fb06d8052d26fe2e59e12312e9.zip
awesomplete-332ca53fc73322fb06d8052d26fe2e59e12312e9.tar.gz
awesomplete-332ca53fc73322fb06d8052d26fe2e59e12312e9.tar.bz2
Merge pull request #16835 from vlazar/feature/add-item-data-to-awesomplete-select-event
Add item data to awesomplete-select event
Diffstat (limited to 'awesomplete.js')
-rw-r--r--awesomplete.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/awesomplete.js b/awesomplete.js
index d7857e7..950a5ac 100644
--- a/awesomplete.js
+++ b/awesomplete.js
@@ -189,6 +189,7 @@ _.prototype = {
if (selected) {
var allowed = $.fire(this.input, "awesomplete-select", {
text: selected.textContent,
+ data: this.suggestions[$.siblingIndex(selected)],
origin: origin || selected
});
@@ -209,15 +210,15 @@ _.prototype = {
// Populate list with options that match
this.ul.innerHTML = "";
- this._list
+ this.suggestions = this._list
.filter(function(item) {
return me.filter(item, value);
})
.sort(this.sort)
- .every(function(text, i) {
- me.ul.appendChild(me.item(text, value));
+ .slice(0, this.maxItems);
- return i < me.maxItems - 1;
+ this.suggestions.forEach(function(text) {
+ me.ul.appendChild(me.item(text, value));
});
if (this.ul.children.length === 0) {
@@ -353,7 +354,13 @@ $.fire = function(target, type, properties) {
$.regExpEscape = function (s) {
return s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
-}
+};
+
+$.siblingIndex = function (el) {
+ /* eslint-disable no-cond-assign */
+ for (var i = 0; el = el.previousElementSibling; i++);
+ return i;
+};
// Initialization