A lot of small changes improving keyboard navigation, readability and accesibility

This commit is contained in:
Alex Shpak
2025-10-09 22:58:13 +02:00
parent 0593f02604
commit 6baf098e54
27 changed files with 95 additions and 101 deletions
+6 -18
View File
@@ -1,23 +1,11 @@
(function () {
function select(element) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
document.querySelectorAll("pre code").forEach(code => {
code.addEventListener("click", function (event) {
if (window.getSelection().toString()) {
return;
}
select(code.parentElement);
document.querySelectorAll("pre:has(code)").forEach(code => {
code.addEventListener("click", code.focus);
code.addEventListener("copy", function (event) {
event.preventDefault();
if (navigator.clipboard) {
navigator.clipboard.writeText(code.parentElement.textContent);
const content = window.getSelection().toString() || code.textContent;
navigator.clipboard.writeText(content);
}
});
});