]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
remove ACTFEEDID container, keep information in a cookie instead (getActiveFeedId...
[tt-rss.git] / tt-rss.js
index 96c9b32addec459d4ab819d0abce5a1ac14358dc..edfd10693d76c9a0ff1ff2012007f850f732344d 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -4,24 +4,10 @@
 */
 
 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 _viewfeed_autoselect_first = false;
-var _viewfeed_autoselect_last = false;
-
-var _update_ids;
-var _update_num_ids;
-
 var search_query = "";
 
 /*@cc_on @*/
@@ -33,22 +19,17 @@ 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();
 }
 
+/*
 function feedlist_callback() {
        var container = document.getElementById('feeds');
        if (xmlhttp.readyState == 4) {
@@ -56,115 +37,44 @@ function feedlist_callback() {
 
                if (first_run) {
                        scheduleFeedUpdate(false);
+                       if (getCookie("ttrss_vf_actfeed")) {
+                               viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
+                       }
                        first_run = false;
                } else {
                        notify("");
                } 
        } 
 }
+*/
 
-function feed_update_callback() {
-       if (xmlhttp_rpc.readyState == 4) {
-               var result = xmlhttp_rpc.responseText;
-               notify(_update_ids);
-               updateFeed(_update_ids.shift());
-       }
-}
+function refetch_callback() {
 
-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 (_viewfeed_autoselect_first == true) {
-                       _viewfeed_autoselect_first = false;
-                       view(getFirstVisibleHeadlineId(), active_feed_id);
-               }
-
-               if (_viewfeed_autoselect_last == true) {
-                       _viewfeed_autoselect_last = false;
-                       view(getLastVisibleHeadlineId(), active_feed_id);
-               }
-
-               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);
-
-                       feedt.innerHTML = ftotal.innerHTML;
-                       feedu.innerHTML = funread.innerHTML;
-
-                       total_feed_entries = ftotal.innerHTML;  
-
-                       if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
-                                       feedr.className = feedr.className + "Unread";
-                       } else if (feedu.innerHTML <= 0) {      
-                                       feedr.className = feedr.className.replace("Unread", "");
-                       }
-
-                       cleanSelected("feedsList");
-
-                       feedr.className = feedr.className + "Selected";
-               }
-
-               var searchbox = document.getElementById("searchbox");
-               searchbox.value = search_query;
-
-               markHeadline(active_post_id);
-
-               notify("");
-
-       }       
-}
 
-function view_callback() {
-       var container = document.getElementById('content');
-       if (xmlhttp_view.readyState == 4) {
-               container.innerHTML=xmlhttp_view.responseText;          
-               markHeadline(active_post_id);
-       }
-}
-
-function refetch_callback() {
-
-       if (xmlhttp_rpc.readyState == 4) {
-               notify("All feeds updated");
-               var container = document.getElementById('feeds');
-               container.innerHTML = xmlhttp_rpc.responseText;
                document.title = "Tiny Tiny RSS";
+               notify("All feeds updated.");
+
+               updateFeedList();
+               
        } 
 }
 
+
 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();
        }   
 
 }
 
-function scheduleSepFeedUpdate(force) {
-       notify("Updating feeds in background (M2)...");
-
-       _update_ids = getFeedIds();
-       _update_num_ids = _update_ids.length;
-
-       updateFeed(_update_ids.pop());
-
-}
-
 function scheduleFeedUpdate(force) {
 
        notify("Updating feeds in background...");
@@ -179,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();
        }   
