Repository navigation
Expand file tree
/
Copy patheyebrow.js
More file actions
72 lines (69 loc) · 2.47 KB
/
Copy patheyebrow.js
File metadata and controls
72 lines (69 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Show the parent group in the page eyebrow when the eyebrow repeats the title.
*
* Mintlify shows the sidebar group name above every page title. On a section's
* overview page the title is the section name, so the eyebrow would repeat it.
* On those pages, show the next group up from the sidebar instead ("Configure"
* above "Proxies", "How it works" above "Configure"). The name goes in a
* data attribute that style.css renders, so React keeps owning the text node.
* If there is no parent group to show, hide the eyebrow.
* Mintlify loads every .js file in this directory on every docs page and
* navigates client-side, so re-check whenever the header changes.
*/
(function () {
function parentGroup() {
var item = document.querySelector(
'#navigation-items li[data-active-nav-item="true"]'
);
if (!item) return null;
var groups = [];
for (var el = item.parentElement; el; el = el.parentElement) {
if (el.matches("li[data-group-tag]")) groups.push(el);
}
// groups[0] is the page's own group, the one the eyebrow names.
if (groups.length > 1) return groups[1].getAttribute("data-title");
if (!groups.length) return null;
var section = groups[0].parentElement.previousElementSibling;
var heading =
section &&
section.classList.contains("sidebar-group-header") &&
section.querySelector(".sidebar-title");
return heading ? heading.textContent.trim() : null;
}
function sync() {
var header = document.getElementById("header");
if (!header) return;
var eyebrow = header.querySelector(".eyebrow");
var title = document.getElementById("page-title");
if (!eyebrow || !title) return;
var same =
eyebrow.textContent.trim().toLowerCase() ===
title.textContent.trim().toLowerCase();
var parent = same ? parentGroup() : null;
if (parent) {
eyebrow.setAttribute("data-parent-group", parent);
} else {
eyebrow.removeAttribute("data-parent-group");
}
eyebrow.style.display = same && !parent ? "none" : "";
}
var scheduled = false;
function schedule() {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(function () {
scheduled = false;
sync();
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", sync);
} else {
sync();
}
new MutationObserver(schedule).observe(document.documentElement, {
childList: true,
subtree: true,
characterData: true,
});
})();