forked from rungalileo/docs-official
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
213 lines (188 loc) · 6.73 KB
/
Copy pathscript.js
File metadata and controls
213 lines (188 loc) · 6.73 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// REO script
!(function () {
var e, t, n;
(e = "638190bf025179e"),
(t = function () {
Reo.init({ clientID: "638190bf025179e" });
}),
((n = document.createElement("script")).src = "https://static.reo.dev/" + e + "/reo.js"),
(n.async = !0),
(n.onload = t),
document.head.appendChild(n);
})();
// Hubspot script
const script = document.createElement("script");
script.type = "text/javascript";
script.id = "hs-script-loader";
script.async = true;
script.defer = true;
script.src = "//js.hs-scripts.com/23114811.js";
document.head.appendChild(script);
// RB2B script.
!(function () {
var reb2b = (window.reb2b = window.reb2b || []);
if (reb2b.invoked) return;
reb2b.invoked = true;
reb2b.methods = ["identify", "collect"];
reb2b.factory = function (method) {
return function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
reb2b.push(args);
return reb2b;
};
};
for (var i = 0; i < reb2b.methods.length; i++) {
var key = reb2b.methods[i];
reb2b[key] = reb2b.factory(key);
}
reb2b.load = function (key) {
var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = "https://s3-us-west-2.amazonaws.com/b2bjsstore/b/" + key + "/8XOE9GH5EDOM.js.gz";
var first = document.getElementsByTagName("script")[0];
first.parentNode.insertBefore(script, first);
};
reb2b.SNIPPET_VERSION = "1.0.1";
reb2b.load("8XOE9GH5EDOM");
})();
// Universal CodeGroup tab synchronization
(function () {
// Store the last selected language to sync across all CodeGroups
let lastSelectedLanguage = null;
// Function to initialize the script
function init() {
console.log("Universal CodeGroup tab sync initialized");
// Set up the click event listener on the document (event delegation)
document.addEventListener("click", handleDocumentClick);
// Set up a MutationObserver to detect when new CodeGroups are added
setupMutationObserver();
// Initial scan for CodeGroups
syncAllCodeGroups();
}
// Handle clicks anywhere in the document
function handleDocumentClick(event) {
// Find if the click was on a CodeGroup tab
let target = event.target;
// Traverse up the DOM to find if we clicked on a tab
while (target && target !== document) {
if (target.getAttribute && target.getAttribute("role") === "tab" && target.id && target.id.startsWith("headlessui-tabs-tab-")) {
// We found a tab click
const tabDiv = target.querySelector("div");
if (tabDiv) {
const language = tabDiv.textContent.trim();
console.log(`Tab clicked: ${language}`);
// Store the selected language
lastSelectedLanguage = language;
// Sync all other CodeGroups to this language (after a small delay)
setTimeout(() => {
syncAllCodeGroups();
}, 10);
}
break;
}
target = target.parentNode;
}
}
// Function to sync all CodeGroups to the last selected language
function syncAllCodeGroups() {
if (!lastSelectedLanguage) {
// If no language has been selected yet, find the first selected tab
const selectedTab = document.querySelector('[role="tab"][aria-selected="true"]');
if (selectedTab) {
const tabDiv = selectedTab.querySelector("div");
if (tabDiv) {
lastSelectedLanguage = tabDiv.textContent.trim();
console.log(`Initial language detected: ${lastSelectedLanguage}`);
}
}
}
if (!lastSelectedLanguage) {
console.log("No language selected yet");
return;
}
// Find all tab containers
const tabLists = document.querySelectorAll('[role="tablist"][aria-orientation="horizontal"]');
console.log(`Found ${tabLists.length} CodeGroup containers`);
// For each container, find and click the tab with the matching language
tabLists.forEach((tabList) => {
const tabs = tabList.querySelectorAll('[role="tab"]');
// Find the tab with the matching language
let matchingTab = null;
tabs.forEach((tab) => {
const tabDiv = tab.querySelector("div");
if (tabDiv) {
const tabLanguage = tabDiv.textContent.trim();
if (tabLanguage === lastSelectedLanguage && tab.getAttribute("aria-selected") !== "true") {
matchingTab = tab;
}
}
});
// Click the matching tab if found and not already selected
if (matchingTab) {
console.log(`Syncing tab to ${lastSelectedLanguage}`);
matchingTab.click();
}
});
}
// Set up a MutationObserver to detect when new CodeGroups are added
function setupMutationObserver() {
const observer = new MutationObserver((mutations) => {
let shouldSync = false;
mutations.forEach((mutation) => {
if (mutation.addedNodes && mutation.addedNodes.length) {
// Check if any of the added nodes are or contain CodeGroup elements
for (let i = 0; i < mutation.addedNodes.length; i++) {
const node = mutation.addedNodes[i];
if (node.nodeType === 1) {
// Element node
if ((node.getAttribute && node.getAttribute("role") === "tablist") || (node.querySelector && node.querySelector('[role="tablist"]'))) {
shouldSync = true;
break;
}
}
}
}
});
if (shouldSync) {
console.log("New CodeGroup detected, syncing...");
setTimeout(syncAllCodeGroups, 100); // Delay to ensure the DOM is fully updated
}
});
// Start observing the entire document
observer.observe(document.documentElement, {
childList: true,
subtree: true,
});
console.log("MutationObserver set up");
}
// Start the script when the DOM is ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();
// API Reference icon theming is now handled by CSS custom properties
// No JavaScript needed - the SVG uses var(--icon-color) and CSS handles the theme switching
// Common Room
(function () {
if (typeof window === 'undefined') return;
if (typeof window.signals !== 'undefined') return;
var script = document.createElement('script');
script.src = 'https://cdn.cr-relay.com/v1/site/e9a1e4dd-e943-4f5f-9626-88d3ca665192/signals.js';
script.async = true;
window.signals = Object.assign(
[],
{ _opts: { apiHost: 'https://api.cr-relay.com' } },
['page', 'identify', 'form'].reduce(function (acc, method) {
acc[method] = function () {
signals.push([method, arguments]);
return signals;
};
return acc;
}, {})
);
document.head.appendChild(script);
})();