-
Notifications
You must be signed in to change notification settings - Fork 2k
Add tabs to the documentation #3838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build | |
build-pico-sdk-docs | ||
documentation/html | ||
documentation/asciidoc/pico-sdk | ||
.venv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
|
||
/*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */ | ||
.tabs { | ||
margin-bottom: 1.25em; | ||
} | ||
|
||
.tablist > ul { | ||
display: flex; | ||
flex-wrap: nowrap; | ||
overflow-x: scroll; | ||
overflow-y: hidden; | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.tablist > ul li { | ||
align-items: center; | ||
background-color: #eee; | ||
cursor: pointer; | ||
display: flex; | ||
font-weight: bold; | ||
line-height: 1.5; | ||
padding: 0.25em 1em; | ||
position: relative; | ||
} | ||
|
||
.tablist > ul li p { | ||
margin-bottom: 0px !important; | ||
} | ||
|
||
.tablist > ul li:focus-visible { | ||
outline: none; | ||
} | ||
|
||
.tablist.ulist, | ||
.tablist.ulist > ul li { | ||
margin: 0; | ||
} | ||
|
||
.tablist.ulist > ul li + li { | ||
margin-left: 0.25em; | ||
} | ||
|
||
.tabs .tablist li::after { | ||
content: ""; | ||
display: block; | ||
height: 1px; | ||
position: absolute; | ||
bottom: -1px; | ||
left: 0; | ||
right: 0; | ||
} | ||
|
||
.tabs.is-loading .tablist li:not(:first-child), | ||
.tabs:not(.is-loading) .tablist li:not(.is-selected) { | ||
background-color: initial; | ||
border-left: 1px solid #eee; | ||
border-right: 1px solid #eee; | ||
border-top: 1px solid #eee; | ||
} | ||
|
||
.tabs.is-loading .tablist li:first-child::after, | ||
.tabs:not(.is-loading) .tablist li.is-selected::after { | ||
background-color: #eee; | ||
border-top: 2px solid var(--red); | ||
} | ||
|
||
/* | ||
.tabs:not(.is-loading) .tablist li, | ||
.tabs:not(.is-loading) .tablist li::after { | ||
transition: background-color 200ms ease-in-out; | ||
} | ||
*/ | ||
|
||
.tablist > ul p { | ||
line-height: inherit; | ||
margin: 0; | ||
} | ||
|
||
.tabpanel { | ||
background-color: #eee; | ||
padding: 1.25em; | ||
} | ||
|
||
.tablist > ul li { | ||
border-bottom: 0; | ||
} | ||
|
||
.tabs.is-loading .tabpanel + .tabpanel, | ||
.tabs:not(.is-loading) .tabpanel.is-hidden { | ||
display: none; | ||
} | ||
|
||
.tabpanel > :first-child { | ||
margin-top: 0; | ||
} | ||
|
||
/* #content is a signature of the Asciidoctor standalone HTML output */ | ||
#content .tabpanel > :last-child, | ||
#content .tabpanel > :last-child > :last-child, | ||
#content .tabpanel > :last-child > :last-child > li:last-child > :last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
.tablecontainer { | ||
overflow-x: auto; | ||
} | ||
|
||
#content .tablecontainer { | ||
margin-bottom: 1.25em; | ||
} | ||
|
||
#content .tablecontainer > table.tableblock { | ||
margin-bottom: 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,4 +79,4 @@ p#release + #container { | |
display: block; | ||
width: 100%; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
;(function () { /*! Asciidoctor Tabs | Copyright (c) 2018-present Dan Allen | MIT License */ | ||
'use strict' | ||
|
||
var config = (document.currentScript || {}).dataset || {} | ||
var forEach = Array.prototype.forEach | ||
|
||
init(document.querySelectorAll('.tabs')) | ||
|
||
function init (tabsBlocks) { | ||
if (!tabsBlocks.length) return | ||
forEach.call(tabsBlocks, function (tabs) { | ||
var syncIds = tabs.classList.contains('is-sync') ? {} : undefined | ||
var tablist = tabs.querySelector('.tablist ul') | ||
tablist.setAttribute('role', 'tablist') | ||
var start | ||
forEach.call(tablist.querySelectorAll('li'), function (tab, idx) { | ||
tab.tabIndex = -1 | ||
tab.setAttribute('role', tab.classList.add('tab') || 'tab') | ||
var id, anchor, syncId | ||
if (!(id = tab.id) && (anchor = tab.querySelector('a[id]'))) { | ||
id = tab.id = anchor.parentNode.removeChild(anchor).id | ||
} | ||
var panel = id && tabs.querySelector('.tabpanel[aria-labelledby~="' + id + '"]') | ||
if (!panel) return idx ? undefined : toggleSelected(tab, true) // invalid state | ||
syncIds && (((syncId = tab.textContent.trim()) in syncIds) ? (syncId = undefined) : true) && | ||
(syncIds[(tab.dataset.syncId = syncId)] = tab) | ||
idx || (syncIds && (start = { tab: tab, panel: panel })) ? toggleHidden(panel, true) : toggleSelected(tab, true) | ||
tab.setAttribute('aria-controls', panel.id) | ||
panel.setAttribute('role', 'tabpanel') | ||
var onClick = syncId === undefined ? activateTab : activateTabSync | ||
tab.addEventListener('click', onClick.bind({ tabs: tabs, tab: tab, panel: panel })) | ||
}) | ||
if (!tabs.closest('.tabpanel')) { | ||
forEach.call(tabs.querySelectorAll('.tabpanel table.tableblock'), function (table) { | ||
var container = Object.assign(document.createElement('div'), { className: 'tablecontainer' }) | ||
table.parentNode.insertBefore(container, table).appendChild(table) | ||
}) | ||
} | ||
if (start) { | ||
var syncGroupId | ||
for (var i = 0, lst = tabs.classList, len = lst.length, className; i !== len; i++) { | ||
if (!(className = lst.item(i)).startsWith('data-sync-group-id=')) continue | ||
tabs.dataset.syncGroupId = syncGroupId = lst.remove(className) || className.slice(19).replace(/\u00a0/g, ' ') | ||
break | ||
} | ||
if (syncGroupId === undefined) tabs.dataset.syncGroupId = syncGroupId = Object.keys(syncIds).sort().join('|') | ||
var preferredSyncId = 'syncStorageKey' in config && | ||
window[(config.syncStorageScope || 'local') + 'Storage'].getItem(config.syncStorageKey + '-' + syncGroupId) | ||
var tab = preferredSyncId && syncIds[preferredSyncId] | ||
tab && Object.assign(start, { tab: tab, panel: document.getElementById(tab.getAttribute('aria-controls')) }) | ||
toggleSelected(start.tab, true) || toggleHidden(start.panel, false) | ||
} | ||
}) | ||
onHashChange() | ||
toggleClassOnEach(tabsBlocks, 'is-loading', 'remove') | ||
window.setTimeout(toggleClassOnEach.bind(null, tabsBlocks, 'is-loaded', 'add'), 0) | ||
window.addEventListener('hashchange', onHashChange) | ||
} | ||
|
||
function activateTab (e) { | ||
var tab = this.tab | ||
var tabs = this.tabs || (this.tabs = tab.closest('.tabs')) | ||
var panel = this.panel || (this.panel = document.getElementById(tab.getAttribute('aria-controls'))) | ||
querySelectorWithSiblings(tabs, '.tablist .tab', 'tab').forEach(function (el) { | ||
toggleSelected(el, el === tab) | ||
}) | ||
querySelectorWithSiblings(tabs, '.tabpanel', 'tabpanel').forEach(function (el) { | ||
toggleHidden(el, el !== panel) | ||
}) | ||
if (!this.isSync && 'syncStorageKey' in config && 'syncGroupId' in tabs.dataset) { | ||
var storageKey = config.syncStorageKey + '-' + tabs.dataset.syncGroupId | ||
window[(config.syncStorageScope || 'local') + 'Storage'].setItem(storageKey, tab.dataset.syncId) | ||
} | ||
if (!e) return | ||
var loc = window.location | ||
var hashIdx = loc.hash ? loc.href.indexOf('#') : -1 | ||
if (~hashIdx) window.history.replaceState(null, '', loc.href.slice(0, hashIdx)) | ||
e.preventDefault() | ||
} | ||
|
||
function activateTabSync (e) { | ||
activateTab.call(this, e) | ||
var thisTabs = this.tabs | ||
var thisTab = this.tab | ||
var initialY = thisTabs.getBoundingClientRect().y | ||
forEach.call(document.querySelectorAll('.tabs'), function (tabs) { | ||
if (tabs === thisTabs || tabs.dataset.syncGroupId !== thisTabs.dataset.syncGroupId) return | ||
querySelectorWithSiblings(tabs, '.tablist .tab', 'tab').forEach(function (tab) { | ||
if (tab.dataset.syncId === thisTab.dataset.syncId) activateTab.call({ tabs: tabs, tab: tab, isSync: true }) | ||
}) | ||
}) | ||
var shiftedBy = thisTabs.getBoundingClientRect().y - initialY | ||
if (shiftedBy && (shiftedBy = Math.round(shiftedBy))) window.scrollBy({ top: shiftedBy, behavior: 'instant' }) | ||
} | ||
|
||
function querySelectorWithSiblings (scope, selector, siblingClass) { | ||
var el = scope.querySelector(selector) | ||
if (!el) return [] | ||
var result = [el] | ||
while ((el = el.nextElementSibling) && el.classList.contains(siblingClass)) result.push(el) | ||
return result | ||
} | ||
|
||
function toggleClassOnEach (elements, className, method) { | ||
forEach.call(elements, function (el) { | ||
el.classList[method](className) | ||
}) | ||
} | ||
|
||
function toggleHidden (el, state) { | ||
el.classList[(el.hidden = state) ? 'add' : 'remove']('is-hidden') | ||
} | ||
|
||
function toggleSelected (el, state) { | ||
el.setAttribute('aria-selected', '' + state) | ||
el.classList[state ? 'add' : 'remove']('is-selected') | ||
el.tabIndex = state ? 0 : -1 | ||
} | ||
|
||
function onHashChange () { | ||
var id = window.location.hash.slice(1) | ||
if (!id) return | ||
var tab = document.getElementById(~id.indexOf('%') ? decodeURIComponent(id) : id) | ||
if (!(tab && tab.classList.contains('tab'))) return | ||
'syncId' in tab.dataset ? activateTabSync.call({ tab: tab }) : activateTab.call({ tab: tab }) | ||
} | ||
})() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.