forked from EnterpriseDB/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
31 lines (27 loc) · 863 Bytes
/
gatsby-browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require("prismjs/themes/prism-okaidia.css");
require("prismjs/plugins/command-line/prism-command-line.css");
exports.onRouteUpdate = ({ location }) => scrollToAnchor(location);
/**
*
* @desc - a function to jump to the correct scroll position
* @param {Object} location -
* @param {Number} [mainNavHeight] - the height of any persistent nav -> document.querySelector(`nav`)
*/
function scrollToAnchor(location, mainNavHeight = 0) {
// Check for location so build does not fail
if (location && location.hash) {
try {
const item = document.querySelector(`${location.hash}`);
if (item) {
window.scrollTo({
top: item.offsetTop - mainNavHeight,
behavior: "smooth",
});
}
} catch (error) {
// if hash is bad exception will be raised
console.error(error);
}
}
return true;
}