2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
11 var search_query = "";
14 var display_tags = false;
15 //var display_read_feeds = true;
17 var global_unread = 0;
20 /*@if (@_jscript_version >= 5)
21 // JScript gives us Conditional compilation, we can cope with old IE versions.
22 // and security blocked creation of the objects.
24 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
27 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
34 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
35 xmlhttp = new XMLHttpRequest();
38 function toggleTags() {
39 display_tags = !display_tags;
41 var p = document.getElementById("dispSwitchPrompt");
44 p.innerHTML = "display feeds";
46 p.innerHTML = "display tags";
52 function dlg_frefresh_callback() {
53 if (xmlhttp.readyState == 4) {
54 updateFeedList(false, false);
59 function dialog_refresh_callback() {
60 if (xmlhttp.readyState == 4) {
61 var dlg = document.getElementById("userDlg");
63 dlg.innerHTML = xmlhttp.responseText;
64 dlg.style.display = "block";
68 function refetch_callback() {
69 if (xmlhttp.readyState == 4) {
71 // document.title = "Tiny Tiny RSS";
73 if (!xmlhttp.responseXML) {
74 notify("refetch_callback: backend did not return valid XML");
78 var reply = xmlhttp.responseXML.firstChild;
81 notify("refetch_callback: backend did not return expected XML object");
85 var f_document = window.frames["feeds-frame"].document;
87 for (var l = 0; l < reply.childNodes.length; l++) {
88 var id = reply.childNodes[l].getAttribute("id");
89 var ctr = reply.childNodes[l].getAttribute("counter");
91 var feedctr = f_document.getElementById("FEEDCTR-" + id);
92 var feedu = f_document.getElementById("FEEDU-" + id);
93 var feedr = f_document.getElementById("FEEDR-" + id);
95 /* TODO figure out how to update this from viewfeed.js->view()
98 if (id == "global-unread") {
102 if (feedctr && feedu && feedr) {
104 feedu.innerHTML = ctr;
107 feedctr.className = "odd";
108 if (!feedr.className.match("Unread")) {
109 feedr.className = feedr.className + "Unread";
112 feedctr.className = "invisible";
113 feedr.className = feedr.className.replace("Unread", "");
119 notify("All feeds updated.");
124 function backend_sanity_check_callback() {
126 if (xmlhttp.readyState == 4) {
128 if (!xmlhttp.responseXML) {
133 var reply = xmlhttp.responseXML.firstChild;
140 var error_code = reply.getAttribute("code");
142 if (error_code && error_code != 0) {
143 return fatalError(error_code);
150 function updateFeed(feed_id) {
152 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
154 if (xmlhttp_ready(xmlhttp)) {
155 xmlhttp.open("GET", query_str, true);
156 xmlhttp.onreadystatechange=feed_update_callback;
164 function scheduleFeedUpdate(force) {
166 notify("Updating feeds in background...");
168 // document.title = "Tiny Tiny RSS - Updating...";
170 updateTitle("Updating...");
172 var query_str = "backend.php?op=rpc&subop=";
175 query_str = query_str + "forceUpdateAllFeeds";
177 query_str = query_str + "updateAllFeeds";
188 query_str = query_str + "&omode=" + omode;
190 if (xmlhttp_ready(xmlhttp)) {
191 xmlhttp.open("GET", query_str, true);
192 xmlhttp.onreadystatechange=refetch_callback;
199 function updateFeedList(silent, fetch) {
201 // if (silent != true) {
202 // notify("Loading feed list...");
205 var query_str = "backend.php?op=feeds";
208 query_str = query_str + "&tags=1";
211 if (getActiveFeedId()) {
212 query_str = query_str + "&actid=" + getActiveFeedId();
215 if (fetch) query_str = query_str + "&fetch=yes";
217 var feeds_frame = document.getElementById("feeds-frame");
219 feeds_frame.src = query_str;
222 function catchupAllFeeds() {
224 var query_str = "backend.php?op=feeds&subop=catchupAll";
226 notify("Marking all feeds as read...");
228 var feeds_frame = document.getElementById("feeds-frame");
230 feeds_frame.src = query_str;
237 function viewCurrentFeed(skip, subop) {
239 if (getActiveFeedId()) {
240 viewfeed(getActiveFeedId(), skip, subop);
242 disableContainerChildren("headlinesToolbar", false, document);
243 viewfeed(-1, skip, subop); // FIXME
247 function viewfeed(feed, skip, subop) {
248 var f = window.frames["feeds-frame"];
249 f.viewfeed(feed, skip, subop);
253 scheduleFeedUpdate(true);
254 setTimeout("timeout()", 1800*1000);
257 function resetSearch() {
258 var searchbox = document.getElementById("searchbox")
260 if (searchbox.value != "" && getActiveFeedId()) {
261 searchbox.value = "";
262 viewfeed(getActiveFeedId(), 0, "");
267 viewCurrentFeed(0, "");
270 function localPiggieFunction(enable) {
272 var query_str = "backend.php?op=feeds&subop=piggie";
274 if (xmlhttp_ready(xmlhttp)) {
276 xmlhttp.open("GET", query_str, true);
277 xmlhttp.onreadystatechange=feedlist_callback;
283 function localHotkeyHandler(keycode) {
285 /* if (keycode == 78) {
286 return moveToPost('next');
290 return moveToPost('prev');
293 if (keycode == 82) { // r
294 return scheduleFeedUpdate(true);
297 if (keycode == 85) { // u
298 if (getActiveFeedId()) {
299 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
303 if (keycode == 65) { // a
304 return toggleDispRead();
307 // notify("KC: " + keycode);
311 function updateTitle(s) {
312 var tmp = "Tiny Tiny RSS";
314 if (global_unread > 0) {
315 tmp = tmp + " (" + global_unread + ")";
319 tmp = tmp + " - " + s;
321 document.title = tmp;
324 function genericSanityCheck() {
326 if (!xmlhttp) fatalError(1);
328 setCookie("ttrss_vf_test", "TEST");
330 if (getCookie("ttrss_vf_test") != "TEST") {
335 document.getElementById("headlines").innerHTML =
336 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
337 "to function properly. Your browser doesn't seem to support it.";
341 setCookie("ttrss_vf_test", "TEST");
342 if (getCookie("ttrss_vf_test") != "TEST") {
344 document.getElementById("headlines").innerHTML =
345 "<b>Fatal error:</b> This program requires cookies " +
346 "to function properly. Your browser doesn't seem to support them.";
356 disableContainerChildren("headlinesToolbar", true);
358 if (!genericSanityCheck())
361 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
362 xmlhttp.onreadystatechange=backend_sanity_check_callback;
367 function init_second_stage() {
369 setCookie("ttrss_vf_actfeed", "");
371 updateFeedList(false, false);
372 document.onkeydown = hotkey_handler;
374 var content = document.getElementById("content");
376 if (getCookie("ttrss_vf_vmode")) {
377 var viewbox = document.getElementById("viewbox");
378 viewbox.value = getCookie("ttrss_vf_vmode");
381 if (getCookie("ttrss_vf_limit")) {
382 var limitbox = document.getElementById("limitbox");
383 limitbox.value = getCookie("ttrss_vf_limit");
386 // if (getCookie("ttrss_vf_actfeed")) {
387 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
390 setTimeout("timeout()", 2*1000);
391 // scheduleFeedUpdate(true);
396 function quickMenuGo() {
398 var chooser = document.getElementById("quickMenuChooser");
399 var opid = chooser[chooser.selectedIndex].id;
401 if (opid == "qmcPrefs") {
405 if (opid == "qmcAdvSearch") {
406 displayDlg("search");
410 if (opid == "qmcAddFeed") {
411 displayDlg("quickAddFeed");
415 if (opid == "qmcRemoveFeed") {
416 var actid = getActiveFeedId();
419 notify("Please select some feed first.");
423 displayDlg("quickDelFeed", actid);
427 if (opid == "qmcUpdateFeeds") {
428 scheduleFeedUpdate(true);
432 if (opid == "qmcCatchupAll") {
437 if (opid == "qmcShowOnlyUnread") {
446 if (!xmlhttp_ready(xmlhttp)) {
451 var link = document.getElementById("qafInput");
453 if (link.value.length == 0) {
454 notify("Missing feed URL.");
456 notify("Adding feed...");
458 var feeds_doc = window.frames["feeds-frame"].document;
460 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
462 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
463 param_escape(link.value), true);
464 xmlhttp.onreadystatechange=dlg_frefresh_callback;
472 function displayDlg(id, param) {
476 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
477 param_escape(id) + "¶m=" + param_escape(param), true);
478 xmlhttp.onreadystatechange=dialog_refresh_callback;
483 function closeDlg() {
484 var dlg = document.getElementById("userDlg");
485 dlg.style.display = "none";
488 function qfdDelete(feed_id) {
490 notify("Removing feed...");
492 var feeds_doc = window.frames["feeds-frame"].document;
493 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
495 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
496 xmlhttp.onreadystatechange=dlg_frefresh_callback;
501 function allFeedsMenuGo() {
502 var chooser = document.getElementById("allFeedsChooser");
504 var opname = chooser[chooser.selectedIndex].text;
506 if (opname == "Update") {
507 scheduleFeedUpdate(true);
511 if (opname == "Mark as read") {
516 if (opname == "Show only read") {
523 function toggleDispRead() {
524 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
526 hide_read_feeds = !hide_read_feeds;
528 var feeds_doc = window.frames["feeds-frame"].document;
530 hideOrShowFeeds(feeds_doc, hide_read_feeds);
532 if (hide_read_feeds) {
533 setCookie("ttrss_vf_hreadf", 1);
535 setCookie("ttrss_vf_hreadf", 0);