Filter summary using search bar

This commit is contained in:
Samy Pessé
2014-04-06 16:46:29 -07:00
parent d2f62fd109
commit a42f287a92
4 changed files with 57 additions and 13 deletions
+11 -3
View File
@@ -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")
);
}
});
};
+16 -2
View File
@@ -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
}
});