diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2025-07-31 18:03:27 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2025-07-31 18:03:27 -0400 |
| commit | f252933553de86be26c25710ca314bc1f15e93b6 (patch) | |
| tree | 811a4252d602aee75490e8b4620182579a8ea167 /docs/tabsync.js | |
| parent | 27223cecc131198166e02b7a3387b65d04daca00 (diff) | |
support for multi-language code block tab syncing
Diffstat (limited to 'docs/tabsync.js')
| -rw-r--r-- | docs/tabsync.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/docs/tabsync.js b/docs/tabsync.js new file mode 100644 index 00000000..86e54b1c --- /dev/null +++ b/docs/tabsync.js @@ -0,0 +1,34 @@ +document.addEventListener("DOMContentLoaded", function () { + const tabSync = () => { + const tabs = document.querySelectorAll(".tabbed-set > input, .tabbed-alternate input"); + + for (const tab of tabs) { + tab.addEventListener("click", () => { + 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.click(); + } + } + } + + const delta = currentLabel.getBoundingClientRect().top - pos; + window.scrollBy(0, delta); + }); + } + }; + + tabSync(); +});
\ No newline at end of file |
