Skip to content

Ensure that doc url hash IDs are scrolled to on page load #4329

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

Merged
merged 3 commits into from
Jul 17, 2020
Merged
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
18 changes: 11 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
shouldStable: false,
version: versionNumber,
oldVersion: undefined,
versionOptions: ['master']
versionOptions: ['master'],
scrolledOnce: false,
},
asyncComputed: {
async outputHtml() {
Expand Down Expand Up @@ -158,7 +159,7 @@
renderer.heading = function(text, level) {
const id = htmlToId(text);
return `<h${level}>
<a href="#${id}" name="${id}" class="header-link">${text}</a>
<a id="${id}" href="#${id}" name="${id}" class="header-link">${text}</a>
</h${level}>`;
};

Expand Down Expand Up @@ -186,12 +187,15 @@
.filter(tag => tag.startsWith('v'));
this.versionOptions = this.versionOptions.concat(tagOptions);
},
mounted() {
updated() {
if (UrlHash === '') return;
const target = document.querySelector(`#${UrlHash}`);
if (target != null) {
target.scrollIntoView(true);
}
this.$nextTick(() => {
const target = document.querySelector(`#${UrlHash}`);
if (target != null && !this.scrolledOnce) {
target.scrollIntoView(true);
this.scrolledOnce = true;
}
});
},
methods: {
handleReqFailure(e) {
Expand Down