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 _qfd_deleted_feed
= 0;
10 var firsttime_update
= true;
12 var cookie_lifetime
= 0;
13 var active_feed_id
= 0;
15 var xmlhttp
= Ajax
.getTransport();
17 var init_params
= new Object();
19 function toggleTags() {
20 display_tags
= !display_tags
;
22 var p
= document
.getElementById("dispSwitchPrompt");
25 p
.innerHTML
= "display feeds";
27 p
.innerHTML
= "display tags";
33 function dlg_frefresh_callback() {
34 if (xmlhttp
.readyState
== 4) {
35 notify(xmlhttp
.responseText
);
36 updateFeedList(false, false);
37 if (_qfd_deleted_feed
) {
38 var hframe
= document
.getElementById("headlines-frame");
40 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
47 function refetch_callback() {
48 if (xmlhttp
.readyState
== 4) {
51 var date
= new Date();
53 last_refetch
= date
.getTime() / 1000;
55 if (!xmlhttp
.responseXML
) {
56 notify("refetch_callback: backend did not return valid XML", true, true);
60 var reply
= xmlhttp
.responseXML
.firstChild
;
63 notify("refetch_callback: backend did not return expected XML object", true, true);
68 var error_code
= reply
.getAttribute("error-code");
70 if (error_code
&& error_code
!= 0) {
71 return fatalError(error_code
, reply
.getAttribute("error-msg"));
74 var counters
= reply
.firstChild
;
76 parse_counters(counters
, true);
78 var runtime_info
= counters
.nextSibling
;
80 parse_runtime_info(runtime_info
);
82 debug("refetch_callback: done");
84 if (!daemon_enabled
) {
85 notify("All feeds updated.");
91 exception_error("refetch_callback", e
);
97 function backend_sanity_check_callback() {
99 if (xmlhttp
.readyState
== 4) {
103 if (!xmlhttp
.responseXML
) {
104 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
108 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
111 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
115 var error_code
= reply
.getAttribute("error-code");
117 if (error_code
&& error_code
!= 0) {
118 return fatalError(error_code
, reply
.getAttribute("error-msg"));
121 debug("sanity check ok");
123 var params
= reply
.nextSibling
;
126 debug('reading init-params...');
127 var param
= params
.firstChild
;
130 var k
= param
.getAttribute("key");
131 var v
= param
.getAttribute("value");
132 debug(k
+ " => " + v
);
134 param
= param
.nextSibling
;
141 exception_error("backend_sanity_check_callback", e
);
146 function scheduleFeedUpdate(force
) {
148 if (!daemon_enabled
) {
149 notify("Updating feeds, please wait.", true);
150 updateTitle("Updating");
153 var query_str
= "backend.php?op=rpc&subop=";
156 query_str
= query_str
+ "forceUpdateAllFeeds";
158 query_str
= query_str
+ "updateAllFeeds";
163 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
164 firsttime_update
= false;
174 query_str
= query_str
+ "&omode=" + omode
;
175 query_str
= query_str
+ "&uctr=" + global_unread
;
177 debug("in scheduleFeedUpdate");
179 var date
= new Date();
181 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
182 debug("<b>xmlhttp seems to be stuck, aborting</b>");
186 if (xmlhttp_ready(xmlhttp
)) {
187 xmlhttp
.open("GET", query_str
, true);
188 xmlhttp
.onreadystatechange
=refetch_callback
;
191 debug("xmlhttp busy");
196 function updateFeedList(silent
, fetch
) {
198 // if (silent != true) {
199 // notify("Loading feed list...");
202 var query_str
= "backend.php?op=feeds";
205 query_str
= query_str
+ "&tags=1";
208 if (getActiveFeedId()) {
209 query_str
= query_str
+ "&actid=" + getActiveFeedId();
212 if (navigator
.userAgent
.match("Opera")) {
213 var date
= new Date();
214 var timestamp
= Math
.round(date
.getTime() / 1000);
215 query_str
= query_str
+ "&ts=" + timestamp
218 if (fetch
) query_str
= query_str
+ "&fetch=yes";
220 var feeds_frame
= document
.getElementById("feeds-frame");
222 feeds_frame
.src
= query_str
;
225 function catchupAllFeeds() {
227 var query_str
= "backend.php?op=feeds&subop=catchupAll";
229 notify("Marking all feeds as read...");
231 var feeds_frame
= document
.getElementById("feeds-frame");
233 feeds_frame
.src
= query_str
;
240 function viewCurrentFeed(skip
, subop
) {
242 if (getActiveFeedId()) {
243 viewfeed(getActiveFeedId(), skip
, subop
);
245 disableContainerChildren("headlinesToolbar", false, document
);
246 viewfeed(-1, skip
, subop
); // FIXME
248 return false; // block unneeded form submits
251 function viewfeed(feed
, skip
, subop
) {
252 var f
= window
.frames
["feeds-frame"];
253 f
.viewfeed(feed
, skip
, subop
);
257 scheduleFeedUpdate(false);
259 var refresh_time
= getInitParam("feeds_frame_refresh");
261 if (!refresh_time
) refresh_time
= 600;
263 setTimeout("timeout()", refresh_time
*1000);
266 function resetSearch() {
267 var searchbox
= document
.getElementById("searchbox")
269 if (searchbox
.value
!= "" && getActiveFeedId()) {
270 searchbox
.value
= "";
271 viewfeed(getActiveFeedId(), 0, "");
275 function searchCancel() {
281 viewCurrentFeed(0, "");
284 function localPiggieFunction(enable
) {
286 var query_str
= "backend.php?op=feeds&subop=piggie";
288 if (xmlhttp_ready(xmlhttp
)) {
290 xmlhttp
.open("GET", query_str
, true);
291 xmlhttp
.onreadystatechange
=feedlist_callback
;
297 // if argument is undefined, current subtitle is not updated
298 // use blank string to clear subtitle
299 function updateTitle(s
) {
300 var tmp
= "Tiny Tiny RSS";
302 if (s
!= undefined) {
303 current_subtitle
= s
;
306 if (global_unread
> 0) {
307 tmp
= tmp
+ " (" + global_unread
+ ")";
310 if (current_subtitle
) {
311 tmp
= tmp
+ " - " + current_subtitle
;
314 if (active_title_text
.length
> 0) {
315 tmp
= tmp
+ " > " + active_title_text
;
318 document
.title
= tmp
;
321 function genericSanityCheck() {
323 if (!xmlhttp
) fatalError(1);
325 setCookie("ttrss_vf_test", "TEST");
327 if (getCookie("ttrss_vf_test") != "TEST") {
338 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
340 if (arguments
.callee
.done
) return;
341 arguments
.callee
.done
= true;
343 disableContainerChildren("headlinesToolbar", true);
345 Form
.disable("main_toolbar_form");
347 if (!genericSanityCheck())
350 if (getURLParam('debug')) {
351 document
.getElementById('debug_output').style
.display
= 'block';
352 debug('debug mode activated');
355 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
356 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
360 exception_error("init", e
);
364 function resize_feeds_frame() {
365 var f
= document
.getElementById("feeds-frame");
366 var tf
= document
.getElementById("mainFooter");
367 var th
= document
.getElementById("mainHeader");
369 var footer_height
= 0;
370 var header_height
= 0;
373 footer_height
= tf
.scrollHeight
;
377 header_height
= th
.scrollHeight
;
380 f
.style
.height
= document
.body
.scrollHeight
- footer_height
-
381 header_height
- 50 + "px";
384 function init_second_stage() {
388 cookie_lifetime
= getCookie("ttrss_cltime");
390 delCookie("ttrss_vf_test");
392 updateFeedList(false, false);
393 document
.onkeydown
= hotkey_handler
;
395 var tb
= parent
.document
.forms
["main_toolbar_form"];
397 dropboxSelect(tb
.view_mode
, getInitParam("toolbar_view_mode"));
398 dropboxSelect(tb
.limit
, getInitParam("toolbar_limit"));
400 daemon_enabled
= getInitParam("daemon_enabled");
402 // FIXME should be callled after window resize
404 var h
= document
.getElementById("headlines");
405 var c
= document
.getElementById("content");
407 if (navigator
.userAgent
.match("Opera")) {
408 resize_feeds_frame();
411 debug("second stage ok");
414 exception_error("init_second_stage", e
);
418 function quickMenuChange() {
419 var chooser
= document
.getElementById("quickMenuChooser");
420 var opid
= chooser
[chooser
.selectedIndex
].value
;
422 chooser
.selectedIndex
= 0;
426 function quickMenuGo(opid
) {
429 if (opid
== "qmcPrefs") {
433 if (opid
== "qmcSearch") {
434 displayDlg("search", getActiveFeedId());
438 if (opid
== "qmcAddFeed") {
439 displayDlg("quickAddFeed");
443 if (opid
== "qmcRemoveFeed") {
444 var actid
= getActiveFeedId();
447 alert("Please select some feed first.");
451 var fn
= getFeedName(actid
);
453 if (confirm("Unsubscribe from " + fn
+ "?")) {
460 if (opid
== "qmcUpdateFeeds") {
461 scheduleFeedUpdate(true);
465 if (opid
== "qmcCatchupAll") {
470 if (opid
== "qmcShowOnlyUnread") {
475 if (opid
== "qmcAddFilter") {
476 displayDlg("quickAddFilter", getActiveFeedId());
479 exception_error("quickMenuGo", e
);
483 function qfdDelete(feed_id
) {
485 notify("Removing feed...");
487 if (!xmlhttp_ready(xmlhttp
)) {
492 _qfd_deleted_feed
= feed_id
;
494 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
495 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
500 function updateFeedTitle(t
) {
501 active_title_text
= t
;
505 function toggleDispRead() {
508 if (!xmlhttp_ready(xmlhttp
)) {
513 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
515 hide_read_feeds
= !hide_read_feeds
;
517 debug("toggle_disp_read => " + hide_read_feeds
);
519 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
521 var query
= "backend.php?op=rpc&subop=setpref" +
522 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
524 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
526 new Ajax
.Request(query
);
529 exception_error("toggleDispRead", e
);
533 function parse_runtime_info(elem
) {
534 var param
= elem
.firstChild
;
536 debug("parse_runtime_info");
539 var k
= param
.getAttribute("key");
540 var v
= param
.getAttribute("value");
542 debug("RI: " + k
+ " => " + v
);
544 var w
= document
.getElementById("noDaemonWarning");
547 if (k
== "daemon_is_running" && v
!= 1) {
548 w
.style
.display
= "block";
550 w
.style
.display
= "none";
553 param
= param
.nextSibling
;