Skip to content

Commit a6bb71e

Browse files
author
Alexandre Stanislawski
committed
fix(live-doc): adds navigation menu for smaller screens
1 parent 60a36ff commit a6bb71e

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

docs/_includes/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<a href="{{ site.baseurl }}{{ link.url }}" title="{{ link.title }}">{{ link.text }}</a>
1616
</li>
1717
{% endfor %}
18-
<li>
18+
<li class="github">
1919
<a
2020
href="http://github.com/algolia/instantsearch.js"
2121
title="See more, open issues and get answers in our Github repository">

docs/_layouts/documentation.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
<div class="hfull row">
77
<div class="col-lg-2 col-md-3 hidden-xs hidden-sm widget-nav hfull">
88
<div class="documentation-menu">
9-
{{ content | toc_generate }}
9+
{{ content | toc_generate}}
1010
</div>
1111
</div>
1212
<div class="col-lg-10 col-md-9 widget-description hfull">
13+
<div class="toc-menu hidden-md hidden-lg">
14+
{{ content | toc_generate_menu}}
15+
</div>
1316
<div class="code-samples hidden-xs"></div>
1417
<article class="documentation-content">
1518
<!-- <h1 class="documentation-title">{{ page.title }}</h1> -->

docs/_plugins/toc_generator.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ def toc_generate(html)
2828

2929
html.join
3030
end
31+
32+
def toc_generate_menu(html)
33+
doc = Nokogiri::HTML(html)
34+
35+
html = []
36+
html << '<select>'
37+
current_level = 1
38+
doc.css('h1, h2, h3, h4').each do |tag|
39+
level = tag.name[1].to_i
40+
html << "<option value=\"#{tag['id']}\">#{tag.text}</option>"
41+
current_level = level
42+
end
43+
44+
html << '</select>'
45+
46+
html.join
47+
end
3148
end
3249

3350
end

docs/css/_documentation.scss

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ code {
4747
}
4848
}
4949

50+
.toc-menu {
51+
position: absolute;
52+
top:0;
53+
left: 0;
54+
width:100%;
55+
background: #122440;
56+
padding: 5px 30px;
57+
z-index: 2;
58+
}
59+
5060
// Main Content
5161

5262
// Left panel
@@ -56,7 +66,7 @@ code {
5666

5767
.main-documentation {
5868
height: 100%;
59-
padding-top: 52px;
69+
padding-top: 50px;
6070
.description {
6171
min-height: 84px;
6272
}
@@ -263,6 +273,7 @@ code {
263273
color: $brand-primary;
264274
background-color: #0a1724;
265275
border: none;
276+
transition: opacity 0.2s;
266277
&:hover {
267278
color: white;
268279
}
@@ -440,7 +451,7 @@ code {
440451

441452
@media (max-width: $screen-xs-max) {
442453
.main-documentation {
443-
padding: 52px 0 0 0;
454+
padding: 57px 0 0 0;
444455
.row {
445456
margin: 0;
446457
}
@@ -453,6 +464,9 @@ code {
453464
padding: 0;
454465
}
455466
}
467+
.toc-menu {
468+
padding: 5px 9.5px;
469+
}
456470
.documentation-content{
457471
padding: 20px 0;
458472
p, h1, h2, h3, h4, .h4, div[id], ul, .highlight {

docs/css/_header.sass

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ header.site-header
77
margin-bottom: 0
88
.navbar-brand
99
font-weight: 600
10-
.fa-github
11-
font-size: 160%
10+
.github
11+
a
12+
padding: 13px 10px
13+
.fa-github
14+
font-size: 160%
1215

1316
.main-content
14-
margin-top: $navbar-height
17+
margin-top: $navbar-height

docs/js/doc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,17 @@
141141
});
142142
}
143143

144+
function tocMenu(){
145+
$('.toc-menu select').change(function(){
146+
var href = $(this).val();
147+
window.location.hash = href;
148+
});
149+
}
150+
144151
search();
145152
codeTabs();
146153
htmlTabs();
147154
anchorableTitles();
148155
copyButtons();
156+
tocMenu();
149157
})(window.jQuery);

0 commit comments

Comments
 (0)