summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--theme/assets/app.js32
-rw-r--r--theme/javascript/core/search.js14
-rw-r--r--theme/javascript/core/sidebar.js18
-rw-r--r--theme/templates/includes/book/summary.html6
4 files changed, 57 insertions, 13 deletions
diff --git a/theme/assets/app.js b/theme/assets/app.js
index fc0f648..d83e1c4 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 e674bb0..c00f662 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 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
diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html
index d8cc22a..485b2ef 100644
--- a/theme/templates/includes/book/summary.html
+++ b/theme/templates/includes/book/summary.html
@@ -13,11 +13,11 @@
<a href="{{ githubHost }}{{ githubId }}/edit/master/{{ _input }}" target="blank">Edit and Contribute</a>
</li>
<li class="divider"></li>
- <li data-level="0">
+ <li data-level="0" data-path="index.html">
<a href="{{ basePath }}/"><i class="fa fa-check"></i> Introduction</a>
</li>
{% for item in summary.chapters %}
- <li {% if item._path == _input %}class="active"{% endif %} data-level="{{ item.level }}">
+ <li {% if item._path == _input %}class="active"{% endif %} data-level="{{ item.level }}" {% if item.path %}data-path="{{ item.path|mdLink }}"{% endif %}>
{% if item.path %}
<a href="{{ basePath }}/{{ item.path|mdLink }}">
<i class="fa fa-check"></i> <b>{{ item.level }})</b> {{ item.title }}
@@ -28,7 +28,7 @@
{% if item.articles.length > 0 %}
<ul class="articles">
{% for article in item.articles %}
- <li {% if article._path == _input %}class="active"{% endif %} data-level="{{ article.level }}">
+ <li {% if article._path == _input %}class="active"{% endif %} data-level="{{ article.level }}" {% if article.path %}data-path="{{ article.path|mdLink }}"{% endif %}>
{% if article.path %}
<a href="{{ basePath }}/{{ article.path|mdLink }}">
<i class="fa fa-check"></i> <b>{{ article.level }})</b> {{ article.title }}