Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve accessibility of the docs (#9338)
Merge pull request 9338
- Loading branch information
1 parent
108c841
commit 55e993b
Showing
13 changed files
with
98 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
<script> | ||
var anchorForId = function (id) { | ||
var anchor = document.createElement("a"); | ||
anchor.className = "header-link"; | ||
anchor.href = "#" + id; | ||
anchor.innerHTML = "<span class=\"sr-only\">Permalink</span><i class=\"fa fa-link\"></i>"; | ||
anchor.title = "Permalink"; | ||
return anchor; | ||
}; | ||
/* Creates an anchor element with the given ID and link for the permalink*/ | ||
const anchorForId = (id) => { | ||
const anchor = document.createElement("a"); | ||
anchor.className = "header-link"; | ||
anchor.href = `#${id}`; | ||
anchor.innerHTML = `<span class="sr-only">Permalink</span><i class="fa fa-link" aria-hidden="true"></i>`; | ||
anchor.title = "Permalink"; | ||
return anchor; | ||
}; | ||
|
||
var linkifyAnchors = function (level, containingElement) { | ||
var headers = containingElement.getElementsByTagName("h" + level); | ||
for (var h = 0; h < headers.length; h++) { | ||
var header = headers[h]; | ||
|
||
if (typeof header.id !== "undefined" && header.id !== "") { | ||
header.appendChild(anchorForId(header.id)); | ||
} | ||
/* Finds all headers of the specified level within the given element, and adds a permalink to each header*/ | ||
const linkifyAnchors = (level, containingElement) => { | ||
const headers = Array.from(containingElement.getElementsByTagName(`h${level}`)); | ||
headers.forEach((header) => { | ||
if (header.id) { | ||
header.appendChild(anchorForId(header.id)); | ||
} | ||
}; | ||
}); | ||
}; | ||
|
||
document.onreadystatechange = function () { | ||
if (this.readyState === "complete") { | ||
var contentBlock = document.getElementsByClassName("docs")[0] || document.getElementsByClassName("news")[0]; | ||
if (!contentBlock) { | ||
return; | ||
} | ||
for (var level = 1; level <= 6; level++) { | ||
linkifyAnchors(level, contentBlock); | ||
} | ||
/* Executes the function when the document is ready */ | ||
document.onreadystatechange = () => { | ||
if (document.readyState === "complete") { | ||
const contentBlock = document.getElementsByClassName("docs")[0] | ||
?? document.getElementsByClassName("news")[0]; | ||
if (!contentBlock) { return; } | ||
for (let level = 1; level <= 6; level++) { | ||
linkifyAnchors(level, contentBlock); | ||
} | ||
}; | ||
} | ||
}; | ||
</script> |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<div class="docs-nav-mobile unit whole show-on-mobiles"> | ||
<select onchange="if (this.value) window.location.href=this.value"> | ||
<select id="doc-nav" onchange="navigateToUrl(this)" aria-label="Select a page from the documentation"> | ||
<option value="">Navigate the docs…</option> | ||
{% for section in site.data.docs_nav -%} | ||
<optgroup label="{{ section.title }}"> | ||
{%- for item in section.docs -%} | ||
{% assign p = site.docs | where: "url", item.link | first %} | ||
<option value="{{ p.url | relative_url }}"> | ||
{{- p.menu_name | default: p.title -}} | ||
</option> | ||
{%- endfor %} | ||
</optgroup> | ||
{% endfor -%} | ||
{% for section in site.data.docs_nav %} | ||
<optgroup label="{{ section.title }}"> | ||
{%- for item in section.docs -%} | ||
{% assign page = site.docs | where: "url", item.link | first %} | ||
<option value="{{ page.url | relative_url }}"> | ||
{{- page.menu_name | default: page.title -}} | ||
</option> | ||
{%- endfor %} | ||
</optgroup> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
</div> |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
<input type="text" id="docsearch-input" placeholder="Search the docs…"> | ||
<input type="text" id="docsearch-input" placeholder="Search the docs…" aria-label="Search"> |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js" defer></script> | ||
<script> docsearch({ | ||
apiKey: '50fe39c839958dfad797000f33e2ec17', | ||
indexName: 'jekyllrb', | ||
inputSelector: '#docsearch-input', | ||
enhancedSearchInput: true, | ||
debug: false // Set debug to true if you want to inspect the dropdown | ||
debug: false | ||
}); | ||
</script> |
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<div class="docs-nav-mobile unit whole show-on-mobiles"> | ||
<select onchange="if (this.value) window.location.href=this.value"> | ||
<select id="tutorial-nav" onchange="navigateToUrl(this)" aria-label="Select a tutorial"> | ||
<option value="">Navigate the tutorials…</option> | ||
{% for section in site.data.tutorials -%} | ||
<optgroup label="{{ section.title }}"> | ||
{% for item in section.tutorials -%} | ||
{% assign item_url = item | prepend:"/tutorials/" | append:"/" -%} | ||
{% assign tutorial = site.tutorials | where: "url", item_url | first -%} | ||
<option value="{{ tutorial.url | relative_url }}">{{ tutorial.title }}</option> | ||
{% endfor -%} | ||
</optgroup> | ||
<optgroup label="{{ section.title }}"> | ||
{% for item in section.tutorials -%} | ||
{% assign item_url = item | prepend:"/tutorials/" | append:"/" -%} | ||
{% assign tutorial = site.tutorials | where: "url", item_url | first -%} | ||
<option value="{{ tutorial.url | relative_url }}">{{ tutorial.title }}</option> | ||
{% endfor -%} | ||
</optgroup> | ||
{% endfor -%} | ||
</select> | ||
</div> | ||
</div> |
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