mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 03:16:40 +00:00
Fix search with pusState navigation
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"core/state",
|
||||
"core/search",
|
||||
"core/progress",
|
||||
"core/exercise",
|
||||
"core/quiz"
|
||||
], function($, state, progress, exercises, quiz) {
|
||||
], function($, state, search, progress, exercises, quiz) {
|
||||
var prev, next;
|
||||
var githubCountStars, githubCountWatch;
|
||||
|
||||
@@ -64,7 +65,7 @@ define([
|
||||
|
||||
var preparePage = function() {
|
||||
var $pageWrapper = $(".book-body .page-wrapper");
|
||||
|
||||
|
||||
// Bind exercises/quiz
|
||||
exercises.init();
|
||||
quiz.init();
|
||||
@@ -81,6 +82,9 @@ define([
|
||||
// Focus on content
|
||||
$pageWrapper.focus();
|
||||
|
||||
// Prepare search bar
|
||||
search.prepare();
|
||||
|
||||
// Update GitHub count
|
||||
if (state.githubId) {
|
||||
if (githubCountStars) {
|
||||
|
||||
@@ -7,8 +7,6 @@ define([
|
||||
"core/sidebar"
|
||||
], function($, _, lunr, storage, state, sidebar) {
|
||||
var index = null;
|
||||
var $searchBar = state.$book.find(".book-search");
|
||||
var $searchInput = $searchBar.find("input");
|
||||
|
||||
// Use a specific idnex
|
||||
var useIndex = function(data) {
|
||||
@@ -41,6 +39,7 @@ define([
|
||||
var toggleSearch = function(_state) {
|
||||
if (state != null && isSearchOpen() == _state) return;
|
||||
|
||||
var $searchInput = $(".book-search input");
|
||||
state.$book.toggleClass("with-search", _state);
|
||||
|
||||
// If search bar is open: focus input
|
||||
@@ -68,6 +67,10 @@ define([
|
||||
e.preventDefault();
|
||||
toggleSearch();
|
||||
});
|
||||
};
|
||||
|
||||
var prepare = function() {
|
||||
var $searchInput = $(".book-search input");
|
||||
|
||||
$searchInput.keyup(function(e) {
|
||||
var key = (e.keyCode ? e.keyCode : e.which);
|
||||
@@ -87,11 +90,12 @@ define([
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
search: search,
|
||||
toggle: toggleSearch
|
||||
toggle: toggleSearch,
|
||||
prepare: prepare
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user