forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tabs for cli/desktop/ui (github#19071)
- Loading branch information
1 parent
3d621ba
commit be8aa2b
Showing
9 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,8 @@ | ||
<nav class="UnderlineNav my-3" id="tool-switcher" | ||
{%- if page.defaultTool %} data-default-tool="{{ page.defaultTool }}"{% endif %}> | ||
<div class="UnderlineNav-body"> | ||
<a href="#" class="UnderlineNav-item tool-switcher" data-tool="webui">GitHub.com</a> | ||
<a href="#" class="UnderlineNav-item tool-switcher" data-tool="cli">CLI</a> | ||
<a href="#" class="UnderlineNav-item tool-switcher" data-tool="desktop">Desktop</a> | ||
</div> | ||
</nav> |
This file contains 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,82 @@ | ||
const supportedTools = ['cli', 'desktop', 'webui'] | ||
const detectedTools = new Set() | ||
|
||
export default function displayToolSpecificContent () { | ||
let tool = getDefaultTool() | ||
|
||
if (!tool) tool = 'webui' | ||
|
||
const toolsInContent = findToolSpecificContent(tool) | ||
|
||
hideSwitcherLinks(toolsInContent) | ||
|
||
showContentForTool(tool) | ||
|
||
// configure links for switching tool content | ||
switcherLinks().forEach(link => { | ||
link.addEventListener('click', (event) => { | ||
event.preventDefault() | ||
showContentForTool(event.target.dataset.tool) | ||
findToolSpecificContent(event.target.dataset.tool) | ||
}) | ||
}) | ||
} | ||
|
||
function showContentForTool (tool) { | ||
// (de)activate switcher link appearances | ||
switcherLinks().forEach(link => { | ||
(link.dataset.tool === tool) | ||
? link.classList.add('selected') | ||
: link.classList.remove('selected') | ||
}) | ||
} | ||
|
||
function findToolSpecificContent (tool) { | ||
// find all tool-specific *block* elements and hide or show as appropriate | ||
// example: {{ #cli }} block content {{/cli}} | ||
Array.from(document.querySelectorAll('.extended-markdown')) | ||
.filter(el => supportedTools.some(tool => el.classList.contains(tool))) | ||
.forEach(el => { | ||
detectTools(el) | ||
el.style.display = el.classList.contains(tool) | ||
? '' | ||
: 'none' | ||
}) | ||
|
||
// find all tool-specific *inline* elements and hide or show as appropriate | ||
// example: <span class="tool-cli">inline content</span> | ||
Array.from(document.querySelectorAll('.tool-cli, .tool-desktop, .tool-webui')) | ||
.forEach(el => { | ||
detectTools(el) | ||
el.style.display = el.classList.contains('tool-' + tool) | ||
? '' | ||
: 'none' | ||
}) | ||
|
||
return Array.from(detectedTools) | ||
} | ||
|
||
// hide links for any tool-specific sections that are not present | ||
function hideSwitcherLinks (toolsInContent) { | ||
Array.from(document.querySelectorAll('a.tool-switcher')) | ||
.forEach(link => { | ||
if (toolsInContent.includes(link.dataset.tool)) return | ||
link.style.display = 'none' | ||
}) | ||
} | ||
|
||
function detectTools (el) { | ||
el.classList.forEach(elClass => { | ||
const value = elClass.replace(/tool-/, '') | ||
if (supportedTools.includes(value)) detectedTools.add(value) | ||
}) | ||
} | ||
|
||
function getDefaultTool () { | ||
const el = document.querySelector('[data-default-tool]') | ||
if (el) return el.dataset.defaultTool | ||
} | ||
|
||
function switcherLinks () { | ||
return Array.from(document.querySelectorAll('a.tool-switcher')) | ||
} |
This file contains 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 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 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 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,25 @@ | ||
--- | ||
title: Default tool | ||
versions: | ||
free-pro-team: '*' | ||
enterprise-server: '*' | ||
github-ae: '*' | ||
defaultTool: cli | ||
--- | ||
|
||
|
||
Intro text | ||
|
||
### Section 1 | ||
|
||
generic text | ||
|
||
{% include tool-switcher %} | ||
{% webui %} dotcom text {% endwebui %} | ||
{% cli %} cli text {% endcli %} | ||
{% desktop %} desktop text {% enddesktop %} | ||
|
||
{% include tool-switcher %} | ||
{% webui %} dotcom text 2 {% endwebui %} | ||
{% cli %} cli text 2 {% endcli %} | ||
{% desktop %} desktop text 2 {% enddesktop %} |
This file contains 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