]> 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 fcafd39bab24a3538549ec06ae74a9a107112757..34ab7102c0c3ae5e330b142899dd8a8233cfaa0c 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -16,12 +16,6 @@ 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 @*/
@@ -63,74 +57,6 @@ function feedlist_callback() {
        } 
 }
 
-function feed_update_callback() {
-       if (xmlhttp_rpc.readyState == 4) {
-               var result = xmlhttp_rpc.responseText;
-               notify(_update_ids);
-               updateFeed(_update_ids.shift());
-       }
-}
-
-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) {
@@ -155,16 +81,6 @@ function updateFeed(feed_id) {
 
 }
 
-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...");
@@ -207,6 +123,7 @@ function updateFeedList(silent, fetch) {
        }
 }
 
+/*
 function catchupPage(feed) {
 
        if (!xmlhttp_ready(xmlhttp)) {
@@ -266,7 +183,7 @@ function catchupPage(feed) {
                notify("No unread items on this page.");
 
        }
-}
+} */
 
 function catchupAllFeeds() {
 
@@ -284,8 +201,16 @@ function catchupAllFeeds() {
 
 }
 
+function viewCurrentFeed(skip, subop) {
+       if (active_feed_id ) {
+               viewfeed(active_feed_id, skip, subop);
+       }
+}
+
 function viewfeed(feed, skip, subop) {
 
+//     notify("Loading headlines...");
+
        enableHotkeys();
 
        var searchbox = document.getElementById("searchbox");
@@ -296,10 +221,28 @@ 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");
+
+       var view_mode;
+
+       if (viewbox) {
+               view_mode = viewbox.value;
+       } else {
+               view_mode = "All Posts";
+       }
+
+       setCookie("ttrss_vf_vmode", view_mode);
+
+       var limitbox = document.getElementById("limitbox");
+
+       var limit;
+
+       if (limitbox) {
+               limit = limitbox.value;
+               setCookie("ttrss_vf_limit", limit);
+       } else {
+               limit = "All";
+       }
 
        if (skip < 0 || skip > total_feed_entries) {
                return;
@@ -317,105 +260,41 @@ function viewfeed(feed, skip, subop) {
        active_feed_id = feed;
        active_offset = skip;
 
-       var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
-               "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop);
-
-       if (search_query != "") {
-               query = query + "&search=" + param_escape(search_query);
-       }
-       
-       xmlhttp.open("GET", query, true);
-       xmlhttp.onreadystatechange=viewfeed_callback;
-       xmlhttp.send(null);
-
-       notify("Loading headlines...");
+       setCookie("ttrss_vf_actfeed", feed);
 
-}
-
-function markHeadline(id) {
-       var row = document.getElementById("RROW-" + id);
-       if (row) {
-               row.className = row.className + "Selected";
-       }
-}
-
-function getFeedIds() {
-       var content = document.getElementById("feedsList");
-
-       var rows = new Array();
-
-       for (i = 0; i < content.rows.length; i++) {
-               var id = content.rows[i].id.replace("FEEDR-", "");
-               if (id.length > 0) {
-                       rows.push(id);
-               }
-       }
-
-       return rows;
-}
-
-function cleanSelected(element) {
-       var content = document.getElementById(element);
-
-       var rows = new Array();
+       if (subop == "MarkAllRead") {
 
-       for (i = 0; i < content.rows.length; i++) {
-               content.rows[i].className = content.rows[i].className.replace("Selected", "");
-       }
-
-}
-
-function view(id,feed_id) {
-
-       enableHotkeys();
-
-       if (!xmlhttp_ready(xmlhttp_view)) {
-               printLockingError();
-               return
-       }
-
-       var crow = document.getElementById("RROW-" + id);
+               var feedr = document.getElementById("FEEDR-" + feed);
+               var feedt = document.getElementById("FEEDT-" + feed);
+               var feedu = document.getElementById("FEEDU-" + feed);
 
-       if (crow.className.match("Unread")) {
-               var umark = document.getElementById("FEEDU-" + feed_id);
-               umark.innerHTML = umark.innerHTML - 1;
-               crow.className = crow.className.replace("Unread", "");
+               feedu.innerHTML = "0";
 
-               if (umark.innerHTML == "0") {
-                       var feedr = document.getElementById("FEEDR-" + feed_id);
+               if (feedr.className.match("Unread")) {
                        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...';         
-
-       var unread_rows = getVisibleUnreadHeadlines();
+       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;
 
-       if (unread_rows.length == 0) {
-               var button = document.getElementById("btnCatchupPage");
-               if (button) {
-                       button.className = "disabledButton";
-                       button.href = "";
-               }
+       if (search_query != "") {
+               query = query + "&search=" + param_escape(search_query);
        }
+       
+       var headlines_frame = document.getElementById("headlines-frame");
+       
+       headlines_frame.src = query + "&addheader=true";
 
-       active_post_id = id;
+       var feedr = document.getElementById("FEEDR-" + feed);
 
-       xmlhttp_view.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
-       xmlhttp_view.onreadystatechange=view_callback;
-       xmlhttp_view.send(null);
+       cleanSelected("feedsList");
+       feedr.className = feedr.className + "Selected";
+       
+       disableContainerChildren("headlinesToolbar", false);
 
+//     notify("");
 
 }
 
@@ -426,11 +305,17 @@ function timeout() {
 
 function resetSearch() {
        document.getElementById("searchbox").value = "";
-       viewfeed(active_feed_id, 0, "");
+       if (active_feed_id) {
+               viewfeed(active_feed_id, 0, "");
+       }
 }
 
-function search(feed) {
-       viewfeed(feed, 0, "");
+function search() {
+       if (active_feed_id) {
+               viewfeed(active_feed_id, 0, "");
+       } else {
+               notify("Please select some feed first.");
+       }
 }
 
 function localPiggieFunction(enable) {
@@ -446,53 +331,7 @@ function localPiggieFunction(enable) {
        }
 }
 
-function relativeid_callback() {
-
-       if (xmlhttp_rpc.readyState == 4) {
-               notify(xmlhttp_rpc.responseText);
-       }
-
-}
-
-function getVisibleUnreadHeadlines() {
-       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 && content.rows[i].className.match("Unread")) {
-                               rows.push(row_id);      
-               }
-       }
-       return rows;
-}
-
-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();
@@ -531,16 +370,17 @@ function moveToPost(mode) {
        }
 
 }
+*/
 
 function localHotkeyHandler(keycode) {
 
-       if (keycode == 78) {
+/*     if (keycode == 78) {
                return moveToPost('next');
        }
 
        if (keycode == 80) {
                return moveToPost('prev');
-       }
+       } */
 
        if (keycode == 82) {
                return scheduleFeedUpdate(true);
@@ -554,9 +394,10 @@ function localHotkeyHandler(keycode) {
 
 }
 
-
 function init() {
 
+       disableContainerChildren("headlinesToolbar", true);
+
        // IE kludge
 
        if (xmlhttp && !xmlhttp_rpc) {
@@ -574,4 +415,18 @@ function init() {
        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");
+       }
+               
 }
+
+