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");
194 //printLockingError();
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() != undefined) {
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(subop
) {
244 // if (getActiveFeedId()) {
245 if (getActiveFeedId() != undefined) {
246 viewfeed(getActiveFeedId(), subop
);
248 disableContainerChildren("headlinesToolbar", false, document
);
249 // viewfeed(-1, subop); // FIXME
251 return false; // block unneeded form submits
254 function viewfeed(feed
, subop
) {
255 var f
= window
.frames
["feeds-frame"];
256 f
.viewfeed(feed
, subop
);
260 scheduleFeedUpdate(false);
262 var refresh_time
= getInitParam("feeds_frame_refresh");
264 if (!refresh_time
) refresh_time
= 600;
266 setTimeout("timeout()", refresh_time
*1000);
269 function resetSearch() {
270 var searchbox
= document
.getElementById("searchbox")
272 if (searchbox
.value
!= "" && getActiveFeedId()) {
273 searchbox
.value
= "";
274 viewfeed(getActiveFeedId(), "");
278 function searchCancel() {
284 viewCurrentFeed(0, "");
287 function localPiggieFunction(enable
) {
289 var query_str
= "backend.php?op=feeds&subop=piggie";
291 if (xmlhttp_ready(xmlhttp
)) {
293 xmlhttp
.open("GET", query_str
, true);
294 xmlhttp
.onreadystatechange
=feedlist_callback
;
300 // if argument is undefined, current subtitle is not updated
301 // use blank string to clear subtitle
302 function updateTitle(s
) {
303 var tmp
= "Tiny Tiny RSS";
305 if (s
!= undefined) {
306 current_subtitle
= s
;
309 if (global_unread
> 0) {
310 tmp
= tmp
+ " (" + global_unread
+ ")";
313 if (current_subtitle
) {
314 tmp
= tmp
+ " - " + current_subtitle
;
317 if (active_title_text
.length
> 0) {
318 tmp
= tmp
+ " > " + active_title_text
;
321 document
.title
= tmp
;
324 function genericSanityCheck() {
326 if (!xmlhttp
) fatalError(1);
328 setCookie("ttrss_vf_test", "TEST");
330 if (getCookie("ttrss_vf_test") != "TEST") {
341 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
343 if (arguments
.callee
.done
) return;
344 arguments
.callee
.done
= true;
346 disableContainerChildren("headlinesToolbar", true);
348 Form
.disable("main_toolbar_form");
350 if (!genericSanityCheck())
353 if (getURLParam('debug')) {
354 document
.getElementById('debug_output').style
.display
= 'block';
355 debug('debug mode activated');
358 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
359 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
363 exception_error("init", e
);
367 function resize_feeds_frame() {
368 var f
= document
.getElementById("feeds-frame");
369 var tf
= document
.getElementById("mainFooter");
370 var th
= document
.getElementById("mainHeader");
372 var footer_height
= 0;
373 var header_height
= 0;
376 footer_height
= tf
.scrollHeight
;
380 header_height
= th
.scrollHeight
;
383 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
384 header_height
- 50 + "px";
387 function init_second_stage() {
391 cookie_lifetime
= getCookie("ttrss_cltime");
393 delCookie("ttrss_vf_test");
395 updateFeedList(false, false);
396 document
.onkeydown
= hotkey_handler
;
398 var tb
= parent
.document
.forms
["main_toolbar_form"];
400 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
401 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
403 daemon_enabled
= getInitParam("daemon_enabled") == 1;
404 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
406 // FIXME should be callled after window resize
408 var h
= document
.getElementById("headlines");
409 var c
= document
.getElementById("content");
411 if (navigator
.userAgent
.match("Opera")) {
412 resize_feeds_frame();
415 debug("second stage ok");
418 exception_error("init_second_stage", e
);
422 function quickMenuChange() {
423 var chooser
= document
.getElementById("quickMenuChooser");
424 var opid
= chooser
[chooser
.selectedIndex
].value
;
426 chooser
.selectedIndex
= 0;
430 function quickMenuGo(opid
) {
433 if (opid
== "qmcPrefs") {
437 if (opid
== "qmcSearch") {
438 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
442 if (opid
== "qmcAddFeed") {
443 displayDlg("quickAddFeed");
447 if (opid
== "qmcRemoveFeed") {
448 var actid
= getActiveFeedId();
450 if (actid
== undefined) {
451 alert("Please select some feed first.");
455 var fn
= getFeedName(actid
);
457 if (confirm("Unsubscribe from " + fn
+ "?")) {
464 if (opid
== "qmcUpdateFeeds") {
465 scheduleFeedUpdate(true);
469 if (opid
== "qmcCatchupAll") {
474 if (opid
== "qmcShowOnlyUnread") {
479 if (opid
== "qmcAddFilter") {
480 displayDlg("quickAddFilter", getActiveFeedId());
483 exception_error("quickMenuGo", e
);
487 function qfdDelete(feed_id
) {
489 notify("Removing feed...");
491 if (!xmlhttp_ready(xmlhttp
)) {
496 _qfd_deleted_feed
= feed_id
;
498 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
499 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
504 function updateFeedTitle(t
) {
505 active_title_text
= t
;
509 function toggleDispRead() {
512 if (!xmlhttp_ready(xmlhttp
)) {
517 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
519 hide_read_feeds
= !hide_read_feeds
;
521 debug("toggle_disp_read => " + hide_read_feeds
);
523 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
525 var query
= "backend.php?op=rpc&subop=setpref" +
526 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
528 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
530 new Ajax
.Request(query
);
533 exception_error("toggleDispRead", e
);
537 function parse_runtime_info(elem
) {
538 var param
= elem
.firstChild
;
540 debug("parse_runtime_info");
543 var k
= param
.getAttribute("key");
544 var v
= param
.getAttribute("value");
546 debug("RI: " + k
+ " => " + v
);
548 var w
= document
.getElementById("noDaemonWarning");
551 if (k
== "daemon_is_running" && v
!= 1) {
552 w
.style
.display
= "block";
554 w
.style
.display
= "none";
557 param
= param
.nextSibling
;
561 function catchupCurrentFeed() {
563 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
565 var str
= "Mark all articles in " + fn
+ " as read?";
567 /* if (active_feed_is_cat) {
568 str = "Mark all articles in this category as read?";
572 return viewCurrentFeed(0, 'MarkAllRead')