in resources/web/docs_js/index-v1.js [223:257]
function highlight_otp() {
let visibleHeadings = []
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
const id = entry.target.getAttribute('id');
const element = document.querySelector(`#sticky_content #this_page a[href="#${id}"]`);
const itemId = $(element).parent().attr('id')
// All heading elements have an `entry` (even the title).
// The title does not exist in the OTP, so we must exclude it.
// Checking for the existence of `itemId` ensures we don't parse elements that don't exist.
if (itemId){
const itemNumber = parseInt(itemId.match(/\d+/)[0], 10);
if (entry.intersectionRatio > 0){
visibleHeadings.push(itemNumber);
} else {
const position = visibleHeadings.indexOf(itemNumber);
visibleHeadings.splice(position, 1)
}
if (visibleHeadings.length > 0) {
visibleHeadings.sort((a, b) => a - b)
// Remove existing active classes
$('a.active').removeClass("active");
// Add active class to the first visible heading
$('#otp-text-' + visibleHeadings[0] + ' > a').addClass('active')
}
}
})
})
document.querySelectorAll('div#content a[id]').forEach((heading, i) => {
// Skip the first heading since it's not visible
if (i === 0) return
observer.observe(heading);
})
}