Skip to content

Commit

Permalink
[Fixes lodash#243] Anchor tags are not working in chrome on first load
Browse files Browse the repository at this point in the history
  • Loading branch information
Janarthanan Chandrasekaran committed May 9, 2022
1 parent c8d41c6 commit b0dba3c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
return string.replace(/^\s+|\s+$/g, '')
}

/**
* credit: https://stackoverflow.com/a/13348618
*/
function isChrome() {
const isChromium = window.chrome;
const winNav = window.navigator;
const vendorName = winNav.vendor;
const isOpera = typeof window.opr !== "undefined";
const isIEedge = winNav.userAgent.indexOf("Edge") > -1;
const isIOSChrome = winNav.userAgent.match("CriOS");
return (
isIOSChrome ||
(isChromium !== null &&
isChromium !== undefined &&
vendorName === "Google Inc." &&
isOpera === false &&
isIEedge === false)
);
}
/*--------------------------------------------------------------------------*/

var Menu = React.createClass({
Expand Down Expand Up @@ -455,6 +474,13 @@
parent.appendChild(button)
})
}

if (location.hash && isChrome()) {
const hash = document.querySelector(location.hash);
if (hash) {
hash.scrollIntoView();
}
}
}

if (document.readyState == 'loading') {
Expand Down

0 comments on commit b0dba3c

Please sign in to comment.