@codedoc/core
Version:
Create beautiful modern documentation websites.
31 lines • 1.37 kB
JavaScript
import { funcTransport, onReady } from '@connectv/sdh/transport';
import { polyfillCustomEvent } from '../../../transport/custom-event';
export function tocHighlight() {
polyfillCustomEvent();
let current$;
function highlightCurrentToCLink(url) {
const toc = document.getElementById('-codedoc-toc');
if (toc) {
let curr$;
toc.querySelectorAll('a').forEach(a$ => {
if (a$.getAttribute('href') === url) {
if (!curr$)
curr$ = a$;
a$.classList.add('current');
}
else
a$.classList.remove('current');
});
if (curr$) {
if (curr$ !== current$)
current$ === null || current$ === void 0 ? void 0 : current$.dispatchEvent(new CustomEvent('collapse-close', { bubbles: true }));
curr$.dispatchEvent(new CustomEvent('collapse-open', { bubbles: true }));
current$ = curr$;
}
}
}
onReady(() => setTimeout(() => highlightCurrentToCLink(location.pathname), 200));
window.addEventListener('navigation-start', event => highlightCurrentToCLink(event.detail.url));
}
export const tocHighlight$ = /*#__PURE__*/ funcTransport(tocHighlight);
//# sourceMappingURL=toc-highlight.js.map