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>");
191 xmlhttp_ctr
= Ajax
.getTransport();
195 debug("REFETCH query: " + query_str
);
197 if (xmlhttp_ready(xmlhttp_ctr
)) {
198 xmlhttp_ctr
.open("GET", query_str
, true);
199 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
200 xmlhttp_ctr
.send(null);
202 debug("xmlhttp_ctr busy");
203 //printLockingError();
207 function updateFeedList(silent
, fetch
) {
209 // if (silent != true) {
210 // notify("Loading feed list...");
213 debug("<b>updateFeedList</b>");
215 var query_str
= "backend.php?op=feeds";
218 query_str
= query_str
+ "&tags=1";
221 if (getActiveFeedId() && !activeFeedIsCat()) {
222 query_str
= query_str
+ "&actid=" + getActiveFeedId();
225 var date
= new Date();
226 var timestamp
= Math
.round(date
.getTime() / 1000);
227 query_str
= query_str
+ "&ts=" + timestamp
229 if (fetch
) query_str
= query_str
+ "&fetch=yes";
231 // var feeds_frame = document.getElementById("feeds-frame");
232 // feeds_frame.src = query_str;
234 debug("updateFeedList Q=" + query_str
);
236 if (xmlhttp_ready(xmlhttp
)) {
237 xmlhttp
.open("GET", query_str
, true);
238 xmlhttp
.onreadystatechange
=feedlist_callback
;
241 debug("xmlhttp busy");
242 //printLockingError();
247 function catchupAllFeeds() {
249 var query_str
= "backend.php?op=feeds&subop=catchupAll";
251 notify_progress("Marking all feeds as read...");
253 debug("catchupAllFeeds Q=" + query_str
);
255 if (xmlhttp_ready(xmlhttp
)) {
256 xmlhttp
.open("GET", query_str
, true);
257 xmlhttp
.onreadystatechange
=feedlist_callback
;
260 debug("xmlhttp busy");
261 //printLockingError();
269 function viewCurrentFeed(subop
) {
271 // if (getActiveFeedId()) {
272 if (getActiveFeedId() != undefined) {
273 viewfeed(getActiveFeedId(), subop
);
275 disableContainerChildren("headlinesToolbar", false, document
);
276 // viewfeed(-1, subop); // FIXME
278 return false; // block unneeded form submits
281 function viewfeed(feed
, subop
) {
282 var f
= window
.frames
["feeds-frame"];
283 f
.viewfeed(feed
, subop
);
287 scheduleFeedUpdate(false);
289 var refresh_time
= getInitParam("feeds_frame_refresh");
291 if (!refresh_time
) refresh_time
= 600;
293 setTimeout("timeout()", refresh_time
*1000);
296 function resetSearch() {
297 var searchbox
= document
.getElementById("searchbox")
299 if (searchbox
.value
!= "" && getActiveFeedId()) {
300 searchbox
.value
= "";
301 viewfeed(getActiveFeedId(), "");
305 function searchCancel() {
311 viewCurrentFeed(0, "");
314 function localPiggieFunction(enable
) {
316 var query_str
= "backend.php?op=feeds&subop=piggie";
318 if (xmlhttp_ready(xmlhttp
)) {
320 xmlhttp
.open("GET", query_str
, true);
321 xmlhttp
.onreadystatechange
=feedlist_callback
;
327 // if argument is undefined, current subtitle is not updated
328 // use blank string to clear subtitle
329 function updateTitle(s
) {
330 var tmp
= "Tiny Tiny RSS";
332 if (s
!= undefined) {
333 current_subtitle
= s
;
336 if (global_unread
> 0) {
337 tmp
= tmp
+ " (" + global_unread
+ ")";
340 if (current_subtitle
) {
341 tmp
= tmp
+ " - " + current_subtitle
;
344 if (active_title_text
.length
> 0) {
345 tmp
= tmp
+ " > " + active_title_text
;
348 document
.title
= tmp
;
351 function genericSanityCheck() {
353 if (!xmlhttp
) fatalError(1);
355 setCookie("ttrss_vf_test", "TEST");
357 if (getCookie("ttrss_vf_test") != "TEST") {
368 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
370 if (arguments
.callee
.done
) return;
371 arguments
.callee
.done
= true;
373 disableContainerChildren("headlinesToolbar", true);
375 Form
.disable("main_toolbar_form");
377 if (!genericSanityCheck())
380 if (getURLParam('debug')) {
381 document
.getElementById('debug_output').style
.display
= 'block';
382 debug('debug mode activated');
385 var params
= "&ua=" + param_escape(navigator
.userAgent
);
387 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
388 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
392 exception_error("init", e
);
396 function resize_headlines() {
398 var h_frame
= document
.getElementById("headlines-frame");
399 var c_frame
= document
.getElementById("content-frame");
400 var f_frame
= document
.getElementById("footer");
402 if (!c_frame
|| !h_frame
) return;
404 debug("resize_headlines");
407 h_frame
.style
.height
= 30 + "%";
408 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
409 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
411 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
412 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
414 var c_bottom
= document
.documentElement
.clientHeight
;
417 c_bottom
= f_frame
.offsetTop
;
420 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
421 h_frame
.offsetHeight
+ 1) + "px";
422 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
427 function init_second_stage() {
431 cookie_lifetime
= getCookie("ttrss_cltime");
433 delCookie("ttrss_vf_test");
435 // document.onresize = resize_headlines;
438 var toolbar
= document
.forms
["main_toolbar_form"];
440 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
441 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
443 daemon_enabled
= getInitParam("daemon_enabled") == 1;
444 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
446 setTimeout('updateFeedList(false, false)', 50);
448 debug("second stage ok");
451 exception_error("init_second_stage", e
);
455 function quickMenuChange() {
456 var chooser
= document
.getElementById("quickMenuChooser");
457 var opid
= chooser
[chooser
.selectedIndex
].value
;
459 chooser
.selectedIndex
= 0;
463 function quickMenuGo(opid
) {
466 if (opid
== "qmcPrefs") {
470 if (opid
== "qmcSearch") {
471 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
475 if (opid
== "qmcAddFeed") {
476 displayDlg("quickAddFeed");
480 if (opid
== "qmcEditFeed") {
481 editFeedDlg(getActiveFeedId());
484 if (opid
== "qmcRemoveFeed") {
485 var actid
= getActiveFeedId();
487 if (activeFeedIsCat()) {
488 alert("You can't unsubscribe from the category.");
493 alert("Please select some feed first.");
497 var fn
= getFeedName(actid
);
499 if (confirm("Unsubscribe from " + fn
+ "?")) {
506 if (opid
== "qmcUpdateFeeds") {
507 scheduleFeedUpdate(true);
511 if (opid
== "qmcCatchupAll") {
516 if (opid
== "qmcShowOnlyUnread") {
521 if (opid
== "qmcAddFilter") {
522 displayDlg("quickAddFilter", getActiveFeedId());
526 exception_error("quickMenuGo", e
);
530 function qfdDelete(feed_id
) {
532 notify_progress("Removing feed...");
534 if (!xmlhttp_ready(xmlhttp
)) {
539 _qfd_deleted_feed
= feed_id
;
541 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
542 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
549 function updateFeedTitle(t
) {
550 active_title_text
= t
;
554 function toggleDispRead() {
557 if (!xmlhttp_ready(xmlhttp
)) {
562 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
564 hide_read_feeds
= !hide_read_feeds
;
566 debug("toggle_disp_read => " + hide_read_feeds
);
568 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
570 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
572 /* var query = "backend.php?op=rpc&subop=setpref" +
573 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
575 new Ajax.Request(query); */
578 exception_error("toggleDispRead", e
);
582 function parse_runtime_info(elem
) {
584 debug("parse_runtime_info: elem is null, aborting");
588 var param
= elem
.firstChild
;
590 debug("parse_runtime_info: " + param
);
593 var k
= param
.getAttribute("key");
594 var v
= param
.getAttribute("value");
596 debug("RI: " + k
+ " => " + v
);
598 if (k
== "new_version_available") {
599 var icon
= document
.getElementById("newVersionIcon");
602 icon
.style
.display
= "inline";
604 icon
.style
.display
= "none";
609 if (k
== "daemon_is_running" && v
!= 1) {
610 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>");
615 /* var w = document.getElementById("noDaemonWarning");
618 if (k == "daemon_is_running" && v != 1) {
619 w.style.display = "block";
621 w.style.display = "none";
624 param
= param
.nextSibling
;
628 function catchupCurrentFeed() {
630 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
632 var str
= "Mark all articles in " + fn
+ " as read?";
634 /* if (active_feed_is_cat) {
635 str = "Mark all articles in this category as read?";
638 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
639 return viewCurrentFeed('MarkAllRead')
643 function userSwitch() {
644 var chooser
= document
.getElementById("userSwitch");
645 var user
= chooser
[chooser
.selectedIndex
].value
;
646 window
.location
= "tt-rss.php?swu=" + user
;
649 function editFeedDlg(feed
) {
654 alert("Please select some feed first.");
658 if (feed
<= 0 || activeFeedIsCat() || tagsAreDisplayed()) {
659 alert("You can't edit this kind of feed.");
663 if (xmlhttp_ready(xmlhttp
)) {
664 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
665 param_escape(feed
), true);
666 xmlhttp
.onreadystatechange
=infobox_callback
;
673 /* this functions duplicate those of prefs.js feed editor, with
674 some differences because there is no feedlist */
676 function feedEditCancel() {
681 function feedEditSave() {
685 if (!xmlhttp_ready(xmlhttp
)) {
690 // FIXME: add parameter validation
692 var query
= Form
.serialize("edit_feed_form");
694 notify_progress("Saving feed...");
696 xmlhttp
.open("POST", "backend.php", true);
697 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
698 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
706 exception_error("feedEditSave (main)", e
);
710 function localHotkeyHandler(e) {
715 keycode = window.event.keyCode;
720 var shift_key = false;
723 shift_key = e.shiftKey;
726 if (keycode == 66 && shift_key) { // shift-B
728 var op = history_pop();
731 var op_s = op.split(":");
734 for (i = 0; i < op_s.length; i++) {
735 if (op_s[i] == 'undefined') {
739 if (op_s[i] == 'false') {
743 if (op_s[i] == 'true') {
749 debug("history split: " + op_s);
751 if (op_s[0] == "ARTICLE") {
752 debug("history: reverting to article " + op_s[1] + "/" + op_s[2]);
753 view(op_s[1], op_s[2], true);
756 if (op_s[0] == "FEED") {
757 viewfeed(op_s[1], op_s[2], op_s[3], op_s[4], true);
761 notify_error("No operation to undo");
768 debug("LKP=" + keycode);
771 function history_push(op) {
772 debug("history_push: " + op);
775 while (op_history.length > 30) {
780 function history_pop() {
781 var op = op_history.pop();
782 debug("history_pop: " + op);
786 function history_clear() {
787 debug("history_clear");