]>
git.wh0rd.org - tt-rss.git/blob - feedlist.js
1 var _feed_cur_page
= 0;
2 var _infscroll_disable
= 0;
3 var _infscroll_request_sent
= 0;
4 var feed_under_pointer
= undefined;
6 var mouse_is_down
= false;
10 var resize_enabled
= false;
11 var selection_disabled
= false;
12 var counters_last_request
= 0;
14 function toggle_sortable_feedlist(enabled
) {
18 Sortable
.create('feedList', {onChange
: feedlist_dragsorted
, only
: "feedCat"});
20 Sortable
.destroy('feedList');
24 exception_error("toggle_sortable_feedlist", e
);
28 function viewCategory(cat
) {
29 viewfeed(cat
, '', true);
33 function printFeedEntry(id
, title
, row_class
, unread
, icon
) {
40 row_class
+= "Unread";
41 fctr_class
= "feedCtrHasUnread";
43 fctr_class
= "feedCtrNoUnread";
47 feed_icon
= "<img id='FIMG-"+id
+"' src='" + icon
+ "'>";
49 feed_icon
= "<img id='FIMG-"+id
+"' src='images/blank_icon.gif'>";
52 var link
= "<a title=\"FIXME\" id=\"FEEDL-"+id
+"\""+
53 "href=\"javascript:viewfeed('"+id
+"', '', false, '', false, 0);\">"+
56 tmp
+= "<li id='FEEDR-"+id
+"' class="+row_class
+">" + feed_icon
+
57 "<span id=\"FEEDN-"+id
+"\">" + link
+ "</span>";
59 tmp
+= " <span class='"+fctr_class
+"' id=\"FEEDCTR-"+id
+"\">" +
60 "(<span id=\"FEEDU-"+id
+"\">"+unread
+"</span>)</span>";
67 function render_feedlist(data
) {
70 var f
= $("feeds-frame");
72 // cache_invalidate("FEEDLIST");
73 // cache_inject("FEEDLIST", data, getInitParam("num_feeds"));
77 exception_error("render_feedlist", e
);
81 function feedlist_callback2(transport
) {
83 debug("feedlist_callback2");
84 if (!transport_error_check(transport
)) return;
85 render_feedlist(transport
.responseText
);
87 exception_error("feedlist_callback2", e
);
91 function viewNextFeedPage() {
93 //if (!getActiveFeedId()) return;
95 debug("viewNextFeedPage: calling viewfeed(), p: " + parseInt(_feed_cur_page
+1));
97 viewfeed(getActiveFeedId(), undefined, activeFeedIsCat(), undefined,
98 undefined, parseInt(_feed_cur_page
+1));
101 exception_error("viewNextFeedPage", e
);
106 function viewfeed(feed
, subop
, is_cat
, subop_param
, skip_history
, offset
) {
109 if (offline_mode
) return viewfeed_offline(feed
, subop
, is_cat
, subop_param
,
110 skip_history
, offset
);
112 // if (!offset) page_offset = 0;
114 last_requested_article
= 0;
115 //counters_last_request = 0;
117 if (feed
== getActiveFeedId()) {
118 cache_invalidate("F:" + feed
);
121 /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") {
122 if (getInitParam("hide_feedlist") == 1) {
123 Element.hide("feeds-holder");
127 var force_nocache
= false;
132 page_offset
= offset
;
136 _infscroll_disable
= 0;
139 if (getActiveFeedId() != feed
) {
142 _infscroll_disable
= 0;
145 if (page_offset
!= 0 && !subop
) {
146 var date
= new Date();
147 var timestamp
= Math
.round(date
.getTime() / 1000);
149 debug("<b>" + _infscroll_request_sent
+ " : " + timestamp
+ "</b>");
151 if (_infscroll_request_sent
&& _infscroll_request_sent
+ 30 > timestamp
) {
152 debug("infscroll request in progress, aborting");
156 _infscroll_request_sent
= timestamp
;
163 Form
.enable("main_toolbar_form");
165 var toolbar_form
= document
.forms
["main_toolbar_form"];
166 var toolbar_query
= Form
.serialize("main_toolbar_form");
168 if (toolbar_form
.query
) {
169 if (toolbar_form
.query
.value
!= "") {
170 force_nocache
= true;
172 toolbar_form
.query
.value
= "";
175 var query
= "backend.php?op=viewfeed&feed=" + feed
+ "&" +
176 toolbar_query
+ "&subop=" + param_escape(subop
);
178 if ($("search_form")) {
179 var search_query
= Form
.serialize("search_form");
180 query
= query
+ "&" + search_query
;
181 $("search_form").query
.value
= "";
183 force_nocache
= true;
186 // debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
188 if (subop
== "MarkAllRead") {
190 catchup_local_feed(feed
, is_cat
);
192 var show_next_feed
= getInitParam("on_catchup_show_next_feed") == "1";
194 if (show_next_feed
) {
196 if (!activeFeedIsCat()) {
198 var feedlist
= $('feedList');
200 var next_unread_feed
= getRelativeFeedId(feedlist
,
203 if (!next_unread_feed
) {
204 next_unread_feed
= getRelativeFeedId(feedlist
,
208 if (next_unread_feed
) {
209 query
= query
+ "&nuf=" + param_escape(next_unread_feed
);
210 //setActiveFeedId(next_unread_feed);
211 feed
= next_unread_feed
;
215 var next_unread_feed
= getNextUnreadCat(feed
);
217 /* we don't need to specify that our next feed is actually
218 a category, because we're in the is_cat mode by definition
221 if (next_unread_feed
&& show_next_feed
) {
222 query
= query
+ "&nuf=" + param_escape(next_unread_feed
);
223 feed
= next_unread_feed
;
231 query
= query
+ "&cat=1";
234 if (page_offset
!= 0) {
235 query
= query
+ "&skip=" + page_offset
;
237 // to prevent duplicate feed titles when showing grouped vfeeds
238 if (vgroup_last_feed
) {
239 query
= query
+ "&vgrlf=" + param_escape(vgroup_last_feed
);
243 var date
= new Date();
244 var timestamp
= Math
.round(date
.getTime() / 1000);
245 query
= query
+ "&ts=" + timestamp
247 disableContainerChildren("headlinesToolbar", false);
248 Form
.enable("main_toolbar_form");
250 // for piggybacked counters
252 if (tagsAreDisplayed()) {
253 query
= query
+ "&omode=lt";
255 query
= query
+ "&omode=flc";
258 if (!async_counters_work
) {
259 query
= query
+ "&csync=true";
264 var container
= $("headlinesInnerContainer");
266 /* if (container && page_offset == 0 && !isCdmMode()) {
267 new Effect.Fade(container, {duration: 1, to: 0.01,
268 queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
273 if (!is_cat
) unread_ctr
= get_feed_unread(feed
);
275 var cache_check
= false;
277 if (unread_ctr
!= -1 && !page_offset
&& !force_nocache
&& !subop
) {
279 var cache_prefix
= "";
287 cache_check
= cache_check_param(cache_prefix
+ feed
, unread_ctr
);
288 debug("headline cache check: " + cache_check
);
292 var f
= $("headlines-frame");
294 clean_feed_selections();
296 setActiveFeedId(feed
, is_cat
);
299 var feedr
= $("FEEDR-" + feed
);
300 if (feedr
&& !feedr
.className
.match("Selected")) {
301 feedr
.className
= feedr
.className
+ "Selected";
304 var feedr
= $("FCAT-" + feed_id
);
305 if (feedr
&& !feedr
.className
.match("Selected")) {
306 feedr
.className
= feedr
.className
+ "Selected";
310 f
.innerHTML
= cache_find_param(cache_prefix
+ feed
, unread_ctr
);
318 notify_progress("Loading, please wait...", true);
321 new Ajax
.Request(query
, {
322 onComplete: function(transport
) {
323 headlines_callback2(transport
, page_offset
);
328 exception_error("viewfeed", e
);
332 function toggleCollapseCat_af(effect
) {
333 //var caption = elem.id.replace("FCATLIST-", "");
337 var elem
= effect
.element
;
338 var cat
= elem
.id
.replace("FCATLIST-", "");
339 var cap
= $("FCAP-" + cat
);
341 if (Element
.visible(elem
)) {
342 cap
.innerHTML
= cap
.innerHTML
.replace("…", "");
344 if (cap
.innerHTML
.lastIndexOf("…") != cap
.innerHTML
.length
-3) {
345 cap
.innerHTML
= cap
.innerHTML
+ "…";
350 exception_error("toggleCollapseCat_af", e
);
354 function toggleCollapseCat(cat
) {
357 var cat_elem
= $("FCAT-" + cat
);
358 var cat_list
= $("FCATLIST-" + cat
).parentNode
;
359 var caption
= $("FCAP-" + cat
);
361 /* if (cat_list.className.match("invisible")) {
362 cat_list.className = "";
363 caption.innerHTML = caption.innerHTML.replace("...", "");
365 setCookie("ttrss_vf_uclps", "0");
368 cat_list.className = "invisible";
369 caption.innerHTML = caption.innerHTML + "...";
371 setCookie("ttrss_vf_uclps", "1");
377 if (Element
.visible("FCATLIST-" + cat
)) {
378 setCookie("ttrss_vf_uclps", "1");
380 setCookie("ttrss_vf_uclps", "0");
385 if (Element
.visible("FCATLIST-" + cat
)) {
386 setCookie("ttrss_vf_lclps", "1");
388 setCookie("ttrss_vf_lclps", "0");
393 if (Element
.visible("FCATLIST-" + cat
)) {
394 setCookie("ttrss_vf_vclps", "1");
396 setCookie("ttrss_vf_vclps", "0");
400 Effect
.toggle('FCATLIST-' + cat
, 'blind', { duration
: 0.5,
401 afterFinish
: toggleCollapseCat_af
});
403 new Ajax
.Request("backend.php?op=feeds&subop=collapse&cid=" +
406 local_collapse_cat(cat
);
409 exception_error("toggleCollapseCat", e
);
413 function feedlist_dragsorted(ctr
) {
415 var elem
= $("feedList");
417 var cats
= elem
.getElementsByTagName("LI");
418 var ordered_cats
= new Array();
420 for (var i
= 0; i
< cats
.length
; i
++) {
421 if (cats
[i
].id
&& cats
[i
].id
.match("FCAT-")) {
422 ordered_cats
.push(cats
[i
].id
.replace("FCAT-", ""));
426 if (ordered_cats
.length
> 0) {
428 var query
= "backend.php?op=feeds&subop=catsort&corder=" +
429 param_escape(ordered_cats
.toString());
433 new Ajax
.Request(query
);
437 exception_error("feedlist_dragsorted", e
);
441 function feedlist_init() {
443 // if (arguments.callee.done) return;
444 // arguments.callee.done = true;
446 loading_set_progress(90);
448 debug("in feedlist init");
450 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
451 document
.onkeydown
= hotkey_handler
;
452 document
.onmousemove
= mouse_move_handler
;
453 document
.onmousedown
= mouse_down_handler
;
454 document
.onmouseup
= mouse_up_handler
;
456 if (!offline_mode
) setTimeout("timeout()", 1);
458 setTimeout("hotkey_prefix_timeout()", 5*1000);
460 if (typeof correctPNG
!= 'undefined') {
464 if (getActiveFeedId()) {
465 //debug("some feed is open on feedlist refresh, reloading");
466 //setTimeout("viewCurrentFeed()", 100);
468 if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) {
469 notify_silent_next();
470 setTimeout("viewfeed(-3)", 100);
476 if (getInitParam("theme") == "") {
477 setTimeout("hide_footer()", 5000);
480 init_collapsable_feedlist(getInitParam("theme"));
482 toggle_sortable_feedlist(isFeedlistSortable());
485 exception_error("feedlist/init", e
);
489 function hide_footer_af(effect
) {
491 var c
= $("content-frame");
494 c
.style
.bottom
= "0px";
496 var ioa
= $("inline_orig_article");
499 ioa
.height
= c
.offsetHeight
;
503 var h
= $("headlines-frame");
506 h
.style
.bottom
= "0px";
511 exception_error("hide_footer_af", e
);
515 function hide_footer() {
517 if (Element
.visible("footer")) {
518 new Effect
.Fade("footer", { afterFinish
: hide_footer_af
});
521 exception_error("hide_footer", e
);
526 function init_hidden_feedlist(theme) {
528 debug("init_hidden_feedlist");
530 if (theme != "" && theme != "compact") return;
532 var fl = $("feeds-holder");
533 var fh = $("headlines-frame");
534 var fc = $("content-frame");
535 var ft = $("toolbar");
536 var ff = $("footer");
537 var fhdr = $("header");
539 var fbtn = $("toggle_feeds_btn");
541 if (fbtn) Element.show(fbtn);
543 fl.style.top = fh.offsetTop + "px";
544 fl.style.backgroundColor = "white"; //FIXME
548 fh.style.left = "0px";
549 ft.style.left = "0px";
550 if (fc) fc.style.left = "0px";
551 if (ff) ff.style.left = "0px";
553 if (theme == "compact") {
554 fhdr.style.left = "10px";
555 fl.style.top = (fh.offsetTop + 1) + "px";
559 exception_error("init_hidden_feedlist", e);
563 function init_collapsable_feedlist(theme
) {
565 debug("init_collapsable_feedlist");
567 if (theme
!= "" && theme
!= "compact" && theme
!= "graycube" &&
568 theme
!= "compat") return;
570 var fbtn
= $("collapse_feeds_btn");
572 if (fbtn
) Element
.show(fbtn
);
574 if (getCookie("ttrss_vf_fclps") == 1) {
579 exception_error("init_hidden_feedlist", e
);
584 function mouse_move_handler(e
) {
590 client_y
= window
.event
.clientY
;
591 client_x
= window
.event
.clientX
;
593 client_x
= e
.screenX
;
594 client_y
= e
.screenY
;
599 if (mouse_y
== 0) mouse_y
= client_y
;
600 if (mouse_x
== 0) mouse_x
= client_x
;
602 resize_headlines(mouse_x
- client_x
, mouse_y
- client_y
);
611 exception_error("mouse_move_handler", e
);
615 function enable_selection(b
) {
616 selection_disabled
= !b
;
619 function enable_resize(b
) {
623 function mouse_down_handler(e
) {
626 /* do not prevent right click */
627 if (e
&& e
.button
&& e
.button
== 2) return;
629 if (resize_enabled
) {
630 mouse_is_down
= true;
633 document
.onselectstart = function() { return false; };
637 if (selection_disabled
) {
638 document
.onselectstart = function() { return false; };
643 exception_error("mouse_down_handler", e
);
647 function mouse_up_handler(e
) {
649 mouse_is_down
= false;
651 if (!selection_disabled
) {
652 document
.onselectstart
= null;
653 var e
= $("headlineActionsBody");
654 if (e
) Element
.hide(e
);
656 var e
= $("offlineModeDrop");
657 if (e
) Element
.hide(e
);
662 exception_error("mouse_up_handler", e
);
666 function request_counters_real() {
670 if (offline_mode
) return;
672 debug("requesting counters...");
674 var query
= "backend.php?op=rpc&subop=getAllCounters";
676 if (tagsAreDisplayed()) {
677 query
= query
+ "&omode=tl";
679 query
= query
+ "&omode=flc";
682 new Ajax
.Request(query
, {
683 onComplete: function(transport
) {
685 all_counters_callback2(transport
, true);
687 exception_error("viewfeed/getcounters", e
);
692 exception_error("request_counters_real", e
);
697 function request_counters() {
701 if (getInitParam("bw_limit") == "1") return;
703 var date
= new Date();
704 var timestamp
= Math
.round(date
.getTime() / 1000);
706 // if (getInitParam("sync_counters") == "1" ||
707 // timestamp - counters_last_request > 10) {
709 if (timestamp
- counters_last_request
> 15) {
710 debug("scheduling request of counters...");
711 window
.setTimeout("request_counters_real()", 1000);
712 counters_last_request
= timestamp
;
714 debug("request_counters: rate limit reached: " + (timestamp
- counters_last_request
));
718 exception_error("request_counters", e
);