|
281 | 281 | topOverflow = -scrollTop + offset.top - containerHeight, |
282 | 282 | bottomOverflow = scrollTop + viewPortHeight - (offset.top + height + containerHeight); |
283 | 283 |
|
284 | | - orientation = (Math.max(topOverflow, bottomOverflow) === topOverflow) |
285 | | - ? 'top' |
286 | | - : 'bottom'; |
| 284 | + orientation = (Math.max(topOverflow, bottomOverflow) === topOverflow) ? 'top' : 'bottom'; |
287 | 285 | } |
288 | 286 |
|
289 | 287 | if (orientation === 'top') { |
|
388 | 386 | that.selectHint(); |
389 | 387 | return; |
390 | 388 | } |
391 | | - // Fall through to RETURN |
| 389 | + /* falls through */ |
392 | 390 | case keys.RETURN: |
393 | 391 | if (that.selectedIndex === -1) { |
394 | 392 | that.hide(); |
|
537 | 535 | return; |
538 | 536 | } |
539 | 537 |
|
| 538 | + if ($.isFunction(that.lookup)){ |
| 539 | + that.lookup(q, function (data) { |
| 540 | + that.suggestions = data.suggestions; |
| 541 | + that.suggest(); |
| 542 | + options.onSearchComplete.call(that.element, q, data.suggestions); |
| 543 | + }); |
| 544 | + return; |
| 545 | + } |
| 546 | + |
540 | 547 | if (that.isLocal) { |
541 | 548 | response = that.getSuggestionsLocal(q); |
542 | 549 | } else { |
|
607 | 614 |
|
608 | 615 | suggest: function () { |
609 | 616 | if (this.suggestions.length === 0) { |
610 | | - this.options.showNoSuggestionNotice ? this.noSuggestions() : this.hide(); |
| 617 | + if (this.options.showNoSuggestionNotice) { |
| 618 | + this.noSuggestions(); |
| 619 | + } else { |
| 620 | + this.hide(); |
| 621 | + } |
611 | 622 | return; |
612 | 623 | } |
613 | 624 |
|
|
658 | 669 | noSuggestionsContainer.detach(); |
659 | 670 | container.html(html); |
660 | 671 |
|
661 | | - // Select first value by default: |
662 | | - if (options.autoSelectFirst) { |
663 | | - that.selectedIndex = 0; |
664 | | - container.children().first().addClass(classSelected); |
665 | | - } |
666 | | - |
667 | 672 | if ($.isFunction(beforeRender)) { |
668 | 673 | beforeRender.call(that.element, container); |
669 | 674 | } |
670 | 675 |
|
671 | 676 | that.fixPosition(); |
672 | | - |
673 | 677 | container.show(); |
674 | | - that.visible = true; |
675 | 678 |
|
| 679 | + // Select first value by default: |
| 680 | + if (options.autoSelectFirst) { |
| 681 | + that.selectedIndex = 0; |
| 682 | + container.scrollTop(0); |
| 683 | + container.children().first().addClass(classSelected); |
| 684 | + } |
| 685 | + |
| 686 | + that.visible = true; |
676 | 687 | that.findBestHint(); |
677 | 688 | }, |
678 | 689 |
|
|
851 | 862 |
|
852 | 863 | adjustScroll: function (index) { |
853 | 864 | var that = this, |
854 | | - activeItem = that.activate(index), |
855 | | - offsetTop, |
856 | | - upperBound, |
857 | | - lowerBound, |
858 | | - heightDelta = 25; |
| 865 | + activeItem = that.activate(index); |
859 | 866 |
|
860 | 867 | if (!activeItem) { |
861 | 868 | return; |
862 | 869 | } |
863 | 870 |
|
| 871 | + var offsetTop, |
| 872 | + upperBound, |
| 873 | + lowerBound, |
| 874 | + heightDelta = $(activeItem).outerHeight(); |
| 875 | + |
864 | 876 | offsetTop = activeItem.offsetTop; |
865 | 877 | upperBound = $(that.suggestionsContainer).scrollTop(); |
866 | 878 | lowerBound = upperBound + that.options.maxHeight - heightDelta; |
|
0 commit comments