Fix missing labels (a11y)
Additionally add some missing translations
This commit is contained in:
43
templates/partials/copy-button.html
Normal file
43
templates/partials/copy-button.html
Normal file
@ -0,0 +1,43 @@
|
||||
<script>
|
||||
// Based on https://www.roboleary.net/2022/01/13/copy-code-to-clipboard-blog.html
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
let blocks = document.querySelectorAll("pre[class^='language-']");
|
||||
|
||||
blocks.forEach((block) => {
|
||||
if (navigator.clipboard) {
|
||||
let container = document.createElement("div");
|
||||
container.classList.add("pre-container");
|
||||
|
||||
block.parentNode.insertBefore(container, block);
|
||||
container.appendChild(block);
|
||||
|
||||
let button = document.createElement("button");
|
||||
let icon = document.createElement("i");
|
||||
let span = document.createElement("span");
|
||||
icon.classList.add("icon");
|
||||
span.classList.add("hidden");
|
||||
span.innerHTML = "{{ trans(key='copy_code', lang=lang) }}";
|
||||
button.appendChild(icon);
|
||||
button.appendChild(span);
|
||||
container.appendChild(button);
|
||||
|
||||
button.addEventListener("click", async () => {
|
||||
await copyCode(block, button);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
async function copyCode(block, button) {
|
||||
let code = block.querySelector("code");
|
||||
let text = code.innerText;
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
|
||||
button.classList.add("active");
|
||||
|
||||
setTimeout(() => {
|
||||
button.classList.remove("active");
|
||||
}, 800);
|
||||
}
|
||||
});
|
||||
</script>
|
@ -32,7 +32,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if config.extra.show_copy_button %}
|
||||
<script src="{{ get_url(path='copy-button.js') }}"></script>
|
||||
{% include "partials/copy-button.html" %}
|
||||
{% endif %}
|
||||
|
||||
{% if config.extra.scripts %}
|
||||
|
@ -49,7 +49,7 @@
|
||||
<details>
|
||||
<summary>
|
||||
<i class="icon"></i>
|
||||
<span>Languages</span>
|
||||
<span class="hidden">{{ trans(key="language", lang=lang) }}</span>
|
||||
</summary>
|
||||
<ul>
|
||||
{% for language in config.extra.nav.langs %}
|
||||
@ -65,7 +65,7 @@
|
||||
<li id="feed">
|
||||
<a href="{{ get_url(path=config.feed_filename) }}">
|
||||
<i class="icon"></i>
|
||||
<span>{{ trans(key="feed", lang=lang) }}</span>
|
||||
<span class="hidden">{{ trans(key="feed", lang=lang) }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user