|
1 | | -// tmp fix for read-the-docs embeded versions injection |
| 1 | +// tmp fix for read-the-docs embedded versions injection |
2 | 2 | let jquery = jQuery; |
3 | 3 |
|
4 | 4 | $(document).ready(function() { |
@@ -101,32 +101,40 @@ $(document).ready(function() { |
101 | 101 | if (!link.length) { |
102 | 102 | link = $('.ds-dropdown-menu').append('<a class="search-page-link" href="" style="position: absolute; bottom: 0px; z-index: 1000;">See all results</a>'); |
103 | 103 | } |
104 | | - if (hits.length >= 10/*hitsPerPage*/) { |
105 | | - let href = '/en/' + branchName + '/search_results/#q=' + encodeURI($(/*this.inputSelector*/'#search_input').val()) + '&p=1'; |
106 | | - link.attr('href', href).show(); |
107 | | - } else { |
| 104 | + let href = '/en/' + branchName + '/search_results/#q=' + encodeURI($(/*this.inputSelector*/'#search_input').val()) + '&p=1'; |
| 105 | + link.attr('href', href).show(); |
| 106 | + if (hits.length < 10/*hitsPerPage*/) { |
108 | 107 | link.hide(); |
109 | 108 | } |
110 | 109 | }, |
111 | 110 | algoliaOptions: { |
112 | 111 | facetFilters: ['lang:en', 'version:' + branchName], |
113 | 112 | hitsPerPage: 10, |
114 | 113 | }, |
| 114 | + handleSelected: function (input, event, suggestion, datasetNumber, context) { |
| 115 | + console.log(suggestion, context); |
| 116 | + if ('click' == context.selectionMethod) { |
| 117 | + window.location = suggestion.url; |
| 118 | + } else if ('enterKey' == context.selectionMethod) { |
| 119 | + window.location = $('.ds-dropdown-menu a.search-page-link').attr('href'); |
| 120 | + } |
| 121 | + }, |
115 | 122 | debug: false, |
116 | 123 | }); |
117 | 124 |
|
118 | | - $(document).on('keypress', '#search_input', function(event) { |
| 125 | + $(document).on('keydown keypress', 'form.md-search__form', function(event) { |
119 | 126 | if (event.keyCode == 13) { |
120 | 127 | event.preventDefault(); |
| 128 | + return false |
121 | 129 | } |
122 | 130 | }); |
123 | | - |
| 131 | +/* |
124 | 132 | $(document).on('blur', '#search_input', function(event) { |
125 | 133 | setTimeout(() => { |
126 | 134 | $('#search_input').val(''); |
127 | 135 | }, 0); |
128 | 136 | }); |
129 | | - |
| 137 | +*/ |
130 | 138 | $('#search_input, label.md-search__icon').on('click', function() { |
131 | 139 | var toggle = document.querySelector('[data-md-toggle=search]'); |
132 | 140 | toggle.checked = true; |
|
0 commit comments