-/*
- This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
- Licensed under GPL v.2 or (at your preference) any later version.
-*/
-
var xmlhttp = false;
-
var total_unread = 0;
var first_run = true;
-
-var search_query = "";
+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)
xmlhttp = new XMLHttpRequest();
}
-/*
-function feedlist_callback() {
- var container = document.getElementById('feeds');
- if (xmlhttp.readyState == 4) {
- container.innerHTML=xmlhttp.responseText;
+function toggleTags() {
+ display_tags = !display_tags;
- if (first_run) {
- scheduleFeedUpdate(false);
- if (getCookie("ttrss_vf_actfeed")) {
- viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
+ var p = document.getElementById("dispSwitchPrompt");
+
+ if (display_tags) {
+ p.innerHTML = "display feeds";
+ } else {
+ p.innerHTML = "display tags";
+ }
+
+ updateFeedList();
+}
+
+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.";
}
- first_run = false;
- } else {
- notify("");
- }
+ }
+ closeDlg();
}
}
-*/
-function refetch_callback() {
+function hide_unread_callback() {
if (xmlhttp.readyState == 4) {
- document.title = "Tiny Tiny RSS";
- notify("All feeds updated.");
+ try {
- var reply = xmlhttp.responseXML.firstChild;
+ 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);
+ }
+
+ }
+}
- var f_document = window.frames["feeds-frame"].document;
+function refetch_callback() {
+ if (xmlhttp.readyState == 4) {
+ try {
+
+ var date = new Date();
+
+ last_refetch = date.getTime() / 1000;
- for (var l = 0; l < reply.childNodes.length; l++) {
- var id = reply.childNodes[l].getAttribute("id");
- var ctr = reply.childNodes[l].getAttribute("counter");
+ if (!xmlhttp.responseXML) {
+ notify("refetch_callback: backend did not return valid XML");
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
+
+ if (!reply) {
+ notify("refetch_callback: backend did not return expected XML object");
+ updateTitle("");
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code, reply.getAttribute("error-msg"));
+ }
+
+ var f_document = window.frames["feeds-frame"].document;
- var feedctr = f_document.getElementById("FEEDCTR-" + id);
- var feedu = f_document.getElementById("FEEDU-" + id);
- var feedr = f_document.getElementById("FEEDR-" + id);
+ parse_counters(reply, f_document, window, true);
- feedu.innerHTML = ctr;
+ debug("refetch_callback: done");
- if (ctr > 0) {
- feedctr.className = "odd";
- if (!feedr.className.match("Unread")) {
- feedr.className = feedr.className + "Unread";
- }
+ if (!daemon_enabled) {
+ notify("All feeds updated.");
+ updateTitle("");
} else {
- feedctr.className = "invisible";
- feedr.className = feedr.className.replace("Unread", "");
+ notify("");
}
- }
+ } catch (e) {
+ exception_error("refetch_callback", e);
+ updateTitle("");
+ }
}
}
-function updateFeed(feed_id) {
+function backend_sanity_check_callback() {
- var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
+ if (xmlhttp.readyState == 4) {
- if (xmlhttp_ready(xmlhttp)) {
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feed_update_callback;
- xmlhttp.send(null);
- } else {
- printLockingError();
- }
+ try {
+
+ if (!xmlhttp.responseXML) {
+ fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
+
+ if (!reply) {
+ fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code, reply.getAttribute("error-msg"));
+ }
+
+ debug("sanity check ok");
+
+ init_second_stage();
+ } catch (e) {
+ exception_error("backend_sanity_check_callback", e);
+ }
+ }
}
function scheduleFeedUpdate(force) {
- notify("Updating feeds in background...");
-
- document.title = "Tiny Tiny RSS - Updating...";
+ if (!daemon_enabled) {
+ notify("Updating feeds, please wait.");
+ updateTitle("Updating");
+ }
var query_str = "backend.php?op=rpc&subop=";
query_str = query_str + "updateAllFeeds";
}
+ var omode;
+
+ if (firsttime_update && !navigator.userAgent.match("Opera")) {
+ firsttime_update = false;
+ omode = "T";
+ } else {
+ 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();
}
}
var query_str = "backend.php?op=feeds";
+ if (display_tags) {
+ query_str = query_str + "&tags=1";
+ }
+
if (getActiveFeedId()) {
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");
feeds_frame.src = query_str;
+ global_unread = 0;
+ updateTitle("");
+
}
function viewCurrentFeed(skip, subop) {
if (getActiveFeedId()) {
viewfeed(getActiveFeedId(), skip, subop);
+ } else {
+ disableContainerChildren("headlinesToolbar", false, document);
+ viewfeed(-1, skip, subop); // FIXME
}
}
function viewfeed(feed, skip, subop) {
+ var f = window.frames["feeds-frame"];
+ f.viewfeed(feed, skip, subop);
+}
-// notify("Loading headlines...");
-
- enableHotkeys();
+function timeout() {
+ scheduleFeedUpdate(false);
- var searchbox = document.getElementById("searchbox");
+ var refresh_time = getCookie('ttrss_vf_refresh');
- if (searchbox) {
- search_query = searchbox.value;
- } else {
- search_query = "";
- }
+ if (!refresh_time) refresh_time = 600;
- var viewbox = document.getElementById("viewbox");
+ setTimeout("timeout()", refresh_time*1000);
+}
- var view_mode;
+function resetSearch() {
+ var searchbox = document.getElementById("searchbox")
- if (viewbox) {
- view_mode = viewbox[viewbox.selectedIndex].text;
- } else {
- view_mode = "All Posts";
+ if (searchbox.value != "" && getActiveFeedId()) {
+ searchbox.value = "";
+ viewfeed(getActiveFeedId(), 0, "");
}
+}
- setCookie("ttrss_vf_vmode", view_mode);
+function search() {
+ closeDlg();
+ viewCurrentFeed(0, "");
+}
- var limitbox = document.getElementById("limitbox");
+function localPiggieFunction(enable) {
+ if (enable) {
+ var query_str = "backend.php?op=feeds&subop=piggie";
- var limit;
+ if (xmlhttp_ready(xmlhttp)) {
- if (limitbox) {
- limit = limitbox[limitbox.selectedIndex].text;
- setCookie("ttrss_vf_limit", limit);
- } else {
- limit = "All";
+ xmlhttp.open("GET", query_str, true);
+ xmlhttp.onreadystatechange=feedlist_callback;
+ xmlhttp.send(null);
+ }
}
+}
- setActiveFeedId(feed);
+function localHotkeyHandler(keycode) {
- var f_doc = frames["feeds-frame"].document;
+ if (keycode == 82) { // r
+ return scheduleFeedUpdate(true);
+ }
-// f_doc.getElementById("ACTFEEDID").innerHTML = feed;
+ if (keycode == 85) { // u
+ if (getActiveFeedId()) {
+ return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+ }
+ }
- if (subop == "MarkAllRead") {
+ if (keycode == 65) { // a
+ return toggleDispRead();
+ }
- var feedr = f_doc.getElementById("FEEDR-" + feed);
- var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
-
- feedctr.className = "invisible";
+ var f_doc = window.frames["feeds-frame"].document;
+ var feedlist = f_doc.getElementById('feedList');
- if (feedr.className.match("Unread")) {
- feedr.className = feedr.className.replace("Unread", "");
- }
+ if (keycode == 74) { // j
+ var feed = getActiveFeedId();
+ var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
+ if (new_feed) viewfeed(new_feed, 0, '');
}
- 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 (keycode == 75) { // k
+ var feed = getActiveFeedId();
+ var new_feed = getRelativeFeedId(feedlist, feed, 'next');
+ if (new_feed) viewfeed(new_feed, 0, '');
+ }
+
+// notify("KC: " + keycode);
+
+}
+
+// if argument is undefined, current subtitle is not updated
+// use blank string to clear subtitle
+function updateTitle(s) {
+ var tmp = "Tiny Tiny RSS";
- if (search_query != "") {
- query = query + "&search=" + param_escape(search_query);
+ if (s != undefined) {
+ current_subtitle = s;
}
-
- var headlines_frame = parent.frames["headlines-frame"];
- headlines_frame.location.href = query + "&addheader=true";
+ if (global_unread > 0) {
+ tmp = tmp + " (" + global_unread + ")";
+ }
- cleanSelected("feedsList");
- var feedr = document.getElementById("FEEDR-" + feed);
- if (feedr) {
- feedr.className = feedr.className + "Selected";
+ if (current_subtitle) {
+ tmp = tmp + " - " + current_subtitle;
}
-
- disableContainerChildren("headlinesToolbar", false, doc);
-// notify("");
+ if (active_title_text.length > 0) {
+ tmp = tmp + " > " + active_title_text;
+ }
+ document.title = tmp;
}
+function genericSanityCheck() {
-function timeout() {
- scheduleFeedUpdate(true);
- setTimeout("timeout()", 1800*1000);
+ if (!xmlhttp) fatalError(1);
+
+ setCookie("ttrss_vf_test", "TEST");
+
+ if (getCookie("ttrss_vf_test") != "TEST") {
+ fatalError(2);
+ }
+
+ return true;
}
-function resetSearch() {
- var searchbox = document.getElementById("searchbox")
+function init() {
- if (searchbox.value != "" && getActiveFeedId()) {
- searchbox.value = "";
- viewfeed(getActiveFeedId(), 0, "");
+ 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);
+
+ } catch (e) {
+ exception_error("init", e);
}
}
-function search() {
- checkActiveFeedId();
- if (getActiveFeedId()) {
- viewfeed(getActiveFeedId(), 0, "");
- } else {
- notify("Please select some feed first.");
- }
+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 localPiggieFunction(enable) {
- if (enable) {
- var query_str = "backend.php?op=feeds&subop=piggie";
+function init_second_stage() {
- if (xmlhttp_ready(xmlhttp)) {
+ try {
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feedlist_callback;
- xmlhttp.send(null);
+ cookie_lifetime = getCookie("ttrss_cltime");
+
+ delCookie("ttrss_vf_test");
+
+ setCookie("ttrss_vf_actfeed", "");
+
+ updateFeedList(false, false);
+ document.onkeydown = hotkey_handler;
+
+ 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;
+
+ h.style.height = nh + "px";
+ c.style.height = c.scrollHeight - nh + "px"; */
+
}
+
+ debug("second stage ok");
+
+ } catch (e) {
+ exception_error("init_second_stage", e);
}
}
-function localHotkeyHandler(keycode) {
+function quickMenuChange() {
+ var chooser = document.getElementById("quickMenuChooser");
+ var opid = chooser[chooser.selectedIndex].id;
-/* if (keycode == 78) {
- return moveToPost('next');
- }
+ chooser.selectedIndex = 0;
+ quickMenuGo(opid);
+}
- if (keycode == 80) {
- return moveToPost('prev');
- } */
+function quickMenuGo(opid) {
+ try {
- if (keycode == 82) {
- return scheduleFeedUpdate(true);
+ if (opid == "qmcPrefs") {
+ gotoPreferences();
+ }
+
+ if (opid == "qmcSearch") {
+ displayDlg("search", getActiveFeedId());
+ return;
+ }
+
+ if (opid == "qmcAddFeed") {
+ displayDlg("quickAddFeed");
+ return;
+ }
+
+ if (opid == "qmcRemoveFeed") {
+ var actid = getActiveFeedId();
+
+ if (!actid) {
+ notify("Please select some feed first.");
+ return;
+ }
+
+ if (confirm("Remove current feed?")) {
+ qfdDelete(actid);
+ }
+
+ return;
+ }
+
+ if (opid == "qmcUpdateFeeds") {
+ scheduleFeedUpdate(true);
+ return;
+ }
+
+ if (opid == "qmcCatchupAll") {
+ catchupAllFeeds();
+ return;
+ }
+
+ if (opid == "qmcShowOnlyUnread") {
+ toggleDispRead();
+ return;
+ }
+
+ if (opid == "qmcAddFilter") {
+ displayDlg("quickAddFilter", getActiveFeedId());
+ }
+ } catch (e) {
+ exception_error("quickMenuGo", e);
}
+}
+
+function qafAdd() {
- if (keycode == 85) {
- return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
}
-// notify("KC: " + keycode);
+ var link = document.getElementById("qafInput");
-}
+ if (link.value.length == 0) {
+ alert("Error: No feed URL given.");
+ } else if (link.value.match("http://") == null &&
+ link.value.match("https://") == null) {
+ alert("Error: Invalid feed URL.");
+ } else {
+ notify("Adding feed...");
-function genericSanityCheck() {
+ closeInfoBox();
+
+ 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) + "&cid=" + param_escape(cat_id), true);
+ xmlhttp.onreadystatechange=dlg_frefresh_callback;
+ xmlhttp.send(null);
+
+ link.value = "";
- 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;
}
+}
- setCookie("ttrss_vf_test", "TEST");
- if (getCookie("ttrss_vf_test") != "TEST") {
+function qfdDelete(feed_id) {
- document.getElementById("headlines").innerHTML =
- "<b>Fatal error:</b> This program requires cookies " +
- "to function properly. Your browser doesn't seem to support them.";
+ notify("Removing feed...");
- return false;
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
}
- return true;
+// 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 init() {
- disableContainerChildren("headlinesToolbar", true);
+function updateFeedTitle(t) {
+ active_title_text = t;
+ updateTitle();
+}
- if (!genericSanityCheck())
- return;
+function toggleDispRead() {
+ try {
- updateFeedList(false, false);
- document.onkeydown = hotkey_handler;
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
- setTimeout("timeout()", 1800*1000);
- scheduleFeedUpdate(true);
+ var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
- var content = document.getElementById("content");
+ 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 (getCookie("ttrss_vf_vmode")) {
- var viewbox = document.getElementById("viewbox");
- viewbox.value = getCookie("ttrss_vf_vmode");
+ xmlhttp.open("GET", query);
+ xmlhttp.onreadystatechange=hide_unread_callback;
+ xmlhttp.send(null);
+
+ } catch (e) {
+ exception_error("toggleDispRead", e);
}
+}
- if (getCookie("ttrss_vf_limit")) {
- var limitbox = document.getElementById("limitbox");
- limitbox.value = getCookie("ttrss_vf_limit");
+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;
}
+}
-// if (getCookie("ttrss_vf_actfeed")) {
-// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-// }
+function fatalError(code, message) {
+ try {
+ var fe = document.getElementById("fatal_error");
+ var fc = document.getElementById("fatal_error_msg");
- setCookie("ttrss_vf_actfeed", "");
-
-}
+ fc.innerHTML = "Code " + code + ": " + message;
+ fe.style.display = "block";
+ } catch (e) {
+ exception_error("fatalError", e);
+ }
+}