Skip to content

Commit 39d3546

Browse files
committed
Add search bar for rpc docs
1 parent ccf086e commit 39d3546

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

_includes/js/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,34 @@ $(function() {
6464
drawer.toggleClass("js-hidden");
6565
});
6666
});
67+
68+
// Search functionality
69+
var toggleDrawers = function(show){
70+
$(".toc header").each(function(){
71+
var header = $(this);
72+
var drawer = header.find(".toc-drawer");
73+
if (show) {
74+
drawer.removeClass("js-hidden");
75+
} else {
76+
drawer.addClass("js-hidden");
77+
}
78+
});
79+
};
80+
81+
$(function() {
82+
$("#searchbar").on('input', function(){
83+
var query = $(this).val();
84+
if (query.length > 1) {
85+
toggleDrawers(true);
86+
$(".leaf-article").each(function(){
87+
$(this).show();
88+
if ($(this).text().indexOf(query) == -1) {
89+
$(this).hide();
90+
}
91+
});
92+
} else {
93+
$(".leaf-article").each(function(){ $(this).show(); });
94+
toggleDrawers(false);
95+
}
96+
})
97+
});

_layouts/doc.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ <h1>{{ custom_title | xml_escape }}</h1>
3535
{% if page.btcversion != "index" %}
3636
{% assign groups = site.doc | where:"btcversion", page.btcversion | group_by:"btcgroup" | sort: "name" %}
3737
<section class="toc">
38+
<input id="searchbar" type="text" value="" placeholder="Search..."/>
3839
{% for group in groups %}
3940
{% if group.name != "index" %}
4041
<header>
@@ -45,7 +46,7 @@ <h3 class="toc-header">
4546
<div class="toc-drawer js-hide-on-start">
4647
<ul>
4748
{% for article in group.items %}
48-
<li><a href="{{article.url}}">{{article.name}}</a></li>
49+
<li class="leaf-article"><a href="{{article.url}}">{{article.name}}</a></li>
4950
{% endfor %}
5051
</ul>
5152
</div>

0 commit comments

Comments
 (0)