Skip to content

Commit

Permalink
Return early from close if not open
Browse files Browse the repository at this point in the history
If the popup is already in a closed state, return early from
`Awesomplete.prototype.close` so as to guarantee that when
`awesomplete-close` events get triggered, the popup *was* actually
closed.
  • Loading branch information
jimf committed Jun 22, 2016
1 parent 5ca3921 commit 2cef2c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ _.prototype = {
},

close: function () {
if (!this.opened) {
return;
}

this.ul.setAttribute("hidden", "");
this.index = -1;

Expand Down
8 changes: 8 additions & 0 deletions test/api/closeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ describe("awesomplete.close", function () {

expect(handler).toHaveBeenCalled();
});

it("returns early if already closed", function () {
var handler = $.spyOnEvent(this.subject.input, "awesomplete-close");
this.subject.close();
this.subject.close();

expect(handler.calls.count()).toBe(1);
});
});

0 comments on commit 2cef2c2

Please sign in to comment.