This commit is contained in:
Jeremy Kidwell 2019-03-14 19:04:29 +00:00
parent a93fabdf61
commit 513e98aaac
23 changed files with 196 additions and 383 deletions

View file

@ -1,6 +1,6 @@
require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
var index = null;
var $searchInput, $searchForm;
var $searchInput, $searchLabel, $searchForm;
var $highlighted, hi = 0, hiOpts = { className: 'search-highlight' };
var collapse = false;
@ -92,6 +92,7 @@ require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
// Create search form
function createForm(value) {
if ($searchForm) $searchForm.remove();
if ($searchLabel) $searchLabel.remove();
if ($searchInput) $searchInput.remove();
$searchForm = $('<div>', {
@ -99,13 +100,22 @@ require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
'role': 'search'
});
$searchLabel = $('<label>', {
'for': 'search-box',
'aria-hidden': 'false',
'hidden': ''
});
$searchInput = $('<input>', {
'id': 'search-box',
'type': 'search',
'class': 'form-control',
'val': value,
'placeholder': 'Type to search'
});
$searchLabel.append("Type to search");
$searchLabel.appendTo($searchForm);
$searchInput.appendTo($searchForm);
$searchForm.prependTo(gitbook.state.$book.find('.book-summary'));
}
@ -180,7 +190,7 @@ require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
scrollToHighlighted();
}
}).on("input", ".book-search input", function(e) {
var q = $(this).val();
var q = $(this).val().trim();
if (q.length === 0) {
gitbook.sidebar.filter(null);
gitbook.storage.remove("keyword");