mailwolt/resources/js/ui/command.js

41 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

(function(){
// OS erkennen (sehr defensiv)
const ua = navigator.userAgent || '';
const platform = navigator.platform || '';
const isMac = /Mac|Macintosh|Mac OS X/i.test(ua) || /Mac|iPhone|iPad|iPod/i.test(platform);
// Shortcut-Label setzen
const kbd = document.getElementById('searchShortcutKbd');
if (kbd) kbd.textContent = isMac ? '⌘K' : 'Ctrl+K';
// Fallback: Tastenkombi abfangen, falls global nicht gebunden
const open = () => {
if (window.Livewire) {
window.Livewire.dispatch('openModal', { component: 'ui.search.modal.search-palette-modal' });
}
};
document.addEventListener('keydown', (e) => {
const k = (e.key || '').toLowerCase();
const meta = isMac ? e.metaKey : e.ctrlKey;
if (meta && k === 'k' && !e.shiftKey && !e.altKey) {
e.preventDefault();
open();
}
});
// Optional: Button auch via JS öffnen können
const btn = document.getElementById('openSearchPaletteBtn');
if (btn) btn.addEventListener('click', open);
})();
// document.addEventListener('keydown', (e) => {
// const isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
// const meta = isMac ? e.metaKey : e.ctrlKey;
// if (meta && e.key.toLowerCase() === 'k') {
// e.preventDefault();
// // LivewireUI Modal öffnen
// Livewire.dispatch('openModal', { component: 'ui.search.modal.search-palette-modal' });
// }
// });