]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
some UI frontend cookies respect session cookie lifetime, misc cookie cleanups (close...
[tt-rss.git] / tt-rss.js
index 545d7915d6df98758fb849414ebc2dbc03297b54..7958291f9bd7d2e32fe7c9d34ec797a0c151b8a8 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -5,8 +5,11 @@ var display_tags = false;
 var global_unread = -1;
 var active_title_text = "";
 var current_subtitle = "";
-
+var daemon_enabled = false;
 var _qfd_deleted_feed = 0;
+var firsttime_update = true;
+var last_refetch = 0;
+var cookie_lifetime = 0;
 
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
@@ -101,6 +104,10 @@ function refetch_callback() {
        if (xmlhttp.readyState == 4) {
                try {
 
+                       var date = new Date();
+
+                       last_refetch = date.getTime() / 1000;
+
                        if (!xmlhttp.responseXML) {
                                notify("refetch_callback: backend did not return valid XML");
                                return;
@@ -110,6 +117,7 @@ function refetch_callback() {
        
                        if (!reply) {
                                notify("refetch_callback: backend did not return expected XML object");
+                               updateTitle("");
                                return;
                        } 
        
@@ -121,12 +129,19 @@ function refetch_callback() {
        
                        var f_document = window.frames["feeds-frame"].document;
 
-                       parse_counters(reply, f_document, window);
-       
-                       updateTitle("");
-                       notify("All feeds updated.");
+                       parse_counters(reply, f_document, window, true);
+
+                       debug("refetch_callback: done");
+
+                       if (!daemon_enabled) {
+                               notify("All feeds updated.");
+                               updateTitle("");
+                       } else {
+                               notify("");
+                       }
                } catch (e) {
                        exception_error("refetch_callback", e);
+                       updateTitle("");
                }
        }
 }
@@ -138,14 +153,14 @@ function backend_sanity_check_callback() {
                try {
                
                        if (!xmlhttp.responseXML) {
-                               fatalError(3);
+                               fatalError(3, "D001;" + xmlhttp.responseText);
                                return;
                        }
        
                        var reply = xmlhttp.responseXML.firstChild;
        
                        if (!reply) {
-                               fatalError(3);
+                               fatalError(3, "D002;" + xmlhttp.responseText);
                                return;
                        }
        
@@ -155,6 +170,8 @@ function backend_sanity_check_callback() {
                                return fatalError(error_code);
                        }
        
+                       debug("sanity check ok");
+
                        init_second_stage();
 
                } catch (e) {
@@ -165,11 +182,10 @@ function backend_sanity_check_callback() {
 
 function scheduleFeedUpdate(force) {
 
-       notify("Updating feeds, please wait.");
-
-//     document.title = "Tiny Tiny RSS - Updating...";
-
-       updateTitle("Updating");
+       if (!daemon_enabled) {
+               notify("Updating feeds, please wait.");
+               updateTitle("Updating");
+       }
 
        var query_str = "backend.php?op=rpc&subop=";
 
@@ -181,19 +197,35 @@ function scheduleFeedUpdate(force) {
 
        var omode;
 
-       if (display_tags) {
-               omode = "t";
+       if (firsttime_update && !navigator.userAgent.match("Opera")) {
+               firsttime_update = false;
+               omode = "T";
        } else {
-               omode = "fl";
+               if (display_tags) {
+                       omode = "t";
+               } else {
+                       omode = "flc";
+               }
        }
-
+       
        query_str = query_str + "&omode=" + omode;
+       query_str = query_str + "&uctr=" + global_unread;
+
+       debug("in scheduleFeedUpdate");
+
+       var date = new Date();
+
+       if (!xmlhttp_ready(xmlhttp) && last_refetch < date.getTime() / 1000 - 60) {
+               debug("xmlhttp seems to be stuck, aborting");
+               xmlhttp.abort();
+       }
 
        if (xmlhttp_ready(xmlhttp)) {
                xmlhttp.open("GET", query_str, true);
                xmlhttp.onreadystatechange=refetch_callback;
                xmlhttp.send(null);
        } else {
+               debug("xmlhttp busy");
                printLockingError();
        }   
 }
@@ -214,6 +246,12 @@ function updateFeedList(silent, fetch) {
                query_str = query_str + "&actid=" + getActiveFeedId();
        }
 
+       if (navigator.userAgent.match("Opera")) {
+               var date = new Date();
+               var timestamp = Math.round(date.getTime() / 1000);
+               query_str = query_str + "&ts=" + timestamp
+       }
+       
        if (fetch) query_str = query_str + "&fetch=yes";
 
        var feeds_frame = document.getElementById("feeds-frame");
@@ -253,7 +291,12 @@ function viewfeed(feed, skip, subop) {
 
 function timeout() {
        scheduleFeedUpdate(false);
-       setTimeout("timeout()", 900*1000);
+
+       var refresh_time = getCookie('ttrss_vf_refresh');
+
+       if (!refresh_time) refresh_time = 600;
+
+       setTimeout("timeout()", refresh_time*1000);
 }
 
 function resetSearch() {
@@ -285,14 +328,6 @@ function localPiggieFunction(enable) {
 
 function localHotkeyHandler(keycode) {
 
-/*     if (keycode == 78) {
-               return moveToPost('next');
-       }
-
-       if (keycode == 80) {
-               return moveToPost('prev');
-       } */
-
        if (keycode == 82) { // r
                return scheduleFeedUpdate(true);
        }
@@ -331,7 +366,7 @@ function localHotkeyHandler(keycode) {
 function updateTitle(s) {
        var tmp = "Tiny Tiny RSS";
 
-       if (s && s.length > 0) {
+       if (s != undefined) {
                current_subtitle = s;
        }
 
@@ -339,7 +374,7 @@ function updateTitle(s) {
                tmp = tmp + " (" + global_unread + ")";
        }
 
-       if (s) {
+       if (current_subtitle) {
                tmp = tmp + " - " + current_subtitle;
        }
 
@@ -367,11 +402,21 @@ function init() {
 
        try {
 
+               // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
+
+               if (arguments.callee.done) return;
+               arguments.callee.done = true;           
+
                disableContainerChildren("headlinesToolbar", true);
 
                if (!genericSanityCheck()) 
                        return;
 
+               if (getURLParam('debug')) {
+                       document.getElementById('debug_output').style.display = 'block';
+                       debug('debug mode activated');
+               }
+
                xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
                xmlhttp.onreadystatechange=backend_sanity_check_callback;
                xmlhttp.send(null);
@@ -381,10 +426,23 @@ function init() {
        }
 }
 
+function resize_feeds_frame() {
+       var f = document.getElementById("feeds-frame");
+       var tf = document.getElementById("mainFooter");
+       var th = document.getElementById("mainHeader");
+                
+       f.style.height = document.body.scrollHeight - tf.scrollHeight - 
+               th.scrollHeight - 50 + "px";
+}
+
 function init_second_stage() {
 
        try {
 
+               cookie_lifetime = getCookie("ttrss_cltime");
+
+               delCookie("ttrss_vf_test");
+
                setCookie("ttrss_vf_actfeed", "");
        
                updateFeedList(false, false);
@@ -395,6 +453,25 @@ function init_second_stage() {
 
                dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
                dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
+
+               daemon_enabled = getCookie("ttrss_vf_daemon");
+
+               // FIXME should be callled after window resize
+
+               if (navigator.userAgent.match("Opera")) {
+                       resize_feeds_frame();
+
+/*                     // fix headlines frame height for Opera
+                       var h = document.getElementById("headlines");
+                       var c = document.getElementById("content");
+                       var nh = document.body.scrollHeight * 0.25;
+       
+                       h.style.height = nh + "px";
+                       c.style.height = c.scrollHeight - nh + "px"; */
+                       
+               }
+
+               debug("second stage ok");
        
        } catch (e) {
                exception_error("init_second_stage", e);
@@ -629,3 +706,16 @@ function toggleDispRead() {
        }
 }
 
+function debug(msg) {
+       var c = document.getElementById('debug_output');
+       if (c && c.style.display == "block") {
+               while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
+                       c.removeChild(c.lastChild);
+               }
+       
+               var d = new Date();
+               var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
+                       ":" + leading_zero(d.getSeconds());
+               c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
+       }
+}