Skip to content

Commit

Permalink
Fix missing anchor icons when anchor in URL does not exist (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenonym authored and yamgent committed Jan 6, 2019
1 parent ac3db42 commit dfceca4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions asset/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Vue.use(VueStrap);
function scrollToUrlAnchorHeading() {
if (window.location.hash) {
// remove leading hash to get element ID
document.getElementById(window.location.hash.slice(1)).scrollIntoView();
window.scrollBy(0, -document.body.style.paddingTop.replace('px', ''));
const headingElement = document.getElementById(window.location.hash.slice(1));
if (headingElement) {
headingElement.scrollIntoView();
window.scrollBy(0, -document.body.style.paddingTop.replace('px', ''));
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions test/test_site/expected/markbind/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ Vue.use(VueStrap);
function scrollToUrlAnchorHeading() {
if (window.location.hash) {
// remove leading hash to get element ID
document.getElementById(window.location.hash.slice(1)).scrollIntoView();
window.scrollBy(0, -document.body.style.paddingTop.replace('px', ''));
const headingElement = document.getElementById(window.location.hash.slice(1));
if (headingElement) {
headingElement.scrollIntoView();
window.scrollBy(0, -document.body.style.paddingTop.replace('px', ''));
}
}
}

Expand Down

0 comments on commit dfceca4

Please sign in to comment.