You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/04 16:24:20 UTC

[4/6] incubator-ponymail git commit: start work on keyboard shortcuts

start work on keyboard shortcuts

this doesn't actually work yet...


Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/d2a1cacb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/d2a1cacb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/d2a1cacb

Branch: refs/heads/coffee-and-cake
Commit: d2a1cacbbd8449817226fb889d0fb32ea14b1a9c
Parents: 4f22ce5
Author: Daniel Gruno <hu...@apache.org>
Authored: Sun Sep 4 17:45:30 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Sun Sep 4 17:45:30 2016 +0200

----------------------------------------------------------------------
 site/js/coffee/keyboard_shortcuts.coffee | 87 +++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/d2a1cacb/site/js/coffee/keyboard_shortcuts.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/keyboard_shortcuts.coffee b/site/js/coffee/keyboard_shortcuts.coffee
new file mode 100644
index 0000000..ddb3129
--- /dev/null
+++ b/site/js/coffee/keyboard_shortcuts.coffee
@@ -0,0 +1,87 @@
+###
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+###
+
+### dealWithKeyboard: Handles what happens when you hit the escape key ###
+dealWithKeyboard = (e) ->
+    splash = get('splash')
+    
+    ### escape key: hide composer/settings/thread ###
+    if (e.keyCode == 27)
+        
+        if (splash and splash.style.display == 'block')
+            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 ###
+            tid = (current_thread||"").toString().replace(/@<.+>/, "")
+            thread = get('thread_' + tid) || get('thread_treeview_' + tid)
+
+            ### minimize datepicker if shown ###
+            dp = get('datepicker_popup')
+            if dp and dp.style.display == "block"
+                dp.show(false)
+            
+            else if thread
+                ### Otherwise, collapse a 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 i in kiddos
+                        kiddos[i].style.display = 'none';
+                    
+                    
+    ### Make sure the below shortcuts don't interfere with normal operations ###
+    if splash.style.display != 'block' and document.activeElement.nodeName != 'INPUT' and not 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
+                  )
+        
+        else if e.keyCode == 67
+            ### C key: compose ###
+            compose(null, ponymail_list, 'new')
+        else if e.keyCode == 82
+            ### R key: reply ###
+            if (openEmail() && last_opened_email)
+                compose(last_opened_email, null, 'reply')
+        else if e.keyCode == 83
+            ### S key: quick search ###
+            if get('q')
+                get('q').focus()
+
+
+### Add listener for keys (mostly for escape key for hiding stuff) ###
+window.addEventListener("keyup", dealWithKeyboard, false);