function dealWithKeyboard()

in site/js/dev/ponymail_zzz.js [20:95]


function dealWithKeyboard(e) {
    
    // escape key: hide composer/settings/thread
    if (e.keyCode == 27) {
        if (document.getElementById('splash').style.display == 'block') {
            document.getElementById('splash').style.display = "none"
            saveDraft()
        } else if (location.href.search(/list\.html/) != -1) { // should only work for the list view
            
            // If datepicker popup is shown, hide it on escape
            var thread = document.getElementById('thread_' + current_thread.toString().replace(/@<.+>/, ""))
            // try treeview if all else fails
            if (!thread) {
                thread = document.getElementById('thread_treeview_' + current_thread.toString().replace(/@<.+>/, ""))
            }
            if (document.getElementById('datepicker_popup') && document.getElementById('datepicker_popup').style.display == "block") {
                document.getElementById('datepicker_popup').style.display = "none"
            }
            // otherwise, collapse a thread?
            else if (thread) {
                if (thread.style.display == 'block') {
                    if (prefs.displayMode == 'treeview') {
                        toggleEmails_threaded(current_thread, true)
                        toggleEmails_treeview(current_thread, true)
                    } else {
                        toggleEmails_threaded(current_thread, true)
                    }
                } else {
                    // Close all threads?
                    kiddos = []
                    traverseThread(document.body, '(thread|helper)_', 'DIV')
                    for (var i in kiddos) {
                        kiddos[i].style.display = 'none';
                    }
                }
            }
        }
    }
    
    // Make sure the below shortcuts don't interfere with normal operations
    if (document.getElementById('splash').style.display != 'block' && document.activeElement.nodeName != 'INPUT' && !e.ctrlKey) {
            
        // H key: show help
        if (e.keyCode == 72) {
            popup("Keyboard shortcuts",
                  "<pre>\
                  <b>H:</b>Show this help menu<br/>\
                  <b>C:</b>Compose a new email to the current list<br/>\
                  <b>R:</b>Reply to the last opened email<br/>\
                  <b>S:</b>Go to the quick search bar<br/>\
                  <b>Esc:</b>Hide/collapse current email or thread<br/>\
                  </pre>\
                  You can also, in some cases, use the mouse wheel to scroll up/down the list view",
                  10
                  )
        }
        
        // C key: compose
        else if (e.keyCode == 67) {
            compose(null, xlist, 'new')
        }
        // R key: reply
        else if (e.keyCode == 82) {
            if (openEmail() && last_opened_email) {
                compose(last_opened_email, null, 'reply')
            }
        }
        // S key: quick search
        else if (e.keyCode == 83) {
            if (document.getElementById('q')) {
                document.getElementById('q').focus()
            }
            
        }
    }
}