]>
git.wh0rd.org - tt-rss.git/blob - tt-rss.js
a8a54fb4c72e4b05f494a2ac063ad6da846f3ef8
3 var display_tags
= false;
4 var global_unread
= -1;
5 var active_title_text
= "";
6 var current_subtitle
= "";
7 var daemon_enabled
= false;
8 var daemon_refresh_only
= false;
9 //var _qfd_deleted_feed = 0;
10 var firsttime_update
= true;
11 var cookie_lifetime
= 0;
12 var active_feed_id
= 0;
13 var active_feed_is_cat
= false;
14 var number_of_feeds
= 0;
15 var sanity_check_done
= false;
16 var _hfd_scrolltop
= 0;
18 var init_params
= new Object();
20 function tagsAreDisplayed() {
24 function toggleTags(show_all
) {
28 debug("toggleTags: " + show_all
+ "; " + display_tags
);
30 var p
= document
.getElementById("dispSwitchPrompt");
32 if (!show_all
&& !display_tags
) {
33 displayDlg("printTagCloud");
34 } else if (show_all
) {
37 p
.innerHTML
= __("display feeds");
38 notify_progress("Loading, please wait...", true);
40 } else if (display_tags
) {
42 p
.innerHTML
= __("tag cloud");
43 notify_progress("Loading, please wait...", true);
48 exception_error("toggleTags", e
);
52 function dlg_frefresh_callback(transport
, deleted_feed
) {
53 if (getActiveFeedId() == deleted_feed
) {
54 var h
= document
.getElementById("headlines-frame");
56 h
.innerHTML
= "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
60 setTimeout('updateFeedList(false, false)', 50);
64 function refetch_callback2(transport
) {
67 var date
= new Date();
69 parse_counters_reply(transport
, true);
71 debug("refetch_callback2: done");
73 /* if (!daemon_enabled && !daemon_refresh_only) {
74 notify_info("All feeds updated.");
80 exception_error("refetch_callback", e
);
85 function backend_sanity_check_callback(transport
) {
89 if (sanity_check_done
) {
90 fatalError(11, "Sanity check request received twice. This can indicate "+
91 "presence of Firebug or some other disrupting extension. "+
92 "Please disable it and try again.");
96 if (!transport
.responseXML
) {
97 fatalError(3, "[D001, Received reply is not XML]: " + transport
.responseText
);
101 var reply
= transport
.responseXML
.firstChild
.firstChild
;
104 fatalError(3, "[D002, Invalid RPC reply]: " + transport
.responseText
);
108 var error_code
= reply
.getAttribute("error-code");
110 if (error_code
&& error_code
!= 0) {
111 return fatalError(error_code
, reply
.getAttribute("error-msg"));
114 debug("sanity check ok");
116 var params
= reply
.nextSibling
;
119 debug('reading init-params...');
120 var param
= params
.firstChild
;
123 var k
= param
.getAttribute("key");
124 var v
= param
.getAttribute("value");
125 debug(k
+ " => " + v
);
127 param
= param
.nextSibling
;
131 sanity_check_done
= true;
136 exception_error("backend_sanity_check_callback", e
);
140 function scheduleFeedUpdate(force
) {
142 debug("in scheduleFeedUpdate");
144 /* if (!daemon_enabled && !daemon_refresh_only) {
145 notify_progress("Updating feeds...", true);
148 var query_str
= "backend.php?op=rpc&subop=";
151 query_str
= query_str
+ "forceUpdateAllFeeds";
153 query_str
= query_str
+ "updateAllFeeds";
158 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
159 firsttime_update
= false;
169 query_str
= query_str
+ "&omode=" + omode
;
170 query_str
= query_str
+ "&uctr=" + global_unread
;
172 var date
= new Date();
173 var timestamp
= Math
.round(date
.getTime() / 1000);
174 query_str
= query_str
+ "&ts=" + timestamp
176 debug("REFETCH query: " + query_str
);
178 new Ajax
.Request(query_str
, {
179 onComplete: function(transport
) {
180 refetch_callback2(transport
);
184 function updateFeedList(silent
, fetch
) {
186 // if (silent != true) {
187 // notify("Loading feed list...");
190 debug("<b>updateFeedList</b>");
192 var query_str
= "backend.php?op=feeds";
195 query_str
= query_str
+ "&tags=1";
198 if (getActiveFeedId() && !activeFeedIsCat()) {
199 query_str
= query_str
+ "&actid=" + getActiveFeedId();
202 var date
= new Date();
203 var timestamp
= Math
.round(date
.getTime() / 1000);
204 query_str
= query_str
+ "&ts=" + timestamp
206 if (fetch
) query_str
= query_str
+ "&fetch=yes";
208 // var feeds_frame = document.getElementById("feeds-frame");
209 // feeds_frame.src = query_str;
211 debug("updateFeedList Q=" + query_str
);
213 new Ajax
.Request(query_str
, {
214 onComplete: function(transport
) {
215 feedlist_callback2(transport
);
220 function catchupAllFeeds() {
222 var str
= __("Mark all articles as read?");
224 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
226 var query_str
= "backend.php?op=feeds&subop=catchupAll";
228 notify_progress("Marking all feeds as read...");
230 debug("catchupAllFeeds Q=" + query_str
);
232 new Ajax
.Request(query_str
, {
233 onComplete: function(transport
) {
234 feedlist_callback2(transport
);
242 function viewCurrentFeed(subop
) {
244 // if (getActiveFeedId()) {
245 if (getActiveFeedId() != undefined) {
246 viewfeed(getActiveFeedId(), subop
, active_feed_is_cat
);
248 disableContainerChildren("headlinesToolbar", false, document
);
249 // viewfeed(-1, subop); // FIXME
251 return false; // block unneeded form submits
254 function viewfeed(feed
, subop
) {
255 var f
= window
.frames
["feeds-frame"];
256 f
.viewfeed(feed
, subop
);
260 scheduleFeedUpdate(false);
262 var refresh_time
= getInitParam("feeds_frame_refresh");
264 if (!refresh_time
) refresh_time
= 600;
266 setTimeout("timeout()", refresh_time
*1000);
269 function resetSearch() {
270 var searchbox
= document
.getElementById("searchbox")
272 if (searchbox
.value
!= "" && getActiveFeedId()) {
273 searchbox
.value
= "";
274 viewfeed(getActiveFeedId(), "");
278 function searchCancel() {
284 viewCurrentFeed(0, "");
287 // if argument is undefined, current subtitle is not updated
288 // use blank string to clear subtitle
289 function updateTitle(s
) {
290 var tmp
= "Tiny Tiny RSS";
292 if (s
!= undefined) {
293 current_subtitle
= s
;
296 if (global_unread
> 0) {
297 tmp
= tmp
+ " (" + global_unread
+ ")";
300 if (current_subtitle
) {
301 tmp
= tmp
+ " - " + current_subtitle
;
304 if (active_title_text
.length
> 0) {
305 tmp
= tmp
+ " > " + active_title_text
;
308 document
.title
= tmp
;
311 function genericSanityCheck() {
313 // if (!Ajax.getTransport()) fatalError(1);
315 setCookie("ttrss_vf_test", "TEST");
317 if (getCookie("ttrss_vf_test") != "TEST") {
328 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
330 if (arguments
.callee
.done
) return;
331 arguments
.callee
.done
= true;
333 disableContainerChildren("headlinesToolbar", true);
335 Form
.disable("main_toolbar_form");
337 if (!genericSanityCheck())
340 if (getURLParam('debug')) {
341 document
.getElementById('debug_output').style
.display
= 'block';
342 debug('debug mode activated');
345 var params
= "&ua=" + param_escape(navigator
.userAgent
);
347 new Ajax
.Request("backend.php?op=rpc&subop=sanityCheck" + params
, {
348 onComplete: function(transport
) {
349 backend_sanity_check_callback(transport
);
353 exception_error("init", e
);
357 function resize_headlines() {
359 var h_frame
= document
.getElementById("headlines-frame");
360 var c_frame
= document
.getElementById("content-frame");
361 var f_frame
= document
.getElementById("footer");
362 var feeds_frame
= document
.getElementById("feeds-holder");
364 if (!c_frame
|| !h_frame
) return;
366 if (feeds_frame
&& getInitParam("theme") == "compat") {
367 feeds_frame
.style
.bottom
= f_frame
.offsetHeight
+ "px";
370 if (getInitParam("theme") == "3pane") {
371 debug("resize_headlines: HOR-mode");
373 c_frame
.style
.width
= '35%';
374 h_frame
.style
.right
= c_frame
.offsetWidth
- 1 + "px";
377 debug("resize_headlines: VER-mode");
380 h_frame
.style
.height
= 30 + "%";
381 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
382 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
384 h_frame
.style
.height
= document
.documentElement
.clientHeight
* 0.3 + "px";
385 c_frame
.style
.top
= h_frame
.offsetTop
+ h_frame
.offsetHeight
+ 1 + "px";
387 var c_bottom
= document
.documentElement
.clientHeight
;
390 c_bottom
= f_frame
.offsetTop
;
393 c_frame
.style
.height
= c_bottom
- (h_frame
.offsetTop
+
394 h_frame
.offsetHeight
+ 1) + "px";
395 h_frame
.style
.height
= h_frame
.offsetHeight
+ "px";
403 function init_second_stage() {
407 cookie_lifetime
= getCookie("ttrss_cltime");
409 delCookie("ttrss_vf_test");
411 // document.onresize = resize_headlines;
414 var toolbar
= document
.forms
["main_toolbar_form"];
416 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
417 dropboxSelect(toolbar
.limit
, getInitParam("default_view_limit"));
419 daemon_enabled
= getInitParam("daemon_enabled") == 1;
420 daemon_refresh_only
= getInitParam("daemon_refresh_only") == 1;
422 setTimeout('updateFeedList(false, false)', 50);
424 debug("second stage ok");
427 exception_error("init_second_stage", e
);
431 function quickMenuChange() {
432 var chooser
= document
.getElementById("quickMenuChooser");
433 var opid
= chooser
[chooser
.selectedIndex
].value
;
435 chooser
.selectedIndex
= 0;
439 function quickMenuGo(opid
) {
442 if (opid
== "qmcPrefs") {
446 if (opid
== "qmcSearch") {
447 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
451 if (opid
== "qmcAddFeed") {
452 displayDlg("quickAddFeed");
456 if (opid
== "qmcEditFeed") {
457 editFeedDlg(getActiveFeedId());
460 if (opid
== "qmcRemoveFeed") {
461 var actid
= getActiveFeedId();
463 if (activeFeedIsCat()) {
464 alert(__("You can't unsubscribe from the category."));
469 alert(__("Please select some feed first."));
473 var fn
= getFeedName(actid
);
475 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
478 unsubscribeFeed(actid
);
484 if (opid
== "qmcClearFeed") {
485 var actid
= getActiveFeedId();
488 alert(__("Please select some feed first."));
492 if (activeFeedIsCat() || actid
< 0) {
493 alert(__("You can't clear this type of feed."));
497 var fn
= getFeedName(actid
);
499 var pr
= __("Erase all non-starred articles in %s?").replace("%s", fn
);
502 clearFeedArticles(actid
);
509 if (opid
== "qmcUpdateFeeds") {
510 scheduleFeedUpdate(true);
514 if (opid
== "qmcCatchupAll") {
519 if (opid
== "qmcShowOnlyUnread") {
524 if (opid
== "qmcAddFilter") {
525 displayDlg("quickAddFilter", getActiveFeedId());
528 if (opid
== "qmcRescoreFeed") {
529 rescoreCurrentFeed();
532 if (opid
== "qmcHKhelp") {
533 Element
.show("hotkey_help_overlay");
537 exception_error("quickMenuGo", e
);
541 function unsubscribeFeed(feed_id
) {
543 notify_progress("Removing feed...");
545 var query
= "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
547 new Ajax
.Request(query
, {
548 onComplete: function(transport
) {
549 dlg_frefresh_callback(transport
, feed_id
);
557 function updateFeedTitle(t
) {
558 active_title_text
= t
;
562 function toggleDispRead() {
565 var hide_read_feeds
= (getInitParam("hide_read_feeds") == "1");
567 hide_read_feeds
= !hide_read_feeds
;
569 debug("toggle_disp_read => " + hide_read_feeds
);
571 hideOrShowFeeds(getFeedsContext().document
, hide_read_feeds
);
573 storeInitParam("hide_read_feeds", hide_read_feeds
, true);
576 exception_error("toggleDispRead", e
);
580 function parse_runtime_info(elem
) {
582 debug("parse_runtime_info: elem is null, aborting");
586 var param
= elem
.firstChild
;
588 debug("parse_runtime_info: " + param
);
591 var k
= param
.getAttribute("key");
592 var v
= param
.getAttribute("value");
594 debug("RI: " + k
+ " => " + v
);
596 if (k
== "new_version_available") {
597 var icon
= document
.getElementById("newVersionIcon");
600 icon
.style
.display
= "inline";
602 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>", true);
614 if (k
== "daemon_stamp_ok" && v
!= 1) {
615 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
623 /* var w = document.getElementById("noDaemonWarning");
626 if (k == "daemon_is_running" && v != 1) {
627 w.style.display = "block";
629 w.style.display = "none";
632 param
= param
.nextSibling
;
636 function catchupCurrentFeed() {
638 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
640 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
642 /* if (active_feed_is_cat) {
643 str = "Mark all articles in this category as read?";
646 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
647 return viewCurrentFeed('MarkAllRead')
651 function editFeedDlg(feed
) {
655 alert(__("Please select some feed first."));
659 if ((feed
<= 0 && feed
> -10) || activeFeedIsCat() || tagsAreDisplayed()) {
660 alert(__("You can't edit this kind of feed."));
667 query
= "backend.php?op=pref-feeds&subop=editfeed&id=" + param_escape(feed
);
669 query
= "backend.php?op=pref-labels&subop=edit&id=" + param_escape(-feed
-11);
674 new Ajax
.Request(query
, {
675 onComplete: function(transport
) {
676 infobox_callback2(transport
);
680 exception_error("editFeedDlg", e
);
684 /* this functions duplicate those of prefs.js feed editor, with
685 some differences because there is no feedlist */
687 function feedEditCancel() {
692 function feedEditSave() {
696 // FIXME: add parameter validation
698 var query
= Form
.serialize("edit_feed_form");
700 notify_progress("Saving feed...");
702 new Ajax
.Request("backend.php", {
704 onComplete: function(transport
) {
705 dlg_frefresh_callback(transport
);
714 exception_error("feedEditSave (main)", e
);
718 function labelEditCancel() {
723 function labelEditSave() {
729 notify_progress("Saving label...");
731 query
= Form
.serialize("label_edit_form");
733 new Ajax
.Request("backend.php?" + query
, {
734 onComplete: function(transport
) {
735 dlg_frefresh_callback(transport
);
741 exception_error("feedEditSave (main)", e
);
746 function clearFeedArticles(feed_id
) {
748 notify_progress("Clearing feed...");
750 var query
= "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id
;
752 new Ajax
.Request(query
, {
753 onComplete: function(transport
) {
754 dlg_frefresh_callback(transport
, feed_id
);
761 function toggle_feedlist() {
763 debug("toggle_feedlist");
765 var fl = document.getElementById("feeds-holder");
767 if (!Element.visible(fl)) {
769 fl.style.zIndex = 30;
770 fl.scrollTop = _hfd_scrolltop;
772 _hfd_scrolltop = fl.scrollTop;
774 // Effect.Fade(fl, {duration : 0.2,
775 // queue: { position: 'end', scope: 'FLFADEQ', limit: 1 }});
778 exception_error(e, "toggle_feedlist");
782 function collapse_feedlist() {
784 debug("toggle_feedlist");
786 var theme
= getInitParam("theme");
787 if (theme
!= "" && theme
!= "compact" && theme
!= "graycube" &&
788 theme
!= "compat") return;
790 var fl
= document
.getElementById("feeds-holder");
791 var fh
= document
.getElementById("headlines-frame");
792 var fc
= document
.getElementById("content-frame");
793 var ft
= document
.getElementById("toolbar");
794 var ff
= document
.getElementById("footer");
795 var fhdr
= document
.getElementById("header");
796 var fbtn
= document
.getElementById("collapse_feeds_btn");
798 if (!Element
.visible(fl
)) {
802 if (theme
!= "graycube") {
804 fh
.style
.left
= fl
.offsetWidth
+ "px";
805 ft
.style
.left
= fl
.offsetWidth
+ "px";
806 if (fc
) fc
.style
.left
= fl
.offsetWidth
+ "px";
807 if (ff
&& theme
!= "compat") ff
.style
.left
= (fl
.offsetWidth
-1) + "px";
809 if (theme
== "compact") fhdr
.style
.left
= (fl
.offsetWidth
+ 10) + "px";
811 fh
.style
.left
= fl
.offsetWidth
+ 40 + "px";
812 ft
.style
.left
= fl
.offsetWidth
+ 40 +"px";
813 if (fc
) fc
.style
.left
= fl
.offsetWidth
+ 40 + "px";
816 setCookie("ttrss_vf_fclps", "0");
822 if (theme
!= "graycube") {
824 fh
.style
.left
= "0px";
825 ft
.style
.left
= "0px";
826 if (fc
) fc
.style
.left
= "0px";
827 if (ff
) ff
.style
.left
= "0px";
829 if (theme
== "compact") fhdr
.style
.left
= "10px";
832 fh
.style
.left
= "20px";
833 ft
.style
.left
= "20px";
834 if (fc
) fc
.style
.left
= "20px";
838 setCookie("ttrss_vf_fclps", "1");
841 exception_error(e
, "toggle_feedlist");
845 function viewModeChanged() {
847 return viewCurrentFeed(0, '')
850 function viewLimitChanged() {
852 return viewCurrentFeed(0, '')
855 function adjustArticleScore(id
, score
) {
858 var pr
= prompt(__("Assign score to article:"), score
);
860 if (pr
!= undefined) {
861 var query
= "backend.php?op=rpc&subop=setScore&id=" + id
+ "&score=" + pr
;
863 new Ajax
.Request(query
, {
864 onComplete: function(transport
) {
870 exception_error(e
, "adjustArticleScore");
874 function rescoreCurrentFeed() {
876 var actid
= getActiveFeedId();
878 if (activeFeedIsCat() || actid
< 0 || tagsAreDisplayed()) {
879 alert(__("You can't rescore this kind of feed."));
884 alert(__("Please select some feed first."));
888 var fn
= getFeedName(actid
);
889 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
892 notify_progress("Rescoring articles...");
894 var query
= "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
896 new Ajax
.Request(query
, {
897 onComplete: function(transport
) {