Skip to content

Commit 720332c

Browse files
committed
Merge #722: Add search bar for rpc docs
caee34d Improve searchbar ui and add noscript tag (Nima Yazdanmehr) 39d3546 Add search bar for rpc docs (Nima Yazdanmehr) Pull request description: This PR is addressing the problem of finding docs for one specific rpc command by its name. In the website one can not simply find his/her desired command in the menu. One should open all the parent categories (`Blockchain`, `Control`, etc) and then use Ctrl+F to find the command. I have added a little javascript code to handle the string search between all commands and make this process much easier. ACKs for top commit: harding: Tested ACK caee34d Reviewed code, tested with Chromium, Firefox with NoJS, and Firefox with JS enabled. Made several searches and didn't see anything odd. Ran all repository tests. Tree-SHA512: 6958cef8ada196e1920417cc44d9012e8d58f5c11441460296fcb238880b0191dce1fcd23f87080a79acaece86bf74bad9d858df3091911c1d52c9c29592d247
2 parents ccf086e + caee34d commit 720332c

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

_includes/head.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@
4545
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/assets/images/apple-touch-icon-72x72-precomposed.png"><!-- 72x72 (precomposed) for 1st generation iPad, iPad 2 and iPad mini -->
4646
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/assets/images/apple-touch-icon-114x114-precomposed.png"><!-- 114x114 (precomposed) for iPhone 4, 4S, 5 and post-2011 iPod Touch -->
4747
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/assets/images/apple-touch-icon-144x144-precomposed.png"><!-- 144x144 (precomposed) for iPad 3rd and 4th generation -->
48+
49+
<!-- Hide Searchbar if nojs -->
50+
<noscript>
51+
<style>
52+
#searchbar { display:none; }
53+
</style>
54+
</noscript>

_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>

_sass/elements.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,12 @@ svg:not(:root) {
164164
@include rounded(4px);
165165
@include box-shadow(inset 0 1px 1px rgba(0, 0, 0, 0.05));
166166
}
167+
168+
/*
169+
Searchbar
170+
========================================================================== */
171+
172+
#searchbar {
173+
background-color: #d3d3d3;
174+
border-color: #2b2b2b;
175+
}

0 commit comments

Comments
 (0)