1
0
Fork 0

better fallback on handle selected

This commit is contained in:
s-pace 2018-11-02 10:25:55 +01:00
parent b3a140645a
commit 3caa399046

View file

@ -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;