]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
inputify buttons, store view modes in session cookies, disable headline toolbar initially
[tt-rss.git] / tt-rss.js
index 392ec70d8f53df647ecee526377aa6c5f85788e8..34ab7102c0c3ae5e330b142899dd8a8233cfaa0c 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -5,10 +5,19 @@
 
 var xmlhttp = false;
 var xmlhttp_rpc = false;
+var xmlhttp_view = false;
 
 var total_unread = 0;
 var first_run = true;
 
+var active_post_id = false;
+var active_feed_id = false;
+var active_offset = false;
+
+var total_feed_entries = false;
+
+var search_query = "";
+
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
 // JScript gives us Conditional compilation, we can cope with old IE versions.
@@ -18,8 +27,12 @@ try {
 } catch (e) {
        try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+               xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
+               xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
                xmlhttp = false;
+               xmlhttp_rpc = false;
+               xmlhttp_view = false;
        }
 }
 @end @*/
@@ -27,18 +40,7 @@ try {
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
        xmlhttp_rpc = new XMLHttpRequest();
-
-}
-
-function printLockingError() {
-       notify("Please wait until operation finishes");
-}
-
-function notify_callback() {
-       var container = document.getElementById('notify');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;
-       }
+       xmlhttp_view = new XMLHttpRequest();
 }
 
 function feedlist_callback() {
@@ -46,86 +48,64 @@ function feedlist_callback() {
        if (xmlhttp.readyState == 4) {
                container.innerHTML=xmlhttp.responseText;
 
-               var feedtu = document.getElementById("FEEDTU");
-
-               if (feedtu) {
-                       total_unread = feedtu.innerHTML;
-                       update_title();
-               }
-
                if (first_run) {
-                       scheduleFeedUpdate();
+                       scheduleFeedUpdate(false);
                        first_run = false;
                } else {
                        notify("");
-               }
-       }
+               } 
+       } 
 }
 
-function viewfeed_callback() {
-       var container = document.getElementById('headlines');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML = xmlhttp.responseText;
-
-               var factive = document.getElementById("FACTIVE");
-               var funread = document.getElementById("FUNREAD");
-               var ftotal = document.getElementById("FTOTAL");
-
-               if (ftotal && factive && funread) {
-                       var feed_id = factive.innerHTML;
-
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
-                       var feedt = document.getElementById("FEEDT-" + feed_id);
-                       var feedu = document.getElementById("FEEDU-" + feed_id);
+function refetch_callback() {
 
-                       feedt.innerHTML = ftotal.innerHTML;
-                       feedu.innerHTML = funread.innerHTML;
+       if (xmlhttp_rpc.readyState == 4) {
+               notify("All feeds updated");
+               var container = document.getElementById('feeds');
+               container.innerHTML = xmlhttp_rpc.responseText;
+               document.title = "Tiny Tiny RSS";
+       } 
+}
 
-                       if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                                       feedr.className = feedr.className + "Unread";
-                       } else if (feedu.innerHTML <= 0) {      
-                                       feedr.className = feedr.className.replace("Unread", "");
-                       }
+function updateFeed(feed_id) {
 
-               }
+       var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
 
-               notify("");
+       if (xmlhttp_ready(xmlhttp_rpc)) {
+               xmlhttp_rpc.open("GET", query_str, true);
+               xmlhttp_rpc.onreadystatechange=feed_update_callback;
+               xmlhttp_rpc.send(null);
+       } else {
+               printLockingError();
+       }   
 
-       }       
 }
 
