Skip to content

Commit cf2ed47

Browse files
choldgrafjorisvandenbossche
authored andcommitted
Add previous and next buttons (#44)
1 parent 4620240 commit cf2ed47

File tree

3 files changed

+96
-27
lines changed

3 files changed

+96
-27
lines changed

pandas_sphinx_theme/layout.html

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11

22
{% extends "basic/layout.html" %}
33

4+
{# prev/next buttons #}
5+
{% macro prev_next(prev, next, prev_title='', next_title='') %}
6+
{%- if prev %}
7+
<a class='left-prev' id="prev-link" href="{{ prev.link|e }}" title="{{ _('previous page')}}">{{ prev_title or prev.title }}</a>
8+
{%- endif %}
9+
{%- if next %}
10+
<a class='right-next' id="next-link" href="{{ next.link|e }}" title="{{ _('next page')}}">{{ next_title or next.title }}</a>
11+
{%- endif %}
12+
{% endmacro %}
13+
414
{%- block css %}
515
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
616
{{- css() }}
@@ -37,7 +47,7 @@
3747
{%- include "docs-sidebar.html" %}
3848
{% endif %}
3949
</div>
40-
50+
4151
<div class="d-none d-xl-block col-xl-2 bd-toc">
4252
{% if not (meta is not none and 'notoc' in meta) %}
4353
{%- include "docs-toc.html" %}
@@ -48,6 +58,9 @@
4858
<div>
4959
{% block body %} {% endblock %}
5060
</div>
61+
<div class='prev-next-bottom'>
62+
{{ prev_next(prev, next) }}
63+
</div>
5164
</main>
5265

5366
</div>

pandas_sphinx_theme/scripts.html

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script>
22
// TOC sidebar - add "active" class to parent list
3-
//
3+
//
44
// Bootstrap's scrollspy adds the active class to the <a> link,
55
// but for the automatic collapsing we need this on the parent list item.
6-
//
6+
//
77
// The event is triggered on "window" (and not the nav item as documented),
88
// see https://github.com/twbs/bootstrap/issues/20086
99
$(window).on("activate.bs.scrollspy", function(){
@@ -18,4 +18,30 @@
1818
navLink.parentElement.classList.add('active');
1919
}
2020
});
21+
22+
/**
23+
* Use left and right arrow keys to navigate forward and backwards.
24+
*/
25+
const LEFT_ARROW_KEYCODE = 37
26+
const RIGHT_ARROW_KEYCODE = 39
27+
28+
const getPrevUrl = () => document.getElementById('prev-link').href
29+
const getNextUrl = () => document.getElementById('next-link').href
30+
const initPageNav = (event) => {
31+
const keycode = event.which
32+
33+
if (keycode === LEFT_ARROW_KEYCODE) {
34+
window.location.href = getPrevUrl();
35+
} else if (keycode === RIGHT_ARROW_KEYCODE) {
36+
window.location.href = getNextUrl();
37+
}
38+
};
39+
40+
var keyboardListener = false;
41+
$( document ).ready(() => {
42+
if (keyboardListener === false) {
43+
document.addEventListener('keydown', initPageNav)
44+
keyboardListener = true;
45+
}
46+
});
2147
</script>

pandas_sphinx_theme/static/css/custom.css

+54-24
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
.navbar-header a {
2323
padding: 0 15px;
24-
/* line-height: 50px; */
24+
/* line-height: 50px; */
2525
}
2626

2727
.bd-search {
@@ -45,7 +45,7 @@
4545
height: calc(100vh - 2rem);
4646
overflow-y: auto;
4747
}
48-
48+
4949
@supports ((position: -webkit-sticky) or (position: sticky)) {
5050
.bd-toc {
5151
position: -webkit-sticky;
@@ -55,39 +55,39 @@
5555
overflow-y: auto;
5656
}
5757
}
58-
58+
5959
.section-nav {
6060
padding-left: 0;
6161
border-left: 1px solid #eee;
6262
border-bottom: none;
6363
}
64-
64+
6565
.section-nav ul {
6666
padding-left: 1rem;
6767
}
68-
68+
6969
.toc-entry {
7070
display: block;
7171
}
72-
72+
7373
.toc-entry a {
7474
display: block;
7575
padding: .125rem 1.5rem;
7676
color: #77757a;
7777
}
78-
78+
7979
.toc-entry a:hover {
8080
color: rgba(0, 0, 0, 0.85);
8181
text-decoration: none;
8282
}
83-
83+
8484

8585
.bd-sidebar {
8686
-ms-flex-order: 0;
8787
order: 0;
8888
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
8989
}
90-
90+
9191
@media (min-width: 768px) {
9292
.bd-sidebar {
9393
border-right: 1px solid rgba(0, 0, 0, 0.1);
@@ -102,21 +102,21 @@
102102
}
103103
}
104104
}
105-
105+
106106
@media (min-width: 1200px) {
107107
.bd-sidebar {
108108
-ms-flex: 0 1 320px;
109109
flex: 0 1 320px;
110110
}
111111
}
112-
112+
113113
.bd-links {
114114
padding-top: 1rem;
115115
padding-bottom: 1rem;
116116
margin-right: -15px;
117117
margin-left: -15px;
118118
}
119-
119+
120120
@media (min-width: 768px) {
121121
@supports ((position: -webkit-sticky) or (position: sticky)) {
122122
.bd-links {
@@ -125,45 +125,45 @@
125125
}
126126
}
127127
}
128-
128+
129129
@media (min-width: 768px) {
130130
.bd-links {
131131
display: block !important;
132132
}
133133
}
134-
134+
135135
.bd-sidenav {
136136
display: none;
137137
}
138-
138+
139139
.bd-toc-link {
140140
display: block;
141141
padding: .25rem 1.5rem;
142142
font-weight: 600;
143143
color: rgba(0, 0, 0, 0.65);
144144
}
145-
145+
146146
.bd-toc-link:hover {
147147
color: rgba(0, 0, 0, 0.85);
148148
text-decoration: none;
149149
}
150-
150+
151151
.bd-toc-item.active {
152152
margin-bottom: 1rem;
153153
}
154-
154+
155155
.bd-toc-item.active:not(:first-child) {
156156
margin-top: 1rem;
157157
}
158-
158+
159159
.bd-toc-item.active > .bd-toc-link {
160160
color: rgba(0, 0, 0, 0.85);
161161
}
162-
162+
163163
.bd-toc-item.active > .bd-toc-link:hover {
164164
background-color: transparent;
165165
}
166-
166+
167167
.bd-toc-item.active > .bd-sidenav {
168168
display: block;
169169
}
@@ -174,13 +174,13 @@
174174
font-size: 90%;
175175
color: rgba(0, 0, 0, 0.65);
176176
}
177-
177+
178178
.bd-sidebar .nav > li > a:hover {
179179
color: rgba(0, 0, 0, 0.85);
180180
text-decoration: none;
181181
background-color: transparent;
182182
}
183-
183+
184184
.bd-sidebar .nav > .active > a,
185185
.bd-sidebar .nav > .active:hover > a {
186186
font-weight: 600;
@@ -209,7 +209,7 @@
209209
}
210210

