]> git.wh0rd.org - tt-rss.git/blobdiff - js/tt-rss.js
remove some unnecessary element IDs
[tt-rss.git] / js / tt-rss.js
index e25dff18ecf34b38f7d7bc8aee180fe5f33b45f7..1270f6e3337f6c8e044aa1be01702eb33fd8ffc5 100644 (file)
@@ -1,13 +1,11 @@
 /* global dijit, __ */
 
 let global_unread = -1;
-let hotkey_prefix = false;
-let hotkey_prefix_pressed = false;
-let hotkey_actions = {};
 let _widescreen_mode = false;
 let _rpc_seq = 0;
 let _active_feed_id = 0;
 let _active_feed_is_cat = false;
+let hotkey_actions = {};
 
 function next_seq() {
        _rpc_seq += 1;
@@ -237,17 +235,15 @@ function init() {
                                                return false;
 
                                        loading_set_progress(30);
-
-                                       const a = document.createElement('audio');
-
-                                       const hasAudio = !!a.canPlayType;
-                                       const hasSandbox = "sandbox" in document.createElement("iframe");
-                                       const hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
-                                       const clientTzOffset = new Date().getTimezoneOffset() * 60;
-
                                        init_hotkey_actions();
 
-                                       const params = {
+                    const a = document.createElement('audio');
+                    const hasAudio = !!a.canPlayType;
+                    const hasSandbox = "sandbox" in document.createElement("iframe");
+                    const hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
+                    const clientTzOffset = new Date().getTimezoneOffset() * 60;
+
+                    const params = {
                             op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
                             hasMp3: hasMp3,
                             clientTzOffset: clientTzOffset,
@@ -303,32 +299,6 @@ function init_hotkey_actions() {
        hotkey_actions["prev_article_noexpand"] = function() {
                moveToPost('prev', true, true);
        };
-       hotkey_actions["collapse_article"] = function() {
-               const id = getActiveArticleId();
-               const elem = $("CICD-"+id);
-
-               if (elem) {
-                       if (elem.visible()) {
-                               cdmCollapseArticle(null, id);
-                       }
-                       else {
-                               cdmExpandArticle(id);
-                       }
-               }
-       };
-       hotkey_actions["toggle_expand"] = function() {
-               const id = getActiveArticleId();
-               const elem = $("CICD-"+id);
-
-               if (elem) {
-                       if (elem.visible()) {
-                               cdmCollapseArticle(null, id, false);
-                       }
-                       else {
-                               cdmExpandArticle(id);
-                       }
-               }
-       };
        hotkey_actions["search_dialog"] = function() {
                search();
        };
@@ -365,13 +335,7 @@ function init_hotkey_actions() {
                scrollArticle(-40);
        };
        hotkey_actions["close_article"] = function() {
-               if (isCdmMode()) {
-                       if (!getInitParam("cdm_expanded")) {
-                               cdmCollapseArticle(false, getActiveArticleId());
-                       }
-               } else {
-                       closeArticlePanel();
-               }
+               closeArticlePanel();
        };
        hotkey_actions["email_article"] = function() {
                if (typeof emailArticle != "undefined") {
@@ -535,16 +499,6 @@ function init_hotkey_actions() {
             viewCurrentFeed();
                })
        };
-       hotkey_actions["toggle_cdm_expanded"] = function() {
-               notify_progress("Loading, please wait...");
-
-        const value = getInitParam("cdm_expanded") ? "false" : "true";
-
-               xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => {
-            setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
-            viewCurrentFeed();
-        });
-       };
 }
 
 function init_second_stage() {
@@ -596,7 +550,7 @@ function init_second_stage() {
        if ('sessionStorage' in window && window['sessionStorage'] !== null)
                sessionStorage.clear();
 
-       const hotkeys = getInitParam("hotkeys");
+       /*const hotkeys = getInitParam("hotkeys");
        const tmp = [];
 
        for (const sequence in hotkeys[1]) {
@@ -605,7 +559,7 @@ function init_second_stage() {
        }
 
        hotkeys[1] = tmp;
-       setInitParam("hotkeys", hotkeys);
+       setInitParam("hotkeys", hotkeys);*/
 
        _widescreen_mode = getInitParam("widescreen");
        switchPanelMode(_widescreen_mode);
@@ -767,65 +721,18 @@ function viewModeChanged() {
 }
 
 function hotkey_handler(e) {
-
        if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
 
-       let keycode = e.which;
-
-       if (keycode == 27) { // escape and drop prefix
-               hotkey_prefix = false;
-       }
-
-       if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl
-
-       const hotkeys = getInitParam("hotkeys");
-       const keychar = String.fromCharCode(keycode).toLowerCase();
-
-       if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
-
-               const date = new Date();
-               const ts = Math.round(date.getTime() / 1000);
-
-               hotkey_prefix = keychar;
-               hotkey_prefix_pressed = ts;
-
-               $("cmdline").innerHTML = keychar;
-               Element.show("cmdline");
-
-               e.stopPropagation();
+    const action_name = keyevent_to_action(e);
 
-               // returning false here literally disables ctrl-c in browser lol (because C is a valid prefix)
-               return true;
-       }
-
-       Element.hide("cmdline");
-
-       let hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
-
-       // ensure ^*char notation
-       if (e.shiftKey) hotkey = "*" + hotkey;
-       if (e.ctrlKey) hotkey = "^" + hotkey;
-       if (e.altKey) hotkey = "+" + hotkey;
-       if (e.metaKey) hotkey = "%" + hotkey;
-
-       hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
-       hotkey_prefix = false;
-
-       let hotkey_action = false;
+    if (action_name) {
+        const action_func = hotkey_actions[action_name];
 
-       for (const sequence in hotkeys[1]) {
-               if (sequence == hotkey) {
-                       hotkey_action = hotkeys[1][sequence];
-                       break;
-               }
-       }
-
-       const action = hotkey_actions[hotkey_action];
-
-       if (action != null) {
-               action();
-               e.stopPropagation();
-               return false;
+        if (action_func != null) {
+            action_func();
+            e.stopPropagation();
+            return false;
+        }
        }
 }