|
3 | 3 |
|
4 | 4 | activateSearch(require('docsearch.js/dist/cdn/docsearch.js'), document.getElementById('search-script').dataset) |
5 | 5 |
|
| 6 | + var F_KEY = 70 |
| 7 | + var S_KEY = 83 |
| 8 | + |
6 | 9 | function activateSearch (docsearch, config) { |
7 | 10 | appendStylesheet(config.stylesheet) |
8 | 11 | var algoliaOptions = { |
|
16 | 19 | apiKey: config.apiKey, |
17 | 20 | indexName: config.indexName, |
18 | 21 | inputSelector: '#search-query', |
19 | | - autocompleteOptions: { autoselect: true, debug: true, hint: false, keyboardShortcuts: ['s'], minLength: 2 }, |
| 22 | + autocompleteOptions: { autoselect: true, debug: true, hint: false, keyboardShortcuts: [], minLength: 2 }, |
20 | 23 | algoliaOptions: algoliaOptions, |
21 | 24 | transformData: transformData, |
22 | 25 | }) |
|
27 | 30 | input.data('aaAutocomplete').dropdown._ensureVisible = ensureVisible |
28 | 31 | searchForm.addEventListener('click', confineEvent) |
29 | 32 | document.documentElement.addEventListener('click', resetSearch.bind(autocomplete)) |
| 33 | + document.documentElement.addEventListener('keydown', handleShortcuts.bind(input)) |
30 | 34 | if (input.attr('autofocus') != null) input.focus() |
31 | 35 | } |
32 | 36 |
|
|
60 | 64 | } |
61 | 65 | } |
62 | 66 |
|
| 67 | + function handleShortcuts (e) { |
| 68 | + if (e.altKey || e.metaKey || e.ctrlKey || e.shiftKey) return |
| 69 | + var keyCode = e.keyCode |
| 70 | + if (keyCode === F_KEY || keyCode === S_KEY) { |
| 71 | + this.focus() |
| 72 | + e.preventDefault() |
| 73 | + } |
| 74 | + } |
| 75 | + |
63 | 76 | function resetSearch () { |
64 | 77 | this.close() |
65 | 78 | this.setVal() |
|
0 commit comments