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 display_tags = false;
13 var global_unread = 0;
15 var active_title_text = "";
17 var current_subtitle = "";
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 error_code = reply.getAttribute("error-code");
87 if (error_code && error_code != 0) {
88 return fatalError(error_code);
91 var f_document = window.frames["feeds-frame"].document;
93 for (var l = 0; l < reply.childNodes.length; l++) {
94 var id = reply.childNodes[l].getAttribute("id");
95 var ctr = reply.childNodes[l].getAttribute("counter");
97 var feedctr = f_document.getElementById("FEEDCTR-" + id);
98 var feedu = f_document.getElementById("FEEDU-" + id);
99 var feedr = f_document.getElementById("FEEDR-" + id);
101 /* TODO figure out how to update this from viewfeed.js->view()
104 if (id == "global-unread") {
108 if (feedctr && feedu && feedr) {
110 feedu.innerHTML = ctr;
113 feedctr.className = "odd";
114 if (!feedr.className.match("Unread")) {
115 feedr.className = feedr.className + "Unread";
118 feedctr.className = "invisible";
119 feedr.className = feedr.className.replace("Unread", "");
125 notify("All feeds updated.");
130 function backend_sanity_check_callback() {
132 if (xmlhttp.readyState == 4) {
134 if (!xmlhttp.responseXML) {
139 var reply = xmlhttp.responseXML.firstChild;
146 var error_code = reply.getAttribute("error-code");
148 if (error_code && error_code != 0) {
149 return fatalError(error_code);
156 /* wtf this is obsolete
157 function updateFeed(feed_id) {
159 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
161 if (xmlhttp_ready(xmlhttp)) {
162 xmlhttp.open("GET", query_str, true);
163 xmlhttp.onreadystatechange=feed_update_callback;
172 function scheduleFeedUpdate(force) {
174 notify("Updating feeds in background...");
176 // document.title = "Tiny Tiny RSS - Updating...";
178 updateTitle("Updating");
180 var query_str = "backend.php?op=rpc&subop=";
183 query_str = query_str + "forceUpdateAllFeeds";
185 query_str = query_str + "updateAllFeeds";
196 query_str = query_str + "&omode=" + omode;
198 if (xmlhttp_ready(xmlhttp)) {
199 xmlhttp.open("GET", query_str, true);
200 xmlhttp.onreadystatechange=refetch_callback;
207 function updateFeedList(silent, fetch) {
209 // if (silent != true) {
210 // notify("Loading feed list...");
213 var query_str = "backend.php?op=feeds";
216 query_str = query_str + "&tags=1";
219 if (getActiveFeedId()) {
220 query_str = query_str + "&actid=" + getActiveFeedId();
223 if (fetch) query_str = query_str + "&fetch=yes";
225 var feeds_frame = document.getElementById("feeds-frame");
227 feeds_frame.src = query_str;
230 function catchupAllFeeds() {
232 var query_str = "backend.php?op=feeds&subop=catchupAll";
234 notify("Marking all feeds as read...");
236 var feeds_frame = document.getElementById("feeds-frame");
238 feeds_frame.src = query_str;
245 function viewCurrentFeed(skip, subop) {
247 if (getActiveFeedId()) {
248 viewfeed(getActiveFeedId(), skip, subop);
250 disableContainerChildren("headlinesToolbar", false, document);
251 viewfeed(-1, skip, subop); // FIXME
255 function viewfeed(feed, skip, subop) {
256 var f = window.frames["feeds-frame"];
257 f.viewfeed(feed, skip, subop);
261 scheduleFeedUpdate(false);
262 setTimeout("timeout()", 1800*1000);
265 function resetSearch() {
266 var searchbox = document.getElementById("searchbox")
268 if (searchbox.value != "" && getActiveFeedId()) {
269 searchbox.value = "";
270 viewfeed(getActiveFeedId(), 0, "");
275 viewCurrentFeed(0, "");
278 function localPiggieFunction(enable) {
280 var query_str = "backend.php?op=feeds&subop=piggie";
282 if (xmlhttp_ready(xmlhttp)) {
284 xmlhttp.open("GET", query_str, true);
285 xmlhttp.onreadystatechange=feedlist_callback;
291 function localHotkeyHandler(keycode) {
293 /* if (keycode == 78) {
294 return moveToPost('next');
298 return moveToPost('prev');
301 if (keycode == 82) { // r
302 return scheduleFeedUpdate(true);
305 if (keycode == 85) { // u
306 if (getActiveFeedId()) {
307 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
311 if (keycode == 65) { // a
312 return toggleDispRead();
315 // notify("KC: " + keycode);
319 function updateTitle(s) {
320 var tmp = "Tiny Tiny RSS";
322 if (s && s.length > 0) {
323 current_subtitle = s;
326 if (global_unread > 0) {
327 tmp = tmp + " (" + global_unread + ")";
331 tmp = tmp + " - " + current_subtitle;
334 if (active_title_text.length > 0) {
335 tmp = tmp + " > " + active_title_text;
338 document.title = tmp;
341 function genericSanityCheck() {
343 if (!xmlhttp) fatalError(1);
345 setCookie("ttrss_vf_test", "TEST");
347 if (getCookie("ttrss_vf_test") != "TEST") {
352 document.getElementById("headlines").innerHTML =
353 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
354 "to function properly. Your browser doesn't seem to support it.";
358 setCookie("ttrss_vf_test", "TEST");
359 if (getCookie("ttrss_vf_test") != "TEST") {
361 document.getElementById("headlines").innerHTML =
362 "<b>Fatal error:</b> This program requires cookies " +
363 "to function properly. Your browser doesn't seem to support them.";
373 disableContainerChildren("headlinesToolbar", true);
375 if (!genericSanityCheck())
378 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
379 xmlhttp.onreadystatechange=backend_sanity_check_callback;
384 function init_second_stage() {
386 setCookie("ttrss_vf_actfeed", "");
388 updateFeedList(false, false);
389 document.onkeydown = hotkey_handler;
391 var content = document.getElementById("content");
393 if (getCookie("ttrss_vf_vmode")) {
394 var viewbox = document.getElementById("viewbox");
395 viewbox.value = getCookie("ttrss_vf_vmode");
398 if (getCookie("ttrss_vf_limit")) {
399 var limitbox = document.getElementById("limitbox");
400 limitbox.value = getCookie("ttrss_vf_limit");
403 // if (getCookie("ttrss_vf_actfeed")) {
404 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
407 // setTimeout("timeout()", 2*1000);
408 // scheduleFeedUpdate(true);
410 var splash = document.getElementById("splash");
413 splash.style.display = "none";
418 function quickMenuGo() {
420 var chooser = document.getElementById("quickMenuChooser");
421 var opid = chooser[chooser.selectedIndex].id;
423 if (opid == "qmcPrefs") {
427 if (opid == "qmcAdvSearch") {
428 displayDlg("search");
432 if (opid == "qmcAddFeed") {
433 displayDlg("quickAddFeed");
437 if (opid == "qmcRemoveFeed") {
438 var actid = getActiveFeedId();
441 notify("Please select some feed first.");
445 displayDlg("quickDelFeed", actid);
449 if (opid == "qmcUpdateFeeds") {
450 scheduleFeedUpdate(true);
454 if (opid == "qmcCatchupAll") {
459 if (opid == "qmcShowOnlyUnread") {
468 if (!xmlhttp_ready(xmlhttp)) {
473 var link = document.getElementById("qafInput");
475 if (link.value.length == 0) {
476 notify("Missing feed URL.");
478 notify("Adding feed...");
480 var feeds_doc = window.frames["feeds-frame"].document;
482 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
484 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
485 param_escape(link.value), true);
486 xmlhttp.onreadystatechange=dlg_frefresh_callback;
494 function displayDlg(id, param) {
498 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
499 param_escape(id) + "¶m=" + param_escape(param), true);
500 xmlhttp.onreadystatechange=dialog_refresh_callback;
505 function closeDlg() {
506 var dlg = document.getElementById("userDlg");
507 dlg.style.display = "none";
510 function qfdDelete(feed_id) {
512 notify("Removing feed...");
514 var feeds_doc = window.frames["feeds-frame"].document;
515 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
517 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
518 xmlhttp.onreadystatechange=dlg_frefresh_callback;
523 function allFeedsMenuGo() {
524 var chooser = document.getElementById("allFeedsChooser");
526 var opname = chooser[chooser.selectedIndex].text;
528 if (opname == "Update") {
529 scheduleFeedUpdate(true);
533 if (opname == "Mark as read") {
538 if (opname == "Show only unread") {
545 function updateFeedTitle(t) {
546 active_title_text = t;
550 function toggleDispRead() {
551 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
553 hide_read_feeds = !hide_read_feeds;
555 var feeds_doc = window.frames["feeds-frame"].document;
557 hideOrShowFeeds(feeds_doc, hide_read_feeds);
559 if (hide_read_feeds) {
560 setCookie("ttrss_vf_hreadf", 1);
562 setCookie("ttrss_vf_hreadf", 0);