docs: Start building quick-assist feature

This commit is contained in:
Matthew Holt 2023-09-19 23:03:11 -06:00 committed by Francis Lavoie
parent 46b6ce9657
commit 2b03c7c866
No known key found for this signature in database
GPG key ID: 0F66EE1687682239
10 changed files with 709 additions and 292 deletions

View file

@ -11,18 +11,24 @@ ready(function() {
}
currentPageLink?.classList?.add('current');
// generate in-page nav before adding anchor links to headings
// generate in-page nav before adding anchor links to headings;
// only show sidebar if there are any navigable headers
// TODO: support h3 too
const spacingMS = 50;
let delay = spacingMS;
$$('main article h2').forEach(elem => {
const a = document.createElement('a');
a.innerText = elem.innerText;
a.href = `#${elem.id}`;
setTimeout(function() {
$('#pagenav').append(a);
}, delay);
delay += spacingMS;
});
const h2elems = $$('main article h2');
if (h2elems.length) {
$('#pagenav .heading').style.display = 'block';
h2elems.forEach(elem => {
const a = document.createElement('a');
a.innerText = elem.innerText;
a.href = `#${elem.id}`;
setTimeout(function() {
$('#pagenav').append(a);
}, delay);
delay += spacingMS;
});
}
// add anchor links, inspired by https://github.com/bryanbraun/anchorjs
$$('article > h2[id], article > h3[id], article > h4[id], article > h5[id], article > h6[id]').forEach(function(elem) {
@ -84,6 +90,7 @@ ready(function() {
});
});
// toggle left-nav when menu link is clicked
on('click', '#docs-menu', e => {
const nav = $('#docs-menu-container');
if (!nav.offsetHeight) {