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() {
31 display_tags
= !display_tags
;
33 var p
= document
.getElementById("dispSwitchPrompt");
36 p
.innerHTML
= __("display feeds");
38 p
.innerHTML
= __("display tags");
41 notify_progress("Loading, please wait...");
46 function dlg_frefresh_callback() {
47 if (xmlhttp
.readyState
== 4) {
48 // notify(xmlhttp.responseText);
50 if (getActiveFeedId() == _qfd_deleted_feed
) {
51 var h
= document
.getElementById("headlines-frame");
53 h
.innerHTML
= "<div class='whiteBox'>No feed selected.</div>";
57 setTimeout('updateFeedList(false, false)', 50);
62 function refetch_callback() {
63 if (xmlhttp_ctr
.readyState
== 4) {
66 var date
= new Date();
68 last_refetch
= date
.getTime() / 1000;
70 parse_counters_reply(xmlhttp_ctr
, true);
72 debug("refetch_callback: done");
74 if (!daemon_enabled
&& !daemon_refresh_only
) {
75 notify_info("All feeds updated.");
81 exception_error("refetch_callback", e
);
87 function backend_sanity_check_callback() {
89 if (xmlhttp
.readyState
== 4) {
93 if (sanity_check_done
) {
94 fatalError(11, "Sanity check request received twice. This can indicate "+
95 "presence of Firebug or some other disrupting extension. "+
96 "Please disable it and try again.");
100 if (!xmlhttp
.responseXML
) {
101 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
105 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
108 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
112 var error_code
= reply
.getAttribute("error-code");
114 if (error_code
&& error_code
!= 0) {
115 return fatalError(error_code
, reply
.getAttribute("error-msg"));
118 debug("sanity check ok");
120 var params
= reply
.nextSibling
;
123 debug('reading init-params...');
124 var param
= params
.firstChild
;
127 var k
= param
.getAttribute("key");
128 var v
= param
.getAttribute("value");
129 debug(k
+ " => " + v
);
131 param
= param
.nextSibling
;
135 sanity_check_done
= true;
140 exception_error("backend_sanity_check_callback", e
);
145 function scheduleFeedUpdate(force
) {
147 if (!daemon_enabled
&& !daemon_refresh_only
) {
148 notify_progress("Updating feeds, please wait.", true);
149 updateTitle("Updating");
152 var query_str
= "backend.php?op=rpc&subop=";
155 query_str
= query_str
+ "forceUpdateAllFeeds";
157 query_str
= query_str
+ "updateAllFeeds";
162 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
163 firsttime_update
= false;
173 query_str
= query_str
+ "&omode=" + omode
;
174 query_str
= query_str
+ "&uctr=" + global_unread
;
176 debug("in scheduleFeedUpdate");
178 var date
= new Date();
180 var timestamp
= Math
.round(date
.getTime() / 1000);
181 query_str
= query_str
+ "&ts=" + timestamp
183 if (!xmlhttp_ready(xmlhttp_ctr
) && last_refetch
< date
.getTime() / 1000 - 60) {
184 debug("<b>xmlhttp seems to be stuck, aborting</b>");
188 debug("REFETCH query: " + query_str
);
190 if (xmlhttp_ready(xmlhttp_ctr
)) {
191 xmlhttp_ctr
.open("GET", query_str
, true);
192 xmlhttp_ctr
.onreadystatechange
=refetch_callback
;
193 xmlhttp_ctr
.send(null);
195 debug("xmlhttp_ctr busy");
196 //printLockingError();
200 function updateFeedList(silent
, fetch
) {
202 // if (silent != true) {
203 // notify("Loading feed list...");
206 debug("<b>updateFeedList</b>");
208 var query_str
= "backend.php?op=feeds";
211 query_str
= query_str
+ "&tags=1";
214 if (getActiveFeedId() && !activeFeedIsCat()) {
215 query_str
= query_str
+ "&actid=" + getActiveFeedId();
218 var date
= new Date();
219 var timestamp
= Math
.round(date
.getTime() / 1000);
220 query_str
= query_str
+ "&ts=" + timestamp
222 if (fetch
) query_str
= query_str
+ "&fetch=yes";
224 // var feeds_frame = document.getElementById("feeds-frame");
225 // feeds_frame.src = query_str;
227 debug("updateFeedList Q=" + query_str
);
229 if (xmlhttp_ready(xmlhttp
)) {
230 xmlhttp
.open("GET", query_str
, true);
231 xmlhttp
.onreadystatechange
=feedlist_callback
;
234 debug("xmlhttp busy");
235 //printLockingError();
240 function catchupAllFeeds() {
242 var query_str
= "backend.php?op=feeds&subop=catchupAll";
244 notify_progress("Marking all feeds as read...");
246 debug("catchupAllFeeds Q=" + query_str
);
248 if (xmlhttp_ready(xmlhttp
)) {
249 xmlhttp
.open("GET", query_str
, true);
250 xmlhttp
.onreadystatechange
=feedlist_callback
;
253 debug("xmlhttp busy");
254 //printLockingError();
262 function viewCurrentFeed(subop
) {
264 // if (getActiveFeedId()) {
265 if (getActiveFeedId() != undefined) {
266 viewfeed(getActiveFeedId(), subop
);
268 disableContainerChildren("headlinesToolbar", false, document
);
269 // viewfeed(-1, subop); // FIXME
271 return false; // block unneeded form submits
274 function viewfeed(feed
, subop
) {
275 var f
= window
.frames
["feeds-frame"];
276 f
.viewfeed(feed
, subop
);
280 scheduleFeedUpdate(false);
282 var refresh_time
= getInitParam("feeds_frame_refresh");
284 if (!refresh_time
) refresh_time
= 600;
286 setTimeout("timeout()", refresh_time
*1000);
289 function resetSearch() {
290 var searchbox
= document
.getElementById("searchbox")
292 if (searchbox
.value
!= "" && getActiveFeedId()) {
293 searchbox
.value
= "";
294 viewfeed(getActiveFeedId(), "");
298 function searchCancel() {
304 viewCurrentFeed(0, "");
307 function localPiggieFunction(enable
) {
309 var query_str
= "backend.php?op=feeds&subop=piggie";
311 if (xmlhttp_ready(xmlhttp
)) {
313 xmlhttp
.open("GET", query_str
, true);
314 xmlhttp
.onreadystatechange
=feedlist_callback
;
320 // if argument is undefined, current subtitle is not updated
321 // use blank string to clear subtitle
322 function updateTitle(s
) {
323 var tmp
= "Tiny Tiny RSS";
325 if (s
!= undefined) {
326 current_subtitle
= s
;
329 if (global_unread
> 0) {
330 tmp
= tmp
+ " (" + global_unread
+ ")";
333 if (current_subtitle
) {
334 tmp
= tmp
+ " - " + current_subtitle
;
337 if (active_title_text
.length
> 0) {
338 tmp
= tmp
+ " > " + active_title_text
;
341 document
.title
= tmp
;
344 function genericSanityCheck() {
346 if (!xmlhttp
) fatalError(1);
348 setCookie("ttrss_vf_test", "TEST");
350 if (getCookie("ttrss_vf_test") != "TEST") {
361 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
363 if (arguments
.callee
.done
) return;
364 arguments
.callee
.done
= true;
366 disableContainerChildren("headlinesToolbar", true);
368 Form
.disable("main_toolbar_form");
370 if (!genericSanityCheck())
373 if (getURLParam('debug')) {
374 document
.getElementById('debug_output').style
.display
= 'block';
375 debug('debug mode activated');
378 var params
= "&ua=" + param_escape(navigator
.userAgent
);
380 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params
, true);
381 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
385 exception_error("init", e
);
389 function resize_headlines() {
390 var h_frame
= document
.getElementById("headlines-frame");
391 var c_frame
= document
.getElementById("content-frame");
393 debug("resize_headlines");
395 if (c_frame
&& h_frame
) {
396 h_frame
.style
.height
= 30 + "%";
397 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
398 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
402 function init_second_stage() {
406 cookie_lifetime
= getCookie("ttrss_cltime");
408 delCookie("ttrss_vf_test");
411 document
.onresize
= resize_headlines
;
415 var toolbar
= document
.forms
["main_toolbar_form"];
417 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
418 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
420 daemon_enabled
= getInitParam("daemon_enabled") == 1;
421 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
423 setTimeout('updateFeedList(false, false)', 50);
425 debug("second stage ok");
428 exception_error("init_second_stage", e
);
432 function quickMenuChange() {
433 var chooser
= document
.getElementById("quickMenuChooser");
434 var opid
= chooser
[chooser
.selectedIndex
].value
;
436 chooser
.selectedIndex
= 0;
440 function quickMenuGo(opid
) {
443 if (opid
== "qmcPrefs") {
447 if (opid
== "qmcSearch") {
448 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
452 if (opid
== "qmcAddFeed") {
453 displayDlg("quickAddFeed");
457 if (opid
== "qmcEditFeed") {
458 editFeedDlg(getActiveFeedId());
461 if (opid
== "qmcRemoveFeed") {
462 var actid
= getActiveFeedId();
464 if (!actid
|| activeFeedIsCat()) {
465 alert("Please select some feed first.");
469 var fn
= getFeedName(actid
);
471 if (confirm("Unsubscribe from " + fn
+ "?")) {
478 if (opid
== "qmcUpdateFeeds") {
479 scheduleFeedUpdate(true);
483 if (opid
== "qmcCatchupAll") {
488 if (opid
== "qmcShowOnlyUnread") {
493 if (opid
== "qmcAddFilter") {
494 displayDlg("quickAddFilter", getActiveFeedId());
497 exception_error("quickMenuGo", e
);
501 function qfdDelete(feed_id
) {
503 notify_progress("Removing feed...");
505 if (!xmlhttp_ready(xmlhttp
)) {
510 _qfd_deleted_feed
= feed_id
;
512 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
513 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
520 function updateFeedTitle(t
) {
521 active_title_text
= t
;
525 function toggleDispRead() {
528 if (!xmlhttp_ready(xmlhttp
)) {
533 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
535 hide_read_feeds
= !hide_read_feeds
;
537 debug("toggle_disp_read => " + hide_read_feeds
);
539 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
541 var query
= "backend.php?op=rpc&subop=setpref" +
542 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
544 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
546 new Ajax
.Request(query
);
549 exception_error("toggleDispRead", e
);
553 function parse_runtime_info(elem
) {
555 debug("parse_runtime_info: elem is null, aborting");
559 var param
= elem
.firstChild
;
561 debug("parse_runtime_info: " + param
);
564 var k
= param
.getAttribute("key");
565 var v
= param
.getAttribute("value");
567 debug("RI: " + k
+ " => " + v
);
569 if (k
== "new_version_available") {
570 var icon
= document
.getElementById("newVersionIcon");
573 icon
.style
.display
= "inline";
575 icon
.style
.display
= "none";
580 if (k
== "daemon_is_running" && v
!= 1) {
581 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not runing.</span>");
584 /* var w = document.getElementById("noDaemonWarning");
587 if (k == "daemon_is_running" && v != 1) {
588 w.style.display = "block";
590 w.style.display = "none";
593 param
= param
.nextSibling
;
597 function catchupCurrentFeed() {
599 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
601 var str
= "Mark all articles in " + fn
+ " as read?";
603 /* if (active_feed_is_cat) {
604 str = "Mark all articles in this category as read?";
607 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
608 return viewCurrentFeed('MarkAllRead')
612 function userSwitch() {
613 var chooser
= document
.getElementById("userSwitch");
614 var user
= chooser
[chooser
.selectedIndex
].value
;
615 window
.location
= "tt-rss.php?swu=" + user
;
618 function editFeedDlg(feed
) {
623 alert("Please select some feed first.");
627 if (feed
<= 0 || active_feed_is_cat
|| tagsAreDisplayed()) {
628 alert("You can't edit this kind of feed.");
632 if (xmlhttp_ready(xmlhttp
)) {
633 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
634 param_escape(feed
), true);
635 xmlhttp
.onreadystatechange
=infobox_callback
;
642 /* this functions duplicate those of prefs.js feed editor, with
643 some differences because there is no feedlist */
645 function feedEditCancel() {
650 function feedEditSave() {
654 if (!xmlhttp_ready(xmlhttp
)) {
659 // FIXME: add parameter validation
661 var query
= Form
.serialize("edit_feed_form");
663 notify_progress("Saving feed...");
665 xmlhttp
.open("POST", "backend.php", true);
666 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
667 xmlhttp
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
675 exception_error("feedEditSave (main)", e
);
679 function localHotkeyHandler(e
) {
684 keycode
= window
.event
.keyCode
;
689 var shift_key
= false;
692 shift_key
= e
.shiftKey
;
695 if (keycode
== 66 && shift_key
) { // shift-B
697 var op
= history_pop();
700 var op_s
= op
.split(":");
703 for (i
= 0; i
< op_s
.length
; i
++) {
704 if (op_s
[i
] == 'undefined') {
708 if (op_s
[i
] == 'false') {
712 if (op_s
[i
] == 'true') {
718 debug("history split: " + op_s
);
720 if (op_s
[0] == "ARTICLE") {
721 debug("history: reverting to article " + op_s
[1] + "/" + op_s
[2]);
722 view(op_s
[1], op_s
[2], true);
725 if (op_s
[0] == "FEED") {
726 viewfeed(op_s
[1], op_s
[2], op_s
[3], op_s
[4], true);
730 notify_error("No operation to undo");
737 debug("LKP=" + keycode
);
740 function history_push(op
) {
741 debug("history_push: " + op
);
744 while (op_history
.length
> 30) {
749 function history_pop() {
750 var op
= op_history
.pop();
751 debug("history_pop: " + op
);
755 function history_clear() {
756 debug("history_clear");