Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option for specifying the top offset #1005

Merged
merged 2 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@vuepress/plugin-active-header-links/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = (options) => ({
clientRootMixin: path.resolve(__dirname, 'mixin.js'),
define: {
AHL_SIDEBAR_LINK_SELECTOR: options.sidebarLinkSelector || '.sidebar-link',
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor'
AHL_HEADER_ANCHOR_SELECTOR: options.headerAnchorSelector || '.header-anchor',
AHL_TOP_OFFSET: options.headerTopOffset || 90
}
})
6 changes: 3 additions & 3 deletions packages/@vuepress/plugin-active-header-links/mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR */
/* global AHL_SIDEBAR_LINK_SELECTOR, AHL_HEADER_ANCHOR_SELECTOR, AHL_TOP_OFFSET */

import throttle from 'lodash.throttle'

Expand Down Expand Up @@ -35,8 +35,8 @@ function getAnchors () {
return {
el,
hash: decodeURIComponent(el.hash),
top: el.getBoundingClientRect().top - 90
/* 90 is to Subtract height of navbar & anchor's padding top */
top: el.getBoundingClientRect().top - AHL_TOP_OFFSET
/* AHL_TOP_OFFSET is to Subtract height of navbar & anchor's padding top */
}
})
}
Expand Down
21 changes: 19 additions & 2 deletions packages/docs/docs/plugin/official/plugin-active-header-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ yarn add -D @vuepress/plugin-active-header-links

```javascript
module.exports = {
plugins: ['@vuepress/active-header-links']
plugins: ['@vuepress/active-header-links']
}
```

### Passing Options
```javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to move this usage to the above.

module.exports = {
plugins: ['@vuepress/active-header-links', {
sidebarLinkSelector: '.sidebar-link',
headerAnchorSelector: '.header-anchor',
headerTopOffset: 120
}]
}
```

Expand All @@ -32,5 +43,11 @@ module.exports = {
### headerAnchorSelector

- Type: `string`
- Default: `.header-anchor'`
- Default: `.header-anchor`

### headerTopOffset
The number of pixels that you want the header to be from the top of the page before updating the url hash switch to that header.

- Type: `integer`
- Default: `90`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing description for this option.