diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-06 17:13:32 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-06 17:13:32 -0700 |
commit | 4c36c592c1cccfbbb7843d74846a5f908bfcab4e (patch) | |
tree | e311663f4303f221b14559217fb5ec02fdb2dc04 /theme/javascript/core/sidebar.js | |
parent | c166a9863ec6c098d5dc2ac11f383214ea9bb246 (diff) | |
parent | 9ffb1a062f6bfa4c3253eb40c89ba54e6e429fe4 (diff) | |
download | gitbook-4c36c592c1cccfbbb7843d74846a5f908bfcab4e.zip gitbook-4c36c592c1cccfbbb7843d74846a5f908bfcab4e.tar.gz gitbook-4c36c592c1cccfbbb7843d74846a5f908bfcab4e.tar.bz2 |
Merge pull request #40 from GitbookIO/feature/searchclient
Feature/searchclient
Diffstat (limited to 'theme/javascript/core/sidebar.js')
-rw-r--r-- | theme/javascript/core/sidebar.js | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js index c36f4fe..d318676 100644 --- a/theme/javascript/core/sidebar.js +++ b/theme/javascript/core/sidebar.js @@ -1,32 +1,31 @@ define([ + "lodash", "utils/storage", "utils/platform", "core/state" -], function(storage, platform, state) { +], function(_, storage, platform, state) { + var $summary = state.$book.find(".book-summary"); // 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; - $book.toggleClass("without-animation", !animation); - $book.toggleClass("with-summary", _state); + state.$book.toggleClass("without-animation", !animation); + state.$book.toggleClass("with-summary", _state); storage.set("sidebar", isOpen()); }; // Return true if sidebar is open var isOpen = function() { - return state().$book.hasClass("with-summary"); + return state.$book.hasClass("with-summary"); }; // Prepare sidebar: state and toggle button var init = function() { - var $book = state().$book; - // Toggle summary - $book.find(".book-header .toggle-summary").click(function(e) { + state.$book.find(".book-header .toggle-summary").click(function(e) { e.preventDefault(); toggleSidebar(); }); @@ -37,8 +36,21 @@ define([ } }; + // Filter summary with a list of path + var filterSummary = function(paths) { + $summary.find("li").each(function() { + var path = $(this).data("path"); + var st = paths == null || _.contains(paths, path); + + $(this).toggle(st); + if (st) $(this).parents("li").show(); + }); + }; + return { + $el: $summary, init: init, - toggle: toggleSidebar + toggle: toggleSidebar, + filter: filterSummary } });
\ No newline at end of file |