diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-06 16:46:29 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-06 16:46:29 -0700 |
commit | a42f287a9299d5e2e67198ae9c4488390da585e9 (patch) | |
tree | 7388a85ef40b5d986443e45ea46001b357e26279 /theme/javascript/core/sidebar.js | |
parent | d2f62fd109e6a30592f1a9767dfc2a0e7293f0cc (diff) | |
download | gitbook-a42f287a9299d5e2e67198ae9c4488390da585e9.zip gitbook-a42f287a9299d5e2e67198ae9c4488390da585e9.tar.gz gitbook-a42f287a9299d5e2e67198ae9c4488390da585e9.tar.bz2 |
Filter summary using search bar
Diffstat (limited to 'theme/javascript/core/sidebar.js')
-rw-r--r-- | theme/javascript/core/sidebar.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js index e324e19..ab5b19a 100644 --- a/theme/javascript/core/sidebar.js +++ b/theme/javascript/core/sidebar.js @@ -1,8 +1,9 @@ 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 @@ -35,9 +36,22 @@ define([ } }; + // Filter summary with a list of path + var filterSummary = function(paths) { + console.log("filter with", 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 |