211211
/* offsetting html anchor titles to adjust for fixed header, https://github.com/pandas-dev/pandas-sphinx-theme/issues/6*/
212-
h2::before, h3::before,
212+
h2::before, h3::before,
213213
h4::before, h5::before,
214214
h6::before {
215215
display: block;
@@ -259,3 +259,33 @@ body {
259259
.bd-toc .nav > .active > ul {
260260
display: block;
261261
}
262+
263+
264+
/* Previous / Next buttons */
265+
div.prev-next-bottom {
266+
margin: 20px 0px;
267+
}
268+
269+
div.prev-next-bottom a.left-prev, div.prev-next-bottom a.right-next {
270+
padding: 10px;
271+
border: 1px solid rgba(0, 0, 0, .2);
272+
max-width: 45%;
273+
overflow-x: hidden;
274+
color: rgba(0, 0, 0, 0.65);
275+
}
276+
277+
div.prev-next-bottom a.left-prev {
278+
float: left;
279+
}
280+
281+
div.prev-next-bottom a.left-prev:before {
282+
content: "<< "
283+
}
284+
285+
div.prev-next-bottom a.right-next {
286+
float: right;
287+
}
288+
289+
div.prev-next-bottom a.right-next:after {
290+
content: " >>"
291+
}

0 commit comments

Comments
 (0)