Skip to content

Commit 823fc42

Browse files
committed
custom.js: See all results on "Enter" key
1 parent 8108976 commit 823fc42

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/js/custom.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// tmp fix for read-the-docs embeded versions injection
1+
// tmp fix for read-the-docs embedded versions injection
22
let jquery = jQuery;
33

44
$(document).ready(function() {
@@ -101,32 +101,40 @@ $(document).ready(function() {
101101
if (!link.length) {
102102
link = $('.ds-dropdown-menu').append('<a class="search-page-link" href="" style="position: absolute; bottom: 0px; z-index: 1000;">See all results</a>');
103103
}
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*/) {
108107
link.hide();
109108
}
110109
},
111110
algoliaOptions: {
112111
facetFilters: ['lang:en', 'version:' + branchName],
113112
hitsPerPage: 10,
114113
},
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+
},
115122
debug: false,
116123
});
117124

118-
$(document).on('keypress', '#search_input', function(event) {
125+
$(document).on('keydown keypress', 'form.md-search__form', function(event) {
119126
if (event.keyCode == 13) {
120127
event.preventDefault();
128+
return false
121129
}
122130
});
123-
131+
/*
124132
$(document).on('blur', '#search_input', function(event) {
125133
setTimeout(() => {
126134
$('#search_input').val('');
127135
}, 0);
128136
});
129-
137+
*/
130138
$('#search_input, label.md-search__icon').on('click', function() {
131139
var toggle = document.querySelector('[data-md-toggle=search]');
132140
toggle.checked = true;

0 commit comments

Comments
 (0)