aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2022-07-26 18:58:35 +0200
committerGitHub <noreply@github.com>2022-07-26 18:58:35 +0200
commit838ec1b30de400f83accfbbf1b28920c0b4ae237 (patch)
tree7c2392ba6033fed19f0006a040a5a3d461b715ed /plugins/base/src/main
parent61de8f746eb0c5451f5584d6744c0925de45593f (diff)
downloaddokka-838ec1b30de400f83accfbbf1b28920c0b4ae237.tar.gz
dokka-838ec1b30de400f83accfbbf1b28920c0b4ae237.tar.bz2
dokka-838ec1b30de400f83accfbbf1b28920c0b4ae237.zip
Add auto-scrolling to selected navigation item on page load (#2575)
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/resources/dokka/scripts/navigation-loader.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js
index 7b6aeb1f..9c824b91 100644
--- a/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js
+++ b/plugins/base/src/main/resources/dokka/scripts/navigation-loader.js
@@ -14,6 +14,8 @@ displayNavigationFromPage = () => {
})
}).then(() => {
revealNavigationForCurrentPage()
+ }).then(() => {
+ scrollNavigationToSelectedElement()
})
document.querySelectorAll('.footer a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
@@ -51,6 +53,28 @@ revealParents = (part) => {
}
};
+scrollNavigationToSelectedElement = () => {
+ let selectedElement = document.querySelector('div.sideMenuPart[data-active]')
+ if (selectedElement == null) { // nothing selected, probably just the main page opened
+ return
+ }
+
+ let isPackageElement = selectedElement.children.length > 1
+ if (isPackageElement) {
+ // if package is selected or linked, it makes sense to align it to top
+ // so that you can see all the members it contains
+ selectedElement.scrollIntoView(true)
+ } else {
+ // if a member within a package is linked, it makes sense to center it since it,
+ // this should make it easier to look at surrounding members
+ selectedElement.scrollIntoView({
+ behavior: 'auto',
+ block: 'center',
+ inline: 'center'
+ })
+ }
+}
+
/*
This is a work-around for safari being IE of our times.
It doesn't fire a DOMContentLoaded, presumabely because eventListener is added after it wants to do it
@@ -61,4 +85,4 @@ if (document.readyState == 'loading') {
})
} else {
displayNavigationFromPage()
-} \ No newline at end of file
+}