Skip to content

Commit 4da1f6b

Browse files
committed
Merge branch '6-dev' into upgrade-guide
2 parents 596af10 + 776a085 commit 4da1f6b

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Patch of scrollToActive of sphinxbook theme
3+
* Scroll to active navigation item
4+
*/
5+
6+
/**
7+
* A helper function to load scripts when the DOM is loaded.
8+
* This waits for everything to be on the page first before running, since
9+
* some functionality doesn't behave properly until everything is ready.
10+
*/
11+
var sbRunWhenDOMLoaded = (cb) => {
12+
if (document.readyState != "loading") {
13+
cb();
14+
} else if (document.addEventListener) {
15+
document.addEventListener("DOMContentLoaded", cb);
16+
} else {
17+
document.attachEvent("onreadystatechange", function () {
18+
if (document.readyState == "complete") cb();
19+
});
20+
}
21+
};
22+
23+
/**
24+
* Sidebar scroll on load.
25+
*
26+
* Detect the active page in the sidebar, and scroll so that it is centered on
27+
* the screen.
28+
*/
29+
30+
var scrollToActive = () => {
31+
let navbar_scrollable = $("#site-navigation").children()[0];
32+
let active_navigation_item = $("#site-navigation .active").last();
33+
if (active_navigation_item) {
34+
if (active_navigation_item.offset().top > $(window).height() * 0.5) {
35+
navbar_scrollable.scrollTop = active_navigation_item.offset().top - $(window).height() * 0.2;
36+
}
37+
}
38+
};
39+
40+
41+
sbRunWhenDOMLoaded(scrollToActive);

docs/conf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
"plone.restapi/src",
130130
]
131131

132+
html_js_files = [
133+
"patch_scrollToActive.js",
134+
]
135+
132136
html_extra_path = [
133137
"robots.txt",
134138
]
@@ -293,11 +297,13 @@ def source_replace(app, docname, source):
293297
result = result.replace(key, app.config.source_replacements[key])
294298
source[0] = result
295299

300+
296301
# Dict of replacements.
297302
source_replacements = {
298303
"{PLONE_BACKEND_VERSION}": "6.0.0b2",
299304
}
300305

306+
301307
def setup(app):
302-
app.add_config_value('source_replacements', {}, True)
303-
app.connect('source-read', source_replace)
308+
app.add_config_value("source_replacements", {}, True)
309+
app.connect("source-read", source_replace)

0 commit comments

Comments
 (0)