@codedoc/core
Version:
Create beautiful modern documentation websites.
59 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.contentNavHighlight$ = exports.contentNavHighlight = void 0;
var transport_1 = require("@connectv/sdh/transport");
function contentNavHighlight() {
transport_1.onReady(function () {
var links = [];
var _exec = function () {
links = [];
document.querySelectorAll('a[data-content-highlight]').forEach(function (_a$) {
var a$ = _a$;
var id = a$.getAttribute('data-content-highlight');
if (id) {
var ref$ = document.getElementById(id);
if (ref$) {
links.push({ a$: a$, ref$: ref$ });
}
}
});
};
_exec();
window.addEventListener('navigation', _exec);
function update() {
var _a;
var noactive = true;
var latest;
links.forEach(function (_a) {
var a$ = _a.a$, ref$ = _a.ref$;
var top = ref$.getBoundingClientRect().top;
if (top < window.innerHeight - 96 && top > 0) {
noactive = false;
a$.classList.add('active');
}
else {
if (top < 0)
latest = a$;
a$.classList.remove('active');
}
});
if (noactive)
latest === null || latest === void 0 ? void 0 : latest.classList.add('active');
var target = (_a = links.find(function (l) { return l.a$.classList.contains('active'); })) === null || _a === void 0 ? void 0 : _a.a$;
if (target) {
var parent_1 = target.parentElement;
if (parent_1.scrollHeight != parent_1.offsetHeight) {
parent_1.scrollTop = target.offsetTop - parent_1.offsetHeight / 3;
}
}
}
if (links.length > 0) {
update();
document.addEventListener('scroll', function () { return setTimeout(update, 1); });
window.addEventListener('navigation', update);
}
});
}
exports.contentNavHighlight = contentNavHighlight;
exports.contentNavHighlight$ = transport_1.funcTransport(contentNavHighlight);
//# sourceMappingURL=highlight.js.map