]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
fix headlines height for Opera
[tt-rss.git] / tt-rss.js
index 7a776a2359a10535457d5f5fb5233ca1d6aca4f8..4deac445623b3bd3bb22c56efa17dd314e065ed7 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1,15 +1,13 @@
 var xmlhttp = false;
-
 var total_unread = 0;
 var first_run = true;
-
 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;
 
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
@@ -48,6 +46,12 @@ function dlg_frefresh_callback() {
        if (xmlhttp.readyState == 4) {
                notify(xmlhttp.responseText);
                updateFeedList(false, false);
+               if (_qfd_deleted_feed) {
+                       var hframe = document.getElementById("headlines-frame");
+                       if (hframe) {
+                               hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
+                       }
+               }
                closeDlg();
        } 
 }
@@ -69,6 +73,31 @@ function dlg_display_callback() {
        } 
 }
 
+function hide_unread_callback() {
+       if (xmlhttp.readyState == 4) {
+
+               try {
+
+                       var reply = xmlhttp.responseXML.firstChild.firstChild;
+                       var value = reply.getAttribute("value");
+                       var hide_read_feeds = (value != "false")
+                       var feeds_doc = window.frames["feeds-frame"].document;
+       
+                       hideOrShowFeeds(feeds_doc, hide_read_feeds);
+       
+                       if (hide_read_feeds) {
+                               setCookie("ttrss_vf_hreadf", 1);
+                       } else {
+                               setCookie("ttrss_vf_hreadf", 0);
+                       } 
+
+               } catch (e) {
+                       exception_error("hide_unread_callback", e);
+               }
+
+       } 
+}
+
 function refetch_callback() {
        if (xmlhttp.readyState == 4) {
                try {
@@ -82,6 +111,7 @@ function refetch_callback() {
        
                        if (!reply) {
                                notify("refetch_callback: backend did not return expected XML object");
+                               updateTitle("");
                                return;
                        } 
        
@@ -93,12 +123,15 @@ function refetch_callback() {
        
                        var f_document = window.frames["feeds-frame"].document;
 
-                       parse_counters(reply, f_document);
-       
-                       updateTitle("");
-                       notify("All feeds updated.");
+                       parse_counters(reply, f_document, window);
+
+                       if (!daemon_enabled) {
+                               notify("All feeds updated.");
+                               updateTitle("");
+                       }
                } catch (e) {
                        exception_error("refetch_callback", e);
+                       updateTitle("");
                }
        }
 }
@@ -137,11 +170,10 @@ function backend_sanity_check_callback() {
 
 function scheduleFeedUpdate(force) {
 
-       notify("Updating feeds in background...");
-
-//     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=";
 
@@ -153,13 +185,20 @@ function scheduleFeedUpdate(force) {
 
        var omode;
 
-       if (display_tags) {
-               omode = "t";
+       if (firsttime_update) {
+               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;
+
 
        if (xmlhttp_ready(xmlhttp)) {
                xmlhttp.open("GET", query_str, true);
@@ -225,7 +264,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() {
@@ -238,6 +282,7 @@ function resetSearch() {
 }
 
 function search() {
+       closeDlg();     
        viewCurrentFeed(0, "");
 }
 
@@ -256,14 +301,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);
        }
@@ -302,7 +339,7 @@ function localHotkeyHandler(keycode) {
 function updateTitle(s) {
        var tmp = "Tiny Tiny RSS";
 
-       if (s && s.length > 0) {
+       if (s != undefined) {
                current_subtitle = s;
        }
 
@@ -310,7 +347,7 @@ function updateTitle(s) {
                tmp = tmp + " (" + global_unread + ")";
        }
 
-       if (s) {
+       if (current_subtitle) {
                tmp = tmp + " - " + current_subtitle;
        }
 
@@ -338,6 +375,11 @@ 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()) 
@@ -352,6 +394,15 @@ 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 {
@@ -361,41 +412,51 @@ function init_second_stage() {
                updateFeedList(false, false);
                document.onkeydown = hotkey_handler;
        
-               var content = document.getElementById("content");
-       
-               if (getCookie("ttrss_vf_vmode")) {
-                       var viewbox = document.getElementById("viewbox");
-                       viewbox.value = getCookie("ttrss_vf_vmode");
-               }
+               var viewbox = document.getElementById("viewbox");                       
+               var limitbox = document.getElementById("limitbox");
+
+               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;
        
-               if (getCookie("ttrss_vf_limit")) {
-                       var limitbox = document.getElementById("limitbox");
-                       limitbox.value = getCookie("ttrss_vf_limit");
+                       h.style.height = nh + "px";
+                       c.style.height = c.scrollHeight - nh + "px";
+                       
                }
        
-       //      if (getCookie("ttrss_vf_actfeed")) {
-       //              viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-       //      }
-       
-       //      setTimeout("timeout()", 2*1000);
-       //      scheduleFeedUpdate(true);
-       
        } catch (e) {
                exception_error("init_second_stage", e);
        }
 }
 
-function quickMenuGo() {
-
+function quickMenuChange() {
        var chooser = document.getElementById("quickMenuChooser");
        var opid = chooser[chooser.selectedIndex].id;
 
+       chooser.selectedIndex = 0;
+       quickMenuGo(opid);
+}
+
+function quickMenuGo(opid) {
+
+
        if (opid == "qmcPrefs") {
                gotoPreferences();
        }
 
-       if (opid == "qmcAdvSearch") {
-               displayDlg("search");
+       if (opid == "qmcSearch") {
+               displayDlg("search", getActiveFeedId());
                return;
        }
 
@@ -453,13 +514,22 @@ function qafAdd() {
                notify("Missing feed URL.");
        } else {
                notify("Adding feed...");
+       
+               var cat = document.getElementById("qafCat");
+               var cat_id = "";
                
+               if (cat) {
+                       cat_id = cat[cat.selectedIndex].id;
+               } else {
+                       cat_id = 0;
+               }
+
                var feeds_doc = window.frames["feeds-frame"].document;
 
                feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
 
                xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
-                       param_escape(link.value), true);
+                       param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
                xmlhttp.onreadystatechange=dlg_frefresh_callback;
                xmlhttp.send(null);
 
@@ -504,6 +574,11 @@ function qaddFilter() {
 
 function displayDlg(id, param) {
 
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
        notify("");
 
        xmlhttp.open("GET", "backend.php?op=dlg&id=" +
@@ -524,20 +599,29 @@ function qfdDelete(feed_id) {
 
        notify("Removing feed...");
 
+       if (!xmlhttp_ready(xmlhttp)) {
+               printLockingError();
+               return
+       }
+
 //     var feeds_doc = window.frames["feeds-frame"].document;
 //     feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
 
+       _qfd_deleted_feed = feed_id;
+
        xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
        xmlhttp.onreadystatechange=dlg_frefresh_callback;
        xmlhttp.send(null);
 }
 
 
-function allFeedsMenuGo() {
+function allFeedsMenuChange() {
        var chooser = document.getElementById("allFeedsChooser");
 
        var opname = chooser[chooser.selectedIndex].text;
 
+       chooser.selectedIndex = 0;
+
        if (opname == "Update") {
                scheduleFeedUpdate(true);
                return;
@@ -561,19 +645,26 @@ function updateFeedTitle(t) {
 }
 
 function toggleDispRead() {
-       var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
+       try {
 
-       hide_read_feeds = !hide_read_feeds;
+               if (!xmlhttp_ready(xmlhttp)) {
+                       printLockingError();
+                       return
+               }
 
-       var feeds_doc = window.frames["feeds-frame"].document;
+               var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
 
-       hideOrShowFeeds(feeds_doc, hide_read_feeds);
+               hide_read_feeds = !hide_read_feeds;
+       
+               var query = "backend.php?op=rpc&subop=setpref" +
+                       "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
 
-       if (hide_read_feeds) {
-               setCookie("ttrss_vf_hreadf", 1);
-       } else {
-               setCookie("ttrss_vf_hreadf", 0);
+               xmlhttp.open("GET", query);
+               xmlhttp.onreadystatechange=hide_unread_callback;
+               xmlhttp.send(null);
+               
+       } catch (e) {
+               exception_error("toggleDispRead", e);
        }
-
 }