summaryrefslogtreecommitdiffstats
path: root/theme/javascript/core/sidebar.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-06 15:53:53 -0700
committerSamy Pessé <samypesse@gmail.com>2014-04-06 15:53:53 -0700
commited41429d58733664d4d8870cda42d86a91f87081 (patch)
treeda4963b02ae4fabfc7a23eb68006ec02ccc8db91 /theme/javascript/core/sidebar.js
parent74edc4f279c8748f072efe3b090a2414b351d697 (diff)
downloadgitbook-ed41429d58733664d4d8870cda42d86a91f87081.zip
gitbook-ed41429d58733664d4d8870cda42d86a91f87081.tar.gz
gitbook-ed41429d58733664d4d8870cda42d86a91f87081.tar.bz2
Add base search bar in sidebar
Diffstat (limited to 'theme/javascript/core/sidebar.js')
-rw-r--r--theme/javascript/core/sidebar.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js
index c36f4fe..89d0d24 100644
--- a/theme/javascript/core/sidebar.js
+++ b/theme/javascript/core/sidebar.js
@@ -1,12 +1,13 @@
define([
"utils/storage",
"utils/platform",
- "core/state"
-], function(storage, platform, state) {
+ "core/state",
+ "core/search"
+], function(storage, platform, state, search) {
// Toggle sidebar with or withour animation
var toggleSidebar = function(_state, animation) {
- if (-state != null && isOpen() == _state) return;
+ if (state != null && isOpen() == _state) return;
if (animation == null) animation = true;
var $book = state().$book;
@@ -16,11 +17,24 @@ define([
storage.set("sidebar", isOpen());
};
+ // Toggle search
+ var toggleSearch = function(_state) {
+ if (state != null && isSearchOpen() == _state) return;
+
+ var $summary = state().$book.find(".book-summary");
+ $summary.toggleClass("with-search", _state);
+ };
+
// Return true if sidebar is open
var isOpen = function() {
return state().$book.hasClass("with-summary");
};
+ // Return true if search bar is open
+ var isSearchOpen = function() {
+ return state().$book.find(".book-summary").hasClass("with-search");
+ };
+
// Prepare sidebar: state and toggle button
var init = function() {
var $book = state().$book;
@@ -31,6 +45,12 @@ define([
toggleSidebar();
});
+ // Toggle search
+ $book.find(".book-header .toggle-search").click(function(e) {
+ e.preventDefault();
+ toggleSearch();
+ });
+
// Init last state if not mobile
if (!platform.isMobile) {
toggleSidebar(storage.get("sidebar", true), false);