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;
16 var xmlhttp
= Ajax
.getTransport();
18 var init_params
= new Object();
20 function toggleTags() {
21 display_tags
= !display_tags
;
23 var p
= document
.getElementById("dispSwitchPrompt");
26 p
.innerHTML
= "display feeds";
28 p
.innerHTML
= "display tags";
34 function dlg_frefresh_callback() {
35 if (xmlhttp
.readyState
== 4) {
36 notify(xmlhttp
.responseText
);
37 updateFeedList(false, false);
38 if (_qfd_deleted_feed
) {
39 var hframe
= document
.getElementById("headlines-frame");
41 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
48 function refetch_callback() {
49 if (xmlhttp
.readyState
== 4) {
52 var date
= new Date();
54 last_refetch
= date
.getTime() / 1000;
56 if (!xmlhttp
.responseXML
) {
57 notify("refetch_callback: backend did not return valid XML", true, true);
61 var reply
= xmlhttp
.responseXML
.firstChild
;
64 notify("refetch_callback: backend did not return expected XML object", true, true);
69 var error_code
= reply
.getAttribute("error-code");
71 if (error_code
&& error_code
!= 0) {
72 return fatalError(error_code
, reply
.getAttribute("error-msg"));
75 var counters
= reply
.firstChild
;
77 parse_counters(counters
, true);
79 var runtime_info
= counters
.nextSibling
;
81 parse_runtime_info(runtime_info
);
83 debug("refetch_callback: done");
85 if (!daemon_enabled
&& !daemon_refresh_only
) {
86 notify("All feeds updated.");
92 exception_error("refetch_callback", e
);
98 function backend_sanity_check_callback() {
100 if (xmlhttp
.readyState
== 4) {
104 if (!xmlhttp
.responseXML
) {
105 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
109 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
112 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
116 var error_code
= reply
.getAttribute("error-code");
118 if (error_code
&& error_code
!= 0) {
119 return fatalError(error_code
, reply
.getAttribute("error-msg"));
122 debug("sanity check ok");
124 var params
= reply
.nextSibling
;
127 debug('reading init-params...');
128 var param
= params
.firstChild
;
131 var k
= param
.getAttribute("key");
132 var v
= param
.getAttribute("value");
133 debug(k
+ " => " + v
);
135 param
= param
.nextSibling
;
142 exception_error("backend_sanity_check_callback", e
);
147 function scheduleFeedUpdate(force
) {
149 if (!daemon_enabled
&& !daemon_refresh_only
) {
150 notify("Updating feeds, please wait.", true);
151 updateTitle("Updating");
154 var query_str
= "backend.php?op=rpc&subop=";
157 query_str
= query_str
+ "forceUpdateAllFeeds";
159 query_str
= query_str
+ "updateAllFeeds";
164 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
165 firsttime_update
= false;
175 query_str
= query_str
+ "&omode=" + omode
;
176 query_str
= query_str
+ "&uctr=" + global_unread
;
178 debug("in scheduleFeedUpdate");
180 var date
= new Date();
182 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
183 debug("<b>xmlhttp seems to be stuck, aborting</b>");
187 if (xmlhttp_ready(xmlhttp
)) {
188 xmlhttp
.open("GET", query_str
, true);
189 xmlhttp
.onreadystatechange
=refetch_callback
;
192 debug("xmlhttp busy");
197 function updateFeedList(silent
, fetch
) {
199 // if (silent != true) {
200 // notify("Loading feed list...");
203 var query_str
= "backend.php?op=feeds";
206 query_str
= query_str
+ "&tags=1";
209 if (getActiveFeedId()) {
210 query_str
= query_str
+ "&actid=" + getActiveFeedId();
213 if (navigator
.userAgent
.match("Opera")) {
214 var date
= new Date();
215 var timestamp
= Math
.round(date
.getTime() / 1000);
216 query_str
= query_str
+ "&ts=" + timestamp
219 if (fetch
) query_str
= query_str
+ "&fetch=yes";
221 var feeds_frame
= document
.getElementById("feeds-frame");
223 feeds_frame
.src
= query_str
;
226 function catchupAllFeeds() {
228 var query_str
= "backend.php?op=feeds&subop=catchupAll";
230 notify("Marking all feeds as read...");
232 var feeds_frame
= document
.getElementById("feeds-frame");
234 feeds_frame
.src
= query_str
;
241 function viewCurrentFeed(skip
, subop
) {
243 if (getActiveFeedId()) {
244 viewfeed(getActiveFeedId(), skip
, subop
);
246 disableContainerChildren("headlinesToolbar", false, document
);
247 viewfeed(-1, skip
, subop
); // FIXME
249 return false; // block unneeded form submits
252 function viewfeed(feed
, skip
, subop
) {
253 var f
= window
.frames
["feeds-frame"];
254 f
.viewfeed(feed
, skip
, subop
);
258 scheduleFeedUpdate(false);
260 var refresh_time
= getInitParam("feeds_frame_refresh");
262 if (!refresh_time
) refresh_time
= 600;
264 setTimeout("timeout()", refresh_time
*1000);
267 function resetSearch() {
268 var searchbox
= document
.getElementById("searchbox")
270 if (searchbox
.value
!= "" && getActiveFeedId()) {
271 searchbox
.value
= "";
272 viewfeed(getActiveFeedId(), 0, "");
276 function searchCancel() {
282 viewCurrentFeed(0, "");
285 function localPiggieFunction(enable
) {
287 var query_str
= "backend.php?op=feeds&subop=piggie";
289 if (xmlhttp_ready(xmlhttp
)) {
291 xmlhttp
.open("GET", query_str
, true);
292 xmlhttp
.onreadystatechange
=feedlist_callback
;
298 // if argument is undefined, current subtitle is not updated
299 // use blank string to clear subtitle
300 function updateTitle(s
) {
301 var tmp
= "Tiny Tiny RSS";
303 if (s
!= undefined) {
304 current_subtitle
= s
;
307 if (global_unread
> 0) {
308 tmp
= tmp
+ " (" + global_unread
+ ")";
311 if (current_subtitle
) {
312 tmp
= tmp
+ " - " + current_subtitle
;
315 if (active_title_text
.length
> 0) {
316 tmp
= tmp
+ " > " + active_title_text
;
319 document
.title
= tmp
;
322 function genericSanityCheck() {
324 if (!xmlhttp
) fatalError(1);
326 setCookie("ttrss_vf_test", "TEST");
328 if (getCookie("ttrss_vf_test") != "TEST") {
339 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
341 if (arguments
.callee
.done
) return;
342 arguments
.callee
.done
= true;
344 disableContainerChildren("headlinesToolbar", true);
346 Form
.disable("main_toolbar_form");
348 if (!genericSanityCheck())
351 if (getURLParam('debug')) {
352 document
.getElementById('debug_output').style
.display
= 'block';
353 debug('debug mode activated');
356 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
357 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
361 exception_error("init", e
);
365 function resize_feeds_frame() {
366 var f
= document
.getElementById("feeds-frame");
367 var tf
= document
.getElementById("mainFooter");
368 var th
= document
.getElementById("mainHeader");
370 var footer_height
= 0;
371 var header_height
= 0;
374 footer_height
= tf
.scrollHeight
;
378 header_height
= th
.scrollHeight
;
381 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
382 header_height
- 50 + "px";
385 function init_second_stage() {
389 cookie_lifetime
= getCookie("ttrss_cltime");
391 delCookie("ttrss_vf_test");
393 updateFeedList(false, false);
394 document
.onkeydown
= hotkey_handler
;
396 var tb
= parent
.document
.forms
["main_toolbar_form"];
398 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
399 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
401 daemon_enabled
= getInitParam("daemon_enabled") == 1;
402 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
404 // FIXME should be callled after window resize
406 var h
= document
.getElementById("headlines");
407 var c
= document
.getElementById("content");
409 if (navigator
.userAgent
.match("Opera")) {
410 resize_feeds_frame();
413 debug("second stage ok");
416 exception_error("init_second_stage", e
);
420 function quickMenuChange() {
421 var chooser
= document
.getElementById("quickMenuChooser");
422 var opid
= chooser
[chooser
.selectedIndex
].value
;
424 chooser
.selectedIndex
= 0;
428 function quickMenuGo(opid
) {
431 if (opid
== "qmcPrefs") {
435 if (opid
== "qmcSearch") {
436 displayDlg("search", getActiveFeedId());
440 if (opid
== "qmcAddFeed") {
441 displayDlg("quickAddFeed");
445 if (opid
== "qmcRemoveFeed") {
446 var actid
= getActiveFeedId();
449 alert("Please select some feed first.");
453 var fn
= getFeedName(actid
);
455 if (confirm("Unsubscribe from " + fn
+ "?")) {
462 if (opid
== "qmcUpdateFeeds") {
463 scheduleFeedUpdate(true);
467 if (opid
== "qmcCatchupAll") {
472 if (opid
== "qmcShowOnlyUnread") {
477 if (opid
== "qmcAddFilter") {
478 displayDlg("quickAddFilter", getActiveFeedId());
481 exception_error("quickMenuGo", e
);
485 function qfdDelete(feed_id
) {
487 notify("Removing feed...");
489 if (!xmlhttp_ready(xmlhttp
)) {
494 _qfd_deleted_feed
= feed_id
;
496 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
497 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
502 function updateFeedTitle(t
) {
503 active_title_text
= t
;
507 function toggleDispRead() {
510 if (!xmlhttp_ready(xmlhttp
)) {
515 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
517 hide_read_feeds
= !hide_read_feeds
;
519 debug("toggle_disp_read => " + hide_read_feeds
);
521 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
523 var query
= "backend.php?op=rpc&subop=setpref" +
524 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
526 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
528 new Ajax
.Request(query
);
531 exception_error("toggleDispRead", e
);
535 function parse_runtime_info(elem
) {
536 var param
= elem
.firstChild
;
538 debug("parse_runtime_info");
541 var k
= param
.getAttribute("key");
542 var v
= param
.getAttribute("value");
544 debug("RI: " + k
+ " => " + v
);
546 var w
= document
.getElementById("noDaemonWarning");
549 if (k
== "daemon_is_running" && v
!= 1) {
550 w
.style
.display
= "block";
552 w
.style
.display
= "none";
555 param
= param
.nextSibling
;
559 function catchupCurrentFeed() {
561 var fn
= getFeedName(getActiveFeedId());
563 if (confirm("Mark all articles in " + fn
+ " as read?")) {
564 return viewCurrentFeed(0, 'MarkAllRead')