]> git.wh0rd.org - tt-rss.git/commitdiff
keyboard navigation and cute active headline selection
authorAndrew Dolgov <fox@bah.spb.su>
Thu, 25 Aug 2005 11:20:50 +0000 (12:20 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Thu, 25 Aug 2005 11:20:50 +0000 (12:20 +0100)
backend.php
functions.js
tt-rss.js

index 0105253dcb87b5b0af262b27e932c14b2b4ddff0..bc8524742ebfdf270399a6d399bd445fd61f5856 100644 (file)
 
                $subop = $_GET["subop"];
 
+               if ($subop == "getRelativeId") {
+                       $mode = $_GET["mode"];
+                       $id = $_GET["id"];
+                       $feed_id = $_GET["feed"];
+
+                       if ($id != 'false' && $feed_id != 'false') {
+
+                               if ($mode == 'next') {
+                                       $check_qpart = "updated >= ";
+                               } else {
+                                       $idcheck_qpart = "id < '$id'";
+                               }
+
+                               $result = pg_query("SELECT id FROM ttrss_entries WHERE
+                                       $check_qpart AND
+                                       feed_id = '$feed_id'
+                                       ORDER BY updated DESC LIMIT 1");
+
+                               $result_id = pg_fetch_result($result, 0, "id");
+
+                               print "M $mode : P $id -> P $result_id : F $feed_id";
+
+                       }
+               }
+
                if ($subop == "forceUpdateAllFeeds") {
                        update_all_feeds($link, true);                  
                        outputFeedList($link);
index 8cd5b47cae976467f3e3dc9ec21a29509332060d..0b05ae2e8a0d71d2a220ba4d79d933832253df96 100644 (file)
@@ -1,3 +1,17 @@
+function notify_callback() {
+       var container = document.getElementById('notify');
+       if (xmlhttp.readyState == 4) {
+               container.innerHTML=xmlhttp.responseText;
+       }
+}
+
+function rpc_notify_callback() {
+       var container = document.getElementById('notify');
+       if (xmlhttp_rpc.readyState == 4) {
+               container.innerHTML=xmlhttp_rpc.responseText;
+       }
+}
+
 function param_escape(arg) {
        if (typeof encodeURIComponent != 'undefined')
                return encodeURIComponent(arg); 
@@ -64,6 +78,10 @@ function hotkey_handler(e) {
                localPiggieFunction(false);
        }
 
+       if (typeof localHotkeyHandler != 'undefined') {
+               localHotkeyHandler(keycode);
+       }
+
 }
 
 
index 455a202c931b53608eb5bab20fd9579196067feb..5f34f311ab2f3f18b016da0467c4a6ae9dabacfb 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -9,6 +9,9 @@ var xmlhttp_rpc = false;
 var total_unread = 0;
 var first_run = true;
 
+var active_post_id = false;
+var active_feed_id = false;
+
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
 // JScript gives us Conditional compilation, we can cope with old IE versions.
@@ -32,13 +35,6 @@ if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 
 }
 
-function notify_callback() {
-       var container = document.getElementById('notify');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;
-       }
-}
-
 function feedlist_callback() {
        var container = document.getElementById('feeds');
        if (xmlhttp.readyState == 4) {
@@ -228,6 +224,9 @@ function viewfeed(feed, skip, subop) {
                printLockingError();
                return
        }
+       
+       active_feed_id = feed;
+       active_post_id = false;
 
        xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
                "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
@@ -238,6 +237,17 @@ function viewfeed(feed, skip, subop) {
 
 }
 
+function cleanSelectedHeadlines() {
+       var content = document.getElementById("headlinesList");
+
+       var rows = new Array();
+
+       for (i = 0; i < content.rows.length; i++) {
+               content.rows[i].className = content.rows[i].className.replace("Selected", "");
+       }
+
+}
+
 function view(id,feed_id) {
 
        if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
@@ -256,12 +266,16 @@ function view(id,feed_id) {
                        var feedr = document.getElementById("FEEDR-" + feed_id);
                        feedr.className = feedr.className.replace("Unread", "");
                }
-       
+
                total_unread--;
 
                update_title(); 
        }       
 
+       cleanSelectedHeadlines();
+
+       crow.className = crow.className + "Selected";
+
        var upd_img_pic = document.getElementById("FUPDPIC-" + id);
 
        if (upd_img_pic) {
@@ -270,6 +284,8 @@ function view(id,feed_id) {
 
        document.getElementById('content').innerHTML='Loading, please wait...';         
 
+       active_post_id = id;
+
        xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
        xmlhttp.onreadystatechange=view_callback;
        xmlhttp.send(null);
@@ -320,6 +336,81 @@ function localPiggieFunction(enable) {
        }
 }
 
+function relativeid_callback() {
+
+       if (xmlhttp_rpc.readyState == 4) {
+               notify(xmlhttp_rpc.responseText);
+       }
+
+}
+
+function getVisibleHeadlineIds() {
+
+       var content = document.getElementById("headlinesList");
+
+       var rows = new Array();
+
+       for (i = 0; i < content.rows.length; i++) {
+               var row_id = content.rows[i].id.replace("RROW-", "");
+               if (row_id.length > 0) {
+                               rows.push(row_id);      
+               }
+       }
+
+       return rows;
+
+}
+
+function moveToPost(mode) {
+
+/*     var query_str = "backend.php?op=rpc&subop=getRelativeId&mode=" + mode + 
+               "&feed=" + active_feed_id + "&id=" + active_post_id;
+
+//     notify(query_str);
+
+       if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
+               xmlhttp_rpc.open("GET", query_str, true);
+               xmlhttp_rpc.onreadystatechange=relativeid_callback;
+               xmlhttp_rpc.send(null);
+       } else {
+               printLockingError();
+       } */
+
+       var rows = getVisibleHeadlineIds();
+
+       var prev_id;
+       var next_id;
+
+       for (var i = 0; i < rows.length; i++) {
+               if (rows[i] == active_post_id) {
+                       prev_id = rows[i-1];
+                       next_id = rows[i+1];                    
+               }
+       }
+
+       if (mode == "next" && next_id != undefined) {
+               view(next_id, active_feed_id);
+       }
+
+       if (mode == "prev" && prev_id != undefined) {
+               view(prev_id, active_feed_id);
+       }
+
+}
+
+function localHotkeyHandler(keycode) {
+
+//     notify(keycode);
+
+       if (keycode == 78) {
+               moveToPost('next');
+       }
+
+       if (keycode == 80) {
+               moveToPost('prev');
+       }
+}
+
 
 function init() {
        updateFeedList(false, false);