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");
226 // feeds_frame.src = query_str;
228 debug("updateFeedList");
230 if (xmlhttp_ready(xmlhttp
)) {
231 xmlhttp
.open("GET", query_str
, true);
232 xmlhttp
.onreadystatechange
=feedlist_callback
;
235 debug("xmlhttp busy");
236 //printLockingError();
241 function catchupAllFeeds() {
243 var query_str
= "backend.php?op=feeds&subop=catchupAll";
245 notify("Marking all feeds as read...");
247 var feeds_frame
= document
.getElementById("feeds-frame");
249 feeds_frame
.src
= query_str
;
256 function viewCurrentFeed(subop
) {
258 // if (getActiveFeedId()) {
259 if (getActiveFeedId() != undefined) {
260 viewfeed(getActiveFeedId(), subop
);
262 disableContainerChildren("headlinesToolbar", false, document
);
263 // viewfeed(-1, subop); // FIXME
265 return false; // block unneeded form submits
268 function viewfeed(feed
, subop
) {
269 var f
= window
.frames
["feeds-frame"];
270 f
.viewfeed(feed
, subop
);
274 scheduleFeedUpdate(false);
276 var refresh_time
= getInitParam("feeds_frame_refresh");
278 if (!refresh_time
) refresh_time
= 600;
280 setTimeout("timeout()", refresh_time
*1000);
283 function resetSearch() {
284 var searchbox
= document
.getElementById("searchbox")
286 if (searchbox
.value
!= "" && getActiveFeedId()) {
287 searchbox
.value
= "";
288 viewfeed(getActiveFeedId(), "");
292 function searchCancel() {
298 viewCurrentFeed(0, "");
301 function localPiggieFunction(enable
) {
303 var query_str
= "backend.php?op=feeds&subop=piggie";
305 if (xmlhttp_ready(xmlhttp
)) {
307 xmlhttp
.open("GET", query_str
, true);
308 xmlhttp
.onreadystatechange
=feedlist_callback
;
314 // if argument is undefined, current subtitle is not updated
315 // use blank string to clear subtitle
316 function updateTitle(s
) {
317 var tmp
= "Tiny Tiny RSS";
319 if (s
!= undefined) {
320 current_subtitle
= s
;
323 if (global_unread
> 0) {
324 tmp
= tmp
+ " (" + global_unread
+ ")";
327 if (current_subtitle
) {
328 tmp
= tmp
+ " - " + current_subtitle
;
331 if (active_title_text
.length
> 0) {
332 tmp
= tmp
+ " > " + active_title_text
;
335 document
.title
= tmp
;
338 function genericSanityCheck() {
340 if (!xmlhttp
) fatalError(1);
342 setCookie("ttrss_vf_test", "TEST");
344 if (getCookie("ttrss_vf_test") != "TEST") {
355 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
357 if (arguments
.callee
.done
) return;
358 arguments
.callee
.done
= true;
360 disableContainerChildren("headlinesToolbar", true);
362 Form
.disable("main_toolbar_form");
364 if (!genericSanityCheck())
367 if (getURLParam('debug')) {
368 document
.getElementById('debug_output').style
.display
= 'block';
369 debug('debug mode activated');
372 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
373 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
377 exception_error("init", e
);
381 function resize_feeds_frame() {
382 var f
= document
.getElementById("feeds-frame");
383 var tf
= document
.getElementById("mainFooter");
384 var th
= document
.getElementById("mainHeader");
386 var footer_height
= 0;
387 var header_height
= 0;
390 footer_height
= tf
.scrollHeight
;
394 header_height
= th
.scrollHeight
;
398 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
399 header_height
- 50 + "px";
403 function init_second_stage() {
407 cookie_lifetime
= getCookie("ttrss_cltime");
409 delCookie("ttrss_vf_test");
411 updateFeedList(false, false);
412 document
.onkeydown
= hotkey_handler
;
414 var tb
= parent
.document
.forms
["main_toolbar_form"];
416 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
417 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
419 daemon_enabled
= getInitParam("daemon_enabled") == 1;
420 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
422 // FIXME should be callled after window resize
424 var h
= document
.getElementById("headlines");
425 var c
= document
.getElementById("content");
427 if (navigator
.userAgent
.match("Opera")) {
428 resize_feeds_frame();
431 debug("second stage ok");
434 exception_error("init_second_stage", e
);
438 function quickMenuChange() {
439 var chooser
= document
.getElementById("quickMenuChooser");
440 var opid
= chooser
[chooser
.selectedIndex
].value
;
442 chooser
.selectedIndex
= 0;
446 function quickMenuGo(opid
) {
449 if (opid
== "qmcPrefs") {
453 if (opid
== "qmcSearch") {
454 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
458 if (opid
== "qmcAddFeed") {
459 displayDlg("quickAddFeed");
463 if (opid
== "qmcRemoveFeed") {
464 var actid
= getActiveFeedId();
466 if (!actid
|| activeFeedIsCat()) {
467 alert("Please select some feed first.");
471 var fn
= getFeedName(actid
);
473 if (confirm("Unsubscribe from " + fn
+ "?")) {
480 if (opid
== "qmcUpdateFeeds") {
481 scheduleFeedUpdate(true);
485 if (opid
== "qmcCatchupAll") {
490 if (opid
== "qmcShowOnlyUnread") {
495 if (opid
== "qmcAddFilter") {
496 displayDlg("quickAddFilter", getActiveFeedId());
499 exception_error("quickMenuGo", e
);
503 function qfdDelete(feed_id
) {
505 notify("Removing feed...");
507 if (!xmlhttp_ready(xmlhttp
)) {
512 _qfd_deleted_feed
= feed_id
;
514 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
515 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
520 function updateFeedTitle(t
) {
521 active_title_text
= t
;
525 function toggleDispRead() {
528 if (!xmlhttp_ready(xmlhttp
)) {
533 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
535 hide_read_feeds
= !hide_read_feeds
;
537 debug("toggle_disp_read => " + hide_read_feeds
);
539 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
541 var query
= "backend.php?op=rpc&subop=setpref" +
542 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
544 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
546 new Ajax
.Request(query
);
549 exception_error("toggleDispRead", e
);
553 function parse_runtime_info(elem
) {
554 var param
= elem
.firstChild
;
556 debug("parse_runtime_info: " + param
);
559 var k
= param
.getAttribute("key");
560 var v
= param
.getAttribute("value");
562 debug("RI: " + k
+ " => " + v
);
564 var w
= document
.getElementById("noDaemonWarning");
567 if (k
== "daemon_is_running" && v
!= 1) {
568 w
.style
.display
= "block";
570 w
.style
.display
= "none";
573 param
= param
.nextSibling
;
577 function catchupCurrentFeed() {
579 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
581 var str
= "Mark all articles in " + fn
+ " as read?";
583 /* if (active_feed_is_cat) {
584 str = "Mark all articles in this category as read?";
587 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
588 return viewCurrentFeed('MarkAllRead')