/
githubmirror
/
jekyll
Обзор
Документация
Войти
/
githubmirror
/
jekyll
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/_includes/anchor_links.html
33 строки
1 KB
Daniel Haim
Improve accessibility of the docs (#9338)
12 янв 2024, 19:57
Не верифицирован
12 янв 2024, 19:57
55e993b
Код
Авторство
О чём код?
<script> /* 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; }; /* 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)); } }); }; /* 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>