summaryrefslogtreecommitdiffstats
path: root/theme/javascript/core
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-14 20:15:04 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-14 20:15:04 +0200
commit28257e1ce7d66e7c2ef47b7f0e200bad7f0e5803 (patch)
treed52ce166d0e29c687731e78982978732f3c90b9c /theme/javascript/core
parent24d8e15ee24f2deef2d37fe731a1bae67faac65a (diff)
downloadgitbook-28257e1ce7d66e7c2ef47b7f0e200bad7f0e5803.zip
gitbook-28257e1ce7d66e7c2ef47b7f0e200bad7f0e5803.tar.gz
gitbook-28257e1ce7d66e7c2ef47b7f0e200bad7f0e5803.tar.bz2
Fix search with pusState navigation
Diffstat (limited to 'theme/javascript/core')
-rwxr-xr-xtheme/javascript/core/navigation.js8
-rwxr-xr-xtheme/javascript/core/search.js12
2 files changed, 14 insertions, 6 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js
index cfc55d1..3136fb5 100755
--- a/theme/javascript/core/navigation.js
+++ b/theme/javascript/core/navigation.js
@@ -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) {
diff --git a/theme/javascript/core/search.js b/theme/javascript/core/search.js
index d8ddc2e..38d99a3 100755
--- a/theme/javascript/core/search.js
+++ b/theme/javascript/core/search.js
@@ -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
};
}); \ No newline at end of file