]> git.wh0rd.org Git - tt-rss.git/commitdiff
implement basic hotkeys map support in digest; implement next/prev feed hotkeys
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 20 Jan 2013 08:11:36 +0000 (12:11 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 20 Jan 2013 08:11:36 +0000 (12:11 +0400)
plugins/digest/digest.js
plugins/digest/init.php

index 88c4d7dc9dcd5c61976d9eb14fbdfe6bede392a1..637f8da8a81ff67e303ee83d18088784979257ec 100644 (file)
@@ -1,5 +1,7 @@
 var last_feeds = [];
 var init_params = {};
+var hotkeys_map = false;
+var hotkey_prefix = false;
 
 var _active_feed_id = false;
 var _update_timeout = false;
@@ -565,8 +567,13 @@ function parse_feeds(transport) {
                        redraw_feedlist(feeds);
                }
 
+               if (reply['hotkeys']) {
+                       hotkeys_map = reply['hotkeys'];
+               }
+
        } catch (e) {
-               exception_error("parse_feeds", e);
+               console.log(e);
+               //exception_error("parse_feeds", e);
        }
 }
 
@@ -647,7 +654,7 @@ function parse_headlines(transport, replace, no_effects) {
 function init_second_stage() {
        try {
                new Ajax.Request("backend.php", {
-                       parameters: "backend.php?op=digest&method=digestinit",
+                       parameters: "backend.php?op=digest&method=digestinit&init=1",
                        onComplete: function(transport) {
                                parse_feeds(transport);
                                Element.hide("overlay");
@@ -834,15 +841,64 @@ function hotkey_handler(e) {
 
                var keychar = String.fromCharCode(keycode);
 
+               if (!shift_key) keychar = keychar.toLowerCase();
+
                if (keycode == 16) return; // ignore lone shift
                if (keycode == 17) return; // ignore lone ctrl
 
+               var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
+               hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
+               hotkey_prefix = false;
+
+               var hotkey_action = false;
+               var hotkeys = getInitParam("hotkeys");
+
+               for (sequence in hotkeys[1]) {
+                       if (sequence == hotkey) {
+                               hotkey_action = hotkeys[1][sequence];
+                               break;
+                       }
+               }
+
                switch (keycode) {
                case 27: // esc
                        close_article();
-                       break;
+                       return false;
+               }
+
+               switch (hotkey_action) {
+               case "next_feed":
+                       var feeds = $$("#feeds li");
+                       for (var i = 0; i < feeds.length; i++) {
+                               var base_id = feeds[i].id.replace("F-", "");
+
+                               if (base_id == _active_feed_id) {
+                                       if (feeds[i+1]) {
+                                               viewfeed(feeds[i+1].id.replace("F-", ""));
+                                       }
+                                       break;
+                               }
+                       }
+                       return false;
+               case "prev_feed":
+                       var feeds = $$("#feeds li");
+                       for (var i = 0; i < feeds.length; i++) {
+                               var base_id = feeds[i].id.replace("F-", "");
+
+                               if (base_id == _active_feed_id) {
+                                       if (feeds[i-1]) {
+                                               viewfeed(feeds[i-1].id.replace("F-", ""));
+                                       }
+                                       break;
+                               }
+                       }
+                       return false;
+               case "next_article":
+                       return false;
+               case "prev_article":
+                       return false;
                default:
-                       console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
                }
 
 
index 503ae5b5cd760ab7e945009cd17627561c991ad3..05d2f37f017379360c98ae60e94afc436d43e86b 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+// TODO: digest should register digest specific hotkey actions within tt-rss
 class Digest extends Plugin implements IHandler {
 
        private $link;
@@ -90,13 +91,19 @@ class Digest extends Plugin implements IHandler {
        function digestinit() {
                $tmp_feeds = api_get_feeds($this->link, -4, true, false, 0);
 
+               $params = array();
                $feeds = array();
 
                foreach ($tmp_feeds as $f) {
                        if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f);
                }
 
-               print json_encode(array("feeds" => $feeds));
+               if ($_REQUEST["init"] == 1) {
+                       $params["hotkeys"] = get_hotkeys_map($link);
+               }
+               $params["feeds"] = $feeds;
+
+               print json_encode($params);
        }
 
 }