-/*
- 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 display_tags = false;
-
-var global_unread = 0;
+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)
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();
}
}
-function dialog_refresh_callback() {
+function dlg_submit_callback() {
+ if (xmlhttp.readyState == 4) {
+ notify(xmlhttp.responseText);
+ closeDlg();
+ }
+}
+
+function dlg_display_callback() {
if (xmlhttp.readyState == 4) {
var dlg = document.getElementById("userDlg");
+ var dlg_s = document.getElementById("userDlgShadow");
dlg.innerHTML = xmlhttp.responseText;
- dlg.style.display = "block";
+ dlg_s.style.display = "block";
}
}
-function refetch_callback() {
+function hide_unread_callback() {
if (xmlhttp.readyState == 4) {
-// document.title = "Tiny Tiny RSS";
+ try {
- if (!xmlhttp.responseXML) {
- notify("refetch_callback: backend did not return valid XML");
- return;
- }
+ 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;
- var reply = xmlhttp.responseXML.firstChild;
-
- if (!reply) {
- notify("refetch_callback: backend did not return expected XML object");
- return;
- }
-
- var error_code = reply.getAttribute("error-code");
+ hideOrShowFeeds(feeds_doc, hide_read_feeds);
- if (error_code && error_code != 0) {
- return fatalError(error_code);
+ 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;
-
- for (var l = 0; l < reply.childNodes.length; l++) {
- var id = reply.childNodes[l].getAttribute("id");
- var ctr = reply.childNodes[l].getAttribute("counter");
-
- var feedctr = f_document.getElementById("FEEDCTR-" + id);
- var feedu = f_document.getElementById("FEEDU-" + id);
- var feedr = f_document.getElementById("FEEDR-" + id);
+ }
+}
-/* TODO figure out how to update this from viewfeed.js->view()
- disabled for now...
+function refetch_callback() {
+ if (xmlhttp.readyState == 4) {
+ try {
- if (id == "global-unread") {
- global_unread = ctr;
- } */
+ var date = new Date();
- if (feedctr && feedu && feedr) {
+ last_refetch = date.getTime() / 1000;
- feedu.innerHTML = ctr;
+ 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;
+ }
- if (ctr > 0) {
- feedctr.className = "odd";
- if (!feedr.className.match("Unread")) {
- feedr.className = feedr.className + "Unread";
- }
- } else {
- feedctr.className = "invisible";
- feedr.className = feedr.className.replace("Unread", "");
- }
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code);
}
- }
+
+ var f_document = window.frames["feeds-frame"].document;
+
+ parse_counters(reply, f_document, window, true);
- updateTitle("");
- notify("All feeds updated.");
+ debug("refetch_callback: done");
+ if (!daemon_enabled) {
+ notify("All feeds updated.");
+ updateTitle("");
+ } else {
+ notify("");
+ }
+ } catch (e) {
+ exception_error("refetch_callback", e);
+ updateTitle("");
+ }
}
}
function backend_sanity_check_callback() {
if (xmlhttp.readyState == 4) {
+
+ try {
- if (!xmlhttp.responseXML) {
- fatalError(3);
- return;
- }
+ if (!xmlhttp.responseXML) {
+ fatalError(3, "D001;" + xmlhttp.responseText);
+ return;
+ }
+
+ var reply = xmlhttp.responseXML.firstChild;
+
+ if (!reply) {
+ fatalError(3, "D002;" + xmlhttp.responseText);
+ return;
+ }
+
+ var error_code = reply.getAttribute("error-code");
+
+ if (error_code && error_code != 0) {
+ return fatalError(error_code);
+ }
+
+ debug("sanity check ok");
- var reply = xmlhttp.responseXML.firstChild;
+ init_second_stage();
- if (!reply) {
- fatalError(3);
- return;
+ } catch (e) {
+ exception_error("backend_sanity_check_callback", e);
}
-
- var error_code = reply.getAttribute("error-code");
-
- if (error_code && error_code != 0) {
- return fatalError(error_code);
- }
-
- init_second_stage();
}
}
-function updateFeed(feed_id) {
-
- var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
-
- if (xmlhttp_ready(xmlhttp)) {
- xmlhttp.open("GET", query_str, true);
- xmlhttp.onreadystatechange=feed_update_callback;
- xmlhttp.send(null);
- } else {
- printLockingError();
- }
-
-}
-
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=";
var omode;
- if (display_tags) {
- omode = "t";
+ if (firsttime_update && !navigator.userAgent.match("Opera")) {
+ 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;
+
+ 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();
}
}
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();
+ updateTitle("");
}
function timeout() {
scheduleFeedUpdate(false);
- setTimeout("timeout()", 1800*1000);
+
+ var refresh_time = getCookie('ttrss_vf_refresh');
+
+ if (!refresh_time) refresh_time = 600;
+
+ setTimeout("timeout()", refresh_time*1000);
}
function resetSearch() {
}
function search() {
+ closeDlg();
viewCurrentFeed(0, "");
}
function localHotkeyHandler(keycode) {
-/* if (keycode == 78) {
- return moveToPost('next');
- }
-
- if (keycode == 80) {
- return moveToPost('prev');
- } */
-
if (keycode == 82) { // r
return scheduleFeedUpdate(true);
}
return toggleDispRead();
}
+ var f_doc = window.frames["feeds-frame"].document;
+ var feedlist = f_doc.getElementById('feedList');
+
+ if (keycode == 74) { // j
+ var feed = getActiveFeedId();
+ var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
+ if (new_feed) viewfeed(new_feed, 0, '');
+ }
+
+ 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 (s != undefined) {
+ current_subtitle = s;
+ }
+
if (global_unread > 0) {
tmp = tmp + " (" + global_unread + ")";
}
- if (s) {
- tmp = tmp + " - " + s;
+ if (current_subtitle) {
+ tmp = tmp + " - " + current_subtitle;
+ }
+
+ if (active_title_text.length > 0) {
+ tmp = tmp + " > " + active_title_text;
}
+
document.title = tmp;
}
fatalError(2);
}
-/* 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;
- }
+ return true;
+}
- setCookie("ttrss_vf_test", "TEST");
- if (getCookie("ttrss_vf_test") != "TEST") {
+function init() {
- document.getElementById("headlines").innerHTML =
- "<b>Fatal error:</b> This program requires cookies " +
- "to function properly. Your browser doesn't seem to support them.";
+ try {
- return false;
- } */
+ // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
- return true;
-}
+ if (arguments.callee.done) return;
+ arguments.callee.done = true;
-function init() {
+ disableContainerChildren("headlinesToolbar", true);
- disableContainerChildren("headlinesToolbar", true);
+ if (!genericSanityCheck())
+ return;
- 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);
+ 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 init_second_stage() {
+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";
+}
- setCookie("ttrss_vf_actfeed", "");
+function init_second_stage() {
- updateFeedList(false, false);
- document.onkeydown = hotkey_handler;
+ try {
- var content = document.getElementById("content");
+ cookie_lifetime = getCookie("ttrss_cltime");
- if (getCookie("ttrss_vf_vmode")) {
- var viewbox = document.getElementById("viewbox");
- viewbox.value = getCookie("ttrss_vf_vmode");
- }
+ delCookie("ttrss_vf_test");
- if (getCookie("ttrss_vf_limit")) {
+ setCookie("ttrss_vf_actfeed", "");
+
+ updateFeedList(false, false);
+ document.onkeydown = hotkey_handler;
+
+ var viewbox = document.getElementById("viewbox");
var limitbox = document.getElementById("limitbox");
- limitbox.value = getCookie("ttrss_vf_limit");
- }
-// if (getCookie("ttrss_vf_actfeed")) {
-// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
-// }
+ dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
+ dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
-// setTimeout("timeout()", 2*1000);
-// scheduleFeedUpdate(true);
+ daemon_enabled = getCookie("ttrss_vf_daemon");
- var splash = document.getElementById("splash");
+ // FIXME should be callled after window resize
- if (splash) {
- splash.style.display = "none";
- }
+ 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"; */
+
+ }
-function quickMenuGo() {
+ debug("second stage ok");
+
+ } catch (e) {
+ exception_error("init_second_stage", e);
+ }
+}
+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;
}
notify("Please select some feed first.");
return;
}
+
+ if (confirm("Remove current feed?")) {
+ qfdDelete(actid);
+ }
- displayDlg("quickDelFeed", actid);
return;
}
return;
}
+ if (opid == "qmcAddFilter") {
+ displayDlg("quickAddFilter", getActiveFeedId());
+ }
+
}
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&subop=add&link=" +
- param_escape(link.value), true);
+ 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);
}
}
+function qaddFilter() {
+
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
+
+ var regexp = document.getElementById("fadd_regexp");
+ var match = document.getElementById("fadd_match");
+ var feed = document.getElementById("fadd_feed");
+ var action = document.getElementById("fadd_action");
+
+ if (regexp.value.length == 0) {
+ notify("Missing filter expression.");
+ } else {
+ notify("Adding filter...");
+
+ var v_match = match[match.selectedIndex].text;
+ var feed_id = feed[feed.selectedIndex].id;
+ var action_id = action[action.selectedIndex].id;
+
+ xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
+ param_escape(regexp.value) + "&match=" + v_match +
+ "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
+
+ xmlhttp.onreadystatechange=dlg_submit_callback;
+ xmlhttp.send(null);
+
+ regexp.value = "";
+ }
+
+}
+
+
function displayDlg(id, param) {
+ if (!xmlhttp_ready(xmlhttp)) {
+ printLockingError();
+ return
+ }
+
notify("");
xmlhttp.open("GET", "backend.php?op=dlg&id=" +
param_escape(id) + "¶m=" + param_escape(param), true);
- xmlhttp.onreadystatechange=dialog_refresh_callback;
+ xmlhttp.onreadystatechange=dlg_display_callback;
xmlhttp.send(null);
+ disableHotkeys();
}
function closeDlg() {
- var dlg = document.getElementById("userDlg");
+ var dlg = document.getElementById("userDlgShadow");
dlg.style.display = "none";
+ enableHotkeys();
}
function qfdDelete(feed_id) {
notify("Removing feed...");
- var feeds_doc = window.frames["feeds-frame"].document;
- feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
+ 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&subop=remove&ids=" + 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;
return;
}
- if (opname == "Show only read") {
+ if (opname == "Show only unread") {
toggleDispRead();
return;
}
}
+function updateFeedTitle(t) {
+ active_title_text = t;
+ updateTitle();
+}
+
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);
}
-
}
-
+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;
+ }
+}