Follow-up: Adds search results page to the docs
From https://gitlab.com/gitlab-com/gitlab-docs/merge_requests/191, for the two unchecked items in the description:
-
Display the results only when the user starts typing (..) => needs this code snippet => when I implement this code snippet, the=> moved to !205 (closed) (we're not doing it)x
button to reset the search stops working. It removes the query from the URL bar, but does not clear the search bar.
How I did it:
In the <head>
, add jQuery library:
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
In the body, replacing urlSync: true
, with this snippet:
urlSync: true,
searchFunction: function(helper) {
var searchResults = $('main');
if (helper.state.query === '') {
searchResults.hide();
return;
}
helper.search();
searchResults.show();
}
});
I've noticed that changing the selector $('main')
it changes what the reset button affects, so maybe the trick is to find the right selector.
I tried :
var searchResults = $('main');
var searchResults = $('#hits');
var searchResults = $('#hits','#pagination');
var searchResults = $('.ais-hits');
var searchResults = $('.ais-hits','.ais-pagination');
Neither of them worked satisfactorily.
-
Check, review, clean up the code of this MR, and fix anything if necessary => this is gonna be necessary as well. = !203 (merged)
Edited by Marcia Ramos