iso-countries-languages/esdoc/script/inner-link.js
pinturic 49a5a4c1ad First commit
README.md edited online with Bitbucket

Add esdoc

Upgraded dependencies

Fixed dependencies in readme

Fix description

Fixed readme

0.1.0

config.env deleted online with Bitbucket
2016-11-09 11:48:48 +01:00

31 lines
935 B
JavaScript

// inner link(#foo) can not correctly scroll, because page has fixed header,
// so, I manually scroll.
(function(){
var matched = location.hash.match(/errorLines=([\d,]+)/);
if (matched) return;
function adjust() {
window.scrollBy(0, -55);
var el = document.querySelector('.inner-link-active');
if (el) el.classList.remove('inner-link-active');
// ``[ ] . ' " @`` are not valid in DOM id. so must escape these.
var id = location.hash.replace(/([\[\].'"@$])/g, '\\$1');
var el = document.querySelector(id);
if (el) el.classList.add('inner-link-active');
}
window.addEventListener('hashchange', adjust);
if (location.hash) {
setTimeout(adjust, 0);
}
})();
(function(){
var els = document.querySelectorAll('[href^="#"]');
for (var i = 0; i < els.length; i++) {
var el = els[i];
el.href = location.href + el.getAttribute('href'); // because el.href is absolute path
}
})();