|
90 | 90 | }, |
91 | 91 | showNoSuggestionNotice: false, |
92 | 92 | noSuggestionNotice: 'No results', |
| 93 | + showMoreCharsNotice: false, |
| 94 | + moreCharsNotice: 'Keep writing...', |
93 | 95 | orientation: 'bottom', |
94 | 96 | forceFixPosition: false |
95 | 97 | }; |
|
108 | 110 | that.isLocal = false; |
109 | 111 | that.suggestionsContainer = null; |
110 | 112 | that.noSuggestionsContainer = null; |
| 113 | + that.moreCharsContainer = null; |
111 | 114 | that.options = $.extend({}, defaults, options); |
112 | 115 | that.classes = { |
113 | 116 | selected: 'autocomplete-selected', |
|
148 | 151 | selected = that.classes.selected, |
149 | 152 | options = that.options, |
150 | 153 | noSuggestionNotice = this.options.noSuggestionNotice, |
| 154 | + moreCharsNotice = this.options.moreCharsNotice, |
151 | 155 | container; |
152 | 156 |
|
153 | 157 | // Remove autocomplete attribute to prevent native suggestions: |
|
167 | 171 | that.noSuggestionsContainer = $('<div class="autocomplete-no-suggestion"></div>') |
168 | 172 | .html(noSuggestionNotice).get(0); |
169 | 173 |
|
| 174 | + if(typeof moreCharsNotice !== 'string') |
| 175 | + moreCharsNotice = $(moreCharsNotice).clone(true); |
| 176 | + that.moreCharsContainer = $('<div class="autocomplete-more-chars"></div>').html(moreCharsNotice).get(0); |
| 177 | + |
170 | 178 | that.suggestionsContainer = Autocomplete.utils.createNode(options.containerClass); |
171 | 179 |
|
172 | 180 | container = $(that.suggestionsContainer); |
|
483 | 491 | } |
484 | 492 |
|
485 | 493 | if (query.length < options.minChars) { |
486 | | - that.hide(); |
| 494 | + var showMoreCharsNotice = that.options.showMoreCharsNotice; |
| 495 | + if(typeof that.options.showMoreCharsNotice === 'function') |
| 496 | + showMoreCharsNotice = that.options.showMoreCharsNotice(query); |
| 497 | + |
| 498 | + if(showMoreCharsNotice) |
| 499 | + that.getMoreCharsNotice(); |
| 500 | + else |
| 501 | + that.hide(); |
487 | 502 | } else { |
488 | 503 | that.getSuggestions(query); |
489 | 504 | } |
|
603 | 618 | } |
604 | 619 | }, |
605 | 620 |
|
| 621 | + getMoreCharsNotice: function() { |
| 622 | + var that = this, |
| 623 | + container = $(that.suggestionsContainer), |
| 624 | + moreCharsContainer = $(that.moreCharsContainer), |
| 625 | + noSuggestionsContainer = $(that.noSuggestionsContainer); |
| 626 | + |
| 627 | + this.adjustContainerWidth(); |
| 628 | + |
| 629 | + // Some explicit steps. Be careful here as it easy to get |
| 630 | + // noSuggestionsContainer removed from DOM if not detached properly. |
| 631 | + moreCharsContainer.detach(); |
| 632 | + noSuggestionsContainer.detach(); |
| 633 | + container.empty(); // clean suggestions if any |
| 634 | + container.append(moreCharsContainer); |
| 635 | + |
| 636 | + that.fixPosition(); |
| 637 | + |
| 638 | + container.show(); |
| 639 | + that.visible = true; |
| 640 | + }, |
| 641 | + |
606 | 642 | isBadQuery: function (q) { |
607 | 643 | if (!this.options.preventBadQueries){ |
608 | 644 | return false; |
|
658 | 694 | classSelected = that.classes.selected, |
659 | 695 | container = $(that.suggestionsContainer), |
660 | 696 | noSuggestionsContainer = $(that.noSuggestionsContainer), |
| 697 | + moreCharsContainer = $(that.moreCharsContainer), |
661 | 698 | beforeRender = options.beforeRender, |
662 | 699 | html = '', |
663 | 700 | category, |
|
695 | 732 |
|
696 | 733 | // Detach noSuggestions not to have it removed when filling container with new suggestions |
697 | 734 | noSuggestionsContainer.detach(); |
| 735 | + moreCharsContainer.detach(); |
698 | 736 | container.html(html); |
699 | 737 |
|
700 | 738 | // If showNoSuggestionNotice is a function, call it to see |
|
725 | 763 | noSuggestions: function() { |
726 | 764 | var that = this, |
727 | 765 | container = $(that.suggestionsContainer), |
| 766 | + moreCharsContainer = $(that.moreCharsContainer), |
728 | 767 | noSuggestionsContainer = $(that.noSuggestionsContainer); |
729 | 768 |
|
730 | 769 | this.adjustContainerWidth(); |
731 | 770 |
|
732 | 771 | // Some explicit steps. Be careful here as it easy to get |
733 | 772 | // noSuggestionsContainer removed from DOM if not detached properly. |
734 | 773 | noSuggestionsContainer.detach(); |
| 774 | + moreCharsContainer.detach(); |
735 | 775 | container.empty(); // clean suggestions if any |
736 | 776 | container.append(noSuggestionsContainer); |
737 | 777 |
|
|
0 commit comments