]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
more cookie magic, basic sanity checks on init()
[tt-rss.git] / tt-rss.js
index 25c608518fecb5ff0d50d4b75f689ac5c42afb56..4f532d60a194100269341bf740aa259833ad7422 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -4,14 +4,10 @@
 */
 
 var xmlhttp = false;
-var xmlhttp_rpc = false;
-var xmlhttp_view = false;
 
 var total_unread = 0;
 var first_run = true;
 
-var active_feed_id = false;
-
 var search_query = "";
 
 /*@cc_on @*/
@@ -23,20 +19,14 @@ 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 @*/
 
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
-       xmlhttp_rpc = new XMLHttpRequest();
-       xmlhttp_view = new XMLHttpRequest();
 }
 
 /*
@@ -58,18 +48,9 @@ function feedlist_callback() {
 }
 */
 
-function checkActiveFeedId() {
-
-       var actfeedid = frames["feeds-frame"].document.getElementById("ACTFEEDID");
-
-       if (actfeedid) {
-               active_feed_id = actfeedid.innerHTML;
-       }
-}
-
 function refetch_callback() {
 
-       if (xmlhttp_rpc.readyState == 4) {
+       if (xmlhttp.readyState == 4) {
 
                document.title = "Tiny Tiny RSS";
                notify("All feeds updated.");
@@ -84,10 +65,10 @@ function updateFeed(feed_id) {
 
        var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
 
-       if (xmlhttp_ready(xmlhttp_rpc)) {
-               xmlhttp_rpc.open("GET", query_str, true);
-               xmlhttp_rpc.onreadystatechange=feed_update_callback;
-               xmlhttp_rpc.send(null);
+       if (xmlhttp_ready(xmlhttp)) {
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=feed_update_callback;
+               xmlhttp.send(null);
        } else {
                printLockingError();
        }   
@@ -108,10 +89,10 @@ function scheduleFeedUpdate(force) {
                query_str = query_str + "updateAllFeeds";
        }
 
-       if (xmlhttp_ready(xmlhttp_rpc)) {
-               xmlhttp_rpc.open("GET", query_str, true);
-               xmlhttp_rpc.onreadystatechange=refetch_callback;
-               xmlhttp_rpc.send(null);
+       if (xmlhttp_ready(xmlhttp)) {
+               xmlhttp.open("GET", query_str, true);
+               xmlhttp.onreadystatechange=refetch_callback;
+               xmlhttp.send(null);
        } else {
                printLockingError();
        }   
@@ -125,8 +106,8 @@ function updateFeedList(silent, fetch) {
 
        var query_str = "backend.php?op=feeds";
 
-       if (active_feed_id) {
-               query_str = query_str + "&actid=" + active_feed_id;
+       if (getActiveFeedId()) {
+               query_str = query_str + "&actid=" + getActiveFeedId();
        }
 
        if (fetch) query_str = query_str + "&fetch=yes";
@@ -150,16 +131,14 @@ function catchupAllFeeds() {
 
 function viewCurrentFeed(skip, subop) {
 
-       active_feed_id = frames["feeds-frame"].document.getElementById("ACTFEEDID").innerHTML;
-
-       if (active_feed_id) {
-               viewfeed(active_feed_id, skip, subop);
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), skip, subop);
        }
 }
 
 function viewfeed(feed, skip, subop) {
 
-       notify("Loading headlines...");
+//     notify("Loading headlines...");
 
        enableHotkeys();
 
@@ -176,7 +155,7 @@ function viewfeed(feed, skip, subop) {
        var view_mode;
 
        if (viewbox) {
-               view_mode = viewbox.value;
+               view_mode = viewbox[viewbox.selectedIndex].text;
        } else {
                view_mode = "All Posts";
        }
@@ -188,20 +167,18 @@ function viewfeed(feed, skip, subop) {
        var limit;
 
        if (limitbox) {
-               limit = limitbox.value;
+               limit = limitbox[limitbox.selectedIndex].text;
                setCookie("ttrss_vf_limit", limit);
        } else {
                limit = "All";
        }
 
-       active_feed_id = feed;
+       setActiveFeedId(feed);
 
        var f_doc = frames["feeds-frame"].document;
 
-       f_doc.getElementById("ACTFEEDID").innerHTML = feed;
+//     f_doc.getElementById("ACTFEEDID").innerHTML = feed;
 
-       setCookie("ttrss_vf_actfeed", feed);
-       
        if (subop == "MarkAllRead") {
 
                var feedr = f_doc.getElementById("FEEDR-" + feed);
@@ -247,16 +224,16 @@ function timeout() {
 function resetSearch() {
        var searchbox = document.getElementById("searchbox")
 
-       if (searchbox.value != "" && active_feed_id) {  
+       if (searchbox.value != "" && getActiveFeedId()) {       
                searchbox.value = "";
-               viewfeed(active_feed_id, 0, "");
+               viewfeed(getActiveFeedId(), 0, "");
        }
 }
 
 function search() {
        checkActiveFeedId();
-       if (active_feed_id) {
-               viewfeed(active_feed_id, 0, "");
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), 0, "");
        } else {
                notify("Please select some feed first.");
        }
@@ -290,30 +267,41 @@ function localHotkeyHandler(keycode) {
        }
 
        if (keycode == 85) {
-               return viewfeed(active_feed_id, active_offset, "ForceUpdate");
+               return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
        }
 
 //     notify("KC: " + keycode);
 
 }
 
-function init() {
+function genericSanityCheck() {
 
-       disableContainerChildren("headlinesToolbar", true);
+       if (!xmlhttp) {
+               document.getElementById("headlines").innerHTML = 
+                       "<b>Fatal error:</b> This program requires XmlHttpRequest " + 
+                       "to function properly. Your browser doesn't seem to support it.";
+               return false;
+       }
 
-       // IE kludge
+       setCookie("ttrss_vf_test", "TEST");
+       if (getCookie("ttrss_vf_test") != "TEST") {
 
-       if (xmlhttp && !xmlhttp_rpc) {
-               xmlhttp_rpc = xmlhttp;
-               xmlhttp_view = xmlhttp;
+               document.getElementById("headlines").innerHTML = 
+                       "<b>Fatal error:</b> This program requires cookies " + 
+                       "to function properly. Your browser doesn't seem to support them.";
+
+               return false;
        }
 
-       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 true;
+}
+
+function init() {
+
+       disableContainerChildren("headlinesToolbar", true);
+
+       if (!genericSanityCheck()) 
                return;
-       }
 
        updateFeedList(false, false);
        document.onkeydown = hotkey_handler;
@@ -332,6 +320,13 @@ function init() {
                var limitbox = document.getElementById("limitbox");
                limitbox.value = getCookie("ttrss_vf_limit");
        }
+
+//     if (getCookie("ttrss_vf_actfeed")) {
+//             viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
+//     }
+
+       setCookie("ttrss_vf_actfeed", "");
+
 }