mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-01 17:08:30 +02:00
* Created Dev-portal pages * changed structure of documents for dev-portal section, renamed dev-portal to docs, related template changes * keeping learn section for future usage * update dev-portal and documents * added feedback and breadcrumbs components * used the docs-side menu partial on documentation pages, and added active state to the docs-header links * search console on docs * small fixes * assigned partitions, css fix * fix links on the core page * update links for cloud * update links for build * Reference -> API Reference * [WIP] Dev portal light theme (#1250) * light theme - docs side menu * background fix * wip: updating layout * layout update * light theme * card titles with a link * upd page-search package * simplified header * fixes * TOC scroll spy (#1259) * scroll spy on table of contents * packages versions fix * custom scroll spy for toc * make spy work again --------- Co-authored-by: generall <andrey@vasnetsov.com> * limit toc depth to 3 * thin scrollbar * No dev template (#1266) * divided the docs template into smaller partials, increased reusability * removed docs section, moved all to the documentation * review fixes * review fixes --------- Co-authored-by: generall <andrey@vasnetsov.com> * side panel more compact * toc margin bottom fix * Refactoring and renaming (#1277) * renamed and moved partials, fixed link * refactoring: docs-card * fix * fix urls * disable scrollbar on table of content * added scrollbar colors for light theme (#1280) * fix language * Dev portal fixes (#1285) * cards fixes * moved files, fixed paddings * fix for my fix * external header links * fix --------- Co-authored-by: trean <trean.mi@gmail.com> Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com> Co-authored-by: davidmyriel <davidmyriel@gmail.com>
86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
import { DOCS_HEADER_OFFSET } from './constants';
|
|
|
|
class TableOfContents {
|
|
constructor(tocSelector, contentSelector) {
|
|
this.tocLinks = Array.from(document.querySelectorAll(`${tocSelector} a`));
|
|
this.headings = Array.from(
|
|
document.querySelectorAll(
|
|
`${contentSelector} h1, ${contentSelector} h2, ${contentSelector} h3`,
|
|
),
|
|
);
|
|
this.currentActiveIndex = -1; // Track the current active heading index
|
|
this.currentActive = null; // Track the current active heading element
|
|
|
|
|
|
this.debounceTimeout = null;
|
|
|
|
this.currentlyVisibleHeaderIds = new Set();
|
|
|
|
this.headerOffset = DOCS_HEADER_OFFSET + 10;
|
|
|
|
this.init();
|
|
}
|
|
|
|
// Initialize the Table of Contents functionality
|
|
init() {
|
|
this.setupObserver();
|
|
}
|
|
|
|
// Clear 'active' class from all links
|
|
clearActiveClasses() {
|
|
this.tocLinks.forEach((link) => link.classList.remove('active'));
|
|
}
|
|
|
|
// Set active link with debounce
|
|
setActiveLink(index) {
|
|
if (index !== this.currentActiveIndex) {
|
|
this.clearActiveClasses();
|
|
if (this.tocLinks[index]) {
|
|
this.tocLinks[index].classList.add('active');
|
|
this.currentActiveIndex = index;
|
|
this.currentActive = this.headings[index];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Setup Intersection Observer
|
|
setupObserver() {
|
|
const observerCallback = (entries) => {
|
|
|
|
entries.forEach((entry) => {
|
|
const entryIndex = this.headings.indexOf(entry.target);
|
|
const isIntersecting = entry.isIntersecting;
|
|
|
|
if (isIntersecting) {
|
|
this.currentlyVisibleHeaderIds.add(entryIndex);
|
|
} else {
|
|
this.currentlyVisibleHeaderIds.delete(entryIndex);
|
|
}
|
|
});
|
|
|
|
if (this.currentlyVisibleHeaderIds.size !== 0) {
|
|
let minimalVisibleHeaderId = Math.min(...Array.from(this.currentlyVisibleHeaderIds));
|
|
this.setActiveLink(minimalVisibleHeaderId);
|
|
} else {
|
|
// No intersection found
|
|
// If current active heading is below the viewport, then set current active to one above it
|
|
if (this.currentActive && this.currentActive.getBoundingClientRect().top > this.headerOffset) {
|
|
this.setActiveLink(this.currentActiveIndex - 1);
|
|
}
|
|
}
|
|
};
|
|
|
|
// Observer options
|
|
const observerOptions = {
|
|
root: null,
|
|
rootMargin: `-${this.headerOffset}px 0px -25% 0px`,
|
|
threshold: 0.0, // Lower threshold for better visibility
|
|
};
|
|
|
|
const observer = new IntersectionObserver(observerCallback, observerOptions);
|
|
this.headings.forEach((heading) => observer.observe(heading));
|
|
}
|
|
}
|
|
|
|
export default TableOfContents;
|