From 64da5a1e9ce77291c894e437ddd959b13c1c4fed Mon Sep 17 00:00:00 2001 From: aaron hendrick Date: Wed, 23 May 2018 16:51:17 -0700 Subject: [PATCH] feat: allow for disabling of active hash on scroll --- docs/default-theme-config/README.md | 12 ++++++++++++ lib/default-theme/Layout.vue | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index 650dddfe36..b803f57003 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -142,6 +142,18 @@ sidebarDepth: 2 --- ``` +### Active Header Links + +By default, the nested header links and the hash in the URL are updated as the user scrolls to view the different sections of the page. This behavior can be disabled with the following theme config: + +``` js +module.exports = { + themeConfig: { + disableActiveHash: true, // boolean + } +} +``` + ### Sidebar Groups You can divide sidebar links into multiple groups by using objects: diff --git a/lib/default-theme/Layout.vue b/lib/default-theme/Layout.vue index c794f6a753..bca4c1168e 100644 --- a/lib/default-theme/Layout.vue +++ b/lib/default-theme/Layout.vue @@ -136,6 +136,10 @@ export default { this.setActiveHash() }, 300), setActiveHash () { + if (this.$site.themeConfig.disableActiveHash) { + return + } + const sidebarLinks = [].slice.call(document.querySelectorAll('.sidebar-link')) const anchors = [].slice.call(document.querySelectorAll('.header-anchor')) .filter(anchor => sidebarLinks.some(sidebarLink => sidebarLink.hash === anchor.hash))