diff --git a/theme/assets/app.js b/theme/assets/app.js index fc0f648ee..d83e1c4b7 100644 --- a/theme/assets/app.js +++ b/theme/assets/app.js @@ -19068,10 +19068,11 @@ define('utils/platform',[], function() { }; }); define('core/sidebar',[ + "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 @@ -19104,10 +19105,23 @@ define('core/sidebar',[ } }; + // 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 } }); /** @@ -20995,8 +21009,9 @@ define('core/search',[ "jQuery", "lodash", "lunr", - "core/state" -], function($, _, lunr, state) { + "core/state", + "core/sidebar" +], function($, _, lunr, state, sidebar) { var index = null; var $searchBar = state.$book.find(".book-search"); var $searchInput = $searchBar.find("input"); @@ -21064,7 +21079,14 @@ define('core/search',[ toggleSearch(false); return; } - console.log("search", q); + if (q.length == 0) { + sidebar.filter(null); + } else { + var results = search(q); + sidebar.filter( + _.pluck(results, "path") + ); + } }); }; diff --git a/theme/javascript/core/search.js b/theme/javascript/core/search.js index e674bb016..c00f662ee 100644 --- a/theme/javascript/core/search.js +++ b/theme/javascript/core/search.js @@ -2,8 +2,9 @@ define([ "jQuery", "lodash", "lunr", - "core/state" -], function($, _, lunr, state) { + "core/state", + "core/sidebar" +], function($, _, lunr, state, sidebar) { var index = null; var $searchBar = state.$book.find(".book-search"); var $searchInput = $searchBar.find("input"); @@ -71,7 +72,14 @@ define([ toggleSearch(false); return; } - console.log("search", q); + if (q.length == 0) { + sidebar.filter(null); + } else { + var results = search(q); + sidebar.filter( + _.pluck(results, "path") + ); + } }); }; diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js index e324e190b..ab5b19af1 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 diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html index d8cc22a56..485b2ef7b 100644 --- a/theme/templates/includes/book/summary.html +++ b/theme/templates/includes/book/summary.html @@ -13,11 +13,11 @@ Edit and Contribute
  • -
  • +
  • Introduction
  • {% for item in summary.chapters %} -
  • +
  • {% if item.path %} {{ item.level }}) {{ item.title }} @@ -28,7 +28,7 @@ {% if item.articles.length > 0 %}