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 updateFeed(feed_id) {
126 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
128 if (xmlhttp_ready(xmlhttp)) {
129 xmlhttp.open("GET", query_str, true);
130 xmlhttp.onreadystatechange=feed_update_callback;
138 function scheduleFeedUpdate(force) {
140 notify("Updating feeds in background...");
142 // document.title = "Tiny Tiny RSS - Updating...";
144 updateTitle("Updating...");
146 var query_str = "backend.php?op=rpc&subop=";
149 query_str = query_str + "forceUpdateAllFeeds";
151 query_str = query_str + "updateAllFeeds";
162 query_str = query_str + "&omode=" + omode;
164 if (xmlhttp_ready(xmlhttp)) {
165 xmlhttp.open("GET", query_str, true);
166 xmlhttp.onreadystatechange=refetch_callback;
173 function updateFeedList(silent, fetch) {
175 // if (silent != true) {
176 // notify("Loading feed list...");
179 var query_str = "backend.php?op=feeds";
182 query_str = query_str + "&tags=1";
185 if (getActiveFeedId()) {
186 query_str = query_str + "&actid=" + getActiveFeedId();
189 if (fetch) query_str = query_str + "&fetch=yes";
191 var feeds_frame = document.getElementById("feeds-frame");
193 feeds_frame.src = query_str;
196 function catchupAllFeeds() {
198 var query_str = "backend.php?op=feeds&subop=catchupAll";
200 notify("Marking all feeds as read...");
202 var feeds_frame = document.getElementById("feeds-frame");
204 feeds_frame.src = query_str;
211 function viewCurrentFeed(skip, subop) {
213 if (getActiveFeedId()) {
214 viewfeed(getActiveFeedId(), skip, subop);
216 disableContainerChildren("headlinesToolbar", false, document);
217 viewfeed(-1, skip, subop); // FIXME
221 function viewfeed(feed, skip, subop) {
222 var f = window.frames["feeds-frame"];
223 f.viewfeed(feed, skip, subop);
227 scheduleFeedUpdate(true);
228 setTimeout("timeout()", 1800*1000);
231 function resetSearch() {
232 var searchbox = document.getElementById("searchbox")
234 if (searchbox.value != "" && getActiveFeedId()) {
235 searchbox.value = "";
236 viewfeed(getActiveFeedId(), 0, "");
241 viewCurrentFeed(0, "");
244 function localPiggieFunction(enable) {
246 var query_str = "backend.php?op=feeds&subop=piggie";
248 if (xmlhttp_ready(xmlhttp)) {
250 xmlhttp.open("GET", query_str, true);
251 xmlhttp.onreadystatechange=feedlist_callback;
257 function localHotkeyHandler(keycode) {
259 /* if (keycode == 78) {
260 return moveToPost('next');
264 return moveToPost('prev');
267 if (keycode == 82) { // r
268 return scheduleFeedUpdate(true);
271 if (keycode == 85) { // u
272 if (getActiveFeedId()) {
273 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
277 if (keycode == 65) { // a
278 return toggleDispRead();
281 // notify("KC: " + keycode);
285 function updateTitle(s) {
286 var tmp = "Tiny Tiny RSS";
288 if (global_unread > 0) {
289 tmp = tmp + " (" + global_unread + ")";
293 tmp = tmp + " - " + s;
295 document.title = tmp;
298 function genericSanityCheck() {
301 document.getElementById("headlines").innerHTML =
302 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
303 "to function properly. Your browser doesn't seem to support it.";
307 setCookie("ttrss_vf_test", "TEST");
308 if (getCookie("ttrss_vf_test") != "TEST") {
310 document.getElementById("headlines").innerHTML =
311 "<b>Fatal error:</b> This program requires cookies " +
312 "to function properly. Your browser doesn't seem to support them.";
322 disableContainerChildren("headlinesToolbar", true);
324 if (!genericSanityCheck())
327 setCookie("ttrss_vf_actfeed", "");
329 updateFeedList(false, false);
330 document.onkeydown = hotkey_handler;
332 setTimeout("timeout()", 1800*1000);
333 scheduleFeedUpdate(true);
335 var content = document.getElementById("content");
337 if (getCookie("ttrss_vf_vmode")) {
338 var viewbox = document.getElementById("viewbox");
339 viewbox.value = getCookie("ttrss_vf_vmode");
342 if (getCookie("ttrss_vf_limit")) {
343 var limitbox = document.getElementById("limitbox");
344 limitbox.value = getCookie("ttrss_vf_limit");
347 // if (getCookie("ttrss_vf_actfeed")) {
348 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
353 function quickMenuGo() {
355 var chooser = document.getElementById("quickMenuChooser");
356 var opid = chooser[chooser.selectedIndex].id;
358 if (opid == "qmcPrefs") {
362 if (opid == "qmcAdvSearch") {
363 displayDlg("search");
367 if (opid == "qmcAddFeed") {
368 displayDlg("quickAddFeed");
372 if (opid == "qmcRemoveFeed") {
373 var actid = getActiveFeedId();
376 notify("Please select some feed first.");
380 displayDlg("quickDelFeed", actid);
384 if (opid == "qmcUpdateFeeds") {
385 scheduleFeedUpdate(true);
389 if (opid == "qmcCatchupAll") {
394 if (opid == "qmcShowOnlyUnread") {
403 if (!xmlhttp_ready(xmlhttp)) {
408 var link = document.getElementById("qafInput");
410 if (link.value.length == 0) {
411 notify("Missing feed URL.");
413 notify("Adding feed...");
415 var feeds_doc = window.frames["feeds-frame"].document;
417 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
419 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
420 param_escape(link.value), true);
421 xmlhttp.onreadystatechange=dlg_frefresh_callback;
429 function displayDlg(id, param) {
433 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
434 param_escape(id) + "¶m=" + param_escape(param), true);
435 xmlhttp.onreadystatechange=dialog_refresh_callback;
440 function closeDlg() {
441 var dlg = document.getElementById("userDlg");
442 dlg.style.display = "none";
445 function qfdDelete(feed_id) {
447 notify("Removing feed...");
449 var feeds_doc = window.frames["feeds-frame"].document;
450 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
452 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
453 xmlhttp.onreadystatechange=dlg_frefresh_callback;
458 function allFeedsMenuGo() {
459 var chooser = document.getElementById("allFeedsChooser");
461 var opname = chooser[chooser.selectedIndex].text;
463 if (opname == "Update") {
464 scheduleFeedUpdate(true);
468 if (opname == "Mark as read") {
473 if (opname == "Show only read") {
480 function toggleDispRead() {
481 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
483 hide_read_feeds = !hide_read_feeds;
485 var feeds_doc = window.frames["feeds-frame"].document;
487 hideOrShowFeeds(feeds_doc, hide_read_feeds);
489 if (hide_read_feeds) {
490 setCookie("ttrss_vf_hreadf", 1);
492 setCookie("ttrss_vf_hreadf", 0);