diff options
Diffstat (limited to 'theme/javascript/core')
-rwxr-xr-x | theme/javascript/core/navigation.js | 8 | ||||
-rwxr-xr-x | theme/javascript/core/search.js | 12 |
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 |