️ fix: improve accessibility and i18n (#183)

This commit is contained in:
Óscar Fernández
2023-10-02 18:08:57 +02:00
committed by GitHub
parent 28fb52581f
commit 2c6ac293ad
25 changed files with 214 additions and 49 deletions

View File

@@ -1,6 +1,13 @@
const copiedText = document.getElementById('copy-success').textContent;
const initCopyText = document.getElementById('copy-init').textContent;
const changeIcon = (copyDiv, className) => {
copyDiv.classList.add(className);
setTimeout(() => copyDiv.classList.remove(className), 2500);
copyDiv.setAttribute("aria-label", copiedText);
setTimeout(() => {
copyDiv.classList.remove(className);
copyDiv.setAttribute("aria-label", initCopyText);
}, 2500);
};
const addCopyEventListenerToDiv = (copyDiv, block) => {
@@ -31,6 +38,9 @@ const getTableCode = (block) => {
document.querySelectorAll("pre").forEach((block) => {
const copyDiv = document.createElement("div");
copyDiv.setAttribute("role", "button");
copyDiv.setAttribute("aria-label", initCopyText);
copyDiv.setAttribute("title", initCopyText);
copyDiv.className = "copy-code";
block.prepend(copyDiv);
addCopyEventListenerToDiv(copyDiv, block);