parent
39760f75be
commit
b9f7913417
2 changed files with 19 additions and 4 deletions
13
README.md
13
README.md
|
|
@ -175,6 +175,19 @@ search.autocomplete.on('autocomplete:opened', function(e) {
|
|||
});
|
||||
```
|
||||
|
||||
We already bind the autocomplete:selected event inside the docsearch.
|
||||
If you want to replace the default behavior you can pass the handleSelected option
|
||||
|
||||
```javascript
|
||||
var search = docsearch({
|
||||
apiKey: '<API_KEY>',
|
||||
indexName: '<INDEX_NAME>',
|
||||
inputSelector: '<YOUR_INPUT_DOM_SELECTOR>',
|
||||
handleSelected: function (input, event, suggestion) {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Algolia options
|
||||
|
||||
You can also pass any specific option to the Algolia API to change the way
|
||||
|
|
|
|||
|
|
@ -42,10 +42,11 @@ class DocSearch {
|
|||
autoselect: true
|
||||
},
|
||||
transformData = false,
|
||||
handleSelected = false,
|
||||
enhancedSearchInput = false,
|
||||
layout = 'collumns'
|
||||
}) {
|
||||
DocSearch.checkArguments({apiKey, indexName, inputSelector, debug, algoliaOptions, autocompleteOptions, transformData, enhancedSearchInput, layout});
|
||||
DocSearch.checkArguments({apiKey, indexName, inputSelector, debug, algoliaOptions, autocompleteOptions, transformData, handleSelected, enhancedSearchInput, layout});
|
||||
|
||||
this.apiKey = apiKey;
|
||||
this.appId = appId;
|
||||
|
|
@ -59,6 +60,8 @@ class DocSearch {
|
|||
prefix: 'ds'
|
||||
};
|
||||
|
||||
handleSelected = handleSelected || this.handleSelected;
|
||||
|
||||
this.isSimpleLayout = (layout === 'simple');
|
||||
|
||||
this.client = algoliasearch(this.appId, this.apiKey);
|
||||
|
|
@ -73,13 +76,12 @@ class DocSearch {
|
|||
source: this.getAutocompleteSource(transformData),
|
||||
templates: {
|
||||
suggestion: DocSearch.getSuggestionTemplate(this.isSimpleLayout),
|
||||
footer: templates.footer,
|
||||
empty: DocSearch.getEmptyTemplate()
|
||||
footer: templates.footer
|
||||
}
|
||||
}]);
|
||||
this.autocomplete.on(
|
||||
'autocomplete:selected',
|
||||
this.handleSelected.bind(null, this.autocomplete.autocomplete)
|
||||
handleSelected.bind(null, this.autocomplete.autocomplete)
|
||||
)
|
||||
this.autocomplete.on(
|
||||
'autocomplete:shown',
|
||||
|
|
|
|||
Loading…
Reference in a new issue