1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-03 14:32:21 +02:00
TableFilter/docs/script/inner-link.js
koalyptus 4481fbe361 publish Docs to gh-pages (auto)
branch:       master
SHA:          c7d6de72f7
range SHA:    81f31a3106fb...c7d6de72f785
build id:     375208741
build number: 1103
2018-05-05 08:21:30 +00:00

33 lines
997 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^="#"]');
var href = location.href.replace(/#.*$/, ''); // remove existed hash
for (var i = 0; i < els.length; i++) {
var el = els[i];
el.href = href + el.getAttribute('href'); // because el.href is absolute path
}
})();