feat: Enhance navigation accessibility and update terminal commands
This commit is contained in:
64
script.js
64
script.js
@@ -8,28 +8,68 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
if (navToggle && navLinks) {
|
||||
const setExpanded = (isOpen) => {
|
||||
navLinks.classList.toggle('is-open', isOpen);
|
||||
navToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
|
||||
};
|
||||
|
||||
navToggle.addEventListener('click', () => {
|
||||
navLinks.classList.toggle('is-open');
|
||||
const nextState = !navLinks.classList.contains('is-open');
|
||||
setExpanded(nextState);
|
||||
});
|
||||
|
||||
navLinks.addEventListener('click', (event) => {
|
||||
if (event.target.closest('a')) {
|
||||
setExpanded(false);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Escape' && navLinks.classList.contains('is-open')) {
|
||||
setExpanded(false);
|
||||
navToggle.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll('[data-copy]').forEach((button) => {
|
||||
const defaultLabel = button.textContent;
|
||||
const setStatus = (label) => {
|
||||
button.textContent = label;
|
||||
setTimeout(() => {
|
||||
button.textContent = defaultLabel;
|
||||
}, 1800);
|
||||
};
|
||||
|
||||
button.addEventListener('click', () => {
|
||||
const target = document.querySelector(button.dataset.copy);
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard?.writeText(target.textContent.trim()).then(() => {
|
||||
button.textContent = 'Copied!';
|
||||
setTimeout(() => {
|
||||
button.textContent = 'Copy Install Command';
|
||||
}, 1800);
|
||||
}).catch(() => {
|
||||
button.textContent = 'Unable to copy';
|
||||
setTimeout(() => {
|
||||
button.textContent = 'Copy Install Command';
|
||||
}, 1800);
|
||||
});
|
||||
const textToCopy = target.textContent.trim();
|
||||
const clipboard = navigator.clipboard;
|
||||
|
||||
if (clipboard && typeof clipboard.writeText === 'function') {
|
||||
clipboard.writeText(textToCopy).then(() => {
|
||||
setStatus('Copied!');
|
||||
}).catch(() => {
|
||||
setStatus('Copy manually');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(target);
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
const successful = document.execCommand('copy');
|
||||
selection.removeAllRanges();
|
||||
setStatus(successful ? 'Copied!' : 'Copy manually');
|
||||
} catch (error) {
|
||||
setStatus('Copy manually');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user