Skip to content
Snippets Groups Projects
hotkeys.js 2.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • Mousetrap.bind('n', function()
    {
    
        {
            window.location.href = rootURL + '/transactions/newTransaction/normal';
        }
    
    Mousetrap.bind('t', function()
    {
    
        {
            window.location.href = rootURL + '/transactions/newTransaction/transfer';
        }
    
    Mousetrap.bind('v', function()
    {
        if(areHotKeysEnabled())
        {
    
            window.location.href = rootURL + '/templates';
    
    Mousetrap.bind('f', function()
    {
    
        {
            window.location.href = rootURL + '/transactions#modalFilter';
        }
    
    Mousetrap.bind('s', function(e)
    
        {
            document.getElementById('search').focus();
    
            e.preventDefault();
    
    Mousetrap.bind('esc', function()
    {
        if(isSearchFocused())
        {
    
            document.getElementById('nav-logo-container').focus();
        }
    });
    
    Mousetrap.bind('o', function()
    {
        if(areHotKeysEnabled())
        {
            window.location.href = rootURL + '/transactions';
        }
    });
    
    
    let saveTransactionOrTemplateButton = document.getElementById('button-save-transaction');
    if(saveTransactionOrTemplateButton !== null)
    {
        Mousetrap(document.querySelector('body')).bind('mod+enter', function(e)
        {
            document.getElementById('button-save-transaction').click();
        });
    }
    
        return !isSearchFocused() && !isCustomSelectFocused()  && !isTemplateSearchFocused();
    
    function isSearchFocused()
    {
    
    Robert Goldmann's avatar
    Robert Goldmann committed
        let searchElement = document.getElementById('search');
    
        return document.activeElement === searchElement;
    }
    
    function isTemplateSearchFocused()
    {
        let templateSearchElement = document.getElementById('searchTemplate');
        return document.activeElement === templateSearchElement;
    }
    
    
    function isCustomSelectFocused()
    
       let customSelects = document.querySelectorAll('.custom-select');
        for(let i = 0; i < customSelects.length; i++)
    
            if(customSelects[i].classList.contains('open'))
            {
                return true;
            }