Skip to content

Commit a17eec0

Browse files
committed
Fixes jump to footnote labels on small screens.
Resolves sighingnow#130. Signed-off-by: Tao He <sighingnow@gmail.com>
1 parent 96552d2 commit a17eec0

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

_includes/footer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
1818
-->
1919

20+
<script src="{{site.baseurl}}/assets/gitbook/custom.js"></script>
21+
<script src="{{site.baseurl}}/assets/gitbook/custom-local.js"></script>
22+
2023
{% if site.extra_footer_js %}
2124
{%- for extra_js in site.extra_header_js -%}
2225
{%- assign starts_with = extra_js | slice: 0,4 -%}

_includes/toc-date.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
$(element).closest('li.chapter').find('ul>li').removeClass('active');
1313
$(element).parent().addClass('active');
1414
if ($(document).width() <= 1240) {
15-
$('div.body-inner').animate({scrollTop: $($(element).attr('href')).get(0).offsetTop});
15+
let target = $($(element).attr('href'));
16+
if (target.length) {
17+
$('div.body-inner').animate({
18+
scrollTop: target.get(0).offsetTop,
19+
});
20+
}
1621
}
1722
return true;
1823
}

assets/gitbook/custom-local.js

Whitespace-only changes.

assets/gitbook/custom.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Enable footnote link support for pages with width < 1240.
2+
//
3+
function bind_footnote_links() {
4+
if ($(document).width() > 1240) {
5+
return;
6+
}
7+
let footnotes = $("div.footnotes").find("ol > li > p > a.reversefootnote");
8+
for (let i = 0; i < footnotes.length; i++) {
9+
let footnote = footnotes[i];
10+
footnote.addEventListener('click', function(e) {
11+
e.preventDefault();
12+
var target = $($(this).attr('href'));
13+
if (target.length) {
14+
$('div.body-inner').animate({
15+
scrollTop: target.get(0).offsetTop,
16+
});
17+
}
18+
});
19+
}
20+
}
21+
22+
if (document.readyState === "loading") {
23+
// Loading hasn't finished yet
24+
document.addEventListener("DOMContentLoaded", bind_footnote_links);
25+
} else {
26+
// `DOMContentLoaded` has already fired
27+
bind_footnote_links();
28+
}
29+

0 commit comments

Comments
 (0)