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 debug("REFETCH query: " + query_str
);
191 if (xmlhttp_ready(xmlhttp
)) {
192 xmlhttp
.open("GET", query_str
, true);
193 xmlhttp
.onreadystatechange
=refetch_callback
;
196 debug("xmlhttp busy");
197 //printLockingError();
201 function updateFeedList(silent
, fetch
) {
203 // if (silent != true) {
204 // notify("Loading feed list...");
207 var query_str
= "backend.php?op=feeds";
210 query_str
= query_str
+ "&tags=1";
213 if (getActiveFeedId() && !activeFeedIsCat()) {
214 query_str
= query_str
+ "&actid=" + getActiveFeedId();
217 if (navigator
.userAgent
.match("Opera")) {
218 var date
= new Date();
219 var timestamp
= Math
.round(date
.getTime() / 1000);
220 query_str
= query_str
+ "&ts=" + timestamp
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(subop
) {
247 // if (getActiveFeedId()) {
248 if (getActiveFeedId() != undefined) {
249 viewfeed(getActiveFeedId(), subop
);
251 disableContainerChildren("headlinesToolbar", false, document
);
252 // viewfeed(-1, subop); // FIXME
254 return false; // block unneeded form submits
257 function viewfeed(feed
, subop
) {
258 var f
= window
.frames
["feeds-frame"];
259 f
.viewfeed(feed
, subop
);
263 scheduleFeedUpdate(false);
265 var refresh_time
= getInitParam("feeds_frame_refresh");
267 if (!refresh_time
) refresh_time
= 600;
269 setTimeout("timeout()", refresh_time
*1000);
272 function resetSearch() {
273 var searchbox
= document
.getElementById("searchbox")
275 if (searchbox
.value
!= "" && getActiveFeedId()) {
276 searchbox
.value
= "";
277 viewfeed(getActiveFeedId(), "");
281 function searchCancel() {
287 viewCurrentFeed(0, "");
290 function localPiggieFunction(enable
) {
292 var query_str
= "backend.php?op=feeds&subop=piggie";
294 if (xmlhttp_ready(xmlhttp
)) {
296 xmlhttp
.open("GET", query_str
, true);
297 xmlhttp
.onreadystatechange
=feedlist_callback
;
303 // if argument is undefined, current subtitle is not updated
304 // use blank string to clear subtitle
305 function updateTitle(s
) {
306 var tmp
= "Tiny Tiny RSS";
308 if (s
!= undefined) {
309 current_subtitle
= s
;
312 if (global_unread
> 0) {
313 tmp
= tmp
+ " (" + global_unread
+ ")";
316 if (current_subtitle
) {
317 tmp
= tmp
+ " - " + current_subtitle
;
320 if (active_title_text
.length
> 0) {
321 tmp
= tmp
+ " > " + active_title_text
;
324 document
.title
= tmp
;
327 function genericSanityCheck() {
329 if (!xmlhttp
) fatalError(1);
331 setCookie("ttrss_vf_test", "TEST");
333 if (getCookie("ttrss_vf_test") != "TEST") {
344 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
346 if (arguments
.callee
.done
) return;
347 arguments
.callee
.done
= true;
349 disableContainerChildren("headlinesToolbar", true);
351 Form
.disable("main_toolbar_form");
353 if (!genericSanityCheck())
356 if (getURLParam('debug')) {
357 document
.getElementById('debug_output').style
.display
= 'block';
358 debug('debug mode activated');
361 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
362 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
366 exception_error("init", e
);
370 function resize_feeds_frame() {
371 var f
= document
.getElementById("feeds-frame");
372 var tf
= document
.getElementById("mainFooter");
373 var th
= document
.getElementById("mainHeader");
375 var footer_height
= 0;
376 var header_height
= 0;
379 footer_height
= tf
.scrollHeight
;
383 header_height
= th
.scrollHeight
;
386 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
387 header_height
- 50 + "px";
390 function init_second_stage() {
394 cookie_lifetime
= getCookie("ttrss_cltime");
396 delCookie("ttrss_vf_test");
398 updateFeedList(false, false);
399 document
.onkeydown
= hotkey_handler
;
401 var tb
= parent
.document
.forms
["main_toolbar_form"];
403 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
404 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
406 daemon_enabled
= getInitParam("daemon_enabled") == 1;
407 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
409 // FIXME should be callled after window resize
411 var h
= document
.getElementById("headlines");
412 var c
= document
.getElementById("content");
414 if (navigator
.userAgent
.match("Opera")) {
415 resize_feeds_frame();
418 debug("second stage ok");
421 exception_error("init_second_stage", e
);
425 function quickMenuChange() {
426 var chooser
= document
.getElementById("quickMenuChooser");
427 var opid
= chooser
[chooser
.selectedIndex
].value
;
429 chooser
.selectedIndex
= 0;
433 function quickMenuGo(opid
) {
436 if (opid
== "qmcPrefs") {
440 if (opid
== "qmcSearch") {
441 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
445 if (opid
== "qmcAddFeed") {
446 displayDlg("quickAddFeed");
450 if (opid
== "qmcRemoveFeed") {
451 var actid
= getActiveFeedId();
453 if (!actid
|| activeFeedIsCat()) {
454 alert("Please select some feed first.");
458 var fn
= getFeedName(actid
);
460 if (confirm("Unsubscribe from " + fn
+ "?")) {
467 if (opid
== "qmcUpdateFeeds") {
468 scheduleFeedUpdate(true);
472 if (opid
== "qmcCatchupAll") {
477 if (opid
== "qmcShowOnlyUnread") {
482 if (opid
== "qmcAddFilter") {
483 displayDlg("quickAddFilter", getActiveFeedId());
486 exception_error("quickMenuGo", e
);
490 function qfdDelete(feed_id
) {
492 notify("Removing feed...");
494 if (!xmlhttp_ready(xmlhttp
)) {
499 _qfd_deleted_feed
= feed_id
;
501 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
502 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
507 function updateFeedTitle(t
) {
508 active_title_text
= t
;
512 function toggleDispRead() {
515 if (!xmlhttp_ready(xmlhttp
)) {
520 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
522 hide_read_feeds
= !hide_read_feeds
;
524 debug("toggle_disp_read => " + hide_read_feeds
);
526 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
528 var query
= "backend.php?op=rpc&subop=setpref" +
529 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
531 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
533 new Ajax
.Request(query
);
536 exception_error("toggleDispRead", e
);
540 function parse_runtime_info(elem
) {
541 var param
= elem
.firstChild
;
543 debug("parse_runtime_info: " + param
);
546 var k
= param
.getAttribute("key");
547 var v
= param
.getAttribute("value");
549 debug("RI: " + k
+ " => " + v
);
551 var w
= document
.getElementById("noDaemonWarning");
554 if (k
== "daemon_is_running" && v
!= 1) {
555 w
.style
.display
= "block";
557 w
.style
.display
= "none";
560 param
= param
.nextSibling
;
564 function catchupCurrentFeed() {
566 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
568 var str
= "Mark all articles in " + fn
+ " as read?";
570 /* if (active_feed_is_cat) {
571 str = "Mark all articles in this category as read?";
574 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
575 return viewCurrentFeed('MarkAllRead')