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;
17 var sanity_check_done
= false;
19 var xmlhttp
= Ajax
.getTransport();
20 var xmlhttp_ctr
= Ajax
.getTransport();
22 var init_params
= new Object();
24 //var op_history = new Array();
26 function tagsAreDisplayed() {
30 function toggleTags(show_all
) {
32 var p
= document
.getElementById("dispSwitchPrompt");
34 if (!show_all
&& !display_tags
) {
35 displayDlg("printTagCloud");
36 } else if (show_all
) {
39 p
.innerHTML
= __("display feeds");
40 notify_progress("Loading, please wait...", true);
42 } else if (display_tags
) {
44 p
.innerHTML
= __("tag cloud");
45 notify_progress("Loading, please wait...", true);
50 function dlg_frefresh_callback() {
51 if (xmlhttp
.readyState
== 4) {
52 // notify(xmlhttp.responseText);
54 if (getActiveFeedId() == _qfd_deleted_feed
) {
55 var h
= document
.getElementById("headlines-frame");
57 h
.innerHTML
= "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
61 setTimeout('updateFeedList(false, false)', 50);
66 function refetch_callback() {
67 if (xmlhttp_ctr
.readyState
== 4) {
70 var date
= new Date();
72 last_refetch
= date
.getTime() / 1000;
74 parse_counters_reply(xmlhttp_ctr
, true);
76 debug("refetch_callback: done");
78 if (!daemon_enabled
&& !daemon_refresh_only
) {
79 notify_info("All feeds updated.");
85 exception_error("refetch_callback", e
);
91 function backend_sanity_check_callback() {
93 if (xmlhttp
.readyState
== 4) {
97 if (sanity_check_done
) {
98 fatalError(11, "Sanity check request received twice. This can indicate "+
99 "presence of Firebug or some other disrupting extension. "+
100 "Please disable it and try again.");
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
;
139 sanity_check_done
= true;
144 exception_error("backend_sanity_check_callback", e
);
149 function scheduleFeedUpdate(force
) {
151 if (!daemon_enabled
&& !daemon_refresh_only
) {
152 notify_progress("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 var timestamp
= Math
.round(date
.getTime() / 1000);
185 query_str
= query_str
+ "&ts=" + timestamp
187 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
188 debug("<b>xmlhttp seems to be stuck, aborting</b>");
192 debug("REFETCH query: " + query_str
);
194 if (xmlhttp_ready(xmlhttp_ctr
)) {
195 xmlhttp_ctr
.open("GET", query_str
, true);
196 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
197 xmlhttp_ctr
.send(null);
199 debug("xmlhttp_ctr busy");
200 //printLockingError();
204 function updateFeedList(silent
, fetch
) {
206 // if (silent != true) {
207 // notify("Loading feed list...");
210 debug("<b>updateFeedList</b>");
212 var query_str
= "backend.php?op=feeds";
215 query_str
= query_str
+ "&tags=1";
218 if (getActiveFeedId() && !activeFeedIsCat()) {
219 query_str
= query_str
+ "&actid=" + getActiveFeedId();
222 var date
= new Date();
223 var timestamp
= Math
.round(date
.getTime() / 1000);
224 query_str
= query_str
+ "&ts=" + timestamp
226 if (fetch
) query_str
= query_str
+ "&fetch=yes";
228 // var feeds_frame = document.getElementById("feeds-frame");
229 // feeds_frame.src = query_str;
231 debug("updateFeedList Q=" + query_str
);
233 if (xmlhttp_ready(xmlhttp
)) {
234 xmlhttp
.open("GET", query_str
, true);
235 xmlhttp
.onreadystatechange
=feedlist_callback
;
238 debug("xmlhttp busy");
239 //printLockingError();
244 function catchupAllFeeds() {
246 var query_str
= "backend.php?op=feeds&subop=catchupAll";
248 notify_progress("Marking all feeds as read...");
250 debug("catchupAllFeeds Q=" + query_str
);
252 if (xmlhttp_ready(xmlhttp
)) {
253 xmlhttp
.open("GET", query_str
, true);
254 xmlhttp
.onreadystatechange
=feedlist_callback
;
257 debug("xmlhttp busy");
258 //printLockingError();
266 function viewCurrentFeed(subop
) {
268 // if (getActiveFeedId()) {
269 if (getActiveFeedId() != undefined) {
270 viewfeed(getActiveFeedId(), subop
);
272 disableContainerChildren("headlinesToolbar", false, document
);
273 // viewfeed(-1, subop); // FIXME
275 return false; // block unneeded form submits
278 function viewfeed(feed
, subop
) {
279 var f
= window
.frames
["feeds-frame"];
280 f
.viewfeed(feed
, subop
);
284 scheduleFeedUpdate(false);
286 var refresh_time
= getInitParam("feeds_frame_refresh");
288 if (!refresh_time
) refresh_time
= 600;
290 setTimeout("timeout()", refresh_time
*1000);
293 function resetSearch() {
294 var searchbox
= document
.getElementById("searchbox")
296 if (searchbox
.value
!= "" && getActiveFeedId()) {
297 searchbox
.value
= "";
298 viewfeed(getActiveFeedId(), "");
302 function searchCancel() {
308 viewCurrentFeed(0, "");
311 function localPiggieFunction(enable
) {
313 var query_str
= "backend.php?op=feeds&subop=piggie";
315 if (xmlhttp_ready(xmlhttp
)) {
317 xmlhttp
.open("GET", query_str
, true);
318 xmlhttp
.onreadystatechange
=feedlist_callback
;
324 // if argument is undefined, current subtitle is not updated
325 // use blank string to clear subtitle
326 function updateTitle(s
) {
327 var tmp
= "Tiny Tiny RSS";
329 if (s
!= undefined) {
330 current_subtitle
= s
;
333 if (global_unread
> 0) {
334 tmp
= tmp
+ " (" + global_unread
+ ")";
337 if (current_subtitle
) {
338 tmp
= tmp
+ " - " + current_subtitle
;
341 if (active_title_text
.length
> 0) {
342 tmp
= tmp
+ " > " + active_title_text
;
345 document
.title
= tmp
;
348 function genericSanityCheck() {
350 if (!xmlhttp
) fatalError(1);
352 setCookie("ttrss_vf_test", "TEST");
354 if (getCookie("ttrss_vf_test") != "TEST") {
365 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
367 if (arguments
.callee
.done
) return;
368 arguments
.callee
.done
= true;
370 disableContainerChildren("headlinesToolbar", true);
372 Form
.disable("main_toolbar_form");
374 if (!genericSanityCheck())
377 if (getURLParam('debug')) {
378 document
.getElementById('debug_output').style
.display
= 'block';
379 debug('debug mode activated');
382 var params
= "&ua=" + param_escape(navigator
.userAgent
);
384 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
385 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
389 exception_error("init", e
);
393 function resize_headlines() {
395 var h_frame
= document
.getElementById("headlines-frame");
396 var c_frame
= document
.getElementById("content-frame");
397 var f_frame
= document
.getElementById("footer");
399 if (!c_frame
|| !h_frame
) return;
401 debug("resize_headlines");
404 h_frame
.style
.height
= 30 + "%";
405 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
406 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
408 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
409 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
411 var c_bottom
= document
.documentElement
.clientHeight
;
414 c_bottom
= f_frame
.offsetTop
;
417 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
418 h_frame
.offsetHeight
+ 1) + "px";
419 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
424 function init_second_stage() {
428 cookie_lifetime
= getCookie("ttrss_cltime");
430 delCookie("ttrss_vf_test");
432 // document.onresize = resize_headlines;
435 var toolbar
= document
.forms
["main_toolbar_form"];
437 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
438 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
440 daemon_enabled
= getInitParam("daemon_enabled") == 1;
441 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
443 setTimeout('updateFeedList(false, false)', 50);
445 debug("second stage ok");
448 exception_error("init_second_stage", e
);
452 function quickMenuChange() {
453 var chooser
= document
.getElementById("quickMenuChooser");
454 var opid
= chooser
[chooser
.selectedIndex
].value
;
456 chooser
.selectedIndex
= 0;
460 function quickMenuGo(opid
) {
463 if (opid
== "qmcPrefs") {
467 if (opid
== "qmcSearch") {
468 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
472 if (opid
== "qmcAddFeed") {
473 displayDlg("quickAddFeed");
477 if (opid
== "qmcEditFeed") {
478 editFeedDlg(getActiveFeedId());
481 if (opid
== "qmcRemoveFeed") {
482 var actid
= getActiveFeedId();
484 if (activeFeedIsCat()) {
485 alert("You can't unsubscribe from the category.");
490 alert("Please select some feed first.");
494 var fn
= getFeedName(actid
);
496 if (confirm("Unsubscribe from " + fn
+ "?")) {
503 if (opid
== "qmcUpdateFeeds") {
504 scheduleFeedUpdate(true);
508 if (opid
== "qmcCatchupAll") {
513 if (opid
== "qmcShowOnlyUnread") {
518 if (opid
== "qmcAddFilter") {
519 displayDlg("quickAddFilter", getActiveFeedId());
523 exception_error("quickMenuGo", e
);
527 function qfdDelete(feed_id
) {
529 notify_progress("Removing feed...");
531 if (!xmlhttp_ready(xmlhttp
)) {
536 _qfd_deleted_feed
= feed_id
;
538 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
539 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
546 function updateFeedTitle(t
) {
547 active_title_text
= t
;
551 function toggleDispRead() {
554 if (!xmlhttp_ready(xmlhttp
)) {
559 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
561 hide_read_feeds
= !hide_read_feeds
;
563 debug("toggle_disp_read => " + hide_read_feeds
);
565 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
567 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
569 /* var query = "backend.php?op=rpc&subop=setpref" +
570 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
572 new Ajax.Request(query); */
575 exception_error("toggleDispRead", e
);
579 function parse_runtime_info(elem
) {
581 debug("parse_runtime_info: elem is null, aborting");
585 var param
= elem
.firstChild
;
587 debug("parse_runtime_info: " + param
);
590 var k
= param
.getAttribute("key");
591 var v
= param
.getAttribute("value");
593 debug("RI: " + k
+ " => " + v
);
595 if (k
== "new_version_available") {
596 var icon
= document
.getElementById("newVersionIcon");
599 icon
.style
.display
= "inline";
601 icon
.style
.display
= "none";
606 if (k
== "daemon_is_running" && v
!= 1) {
607 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>");
612 /* var w = document.getElementById("noDaemonWarning");
615 if (k == "daemon_is_running" && v != 1) {
616 w.style.display = "block";
618 w.style.display = "none";
621 param
= param
.nextSibling
;
625 function catchupCurrentFeed() {
627 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
629 var str
= "Mark all articles in " + fn
+ " as read?";
631 /* if (active_feed_is_cat) {
632 str = "Mark all articles in this category as read?";
635 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
636 return viewCurrentFeed('MarkAllRead')
640 function userSwitch() {
641 var chooser
= document
.getElementById("userSwitch");
642 var user
= chooser
[chooser
.selectedIndex
].value
;
643 window
.location
= "tt-rss.php?swu=" + user
;
646 function editFeedDlg(feed
) {
651 alert("Please select some feed first.");
655 if (feed
<= 0 || activeFeedIsCat() || tagsAreDisplayed()) {
656 alert("You can't edit this kind of feed.");
660 if (xmlhttp_ready(xmlhttp
)) {
661 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
662 param_escape(feed
), true);
663 xmlhttp
.onreadystatechange
=infobox_callback
;
670 /* this functions duplicate those of prefs.js feed editor, with
671 some differences because there is no feedlist */
673 function feedEditCancel() {
678 function feedEditSave() {
682 if (!xmlhttp_ready(xmlhttp
)) {
687 // FIXME: add parameter validation
689 var query
= Form
.serialize("edit_feed_form");
691 notify_progress("Saving feed...");
693 xmlhttp
.open("POST", "backend.php", true);
694 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
695 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
703 exception_error("feedEditSave (main)", e
);
707 function localHotkeyHandler(e) {
712 keycode = window.event.keyCode;
717 var shift_key = false;
720 shift_key = e.shiftKey;
723 if (keycode == 66 && shift_key) { // shift-B
725 var op = history_pop();
728 var op_s = op.split(":");
731 for (i = 0; i < op_s.length; i++) {
732 if (op_s[i] == 'undefined') {
736 if (op_s[i] == 'false') {
740 if (op_s[i] == 'true') {
746 debug("history split: " + op_s);
748 if (op_s[0] == "ARTICLE") {
749 debug("history: reverting to article " + op_s[1] + "/" + op_s[2]);
750 view(op_s[1], op_s[2], true);
753 if (op_s[0] == "FEED") {
754 viewfeed(op_s[1], op_s[2], op_s[3], op_s[4], true);
758 notify_error("No operation to undo");
765 debug("LKP=" + keycode);
768 function history_push(op) {
769 debug("history_push: " + op);
772 while (op_history.length > 30) {
777 function history_pop() {
778 var op = op_history.pop();
779 debug("history_pop: " + op);
783 function history_clear() {
784 debug("history_clear");