better fallback on handle selected
This commit is contained in:
parent
b3a140645a
commit
3caa399046
1 changed files with 12 additions and 1 deletions
|
|
@ -101,9 +101,15 @@ class DocSearch {
|
|||
},
|
||||
]);
|
||||
if (handleSelected) {
|
||||
let handleSelectedFn = null;
|
||||
if (typeof handleSelected === 'function') {
|
||||
handleSelectedFn = handleSelected;
|
||||
} else {
|
||||
handleSelectedFn = this.handleSelected;
|
||||
}
|
||||
this.autocomplete.on(
|
||||
'autocomplete:selected',
|
||||
handleSelected.bind(null, this.autocomplete.autocomplete)
|
||||
handleSelectedFn.bind(null, this.autocomplete.autocomplete)
|
||||
);
|
||||
}
|
||||
this.autocomplete.on(
|
||||
|
|
@ -328,6 +334,11 @@ class DocSearch {
|
|||
return suggestion => template.render(suggestion);
|
||||
}
|
||||
|
||||
handleSelected(input, event, suggestion) {
|
||||
input.setVal('');
|
||||
window.location.assign(suggestion.url);
|
||||
}
|
||||
|
||||
handleShown(input) {
|
||||
const middleOfInput = input.offset().left + input.width() / 2;
|
||||
let middleOfWindow = $(document).width() / 2;
|
||||
|
|
|
|||
Loading…
Reference in a new issue