Skip to content

Commit

Permalink
onListOpen/onListClose events added
Browse files Browse the repository at this point in the history
  • Loading branch information
fitiskin committed Apr 6, 2022
1 parent 6dd1b82 commit f9cf670
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Autocompleter has the following options:
| onBeforeShow | function | This function is triggered when the list is ready to be shown | \$.noop |
| onEmpty | function | If data list if empty, trigger this function | \$.noop |
| onItem | function | This function is triggered when each item is being prepared to be shown | \$.noop |
| onListOpen | function | This function is triggered when the list is shown | \$.noop |
| onListClose | function | This function is triggered when the list is hidden | \$.noop |
| template | str | Custom template for list items. For example: `<span>{{ label }} is {{ customPropertyFromSource }}</span>`. Template appends to `.autocompleter-item`. | false |
| offset | str | Source response offset, for example: `"response.items.posts"`. <br />**@deprecated** use `format` instead | false |
| format | function | Format response payload to return source data | null |
Expand Down
10 changes: 10 additions & 0 deletions src/jquery.autocompleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var guid = 0,
"onBeforeShow",
"onEmpty",
"onItem",
"onListOpen",
"onListClose",
"template",
"offset",
"format",
Expand Down Expand Up @@ -78,6 +80,8 @@ var guid = 0,
* @param onBeforeShow [function] <$.noop> "This function is triggered when the list is ready to be shown"
* @param onEmpty [function] <$.noop> "If data list if empty, trigger this function"
* @param onItem [function] <$.noop> "This function is triggered when each item is being prepared to be shown"
* @param onListOpen [function] <$.noop> "This function is triggered when the list is shown"
* @param onListClose [function] <$.noop> "This function is triggered when the list is hidden"
* @param template [(string|boolean)] <false> "Custom template for list items"
* @param offset [(string|boolean)] <false> "Source response offset, for example: response.items.posts"
* @param format [function] null "Format response payload to source data"
Expand Down Expand Up @@ -106,6 +110,8 @@ var options = {
onBeforeShow: $.noop,
onEmpty: $.noop,
onItem: $.noop,
onListOpen: $.noop,
onListClose: $.noop,
template: false,
offset: false,
format: null,
Expand Down Expand Up @@ -861,6 +867,8 @@ function _onMousedown(e) {
function _open(e, instanceData) {
var data = e ? e.data : instanceData;

data.onListOpen(data.$autocompleter, data.response);

if (
!data.$node.prop("disabled") &&
!data.$autocompleter.hasClass("autocompleter-show") &&
Expand Down Expand Up @@ -905,6 +913,8 @@ function _closeHelper(e) {
function _close(e, instanceData) {
var data = e ? e.data : instanceData;

data.onListClose();

if (data.$autocompleter.hasClass("autocompleter-show")) {
data.$autocompleter
.removeClass("autocompleter-show")
Expand Down

0 comments on commit f9cf670

Please sign in to comment.