/** * Keyboard shortcuts for power users */ document.addEventListener('DOMContentLoaded', function() { document.addEventListener('keydown', function(e) { // ESC: Close modals, cancel edit mode, blur inputs if (e.key === 'Escape') { // Close any open modals first const openModals = document.querySelectorAll('.modal-overlay'); let closedModal = false; openModals.forEach(modal => { if (modal.style.display !== 'none' && modal.offsetParent !== null) { modal.remove(); document.body.classList.remove('modal-open'); closedModal = true; } }); // Close settings modal if open const settingsModal = document.getElementById('settingsModal'); if (settingsModal && settingsModal.style.display !== 'none') { settingsModal.style.display = 'none'; document.body.classList.remove('modal-open'); closedModal = true; } // Close advanced search modal if open const searchModal = document.getElementById('advancedSearchModal'); if (searchModal && searchModal.style.display !== 'none') { searchModal.style.display = 'none'; document.body.classList.remove('modal-open'); closedModal = true; } // If we closed a modal, stop here if (closedModal) { e.preventDefault(); return; } // Blur any focused input if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable) { e.target.blur(); } // Cancel edit mode on ticket pages const editButton = document.getElementById('editButton'); if (editButton && editButton.classList.contains('active')) { window.location.reload(); } return; } // Skip other shortcuts if user is typing in an input/textarea if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.isContentEditable) { return; } // Ctrl/Cmd + E: Toggle edit mode (on ticket pages) if ((e.ctrlKey || e.metaKey) && e.key === 'e') { e.preventDefault(); const editButton = document.getElementById('editButton'); if (editButton) { editButton.click(); toast.info('Edit mode ' + (editButton.classList.contains('active') ? 'enabled' : 'disabled')); } } // Ctrl/Cmd + S: Save ticket (on ticket pages) if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); const editButton = document.getElementById('editButton'); if (editButton && editButton.classList.contains('active')) { editButton.click(); toast.success('Saving ticket...'); } } // Ctrl/Cmd + K: Focus search (on dashboard) if ((e.ctrlKey || e.metaKey) && e.key === 'k') { e.preventDefault(); const searchBox = document.querySelector('.search-box'); if (searchBox) { searchBox.focus(); searchBox.select(); } } // ? : Show keyboard shortcuts help (requires Shift on most keyboards) if (e.key === '?') { e.preventDefault(); showKeyboardHelp(); } }); }); function showKeyboardHelp() { // Check if help is already showing if (document.getElementById('keyboardHelpModal')) { return; } const modal = document.createElement('div'); modal.id = 'keyboardHelpModal'; modal.className = 'modal-overlay'; modal.innerHTML = ` `; document.body.appendChild(modal); // Add event listener for the close button modal.querySelector('[data-action="close-shortcuts-modal"]').addEventListener('click', function() { modal.remove(); }); }