-function view_callback() {
-       var container = document.getElementById('content');
-       if (xmlhttp.readyState == 4) {
-               container.innerHTML=xmlhttp.responseText;               
-       }
-}
+function scheduleFeedUpdate(force) {
 
-function refetch_callback() {
-       if (xmlhttp_rpc.readyState == 4) {
-               // feeds are updated in background
-               updateFeedList(false, false);
-//             notify("All feeds updated");
-       }
-}
+       notify("Updating feeds in background...");
 
-function scheduleFeedUpdate() {
+       document.title = "Tiny Tiny RSS - Updating...";
 
-       notify("Updating feeds in background...");
+       var query_str = "backend.php?op=rpc&subop=";
 
-       var query_str = "backend.php?op=rpc&subop=forceUpdateAllFeeds";
+       if (force) {
+               query_str = query_str + "forceUpdateAllFeeds";
+       } else {
+               query_str = query_str + "updateAllFeeds";
+       }
 
-       if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
+       if (xmlhttp_ready(xmlhttp_rpc)) {
                xmlhttp_rpc.open("GET", query_str, true);
                xmlhttp_rpc.onreadystatechange=refetch_callback;
                xmlhttp_rpc.send(null);
        } else {
                printLockingError();
-       }
+       }   
 }
 
 function updateFeedList(silent, fetch) {
-       
+
        if (silent != true) {
                notify("Loading feed list...");
        }
@@ -134,7 +114,7 @@ function updateFeedList(silent, fetch) {
 
        if (fetch) query_str = query_str + "&fetch=yes";
 
-       if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
+       if (xmlhttp_ready(xmlhttp)) {
                xmlhttp.open("GET", query_str, true);
                xmlhttp.onreadystatechange=feedlist_callback;
                xmlhttp.send(null);
@@ -143,9 +123,10 @@ function updateFeedList(silent, fetch) {
        }
 }
 
+/*
 function catchupPage(feed) {
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
@@ -157,36 +138,56 @@ function catchupPage(feed) {
        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);      
-                       content.rows[i].className = content.rows[i].className.replace("Unread", "");
+                       if (content.rows[i].className.match("Unread")) {
+                               rows.push(row_id);      
+                               content.rows[i].className = content.rows[i].className.replace("Unread", "");
+                       }
+
+                       var upd_img_pic = document.getElementById("FUPDPIC-" + row_id);
+                       if (upd_img_pic) {
+                               upd_img_pic.innerHTML = "";
+                       } 
                }
        }
 
-       var feedr = document.getElementById("FEEDR-" + feed);
-       var feedu = document.getElementById("FEEDU-" + feed);
-
-       feedu.innerHTML = feedu.innerHTML - rows.length;
+       if (rows.length > 0) {
 
-       if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                       feedr.className = feedr.className + "Unread";
-       } else if (feedu.innerHTML <= 0) {      
-                       feedr.className = feedr.className.replace("Unread", "");
-       } 
+               var feedr = document.getElementById("FEEDR-" + feed);
+               var feedu = document.getElementById("FEEDU-" + feed);
+       
+               feedu.innerHTML = feedu.innerHTML - rows.length;
+       
+               if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
+                               feedr.className = feedr.className + "Unread";
+               } else if (feedu.innerHTML <= 0) {      
+                               feedr.className = feedr.className.replace("Unread", "");
+               } 
+
+               var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + 
+                       param_escape(rows.toString());
+       
+               notify("Marking this page as read...");
 
-       var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + 
-               param_escape(rows.toString());
+               var button = document.getElementById("btnCatchupPage");
 
-       notify("Marking this page as read...");
+               if (button) {
+                       button.className = "disabledButton";
+                       button.href = "";
+               }
+       
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=notify_callback;
+               xmlhttp.send(null);
 
-       xmlhttp.open("GET", query_str, true);
-       xmlhttp.onreadystatechange=notify_callback;
-       xmlhttp.send(null);
+       } else {
+               notify("No unread items on this page.");
 
-}
+       }
+} */
 
 function catchupAllFeeds() {
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
@@ -200,95 +201,232 @@ function catchupAllFeeds() {
 
 }
 
+function viewCurrentFeed(skip, subop) {
+       if (active_feed_id ) {
+               viewfeed(active_feed_id, skip, subop);
+       }
+}
+
 function viewfeed(feed, skip, subop) {
 
-//     document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-//     document.getElementById('content').innerHTML='&nbsp;';          
+//     notify("Loading headlines...");
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
-               printLockingError();
-               return
+       enableHotkeys();
+
+       var searchbox = document.getElementById("searchbox");
+
+       if (searchbox) {
+               search_query = searchbox.value;
+       } else {
+               search_query = "";
+       } 
+
+       var viewbox = document.getElementById("viewbox");
+
+       var view_mode;
+
+       if (viewbox) {
+               view_mode = viewbox.value;
+       } else {
+               view_mode = "All Posts";
        }
 
-       xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
+       setCookie("ttrss_vf_vmode", view_mode);
 
-       notify("Loading headlines...");
+       var limitbox = document.getElementById("limitbox");
 
-}
+       var limit;
 
-function view(id,feed_id) {
+       if (limitbox) {
+               limit = limitbox.value;
+               setCookie("ttrss_vf_limit", limit);
+       } else {
+               limit = "All";
+       }
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
+       if (skip < 0 || skip > total_feed_entries) {
+               return;
+       }
+
+       if (!xmlhttp_ready(xmlhttp)) {
                printLockingError();
                return
        }
 
-       var crow = document.getElementById("RROW-" + id);
+       if (active_feed_id != feed || skip != active_offset) {
+               active_post_id = false;
+       }
 
-       if (crow.className.match("Unread")) {
-               var umark = document.getElementById("FEEDU-" + feed_id);
-               umark.innerHTML = umark.innerHTML - 1;
-               crow.className = crow.className.replace("Unread", "");
+       active_feed_id = feed;
+       active_offset = skip;
 
-               if (umark.innerHTML == "0") {
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
+       setCookie("ttrss_vf_actfeed", feed);
+
+       if (subop == "MarkAllRead") {
+
+               var feedr = document.getElementById("FEEDR-" + feed);
+               var feedt = document.getElementById("FEEDT-" + feed);
+               var feedu = document.getElementById("FEEDU-" + feed);
+
+               feedu.innerHTML = "0";
+
+               if (feedr.className.match("Unread")) {
                        feedr.className = feedr.className.replace("Unread", "");
                }
-       
-               total_unread--;
+       }
 
-               update_title(); 
-       }       
+       var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
+               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
+               "&view=" + param_escape(view_mode) + "&limit=" + limit;
 
-       var upd_img_pic = document.getElementById("FUPDPIC-" + id);
+       if (search_query != "") {
+               query = query + "&search=" + param_escape(search_query);
+       }
+       
+       var headlines_frame = document.getElementById("headlines-frame");
+       
+       headlines_frame.src = query + "&addheader=true";
 
-       if (upd_img_pic) {
-               upd_img_pic.innerHTML = "";
-       } 
+       var feedr = document.getElementById("FEEDR-" + feed);
 
-       document.getElementById('content').innerHTML='Loading, please wait...';         
+       cleanSelected("feedsList");
+       feedr.className = feedr.className + "Selected";
+       
+       disableContainerChildren("headlinesToolbar", false);
 
-       xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
-       xmlhttp.onreadystatechange=view_callback;
-       xmlhttp.send(null);
+//     notify("");
 
 }
 
 function timeout() {
-
-       scheduleFeedUpdate();
-
+       scheduleFeedUpdate(true);
        setTimeout("timeout()", 1800*1000);
+}
+
+function resetSearch() {
+       document.getElementById("searchbox").value = "";
+       if (active_feed_id) {
+               viewfeed(active_feed_id, 0, "");
+       }
+}
 
+function search() {
+       if (active_feed_id) {
+               viewfeed(active_feed_id, 0, "");
+       } else {
+               notify("Please select some feed first.");
+       }
 }
 
-function search(feed, sender) {
+function localPiggieFunction(enable) {
+       if (enable) {
+               var query_str = "backend.php?op=feeds&subop=piggie";
 
-       if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
-               printLockingError();
-               return
+               if (xmlhttp_ready(xmlhttp)) {
+
+                       xmlhttp.open("GET", query_str, true);
+                       xmlhttp.onreadystatechange=feedlist_callback;
+                       xmlhttp.send(null);
+               }
        }
+}
+
+/*
+function moveToPost(mode) {
 
-       notify("Search: " + feed + ", " + sender.value)
+       var rows = getVisibleHeadlineIds();
 
-       document.getElementById('headlines').innerHTML='Loading headlines, please wait...';             
-       document.getElementById('content').innerHTML='&nbsp;';          
+       var prev_id;
+       var next_id;
 
-       xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
+       if (active_post_id == false) {
+               next_id = getFirstVisibleHeadlineId();
+               prev_id = getLastVisibleHeadlineId();
+       } else {        
+               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") {
+               if (next_id != undefined) {
+                       view(next_id, active_feed_id);
+               } else {
+                       _viewfeed_autoselect_first = true;
+                       viewfeed(active_feed_id, active_offset+15);
+               }
+       }
+
+       if (mode == "prev") {
+               if ( prev_id != undefined) {
+                       view(prev_id, active_feed_id);
+               } else {
+                       _viewfeed_autoselect_last = true;
+                       viewfeed(active_feed_id, active_offset-15);
+               }
+       }
 
 }
+*/
+
+function localHotkeyHandler(keycode) {
+
+/*     if (keycode == 78) {
+               return moveToPost('next');
+       }
+
+       if (keycode == 80) {
+               return moveToPost('prev');
+       } */
+
+       if (keycode == 82) {
+               return scheduleFeedUpdate(true);
+       }
+
+       if (keycode == 85) {
+               return viewfeed(active_feed_id, active_offset, "ForceUpdate");
+       }
+
+//     notify("KC: " + keycode);
 
-function update_title() {
-       //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
 }
 
 function init() {
+
+       disableContainerChildren("headlinesToolbar", true);
+
+       // IE kludge
+
+       if (xmlhttp && !xmlhttp_rpc) {
+               xmlhttp_rpc = xmlhttp;
+               xmlhttp_view = xmlhttp;
+       }
+
+       if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) {
+               document.getElementById("headlines").innerHTML = 
+                       "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
+                       "to function properly. Your browser doesn't seem to support it.";
+               return;
+       }
+
        updateFeedList(false, false);
+       document.onkeydown = hotkey_handler;
        setTimeout("timeout()", 1800*1000);
+
+       var content = document.getElementById("content");
+
+//     active_feed_id = getCookie("ttrss_vf_actfeed");
+
+       var limitbox = document.getElementById("limitbox");
+
+       if (getCookie("ttrss_vf_vmode")) {
+               var viewbox = document.getElementById("viewbox");
+               viewbox.value = getCookie("ttrss_vf_vmode");
+       }
+               
 }
+
+