diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2016-03-13 12:12:25 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2016-03-13 12:12:25 +0300 |
commit | 42d8bc547ca5f6894fa6b96194ed7271a9256693 (patch) | |
tree | 5c0edb278eb73e736dfe96b9eaba3c33caed9eaf | |
parent | a8823bd996e7e2b713991a75b8fe267994b34981 (diff) | |
download | awesomplete-42d8bc547ca5f6894fa6b96194ed7271a9256693.zip awesomplete-42d8bc547ca5f6894fa6b96194ed7271a9256693.tar.gz awesomplete-42d8bc547ca5f6894fa6b96194ed7271a9256693.tar.bz2 |
Pass suggestion item to awesomplete-selectcomplete and awesomplete-highlight events
-rw-r--r-- | awesomplete.js | 14 | ||||
-rw-r--r-- | test/api/gotoSpec.js | 6 | ||||
-rw-r--r-- | test/api/selectSpec.js | 6 |
3 files changed, 20 insertions, 6 deletions
diff --git a/awesomplete.js b/awesomplete.js index 4666750..fe8e466 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -190,7 +190,9 @@ _.prototype = { this.status.textContent = lis[i].textContent; } - $.fire(this.input, "awesomplete-highlight"); + $.fire(this.input, "awesomplete-highlight", { + text: this.suggestions[this.index] + }); }, select: function (selected, origin) { @@ -201,15 +203,19 @@ _.prototype = { } if (selected) { + var suggestion = this.suggestions[this.index]; + var allowed = $.fire(this.input, "awesomplete-select", { - text: this.suggestions[this.index], + text: suggestion, origin: origin || selected }); if (allowed) { - this.replace(this.suggestions[this.index]); + this.replace(suggestion); this.close(); - $.fire(this.input, "awesomplete-selectcomplete"); + $.fire(this.input, "awesomplete-selectcomplete", { + text: suggestion + }); } } }, diff --git a/test/api/gotoSpec.js b/test/api/gotoSpec.js index fd7c242..dedf779 100644 --- a/test/api/gotoSpec.js +++ b/test/api/gotoSpec.js @@ -33,7 +33,11 @@ describe("awesomplete.goto", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-highlight"); this.subject.goto(1); - expect(handler).toHaveBeenCalled(); + expect(handler).toHaveBeenCalledWith( + jasmine.objectContaining({ + text: jasmine.objectContaining({ label: "item2", value: "item2" }) + }) + ); }); describe("with item index > -1", function () { diff --git a/test/api/selectSpec.js b/test/api/selectSpec.js index 1117341..f972142 100644 --- a/test/api/selectSpec.js +++ b/test/api/selectSpec.js @@ -73,7 +73,11 @@ describe("awesomplete.select", function () { var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete"); this.subject.select(this.selectArgument); - expect(handler).toHaveBeenCalled(); + expect(handler).toHaveBeenCalledWith( + jasmine.objectContaining({ + text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt }) + }) + ); }); }); |