@@ -190,95 +100,46 @@ function scheduleFeedUpdate(force) {
 
 function updateFeedList(silent, fetch) {
 
-       if (silent != true) {
-               notify("Loading feed list...");
-       }
+//     if (silent != true) {
+//             notify("Loading feed list...");
+//     }
 
        var query_str = "backend.php?op=feeds";
 
-       if (fetch) query_str = query_str + "&fetch=yes";
-
-       if (xmlhttp_ready(xmlhttp)) {
-               xmlhttp.open("GET", query_str, true);
-               xmlhttp.onreadystatechange=feedlist_callback;
-               xmlhttp.send(null);
-       } else {
-               printLockingError();
+       if (getActiveFeedId()) {
+               query_str = query_str + "&actid=" + getActiveFeedId();
        }
-}
-
-function catchupPage(feed) {
 
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
-       var content = document.getElementById("headlinesList");
+       if (fetch) query_str = query_str + "&fetch=yes";
 
-       var rows = new Array();
+       var feeds_frame = document.getElementById("feeds-frame");
 
-       for (i = 0; i < content.rows.length; i++) {
-               var row_id = content.rows[i].id.replace("RROW-", "");
-               if (row_id.length > 0) {
-                       if (content.rows[i].className.match("Unread")) {
-                               rows.push(row_id);      
-                               content.rows[i].className = content.rows[i].className.replace("Unread", "");
-                       }
-               }
-       }
-
-       if (rows.length > 0) {
+       feeds_frame.src = query_str;
+}
 
-               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", "");
-               } 
+function catchupAllFeeds() {
 
-               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=feeds&subop=catchupAll";
 
-               var button = document.getElementById("btnCatchupPage");
+       notify("Marking all feeds as read...");
 
-               button.className = "disabledButton";
-               button.href = "";
-       
-               xmlhttp.open("GET", query_str, true);
-               xmlhttp.onreadystatechange=notify_callback;
-               xmlhttp.send(null);
+       var feeds_frame = document.getElementById("feeds-frame");
 
-       } else {
-               notify("No unread items on this page.");
+       feeds_frame.src = query_str;
 
-       }
 }
 
-function catchupAllFeeds() {
+function viewCurrentFeed(skip, subop) {
 
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), skip, subop);
        }
-       var query_str = "backend.php?op=feeds&subop=catchupAll";
-
-       notify("Marking all feeds as read...");
-
-       xmlhttp.open("GET", query_str, true);
-       xmlhttp.onreadystatechange=feedlist_callback;
-       xmlhttp.send(null);
-
 }
 
 function viewfeed(feed, skip, subop) {
 
+//     notify("Loading headlines...");
+
        enableHotkeys();
 
        var searchbox = document.getElementById("searchbox");
@@ -289,131 +150,93 @@ function viewfeed(feed, skip, subop) {
                search_query = "";
        } 
 
-/*     if (active_feed_id == feed && subop != "ForceUpdate") {
-               notify("This feed is currently selected.");
-               return;
-       } */
+       var viewbox = document.getElementById("viewbox");
 
-       if (skip < 0 || skip > total_feed_entries) {
-               return;
-       }
+       var view_mode;
 
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
+       if (viewbox) {
+               view_mode = viewbox[viewbox.selectedIndex].text;
+       } else {
+               view_mode = "All Posts";
        }
 
-       if (active_feed_id != feed || skip != active_offset) {
-               active_post_id = false;
-       }
+       setCookie("ttrss_vf_vmode", view_mode);
 
-       active_feed_id = feed;
-       active_offset = skip;
+       var limitbox = document.getElementById("limitbox");
 
-       var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop);
+       var limit;
 
