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();
19 var xmlhttp_ctr
= Ajax
.getTransport();
21 var init_params
= new Object();
23 var op_history
= new Array();
25 function toggleTags() {
26 display_tags
= !display_tags
;
28 var p
= document
.getElementById("dispSwitchPrompt");
31 p
.innerHTML
= "display feeds";
33 p
.innerHTML
= "display tags";
36 notify("Loading, please wait...");
41 function dlg_frefresh_callback() {
42 if (xmlhttp
.readyState
== 4) {
43 // notify(xmlhttp.responseText);
45 if (getActiveFeedId() == _qfd_deleted_feed
) {
46 var h
= document
.getElementById("headlines-frame");
48 h
.innerHTML
= "<div class='whiteBox'>No feed selected.</div>";
52 setTimeout('updateFeedList(false, false)', 50);
57 function refetch_callback() {
58 if (xmlhttp_ctr
.readyState
== 4) {
61 var date
= new Date();
63 last_refetch
= date
.getTime() / 1000;
65 parse_counters_reply(xmlhttp_ctr
, true);
67 debug("refetch_callback: done");
69 if (!daemon_enabled
&& !daemon_refresh_only
) {
70 notify("All feeds updated.");
76 exception_error("refetch_callback", e
);
82 function backend_sanity_check_callback() {
84 if (xmlhttp
.readyState
== 4) {
88 if (!xmlhttp
.responseXML
) {
89 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
93 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
96 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
100 var error_code
= reply
.getAttribute("error-code");
102 if (error_code
&& error_code
!= 0) {
103 return fatalError(error_code
, reply
.getAttribute("error-msg"));
106 debug("sanity check ok");
108 var params
= reply
.nextSibling
;
111 debug('reading init-params...');
112 var param
= params
.firstChild
;
115 var k
= param
.getAttribute("key");
116 var v
= param
.getAttribute("value");
117 debug(k
+ " => " + v
);
119 param
= param
.nextSibling
;
126 exception_error("backend_sanity_check_callback", e
);
131 function scheduleFeedUpdate(force
) {
133 if (!daemon_enabled
&& !daemon_refresh_only
) {
134 notify("Updating feeds, please wait.", true);
135 updateTitle("Updating");
138 var query_str
= "backend.php?op=rpc&subop=";
141 query_str
= query_str
+ "forceUpdateAllFeeds";
143 query_str
= query_str
+ "updateAllFeeds";
148 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
149 firsttime_update
= false;
159 query_str
= query_str
+ "&omode=" + omode
;
160 query_str
= query_str
+ "&uctr=" + global_unread
;
162 debug("in scheduleFeedUpdate");
164 var date
= new Date();
166 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
167 debug("<b>xmlhttp seems to be stuck, aborting</b>");
171 debug("REFETCH query: " + query_str
);
173 if (xmlhttp_ready(xmlhttp_ctr
)) {
174 xmlhttp_ctr
.open("GET", query_str
, true);
175 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
176 xmlhttp_ctr
.send(null);
178 debug("xmlhttp_ctr busy");
179 //printLockingError();
183 function updateFeedList(silent
, fetch
) {
185 // if (silent != true) {
186 // notify("Loading feed list...");
189 var query_str
= "backend.php?op=feeds";
192 query_str
= query_str
+ "&tags=1";
195 if (getActiveFeedId() && !activeFeedIsCat()) {
196 query_str
= query_str
+ "&actid=" + getActiveFeedId();
199 if (navigator
.userAgent
.match("Opera")) {
200 var date
= new Date();
201 var timestamp
= Math
.round(date
.getTime() / 1000);
202 query_str
= query_str
+ "&ts=" + timestamp
205 if (fetch
) query_str
= query_str
+ "&fetch=yes";
207 // var feeds_frame = document.getElementById("feeds-frame");
208 // feeds_frame.src = query_str;
210 debug("updateFeedList Q=" + query_str
);
212 if (xmlhttp_ready(xmlhttp
)) {
213 xmlhttp
.open("GET", query_str
, true);
214 xmlhttp
.onreadystatechange
=feedlist_callback
;
217 debug("xmlhttp busy");
218 //printLockingError();
223 function catchupAllFeeds() {
225 var query_str
= "backend.php?op=feeds&subop=catchupAll";
227 notify("Marking all feeds as read...");
229 debug("catchupAllFeeds Q=" + query_str
);
231 if (xmlhttp_ready(xmlhttp
)) {
232 xmlhttp
.open("GET", query_str
, true);
233 xmlhttp
.onreadystatechange
=feedlist_callback
;
236 debug("xmlhttp busy");
237 //printLockingError();
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 init_second_stage() {
374 cookie_lifetime
= getCookie("ttrss_cltime");
376 delCookie("ttrss_vf_test");
378 document
.onkeydown
= hotkey_handler
;
380 var tb
= parent
.document
.forms
["main_toolbar_form"];
382 // dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode"));
383 // dropboxSelect(tb.limit, getInitParam("toolbar_limit"));
385 daemon_enabled
= getInitParam("daemon_enabled") == 1;
386 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
388 setTimeout('updateFeedList(false, false)', 50);
390 debug("second stage ok");
393 exception_error("init_second_stage", e
);
397 function quickMenuChange() {
398 var chooser
= document
.getElementById("quickMenuChooser");
399 var opid
= chooser
[chooser
.selectedIndex
].value
;
401 chooser
.selectedIndex
= 0;
405 function quickMenuGo(opid
) {
408 if (opid
== "qmcPrefs") {
412 if (opid
== "qmcSearch") {
413 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
417 if (opid
== "qmcAddFeed") {
418 displayDlg("quickAddFeed");
422 if (opid
== "qmcEditFeed") {
423 editFeedDlg(getActiveFeedId());
426 if (opid
== "qmcRemoveFeed") {
427 var actid
= getActiveFeedId();
429 if (!actid
|| activeFeedIsCat()) {
430 alert("Please select some feed first.");
434 var fn
= getFeedName(actid
);
436 if (confirm("Unsubscribe from " + fn
+ "?")) {
443 if (opid
== "qmcUpdateFeeds") {
444 scheduleFeedUpdate(true);
448 if (opid
== "qmcCatchupAll") {
453 if (opid
== "qmcShowOnlyUnread") {
458 if (opid
== "qmcAddFilter") {
459 displayDlg("quickAddFilter", getActiveFeedId());
462 exception_error("quickMenuGo", e
);
466 function qfdDelete(feed_id
) {
468 notify("Removing feed...");
470 if (!xmlhttp_ready(xmlhttp
)) {
475 _qfd_deleted_feed
= feed_id
;
477 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
478 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
485 function updateFeedTitle(t
) {
486 active_title_text
= t
;
490 function toggleDispRead() {
493 if (!xmlhttp_ready(xmlhttp
)) {
498 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
500 hide_read_feeds
= !hide_read_feeds
;
502 debug("toggle_disp_read => " + hide_read_feeds
);
504 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
506 var query
= "backend.php?op=rpc&subop=setpref" +
507 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
509 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
511 new Ajax
.Request(query
);
514 exception_error("toggleDispRead", e
);
518 function parse_runtime_info(elem
) {
520 debug("parse_runtime_info: elem is null, aborting");
524 var param
= elem
.firstChild
;
526 debug("parse_runtime_info: " + param
);
529 var k
= param
.getAttribute("key");
530 var v
= param
.getAttribute("value");
532 debug("RI: " + k
+ " => " + v
);
534 var w
= document
.getElementById("noDaemonWarning");
537 if (k
== "daemon_is_running" && v
!= 1) {
538 w
.style
.display
= "block";
540 w
.style
.display
= "none";
543 param
= param
.nextSibling
;
547 function catchupCurrentFeed() {
549 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
551 var str
= "Mark all articles in " + fn
+ " as read?";
553 /* if (active_feed_is_cat) {
554 str = "Mark all articles in this category as read?";
557 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
558 return viewCurrentFeed('MarkAllRead')
562 function userSwitch() {
563 var chooser
= document
.getElementById("userSwitch");
564 var user
= chooser
[chooser
.selectedIndex
].value
;
565 window
.location
= "tt-rss.php?swu=" + user
;
568 function editFeedDlg(feed
) {
573 alert("Please select some feed first.");
577 if (xmlhttp_ready(xmlhttp
)) {
578 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
579 param_escape(feed
), true);
580 xmlhttp
.onreadystatechange
=infobox_callback
;
587 /* this functions duplicate those of prefs.js feed editor, with
588 some differences because there is no feedlist */
590 function feedEditCancel() {
595 function feedEditSave() {
599 if (!xmlhttp_ready(xmlhttp
)) {
604 // FIXME: add parameter validation
606 var query
= Form
.serialize("edit_feed_form");
608 notify("Saving feed...");
610 xmlhttp
.open("POST", "backend.php", true);
611 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
612 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
620 exception_error("feedEditSave (main)", e
);
624 function localHotkeyHandler(e
) {
629 keycode
= window
.event
.keyCode
;
634 var shift_key
= false;
637 shift_key
= e
.shiftKey
;
640 if (keycode
== 66 && shift_key
) { // shift-B
642 var op
= history_pop();
645 var op_s
= op
.split(":");
648 for (i
= 0; i
< op_s
.length
; i
++) {
649 if (op_s
[i
] == 'undefined') {
653 if (op_s
[i
] == 'false') {
657 if (op_s
[i
] == 'true') {
663 debug("history split: " + op_s
);
665 if (op_s
[0] == "ARTICLE") {
666 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
667 view(op_s
[1], op_s
[2], true);
670 if (op_s
[0] == "FEED") {
671 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
675 notify("No operation to undo");
682 debug("LKP=" + keycode
);
685 function history_push(op
) {
686 debug("history_push: " + op
);
689 while (op_history
.length
> 30) {
694 function history_pop() {
695 var op
= op_history
.pop();
696 debug("history_pop: " + op
);
700 function history_clear() {
701 debug("history_clear");