-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathtabsync.js
More file actions
38 lines (31 loc) · 1.22 KB
/
tabsync.js
File metadata and controls
38 lines (31 loc) · 1.22 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
document.addEventListener("DOMContentLoaded", function () {
const tabSync = () => {
const tabs = document.querySelectorAll(".tabbed-set > input, .tabbed-alternate input");
for (const tab of tabs) {
tab.addEventListener("click", () => {
if (tab.dataset.syncing === "true") return;
const currentLabel = document.querySelector(`label[for="${tab.id}"]`);
if (!currentLabel) return;
const pos = currentLabel.getBoundingClientRect().top;
const labelText = currentLabel.textContent.trim();
const allLabels = document.querySelectorAll(
".tabbed-set > label, .tabbed-alternate > .tabbed-labels > label"
);
for (const label of allLabels) {
if (label.textContent.trim() === labelText) {
const inputId = label.getAttribute("for");
const input = document.getElementById(inputId);
if (input && input !== tab) {
input.dataset.syncing = "true";
input.click();
input.dataset.syncing = "false";
}
}
}
const delta = currentLabel.getBoundingClientRect().top - pos;
window.scrollBy(0, delta);
});
}
};
tabSync();
});