mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Filter summary using search bar
This commit is contained in:
@@ -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")
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user