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;
16 var number_of_feeds
= 0;
18 var xmlhttp
= Ajax
.getTransport();
20 var init_params
= new Object();
22 function toggleTags() {
23 display_tags
= !display_tags
;
25 var p
= document
.getElementById("dispSwitchPrompt");
28 p
.innerHTML
= "display feeds";
30 p
.innerHTML
= "display tags";
36 function dlg_frefresh_callback() {
37 if (xmlhttp
.readyState
== 4) {
38 notify(xmlhttp
.responseText
);
39 updateFeedList(false, false);
40 if (_qfd_deleted_feed
) {
41 var hframe
= document
.getElementById("headlines-frame");
43 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
50 function refetch_callback() {
51 if (xmlhttp
.readyState
== 4) {
54 var date
= new Date();
56 last_refetch
= date
.getTime() / 1000;
58 if (!xmlhttp
.responseXML
) {
59 notify("refetch_callback: backend did not return valid XML", true, true);
63 var reply
= xmlhttp
.responseXML
.firstChild
;
66 notify("refetch_callback: backend did not return expected XML object", true, true);
71 var error_code
= reply
.getAttribute("error-code");
73 if (error_code
&& error_code
!= 0) {
74 return fatalError(error_code
, reply
.getAttribute("error-msg"));
77 var counters
= reply
.firstChild
;
79 parse_counters(counters
, true);
81 var runtime_info
= counters
.nextSibling
;
83 parse_runtime_info(runtime_info
);
85 debug("refetch_callback: done");
87 if (!daemon_enabled
&& !daemon_refresh_only
) {
88 notify("All feeds updated.");
94 exception_error("refetch_callback", e
);
100 function backend_sanity_check_callback() {
102 if (xmlhttp
.readyState
== 4) {
106 if (!xmlhttp
.responseXML
) {
107 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
111 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
114 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
118 var error_code
= reply
.getAttribute("error-code");
120 if (error_code
&& error_code
!= 0) {
121 return fatalError(error_code
, reply
.getAttribute("error-msg"));
124 debug("sanity check ok");
126 var params
= reply
.nextSibling
;
129 debug('reading init-params...');
130 var param
= params
.firstChild
;
133 var k
= param
.getAttribute("key");
134 var v
= param
.getAttribute("value");
135 debug(k
+ " => " + v
);
137 param
= param
.nextSibling
;
144 exception_error("backend_sanity_check_callback", e
);
149 function scheduleFeedUpdate(force
) {
151 if (!daemon_enabled
&& !daemon_refresh_only
) {
152 notify("Updating feeds, please wait.", true);
153 updateTitle("Updating");
156 var query_str
= "backend.php?op=rpc&subop=";
159 query_str
= query_str
+ "forceUpdateAllFeeds";
161 query_str
= query_str
+ "updateAllFeeds";
166 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
167 firsttime_update
= false;
177 query_str
= query_str
+ "&omode=" + omode
;
178 query_str
= query_str
+ "&uctr=" + global_unread
;
180 debug("in scheduleFeedUpdate");
182 var date
= new Date();
184 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
185 debug("<b>xmlhttp seems to be stuck, aborting</b>");
189 if (xmlhttp_ready(xmlhttp
)) {
190 xmlhttp
.open("GET", query_str
, true);
191 xmlhttp
.onreadystatechange
=refetch_callback
;
194 debug("xmlhttp busy");
195 //printLockingError();
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() && !activeFeedIsCat()) {
212 query_str
= query_str
+ "&actid=" + getActiveFeedId();
215 if (navigator
.userAgent
.match("Opera")) {
216 var date
= new Date();
217 var timestamp
= Math
.round(date
.getTime() / 1000);
218 query_str
= query_str
+ "&ts=" + timestamp
221 if (fetch
) query_str
= query_str
+ "&fetch=yes";
223 var feeds_frame
= document
.getElementById("feeds-frame");
225 feeds_frame
.src
= query_str
;
228 function catchupAllFeeds() {
230 var query_str
= "backend.php?op=feeds&subop=catchupAll";
232 notify("Marking all feeds as read...");
234 var feeds_frame
= document
.getElementById("feeds-frame");
236 feeds_frame
.src
= query_str
;
243 function viewCurrentFeed(subop
) {
245 // if (getActiveFeedId()) {
246 if (getActiveFeedId() != undefined) {
247 viewfeed(getActiveFeedId(), subop
);
249 disableContainerChildren("headlinesToolbar", false, document
);
250 // viewfeed(-1, subop); // FIXME
252 return false; // block unneeded form submits
255 function viewfeed(feed
, subop
) {
256 var f
= window
.frames
["feeds-frame"];
257 f
.viewfeed(feed
, subop
);
261 scheduleFeedUpdate(false);
263 var refresh_time
= getInitParam("feeds_frame_refresh");
265 if (!refresh_time
) refresh_time
= 600;
267 setTimeout("timeout()", refresh_time
*1000);
270 function resetSearch() {
271 var searchbox
= document
.getElementById("searchbox")
273 if (searchbox
.value
!= "" && getActiveFeedId()) {
274 searchbox
.value
= "";
275 viewfeed(getActiveFeedId(), "");
279 function searchCancel() {
285 viewCurrentFeed(0, "");
288 function localPiggieFunction(enable
) {
290 var query_str
= "backend.php?op=feeds&subop=piggie";
292 if (xmlhttp_ready(xmlhttp
)) {
294 xmlhttp
.open("GET", query_str
, true);
295 xmlhttp
.onreadystatechange
=feedlist_callback
;
301 // if argument is undefined, current subtitle is not updated
302 // use blank string to clear subtitle
303 function updateTitle(s
) {
304 var tmp
= "Tiny Tiny RSS";
306 if (s
!= undefined) {
307 current_subtitle
= s
;
310 if (global_unread
> 0) {
311 tmp
= tmp
+ " (" + global_unread
+ ")";
314 if (current_subtitle
) {
315 tmp
= tmp
+ " - " + current_subtitle
;
318 if (active_title_text
.length
> 0) {
319 tmp
= tmp
+ " > " + active_title_text
;
322 document
.title
= tmp
;
325 function genericSanityCheck() {
327 if (!xmlhttp
) fatalError(1);
329 setCookie("ttrss_vf_test", "TEST");
331 if (getCookie("ttrss_vf_test") != "TEST") {
342 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
344 if (arguments
.callee
.done
) return;
345 arguments
.callee
.done
= true;
347 disableContainerChildren("headlinesToolbar", true);
349 Form
.disable("main_toolbar_form");
351 if (!genericSanityCheck())
354 if (getURLParam('debug')) {
355 document
.getElementById('debug_output').style
.display
= 'block';
356 debug('debug mode activated');
359 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
360 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
364 exception_error("init", e
);
368 function resize_feeds_frame() {
369 var f
= document
.getElementById("feeds-frame");
370 var tf
= document
.getElementById("mainFooter");
371 var th
= document
.getElementById("mainHeader");
373 var footer_height
= 0;
374 var header_height
= 0;
377 footer_height
= tf
.scrollHeight
;
381 header_height
= th
.scrollHeight
;
384 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
385 header_height
- 50 + "px";
388 function init_second_stage() {
392 cookie_lifetime
= getCookie("ttrss_cltime");
394 delCookie("ttrss_vf_test");
396 updateFeedList(false, false);
397 document
.onkeydown
= hotkey_handler
;
399 var tb
= parent
.document
.forms
["main_toolbar_form"];
401 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
402 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
404 daemon_enabled
= getInitParam("daemon_enabled") == 1;
405 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
407 // FIXME should be callled after window resize
409 var h
= document
.getElementById("headlines");
410 var c
= document
.getElementById("content");
412 if (navigator
.userAgent
.match("Opera")) {
413 resize_feeds_frame();
416 debug("second stage ok");
419 exception_error("init_second_stage", e
);
423 function quickMenuChange() {
424 var chooser
= document
.getElementById("quickMenuChooser");
425 var opid
= chooser
[chooser
.selectedIndex
].value
;
427 chooser
.selectedIndex
= 0;
431 function quickMenuGo(opid
) {
434 if (opid
== "qmcPrefs") {
438 if (opid
== "qmcSearch") {
439 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
443 if (opid
== "qmcAddFeed") {
444 displayDlg("quickAddFeed");
448 if (opid
== "qmcRemoveFeed") {
449 var actid
= getActiveFeedId();
451 if (!actid
|| activeFeedIsCat()) {
452 alert("Please select some feed first.");
456 var fn
= getFeedName(actid
);
458 if (confirm("Unsubscribe from " + fn
+ "?")) {
465 if (opid
== "qmcUpdateFeeds") {
466 scheduleFeedUpdate(true);
470 if (opid
== "qmcCatchupAll") {
475 if (opid
== "qmcShowOnlyUnread") {
480 if (opid
== "qmcAddFilter") {
481 displayDlg("quickAddFilter", getActiveFeedId());
484 exception_error("quickMenuGo", e
);
488 function qfdDelete(feed_id
) {
490 notify("Removing feed...");
492 if (!xmlhttp_ready(xmlhttp
)) {
497 _qfd_deleted_feed
= feed_id
;
499 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
500 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
505 function updateFeedTitle(t
) {
506 active_title_text
= t
;
510 function toggleDispRead() {
513 if (!xmlhttp_ready(xmlhttp
)) {
518 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
520 hide_read_feeds
= !hide_read_feeds
;
522 debug("toggle_disp_read => " + hide_read_feeds
);
524 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
526 var query
= "backend.php?op=rpc&subop=setpref" +
527 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
529 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
531 new Ajax
.Request(query
);
534 exception_error("toggleDispRead", e
);
538 function parse_runtime_info(elem
) {
539 var param
= elem
.firstChild
;
541 debug("parse_runtime_info");
544 var k
= param
.getAttribute("key");
545 var v
= param
.getAttribute("value");
547 debug("RI: " + k
+ " => " + v
);
549 var w
= document
.getElementById("noDaemonWarning");
552 if (k
== "daemon_is_running" && v
!= 1) {
553 w
.style
.display
= "block";
555 w
.style
.display
= "none";
558 param
= param
.nextSibling
;
562 function catchupCurrentFeed() {
564 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
566 var str
= "Mark all articles in " + fn
+ " as read?";
568 /* if (active_feed_is_cat) {
569 str = "Mark all articles in this category as read?";
573 return viewCurrentFeed('MarkAllRead')