Skip to content

Commit 99a17c5

Browse files
committed
accordion doc navigation & search
1 parent 1901d03 commit 99a17c5

13 files changed

+158
-28
lines changed

_includes/docs_contents.html

-8
This file was deleted.

_includes/docs_nav.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
2+
{% for section in site.data.docs %}
3+
<div class="panel panel-default">
4+
<div class="panel-heading">
5+
<h4 class="panel-title">
6+
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-{{forloop.index}}" aria-expanded="false" aria-controls="collapse-{{forloop.index}}">
7+
{{ section.title }}
8+
</a>
9+
</h4>
10+
</div>
11+
<div id="collapse-{{forloop.index}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
12+
<ul class="list-group">
13+
{% for item in section.docs %}
14+
{% assign item_url = item | prepend:"/docs/" | append:"/" %}
15+
{% assign p = site.docs | where:"url", item_url | first %}
16+
<a class="list-group-item {% if item_url == page.url %}active{% endif %}" href="{{ p.url }}">{{ p.title }}</a>
17+
{% endfor %}
18+
</ul>
19+
</div>
20+
</div>
21+
{% endfor %}
22+
</div>

_includes/docs_ul.html

-7
This file was deleted.

_includes/footer.html

-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@
1010
<!-- <p class="text-muted">Place sticky footer content here.</p> -->
1111
</div>
1212
</footer>
13-
14-
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
15-
<script src="{{ " /js/bootstrap.min.js " | prepend: site.baseurl }} "></script>

_includes/js_files.html

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
2+
<script src="{{ " /js/bootstrap.min.js " | prepend: site.baseurl }} "></script>
3+
<script src="{{ " /js/typeahead.bundle.min.js " | prepend: site.baseurl }} "></script>
4+
5+
<script src="{{ " /js/main.js " | prepend: site.baseurl }} "></script>

_includes/topnav.html

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
<li {% if page.sectionid=='blog' %} class="active" {% endif %}><a href="{{ site.posts.first.url | prepend: site.baseurl }}">Blog</a></li>
1818
<li><a href="{{ site.github_address }}"><i class="fa fa-github" aria-hidden="true"></i> GitHub</a></li>
1919
</ul>
20+
<form class="navbar-form navbar-right">
21+
<input id="search-box" type="text" class="form-control" placeholder="Search...">
22+
23+
<!-- <div id="search-box-container">
24+
25+
</div> -->
26+
</form>
2027
</div>
2128
</div>
2229
</nav>

_layouts/default.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515

1616
{% include footer.html %}
17-
17+
{% include js_files.html %}
1818
</body>
1919

2020
</html>

_layouts/docs.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@
77
<div class="container">
88
<div class="row">
99
<div class="col-md-4">
10-
11-
<div class="panel panel-default">
12-
<div class="panel-body">
13-
{% include docs_contents.html %}
14-
</div>
15-
</div>
10+
{% include docs_nav.html %}
1611
</div>
1712

18-
<div class="col-lg-8">
13+
<div class="col-md-8">
1914
<h1>{{ page.title }}</h1>
2015
<div>{{ content }}</div>
2116
<hr>
2217
{% include section_nav.html %}
2318
</div>
2419

25-
2620
</div>
2721
</div>

_sass/_typeahead.scss

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//http://stackoverflow.com/questions/21749179/typeahead-js-v0-10-1-and-bootstrap-3/33177315#33177315
2+
@mixin typeahead-active() {
3+
// mimics @extend .dropdown-menu > .active > a;
4+
color: $dropdown-link-active-color;
5+
text-decoration: none;
6+
outline: 0;
7+
background-color: $dropdown-link-active-bg;
8+
}
9+
10+
//https://github.com/corejavascript/typeahead.js/blob/master/doc/jquery_typeahead.md#class-names
11+
span.twitter-typeahead {
12+
// this is the suggested matches dropdown
13+
.tt-menu {
14+
@extend .dropdown-menu;
15+
}
16+
17+
.tt-hint {
18+
color: #999;
19+
}
20+
// Added to suggestion elements.
21+
.tt-suggestion {
22+
// mimic .dropdown-menu > li > a
23+
padding: 3px 20px;
24+
line-height: $line-height-base;
25+
// Added to suggestion element when menu cursor moves to said suggestion.
26+
&.tt-cursor {
27+
@include typeahead-active;
28+
}
29+
// Hover/focus on suggestion
30+
&:focus,
31+
&:hover {
32+
@include typeahead-active;
33+
}
34+
35+
p {
36+
margin: 0;
37+
}
38+
}
39+
40+
.input-group & {
41+
display: block !important;
42+
43+
.tt-dropdown-menu {
44+
top: 32px !important;
45+
}
46+
}
47+
48+
.input-group.input-group-lg & {
49+
.tt-dropdown-menu {
50+
top: 44px !important;
51+
}
52+
}
53+
54+
.input-group.input-group-sm & {
55+
.tt-dropdown-menu {
56+
top: 28px !important;
57+
}
58+
}
59+
}

css/main.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"variables",
99
"bootstrap",
1010
"bootswatch",
11-
"syntax-highlighting"
11+
"syntax-highlighting",
12+
"typeahead"
1213
;
1314

1415
html {

js/main.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$(function() {
2+
3+
// $('.collapse').collapse('hide');
4+
$('.list-group-item.active').parent().parent('.collapse').collapse('show');
5+
6+
7+
var pages = new Bloodhound({
8+
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
9+
// datumTokenizer: Bloodhound.tokenizers.whitespace,
10+
queryTokenizer: Bloodhound.tokenizers.whitespace,
11+
12+
// local: ['dog', 'pig', 'moose'],
13+
14+
prefetch: '/search.json'
15+
});
16+
17+
$('#search-box').typeahead({
18+
minLength: 0,
19+
highlight: true
20+
}, {
21+
name: 'pages',
22+
display: 'title',
23+
source: pages
24+
});
25+
26+
$('#search-box').bind('typeahead:select', function(ev, suggestion) {
27+
window.location.href = suggestion.url;
28+
});
29+
30+
});

js/typeahead.bundle.min.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

search.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
---
3+
[
4+
{% for section in site.data.docs %}
5+
{% for item in section.docs %}
6+
{% assign item_url = item | prepend:"/docs/" | append:"/" %}
7+
{% assign p = site.docs | where:"url", item_url | first %}
8+
{
9+
"title": "{{ p.title }}",
10+
"url": "{{ p.url }}"
11+
12+
},
13+
{% endfor %}
14+
{% endfor %}
15+
16+
{% for post in site.posts %}
17+
{
18+
"title": "{{ post.title | escape }}",
19+
"url": "{{ post.url | prepend: site.baseurl }}"
20+
}{% unless forloop.last %},{% endunless %}
21+
{% endfor %}
22+
]

0 commit comments

Comments
 (0)