4 var display_tags
= false;
5 var global_unread
= -1;
6 var active_title_text
= "";
7 var current_subtitle
= "";
8 var daemon_enabled
= false;
9 var daemon_refresh_only
= false;
10 var _qfd_deleted_feed
= 0;
11 var firsttime_update
= true;
13 var cookie_lifetime
= 0;
14 var active_feed_id
= 0;
15 var active_feed_is_cat
= false;
17 var xmlhttp
= Ajax
.getTransport();
19 var init_params
= new Object();
21 function toggleTags() {
22 display_tags
= !display_tags
;
24 var p
= document
.getElementById("dispSwitchPrompt");
27 p
.innerHTML
= "display feeds";
29 p
.innerHTML
= "display tags";
35 function dlg_frefresh_callback() {
36 if (xmlhttp
.readyState
== 4) {
37 notify(xmlhttp
.responseText
);
38 updateFeedList(false, false);
39 if (_qfd_deleted_feed
) {
40 var hframe
= document
.getElementById("headlines-frame");
42 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
49 function refetch_callback() {
50 if (xmlhttp
.readyState
== 4) {
53 var date
= new Date();
55 last_refetch
= date
.getTime() / 1000;
57 if (!xmlhttp
.responseXML
) {
58 notify("refetch_callback: backend did not return valid XML", true, true);
62 var reply
= xmlhttp
.responseXML
.firstChild
;
65 notify("refetch_callback: backend did not return expected XML object", true, true);
70 var error_code
= reply
.getAttribute("error-code");
72 if (error_code
&& error_code
!= 0) {
73 return fatalError(error_code
, reply
.getAttribute("error-msg"));
76 var counters
= reply
.firstChild
;
78 parse_counters(counters
, true);
80 var runtime_info
= counters
.nextSibling
;
82 parse_runtime_info(runtime_info
);
84 debug("refetch_callback: done");
86 if (!daemon_enabled
&& !daemon_refresh_only
) {
87 notify("All feeds updated.");
93 exception_error("refetch_callback", e
);
99 function backend_sanity_check_callback() {
101 if (xmlhttp
.readyState
== 4) {
105 if (!xmlhttp
.responseXML
) {
106 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
110 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
113 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
117 var error_code
= reply
.getAttribute("error-code");
119 if (error_code
&& error_code
!= 0) {
120 return fatalError(error_code
, reply
.getAttribute("error-msg"));
123 debug("sanity check ok");
125 var params
= reply
.nextSibling
;
128 debug('reading init-params...');
129 var param
= params
.firstChild
;
132 var k
= param
.getAttribute("key");
133 var v
= param
.getAttribute("value");
134 debug(k
+ " => " + v
);
136 param
= param
.nextSibling
;
143 exception_error("backend_sanity_check_callback", e
);
148 function scheduleFeedUpdate(force
) {
150 if (!daemon_enabled
&& !daemon_refresh_only
) {
151 notify("Updating feeds, please wait.", true);
152 updateTitle("Updating");
155 var query_str
= "backend.php?op=rpc&subop=";
158 query_str
= query_str
+ "forceUpdateAllFeeds";
160 query_str
= query_str
+ "updateAllFeeds";
165 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
166 firsttime_update
= false;
176 query_str
= query_str
+ "&omode=" + omode
;
177 query_str
= query_str
+ "&uctr=" + global_unread
;
179 debug("in scheduleFeedUpdate");
181 var date
= new Date();
183 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
184 debug("<b>xmlhttp seems to be stuck, aborting</b>");
188 if (xmlhttp_ready(xmlhttp
)) {
189 xmlhttp
.open("GET", query_str
, true);
190 xmlhttp
.onreadystatechange
=refetch_callback
;
193 debug("xmlhttp busy");
198 function updateFeedList(silent
, fetch
) {
200 // if (silent != true) {
201 // notify("Loading feed list...");
204 var query_str
= "backend.php?op=feeds";
207 query_str
= query_str
+ "&tags=1";
210 if (getActiveFeedId()) {
211 query_str
= query_str
+ "&actid=" + getActiveFeedId();
214 if (navigator
.userAgent
.match("Opera")) {
215 var date
= new Date();
216 var timestamp
= Math
.round(date
.getTime() / 1000);
217 query_str
= query_str
+ "&ts=" + timestamp
220 if (fetch
) query_str
= query_str
+ "&fetch=yes";
222 var feeds_frame
= document
.getElementById("feeds-frame");
224 feeds_frame
.src
= query_str
;
227 function catchupAllFeeds() {
229 var query_str
= "backend.php?op=feeds&subop=catchupAll";
231 notify("Marking all feeds as read...");
233 var feeds_frame
= document
.getElementById("feeds-frame");
235 feeds_frame
.src
= query_str
;
242 function viewCurrentFeed(skip
, subop
) {
244 if (getActiveFeedId()) {
245 viewfeed(getActiveFeedId(), skip
, subop
);
247 disableContainerChildren("headlinesToolbar", false, document
);
248 viewfeed(-1, skip
, subop
); // FIXME
250 return false; // block unneeded form submits
253 function viewfeed(feed
, skip
, subop
) {
254 var f
= window
.frames
["feeds-frame"];
255 f
.viewfeed(feed
, skip
, subop
);
259 scheduleFeedUpdate(false);
261 var refresh_time
= getInitParam("feeds_frame_refresh");
263 if (!refresh_time
) refresh_time
= 600;
265 setTimeout("timeout()", refresh_time
*1000);
268 function resetSearch() {
269 var searchbox
= document
.getElementById("searchbox")
271 if (searchbox
.value
!= "" && getActiveFeedId()) {
272 searchbox
.value
= "";
273 viewfeed(getActiveFeedId(), 0, "");
277 function searchCancel() {
283 viewCurrentFeed(0, "");
286 function localPiggieFunction(enable
) {
288 var query_str
= "backend.php?op=feeds&subop=piggie";
290 if (xmlhttp_ready(xmlhttp
)) {
292 xmlhttp
.open("GET", query_str
, true);
293 xmlhttp
.onreadystatechange
=feedlist_callback
;
299 // if argument is undefined, current subtitle is not updated
300 // use blank string to clear subtitle
301 function updateTitle(s
) {
302 var tmp
= "Tiny Tiny RSS";
304 if (s
!= undefined) {
305 current_subtitle
= s
;
308 if (global_unread
> 0) {
309 tmp
= tmp
+ " (" + global_unread
+ ")";
312 if (current_subtitle
) {
313 tmp
= tmp
+ " - " + current_subtitle
;
316 if (active_title_text
.length
> 0) {
317 tmp
= tmp
+ " > " + active_title_text
;
320 document
.title
= tmp
;
323 function genericSanityCheck() {
325 if (!xmlhttp
) fatalError(1);
327 setCookie("ttrss_vf_test", "TEST");
329 if (getCookie("ttrss_vf_test") != "TEST") {
340 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
342 if (arguments
.callee
.done
) return;
343 arguments
.callee
.done
= true;
345 disableContainerChildren("headlinesToolbar", true);
347 Form
.disable("main_toolbar_form");
349 if (!genericSanityCheck())
352 if (getURLParam('debug')) {
353 document
.getElementById('debug_output').style
.display
= 'block';
354 debug('debug mode activated');
357 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
358 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
362 exception_error("init", e
);
366 function resize_feeds_frame() {
367 var f
= document
.getElementById("feeds-frame");
368 var tf
= document
.getElementById("mainFooter");
369 var th
= document
.getElementById("mainHeader");
371 var footer_height
= 0;
372 var header_height
= 0;
375 footer_height
= tf
.scrollHeight
;
379 header_height
= th
.scrollHeight
;
382 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
383 header_height
- 50 + "px";
386 function init_second_stage() {
390 cookie_lifetime
= getCookie("ttrss_cltime");
392 delCookie("ttrss_vf_test");
394 updateFeedList(false, false);
395 document
.onkeydown
= hotkey_handler
;
397 var tb
= parent
.document
.forms
["main_toolbar_form"];
399 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
400 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
402 daemon_enabled
= getInitParam("daemon_enabled") == 1;
403 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
405 // FIXME should be callled after window resize
407 var h
= document
.getElementById("headlines");
408 var c
= document
.getElementById("content");
410 if (navigator
.userAgent
.match("Opera")) {
411 resize_feeds_frame();
414 debug("second stage ok");
417 exception_error("init_second_stage", e
);
421 function quickMenuChange() {
422 var chooser
= document
.getElementById("quickMenuChooser");
423 var opid
= chooser
[chooser
.selectedIndex
].value
;
425 chooser
.selectedIndex
= 0;
429 function quickMenuGo(opid
) {
432 if (opid
== "qmcPrefs") {
436 if (opid
== "qmcSearch") {
437 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
441 if (opid
== "qmcAddFeed") {
442 displayDlg("quickAddFeed");
446 if (opid
== "qmcRemoveFeed") {
447 var actid
= getActiveFeedId();
450 alert("Please select some feed first.");
454 var fn
= getFeedName(actid
);
456 if (confirm("Unsubscribe from " + fn
+ "?")) {
463 if (opid
== "qmcUpdateFeeds") {
464 scheduleFeedUpdate(true);
468 if (opid
== "qmcCatchupAll") {
473 if (opid
== "qmcShowOnlyUnread") {
478 if (opid
== "qmcAddFilter") {
479 displayDlg("quickAddFilter", getActiveFeedId());
482 exception_error("quickMenuGo", e
);
486 function qfdDelete(feed_id
) {
488 notify("Removing feed...");
490 if (!xmlhttp_ready(xmlhttp
)) {
495 _qfd_deleted_feed
= feed_id
;
497 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
498 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
503 function updateFeedTitle(t
) {
504 active_title_text
= t
;
508 function toggleDispRead() {
511 if (!xmlhttp_ready(xmlhttp
)) {
516 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
518 hide_read_feeds
= !hide_read_feeds
;
520 debug("toggle_disp_read => " + hide_read_feeds
);
522 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
524 var query
= "backend.php?op=rpc&subop=setpref" +
525 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
527 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
529 new Ajax
.Request(query
);
532 exception_error("toggleDispRead", e
);
536 function parse_runtime_info(elem
) {
537 var param
= elem
.firstChild
;
539 debug("parse_runtime_info");
542 var k
= param
.getAttribute("key");
543 var v
= param
.getAttribute("value");
545 debug("RI: " + k
+ " => " + v
);
547 var w
= document
.getElementById("noDaemonWarning");
550 if (k
== "daemon_is_running" && v
!= 1) {
551 w
.style
.display
= "block";
553 w
.style
.display
= "none";
556 param
= param
.nextSibling
;
560 function catchupCurrentFeed() {
562 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
564 var str
= "Mark all articles in " + fn
+ " as read?";
566 /* if (active_feed_is_cat) {
567 str = "Mark all articles in this category as read?";
571 return viewCurrentFeed(0, 'MarkAllRead')