Skip to content

Commit 549a9ff

Browse files
Merge pull request #470 from stgn/sidebar-page-ux
Improve experience on smaller screens
2 parents 06c9d67 + 31fb443 commit 549a9ff

File tree

9 files changed

+102
-184
lines changed

9 files changed

+102
-184
lines changed

src/theme/book.css

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
html,
2-
body {
1+
html {
32
font-family: "Open Sans", sans-serif;
43
color: #333;
4+
overflow-x: hidden;
55
}
66
body {
77
margin: 0;
88
font-size: 1rem;
9+
overflow-x: hidden;
910
}
1011
code {
1112
font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace;
@@ -66,20 +67,12 @@ table thead td {
6667
-ms-transition: left 0.5s;
6768
transition: left 0.5s;
6869
}
69-
@media only screen and (max-width: 1060px) {
70-
.sidebar {
71-
left: -300px;
72-
}
73-
}
7470
.sidebar code {
7571
line-height: 2em;
7672
}
7773
.sidebar-hidden .sidebar {
7874
left: -300px;
7975
}
80-
.sidebar-visible .sidebar {
81-
left: 0;
82-
}
8376
.chapter {
8477
list-style: none outside none;
8578
padding-left: 0;
@@ -109,28 +102,25 @@ table thead td {
109102
white-space: nowrap;
110103
}
111104
.page-wrapper {
112-
padding-left: 300px;
113105
-webkit-box-sizing: border-box;
114106
-moz-box-sizing: border-box;
115107
box-sizing: border-box;
116108
min-height: 100%;
117-
-webkit-transition: padding-left 0.5s, margin-right 0.5s;
118-
-moz-transition: padding-left 0.5s, margin-right 0.5s;
119-
-o-transition: padding-left 0.5s, margin-right 0.5s;
120-
-ms-transition: padding-left 0.5s, margin-right 0.5s;
121-
transition: padding-left 0.5s, margin-right 0.5s;
122-
}
123-
@media only screen and (max-width: 1060px) {
124-
.page-wrapper {
125-
padding-left: 0;
126-
}
127-
}
128-
.sidebar-hidden .page-wrapper {
129-
padding-left: 0;
109+
width: 100%;
110+
-webkit-transition: padding-left 0.5s, margin-left 0.5s;
111+
-moz-transition: padding-left 0.5s, margin-left 0.5s;
112+
-o-transition: padding-left 0.5s, margin-left 0.5s;
113+
-ms-transition: padding-left 0.5s, margin-left 0.5s;
114+
transition: padding-left 0.5s, margin-left 0.5s;
130115
}
131116
.sidebar-visible .page-wrapper {
132117
padding-left: 300px;
133-
margin-right: -300px;
118+
}
119+
@media only screen and (max-width: 1079px) {
120+
.sidebar-visible .page-wrapper {
121+
padding-left: 0;
122+
margin-left: 300px;
123+
}
134124
}
135125
.page {
136126
outline: 0;
@@ -238,38 +228,41 @@ table thead td {
238228
-ms-transition: color 0.5s;
239229
transition: color 0.5s;
240230
}
241-
.mobile-nav-chapters {
231+
.nav-chapters:hover {
232+
text-decoration: none;
233+
}
234+
.nav-wrapper {
235+
margin-top: 50px;
242236
display: none;
243237
}
244-
.nav-chapters:hover {
238+
.mobile-nav-chapters {
239+
font-size: 2.5em;
240+
text-align: center;
245241
text-decoration: none;
242+
width: 90px;
243+
border-radius: 5px;
246244
}
247245
.previous {
248-
left: 315px;
249-
-webkit-transition: left 0.5s;
250-
-moz-transition: left 0.5s;
251-
-o-transition: left 0.5s;
252-
-ms-transition: left 0.5s;
253-
transition: left 0.5s;
254-
}
255-
@media only screen and (max-width: 1060px) {
256-
.previous {
257-
left: 15px;
258-
}
246+
float: left;
259247
}
260248
.next {
249+
float: right;
261250
right: 15px;
262251
}
263-
.sidebar-hidden .previous {
264-
left: 15px;
265-
}
266-
.sidebar-visible .previous {
267-
left: 315px;
268-
}
269-
@media only screen and (max-width: 1060px) {
252+
@media only screen and (max-width: 1080px) {
253+
.nav-chapters {
254+
display: none;
255+
}
270256
.nav-wrapper {
271-
max-width: 750px;
272-
margin: 0 auto;
257+
display: block;
258+
}
259+
}
260+
@media only screen and (max-width: 1380px) {
261+
.sidebar-visible .nav-chapters {
262+
display: none;
263+
}
264+
.sidebar-visible .nav-wrapper {
265+
display: block;
273266
}
274267
}
275268
.theme-popup {
@@ -291,37 +284,6 @@ table thead td {
291284
border-top-left-radius: inherit;
292285
border-top-right-radius: inherit;
293286
}
294-
@media only screen and (max-width: 1060px) {
295-
.nav-chapters {
296-
display: none;
297-
}
298-
.mobile-nav-chapters {
299-
font-size: 2.5em;
300-
text-align: center;
301-
text-decoration: none;
302-
max-width: 150px;
303-
min-width: 90px;
304-
-webkit-box-pack: center;
305-
-moz-box-pack: center;
306-
-o-box-pack: center;
307-
-ms-flex-pack: center;
308-
-webkit-justify-content: center;
309-
justify-content: center;
310-
-ms-flex-line-pack: center;
311-
-webkit-align-content: center;
312-
align-content: center;
313-
position: relative;
314-
display: inline-block;
315-
margin-bottom: 50px;
316-
border-radius: 5px;
317-
}
318-
.next {
319-
float: right;
320-
}
321-
.previous {
322-
float: left;
323-
}
324-
}
325287
.light {
326288
color: #333;
327289
background-color: #fff;

src/theme/book.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ $( document ).ready(function() {
6868
// Toggle sidebar
6969
$("#sidebar-toggle").click(sidebarToggle);
7070

71-
// Hide sidebar on section link click if it occupies large space
72-
// in relation to the whole screen (phone in portrait)
73-
$("#sidebar a").click(function(event){
74-
if (sidebar.width() > window.screen.width * 0.4) {
75-
sidebarToggle();
76-
}
77-
});
78-
7971
// Scroll sidebar to current active section
8072
var activeSection = sidebar.find(".active");
8173
if(activeSection.length) {

src/theme/index.hbs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@
6262

6363
<!-- Hide / unhide sidebar before it is displayed -->
6464
<script type="text/javascript">
65-
var sidebar = store.get('mdbook-sidebar');
66-
if (sidebar === "hidden") { $("html").addClass("sidebar-hidden") }
67-
else if (sidebar === "visible") { $("html").addClass("sidebar-visible") }
65+
var sidebar = 'hidden';
66+
if (document.body.clientWidth >= 1080)
67+
sidebar = store.get('mdbook-sidebar') || 'visible';
68+
$("html").addClass("sidebar-" + sidebar);
6869
</script>
6970

7071
<div id="sidebar" class="sidebar">
@@ -92,30 +93,24 @@
9293

9394
<div id="content" class="content">
9495
{{{ content }}}
95-
</div>
96-
97-
<!--
98-
Constrain the space between buttons on small screen so the total
99-
width of the buttons group will not exceed the main content
100-
above.
101-
-->
102-
<div class="nav-wrapper">
103-
<!-- Mobile navigation buttons -->
104-
{{#previous}}
105-
<a rel="prev" href="{{link}}" class="mobile-nav-chapters previous" title="Previous chapter">
106-
<i class="fa fa-angle-left"></i>
107-
</a>
108-
{{/previous}}
10996

110-
{{#next}}
111-
<a rel="next" href="{{link}}" class="mobile-nav-chapters next" title="Next chapter">
112-
<i class="fa fa-angle-right"></i>
113-
</a>
114-
{{/next}}
115-
116-
<div style="clear: both"></div>
97+
<div class="nav-wrapper">
98+
<!-- Mobile navigation buttons -->
99+
{{#previous}}
100+
<a rel="prev" href="{{link}}" class="mobile-nav-chapters previous" title="Previous chapter">
101+
<i class="fa fa-angle-left"></i>
102+
</a>
103+
{{/previous}}
104+
105+
{{#next}}
106+
<a rel="next" href="{{link}}" class="mobile-nav-chapters next" title="Next chapter">
107+
<i class="fa fa-angle-right"></i>
108+
</a>
109+
{{/next}}
110+
111+
<div style="clear: both"></div>
112+
</div>
117113
</div>
118-
119114
</div>
120115

121116
{{#previous}}

src/theme/stylus/general.styl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
html, body {
1+
html {
22
font-family: "Open Sans", sans-serif
33
color: #333
4+
overflow-x: hidden
45
}
56

67
body {
78
margin: 0;
89
font-size: 1rem;
10+
overflow-x: hidden
911
}
1012

1113
code {

src/theme/stylus/nav-icons.styl

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
margin: 0
1010
max-width: 150px
1111
min-width: 90px
12+
1213
display: flex
1314
justify-content: center
1415
align-content: center
@@ -17,29 +18,38 @@
1718
transition: color 0.5s
1819
}
1920

20-
.mobile-nav-chapters { display: none }
2121
.nav-chapters:hover { text-decoration: none }
22-
.previous {
23-
left: $sidebar-width + $page-padding
24-
transition: left 0.5s
2522

26-
@media only screen and (max-width: $max-page-width-with-hidden-sidebar) {
27-
left: $page-padding
28-
}
23+
.nav-wrapper {
24+
margin-top: 50px
25+
display: none
26+
}
27+
28+
.mobile-nav-chapters {
29+
font-size: 2.5em
30+
text-align: center
31+
text-decoration: none
32+
width: 90px
33+
border-radius: 5px
2934
}
30-
.next { right: $page-padding }
3135

32-
.sidebar-hidden .previous {
33-
left: $page-padding
36+
.previous {
37+
float: left
3438
}
3539

36-
.sidebar-visible .previous {
37-
left: $sidebar-width + $page-padding
40+
.next {
41+
float: right
42+
right: $page-padding
3843
}
3944

40-
.nav-wrapper {
41-
@media only screen and (max-width: $max-page-width-with-hidden-sidebar) {
42-
max-width: $content-max-width
43-
margin: 0 auto
44-
}
45+
@media only screen and (max-width: $page-plus-sidebar-width) {
46+
.nav-chapters { display: none }
47+
.nav-wrapper { display: block }
48+
}
49+
50+
@media only screen and (max-width: $page-plus-sidebar-width + $sidebar-width) {
51+
.sidebar-visible {
52+
.nav-chapters { display: none }
53+
.nav-wrapper { display: block }
54+
}
4555
}

src/theme/stylus/page.styl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
@require 'variables'
22

33
.page-wrapper {
4-
padding-left: $sidebar-width
54
box-sizing: border-box
65

76
min-height: 100%
7+
width: 100%
88

99
// Animation: slide away
10-
transition: padding-left 0.5s, margin-right 0.5s
11-
12-
@media only screen and (max-width: $max-page-width-with-hidden-sidebar) {
13-
padding-left: 0
14-
}
15-
}
16-
17-
.sidebar-hidden .page-wrapper {
18-
padding-left: 0
10+
transition: padding-left 0.5s, margin-left 0.5s
1911
}
2012

2113
.sidebar-visible .page-wrapper {
2214
padding-left: $sidebar-width
23-
margin-right: - $sidebar-width
15+
}
16+
17+
@media only screen and (max-width: $page-plus-sidebar-width - 1) {
18+
.sidebar-visible .page-wrapper {
19+
padding-left: 0
20+
margin-left: $sidebar-width
21+
}
2422
}
2523

2624
.page {
@@ -30,7 +28,7 @@
3028

3129
.content {
3230
margin-left: auto
33-
margin-right:auto
31+
margin-right: auto
3432
max-width: $content-max-width
3533
padding-bottom: 50px
3634

0 commit comments

Comments
 (0)