File: //var/www/innodrive/src/js/modules/hash.js
import { $, $$ } from '@utils';
const goToHash = function(hash, smooth) {
const clearHash = hash.substr(1);
if ($(`[id="${clearHash}"]`) !== null) {
$(`[id="${clearHash}"]`).style.scrollMargin = '20px';
$(`[id="${clearHash}"]`).scrollIntoView({
behavior: smooth ? 'smooth' : 'auto'
});
}
}
export default () => {
$$('a').forEach((item) => {
if (item.hash) {
item.addEventListener('click', (ev) => {
ev.stopPropagation();
ev.preventDefault();
goToHash(item.hash, true);
return false;
})
}
});
if (window.location.hash) {
goToHash(window.location.hash, false);
}
};