-       if (search_query != "") {
-               query = query + "&search=" + param_escape(search_query);
+       if (limitbox) {
+               limit = limitbox[limitbox.selectedIndex].text;
+               setCookie("ttrss_vf_limit", limit);
+       } else {
+               limit = "All";
        }
-       
-       xmlhttp.open("GET", query, true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
 
-       notify("Loading headlines...");
+       setActiveFeedId(feed);
 
-}
+       var f_doc = frames["feeds-frame"].document;
 
-function markHeadline(id) {
-       var row = document.getElementById("RROW-" + id);
-       if (row) {
-               row.className = row.className + "Selected";
-       }
-}
+//     f_doc.getElementById("ACTFEEDID").innerHTML = feed;
 
-function getFeedIds() {
-       var content = document.getElementById("feedsList");
+       if (subop == "MarkAllRead") {
 
-       var rows = new Array();
+               var feedr = f_doc.getElementById("FEEDR-" + feed);
+               var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
+               
+               feedctr.className = "invisible";
 
-       for (i = 0; i < content.rows.length; i++) {
-               var id = content.rows[i].id.replace("FEEDR-", "");
-               if (id.length > 0) {
-                       rows.push(id);
+               if (feedr.className.match("Unread")) {
+                       feedr.className = feedr.className.replace("Unread", "");
                }
        }
 
-       return rows;
-}
-
-function cleanSelected(element) {
-       var content = document.getElementById(element);
-
-       var rows = new Array();
+       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;
 
-       for (i = 0; i < content.rows.length; i++) {
-               content.rows[i].className = content.rows[i].className.replace("Selected", "");
+       if (search_query != "") {
+               query = query + "&search=" + param_escape(search_query);
        }
+       
+       var headlines_frame = parent.frames["headlines-frame"];
 
-}
-
-function view(id,feed_id) {
-
-       enableHotkeys();
+       headlines_frame.location.href = query + "&addheader=true";
 
-       if (!xmlhttp_ready(xmlhttp_view)) {
-               printLockingError();
-               return
+       cleanSelected("feedsList");
+       var feedr = document.getElementById("FEEDR-" + feed);
+       if (feedr) {
+               feedr.className = feedr.className + "Selected";
        }
+       
+       disableContainerChildren("headlinesToolbar", false, doc);
 
-       var crow = document.getElementById("RROW-" + id);
-
-       if (crow.className.match("Unread")) {
-               var umark = document.getElementById("FEEDU-" + feed_id);
-               umark.innerHTML = umark.innerHTML - 1;
-               crow.className = crow.className.replace("Unread", "");
-
-               if (umark.innerHTML == "0") {
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
-                       feedr.className = feedr.className.replace("Unread", "");
-               }
-
-               total_unread--;
-       }       
-
-       cleanSelected("headlinesList");
-//     crow.className = crow.className + "Selected";
-
-       var upd_img_pic = document.getElementById("FUPDPIC-" + id);
-
-       if (upd_img_pic) {
-               upd_img_pic.innerHTML = "";
-       } 
-
-//     document.getElementById('content').innerHTML='Loading, please wait...';         
-
-       active_post_id = id;
-
-       xmlhttp_view.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
-       xmlhttp_view.onreadystatechange=view_callback;
-       xmlhttp_view.send(null);
-
+//     notify("");
 
 }
 
+
 function timeout() {
        scheduleFeedUpdate(true);
        setTimeout("timeout()", 1800*1000);
 }
 
 function resetSearch() {
-       document.getElementById("searchbox").value = "";
-       viewfeed(active_feed_id, 0, "");
+       var searchbox = document.getElementById("searchbox")
+
+       if (searchbox.value != "" && getActiveFeedId()) {       
+               searchbox.value = "";
+               viewfeed(getActiveFeedId(), 0, "");
+       }
 }
 
-function search(feed) {
-       viewfeed(feed, 0, "");
+function search() {
+       checkActiveFeedId();
+       if (getActiveFeedId()) {
+               viewfeed(getActiveFeedId(), 0, "");
+       } else {
+               notify("Please select some feed first.");
+       }
 }
 
 function localPiggieFunction(enable) {
@@ -429,118 +252,63 @@ 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 getFirstVisibleHeadlineId() {
-       var rows = getVisibleHeadlineIds();
-       return rows[0];
-}
-
-function getLastVisibleHeadlineId() {
-       var rows = getVisibleHeadlineIds();
-       return rows[rows.length-1];
-}
-
-function moveToPost(mode) {
-
-       var rows = getVisibleHeadlineIds();
-
-       var prev_id;
-       var next_id;
-
-       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) {
+/*     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");
+               return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
        }
 
 //     notify("KC: " + keycode);
 
 }
 
-
 function init() {
 
-       // IE kludge
+       disableContainerChildren("headlinesToolbar", true);
 
-       if (xmlhttp && !xmlhttp_rpc) {
-               xmlhttp_rpc = xmlhttp;
-               xmlhttp_view = xmlhttp;
-       }
-
-       if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) {
+       if (!xmlhttp) {
                document.getElementById("headlines").innerHTML = 
-                       "<b>Fatal error:</b> This program needs XmlHttpRequest " + 
+                       "<b>Fatal error:</b> This program requires XmlHttpRequest " + 
                        "to function properly. Your browser doesn't seem to support it.";
                return;
        }
 
        updateFeedList(false, false);
        document.onkeydown = hotkey_handler;
+
        setTimeout("timeout()", 1800*1000);
+       scheduleFeedUpdate(true);
+
+       var content = document.getElementById("content");
+
+       if (getCookie("ttrss_vf_vmode")) {
+               var viewbox = document.getElementById("viewbox");
+               viewbox.value = getCookie("ttrss_vf_vmode");
+       }
+
+       if (getCookie("ttrss_vf_limit")) {
+               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", "");
+
 }
+
+