26 lines
889 B
JavaScript
26 lines
889 B
JavaScript
function initKeyboardShortcuts() {
|
|
document.addEventListener('keydown', (e) => {
|
|
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
|
|
const activeElement = document.activeElement;
|
|
if (activeElement && activeElement.tagName === 'TEXTAREA') {
|
|
const form = activeElement.closest('form');
|
|
if (form) {
|
|
e.preventDefault();
|
|
form.requestSubmit();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (e.key === 'Escape') {
|
|
if (document.activeElement && document.activeElement.tagName === 'TEXTAREA') {
|
|
document.activeElement.blur();
|
|
}
|
|
|
|
document.querySelectorAll('.notification').forEach(notif => {
|
|
notif.classList.add('hiding');
|
|
setTimeout(() => notif.remove(), 300);
|
|
});
|
|
}
|
|
});
|
|
}
|