Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ build-dir = "book"
[preprocessor.tabs]

[output.html]
additional-js = ["mermaid.min.js", "mermaid-init.js", "theme/version-picker.js", "theme/toc.js"]
additional-css = ["theme/version-picker.css", "theme/toc.css"]
additional-js = ["mermaid.min.js", "mermaid-init.js", "theme/version-picker.js", "theme/toc.js", "theme/tabs.js"]
additional-css = ["theme/version-picker.css", "theme/toc.css", "theme/tabs.css"]
smart-punctuation = true
git-repository-url = "https://github.com/microsoft/wassette"
edit-url-template = "https://github.com/microsoft/wassette/edit/main/docs/{path}"
Expand Down
25 changes: 25 additions & 0 deletions docs/theme/tabs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.mdbook-tabs {
display: flex;
}

.mdbook-tab {
background-color: var(--table-alternate-bg);
padding: 0.5rem 1rem;
cursor: pointer;
border: none;
font-size: 1.6rem;
line-height: 1.45em;
}

.mdbook-tab.active {
background-color: var(--table-header-bg);
font-weight: bold;
}

.mdbook-tab-content {
padding: 1rem 0rem;
}

.mdbook-tab-content table {
margin: unset;
}
75 changes: 75 additions & 0 deletions docs/theme/tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Change active tab of tabs.
*
* @param {Element} container
* @param {string} name
*/
const changeTab = (container, name) => {
for (const child of container.children) {
if (!(child instanceof HTMLElement)) {
continue;
}

if (child.classList.contains('mdbook-tabs')) {
for (const tab of child.children) {
if (!(tab instanceof HTMLElement)) {
continue;
}

if (tab.dataset.tabname === name) {
tab.classList.add('active');
} else {
tab.classList.remove('active');
}
}
} else if (child.classList.contains('mdbook-tab-content')) {
if (child.dataset.tabname === name) {
child.classList.remove('hidden');
} else {
child.classList.add('hidden');
}
}
}
};

document.addEventListener('DOMContentLoaded', () => {
const tabs = document.querySelectorAll('.mdbook-tab');
for (const tab of tabs) {
tab.addEventListener('click', () => {
if (!(tab instanceof HTMLElement)) {
return;
}

if (!tab.parentElement || !tab.parentElement.parentElement) {
return;
}

const container = tab.parentElement.parentElement;
const name = tab.dataset.tabname;
const global = container.dataset.tabglobal;

changeTab(container, name);

if (global) {
localStorage.setItem(`mdbook-tabs-${global}`, name);

const globalContainers = document.querySelectorAll(
`.mdbook-tabs-container[data-tabglobal="${global}"]`
);
for (const globalContainer of globalContainers) {
changeTab(globalContainer, name);
}
}
});
}

const containers = document.querySelectorAll('.mdbook-tabs-container[data-tabglobal]');
for (const container of containers) {
const global = container.dataset.tabglobal;

const name = localStorage.getItem(`mdbook-tabs-${global}`);
if (name && document.querySelector(`.mdbook-tab[data-tabname="${name}"]`)) {
changeTab(container, name);
}
}
});
Loading