-
- function addNavObserver(headings) {
- // Setup the intersection observer.
- const intersectOpts = {
- rootMargin: '0px 0px 0px 0px',
- threshold: 1.0,
- };
- const pageNavObserver = new IntersectionObserver(headingVisibilityChange, intersectOpts);
-
- // observe each heading
- for (const heading of headings) {
- pageNavObserver.observe(heading);
- }
- }
-
- function headingVisibilityChange(entries, observer) {
- for (const entry of entries) {
- const isVisible = (entry.intersectionRatio === 1);
- toggleAnchorHighlighting(entry.target.id, isVisible);
- }
- }
-
- function toggleAnchorHighlighting(elementId, shouldHighlight) {
- DOM.forEach(`a[href="#${elementId}"]`, anchor => {
- anchor.closest('li').classList.toggle('current-heading', shouldHighlight);
- });
- }
- }
-
- setupDetailsCodeBlockRefresh() {
- const onToggle = event => {
- const codeMirrors = [...event.target.querySelectorAll('.CodeMirror')];
- codeMirrors.forEach(cm => cm.CodeMirror && cm.CodeMirror.refresh());
- };
-
- const details = [...this.container.querySelectorAll('details')];
- details.forEach(detail => detail.addEventListener('toggle', onToggle));