Skip to content

Commit 4f1b3a6

Browse files
authored
fastlane#1114 Fix links with anchors nested in details not scrolling to the content
2 parents 7c997f9 + 5938ea2 commit 4f1b3a6

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

theme/base.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
<div class="wy-side-nav-search">
8181
{%- block site_name %}
8282
<a href="{{ nav.homepage.url|url }}" class="icon icon-home"> {{ config.site_name }}</a>
83-
{%- endblock %}
84-
{%- block search_button %}
83+
{%- endblock %}
84+
{%- block search_button %}
8585
{% if 'search' in config['plugins'] %}{% include "searchbox.html" %}{% endif %}
86-
{%- endblock %}
86+
{%- endblock %}
8787
</div>
8888

8989
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
@@ -152,7 +152,7 @@
152152
{%- for path in config['extra_javascript'] %}
153153
<script src="{{ path|url }}" defer></script>
154154
{%- endfor %}
155-
<script defer>
155+
<script>
156156
window.onload = function () {
157157
$(document).on("click","[data-toggle='wy-nav-top']",function(){$("[data-toggle='wy-nav-shift']").toggleClass("shift")})
158158
$("div[role=main] table").toggleClass("docutils");

theme/footer.html

+59-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,64 @@
2626
</footer>
2727

2828
<script type="text/javascript">
29-
var links = document.links;
30-
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
31-
if (links[i].hostname != window.location.hostname) {
32-
links[i].target = '_blank';
33-
}
29+
function ensureExternalLinksOpenInNewTab() {
30+
const links = document.links;
31+
for (let i = 0, linksLength = links.length; i < linksLength; i++) {
32+
if (links[i].hostname != window.location.hostname) {
33+
links[i].target = '_blank';
34+
}
35+
}
3436
}
37+
38+
function scrollToAnchorNestedInDetailsIfNeeded() {
39+
function scrollToElement() {
40+
const id = window.location.hash.substr(1);
41+
if (id === '') {
42+
return;
43+
}
44+
45+
const element = document.getElementById(id);
46+
if (!element) {
47+
return;
48+
}
49+
50+
const details = document.getElementsByTagName('details');
51+
for (const element of details) {
52+
element.open = false;
53+
}
54+
55+
let temp = element;
56+
while (temp && temp.tagName) {
57+
if (temp.tagName.toLowerCase() === 'details') {
58+
temp.open = true;
59+
}
60+
61+
temp = temp.parentNode;
62+
}
63+
64+
element.scrollIntoView();
65+
}
66+
67+
function onReady(callback) {
68+
if (document.readyState !== 'loading') {
69+
callback();
70+
} else if (document.addEventListener) {
71+
document.addEventListener('DOMContentLoaded', callback);
72+
} else {
73+
document.attachEvent('onreadystatechange', function() {
74+
if (document.readyState === 'complete') {
75+
callback();
76+
}
77+
});
78+
}
79+
}
80+
81+
onReady(function () {
82+
scrollToElement();
83+
window.addEventListener('hashchange', scrollToElement);
84+
});
85+
}
86+
87+
ensureExternalLinksOpenInNewTab();
88+
scrollToAnchorNestedInDetailsIfNeeded();
3589
</script>

0 commit comments

Comments
 (0)