]>
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
= document
.getElementById("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 (document
.getElementById("search_form")) {
179 var search_query
= Form
.serialize("search_form");
180 query
= query
+ "&" + search_query
;
182 force_nocache
= true;
185 // debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
187 if (subop
== "MarkAllRead") {
189 var show_next_feed
= getInitParam("on_catchup_show_next_feed") == "1";
191 if (show_next_feed
) {
193 if (!activeFeedIsCat()) {
195 var feedlist
= document
.getElementById('feedList');
197 var next_unread_feed
= getRelativeFeedId(feedlist
,
200 if (!next_unread_feed
) {
201 next_unread_feed
= getRelativeFeedId(feedlist
,
205 if (next_unread_feed
) {
206 query
= query
+ "&nuf=" + param_escape(next_unread_feed
);
207 //setActiveFeedId(next_unread_feed);
208 feed
= next_unread_feed
;
212 var next_unread_feed
= getNextUnreadCat(feed
);
214 /* we don't need to specify that our next feed is actually
215 a category, because we're in the is_cat mode by definition
218 if (next_unread_feed
&& show_next_feed
) {
219 query
= query
+ "&nuf=" + param_escape(next_unread_feed
);
220 feed
= next_unread_feed
;
228 query
= query
+ "&cat=1";
231 if (page_offset
!= 0) {
232 query
= query
+ "&skip=" + page_offset
;
234 // to prevent duplicate feed titles when showing grouped vfeeds
235 if (vgroup_last_feed
) {
236 query
= query
+ "&vgrlf=" + param_escape(vgroup_last_feed
);
240 var date
= new Date();
241 var timestamp
= Math
.round(date
.getTime() / 1000);
242 query
= query
+ "&ts=" + timestamp
244 disableContainerChildren("headlinesToolbar", false);
245 Form
.enable("main_toolbar_form");
247 // for piggybacked counters
249 if (tagsAreDisplayed()) {
250 query
= query
+ "&omode=lt";
252 query
= query
+ "&omode=flc";
255 if (!async_counters_work
) {
256 query
= query
+ "&csync=true";
261 var container
= document
.getElementById("headlinesInnerContainer");
263 /* if (container && page_offset == 0 && !isCdmMode()) {
264 new Effect.Fade(container, {duration: 1, to: 0.01,
265 queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
270 if (!is_cat
) unread_ctr
= get_feed_unread(feed
);
272 var cache_check
= false;
274 if (unread_ctr
!= -1 && !page_offset
&& !force_nocache
&& !subop
) {
276 var cache_prefix
= "";
284 cache_check
= cache_check_param(cache_prefix
+ feed
, unread_ctr
);
285 debug("headline cache check: " + cache_check
);
289 var f
= document
.getElementById("headlines-frame");
291 clean_feed_selections();
293 setActiveFeedId(feed
, is_cat
);
296 var feedr
= document
.getElementById("FEEDR-" + feed
);
297 if (feedr
&& !feedr
.className
.match("Selected")) {
298 feedr
.className
= feedr
.className
+ "Selected";
301 var feedr
= document
.getElementById("FCAT-" + feed_id
);
302 if (feedr
&& !feedr
.className
.match("Selected")) {
303 feedr
.className
= feedr
.className
+ "Selected";
307 f
.innerHTML
= cache_find_param(cache_prefix
+ feed
, unread_ctr
);
315 notify_progress("Loading, please wait...", true);
318 new Ajax
.Request(query
, {
319 onComplete: function(transport
) {
320 headlines_callback2(transport
, page_offset
);
325 exception_error("viewfeed", e
);
329 function toggleCollapseCat_af(effect
) {
330 //var caption = elem.id.replace("FCATLIST-", "");
334 var elem
= effect
.element
;
335 var cat
= elem
.id
.replace("FCATLIST-", "");
336 var cap
= document
.getElementById("FCAP-" + cat
);
338 if (Element
.visible(elem
)) {
339 cap
.innerHTML
= cap
.innerHTML
.replace("…", "");
341 if (cap
.innerHTML
.lastIndexOf("…") != cap
.innerHTML
.length
-3) {
342 cap
.innerHTML
= cap
.innerHTML
+ "…";
347 exception_error("toggleCollapseCat_af", e
);
351 function toggleCollapseCat(cat
) {
354 var cat_elem
= document
.getElementById("FCAT-" + cat
);
355 var cat_list
= document
.getElementById("FCATLIST-" + cat
).parentNode
;
356 var caption
= document
.getElementById("FCAP-" + cat
);
358 /* if (cat_list.className.match("invisible")) {
359 cat_list.className = "";
360 caption.innerHTML = caption.innerHTML.replace("...", "");
362 setCookie("ttrss_vf_uclps", "0");
365 cat_list.className = "invisible";
366 caption.innerHTML = caption.innerHTML + "...";
368 setCookie("ttrss_vf_uclps", "1");
374 if (Element
.visible("FCATLIST-" + cat
)) {
375 setCookie("ttrss_vf_uclps", "1");
377 setCookie("ttrss_vf_uclps", "0");
382 if (Element
.visible("FCATLIST-" + cat
)) {
383 setCookie("ttrss_vf_lclps", "1");
385 setCookie("ttrss_vf_lclps", "0");
390 if (Element
.visible("FCATLIST-" + cat
)) {
391 setCookie("ttrss_vf_vclps", "1");
393 setCookie("ttrss_vf_vclps", "0");
397 Effect
.toggle('FCATLIST-' + cat
, 'blind', { duration
: 0.5,
398 afterFinish
: toggleCollapseCat_af
});
400 new Ajax
.Request("backend.php?op=feeds&subop=collapse&cid=" +
404 exception_error("toggleCollapseCat", e
);
408 function feedlist_dragsorted(ctr
) {
410 var elem
= document
.getElementById("feedList");
412 var cats
= elem
.getElementsByTagName("LI");
413 var ordered_cats
= new Array();
415 for (var i
= 0; i
< cats
.length
; i
++) {
416 if (cats
[i
].id
&& cats
[i
].id
.match("FCAT-")) {
417 ordered_cats
.push(cats
[i
].id
.replace("FCAT-", ""));
421 if (ordered_cats
.length
> 0) {
423 var query
= "backend.php?op=feeds&subop=catsort&corder=" +
424 param_escape(ordered_cats
.toString());
428 new Ajax
.Request(query
);
432 exception_error("feedlist_dragsorted", e
);
436 function feedlist_init() {
438 // if (arguments.callee.done) return;
439 // arguments.callee.done = true;
441 loading_set_progress(90);
443 debug("in feedlist init");
445 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
446 document
.onkeydown
= hotkey_handler
;
447 document
.onmousemove
= mouse_move_handler
;
448 document
.onmousedown
= mouse_down_handler
;
449 document
.onmouseup
= mouse_up_handler
;
451 if (!offline_mode
) setTimeout("timeout()", 1);
453 if (typeof correctPNG
!= 'undefined') {
457 if (getActiveFeedId()) {
458 //debug("some feed is open on feedlist refresh, reloading");
459 //setTimeout("viewCurrentFeed()", 100);
461 if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) {
462 notify_silent_next();
463 setTimeout("viewfeed(-3)", 100);
469 if (getInitParam("theme") == "") {
470 setTimeout("hide_footer()", 5000);
473 init_collapsable_feedlist(getInitParam("theme"));
475 toggle_sortable_feedlist(isFeedlistSortable());
478 exception_error("feedlist/init", e
);
482 function hide_footer_af(effect
) {
484 var c
= document
.getElementById("content-frame");
487 c
.style
.bottom
= "0px";
489 var ioa
= document
.getElementById("inline_orig_article");
492 ioa
.height
= c
.offsetHeight
;
496 var h
= document
.getElementById("headlines-frame");
499 h
.style
.bottom
= "0px";
504 exception_error("hide_footer_af", e
);
508 function hide_footer() {
510 if (Element
.visible("footer")) {
511 new Effect
.Fade("footer", { afterFinish
: hide_footer_af
});
514 exception_error("hide_footer", e
);
519 function init_hidden_feedlist(theme) {
521 debug("init_hidden_feedlist");
523 if (theme != "" && theme != "compact") return;
525 var fl = document.getElementById("feeds-holder");
526 var fh = document.getElementById("headlines-frame");
527 var fc = document.getElementById("content-frame");
528 var ft = document.getElementById("toolbar");
529 var ff = document.getElementById("footer");
530 var fhdr = document.getElementById("header");
532 var fbtn = document.getElementById("toggle_feeds_btn");
534 if (fbtn) Element.show(fbtn);
536 fl.style.top = fh.offsetTop + "px";
537 fl.style.backgroundColor = "white"; //FIXME
541 fh.style.left = "0px";
542 ft.style.left = "0px";
543 if (fc) fc.style.left = "0px";
544 if (ff) ff.style.left = "0px";
546 if (theme == "compact") {
547 fhdr.style.left = "10px";
548 fl.style.top = (fh.offsetTop + 1) + "px";
552 exception_error("init_hidden_feedlist", e);
556 function init_collapsable_feedlist(theme
) {
558 debug("init_collapsable_feedlist");
560 if (theme
!= "" && theme
!= "compact" && theme
!= "graycube" &&
561 theme
!= "compat") return;
563 var fbtn
= document
.getElementById("collapse_feeds_btn");
565 if (fbtn
) Element
.show(fbtn
);
567 if (getCookie("ttrss_vf_fclps") == 1) {
572 exception_error("init_hidden_feedlist", e
);
577 function mouse_move_handler(e
) {
583 client_y
= window
.event
.clientY
;
584 client_x
= window
.event
.clientX
;
586 client_x
= e
.screenX
;
587 client_y
= e
.screenY
;
592 if (mouse_y
== 0) mouse_y
= client_y
;
593 if (mouse_x
== 0) mouse_x
= client_x
;
595 resize_headlines(mouse_x
- client_x
, mouse_y
- client_y
);
604 exception_error("mouse_move_handler", e
);
608 function enable_selection(b
) {
609 selection_disabled
= !b
;
612 function enable_resize(b
) {
616 function mouse_down_handler(e
) {
619 /* do not prevent right click */
620 if (e
.button
&& e
.button
== 2) return;
622 if (resize_enabled
) {
623 mouse_is_down
= true;
626 document
.onselectstart = function() { return false; };
630 if (selection_disabled
) {
631 document
.onselectstart = function() { return false; };
636 exception_error("mouse_move_handler", e
);
640 function mouse_up_handler(e
) {
642 mouse_is_down
= false;
644 if (!selection_disabled
) {
645 document
.onselectstart
= null;
646 var e
= document
.getElementById("headlineActionsBody");
647 if (e
) Element
.hide(e
);
651 exception_error("mouse_move_handler", e
);
655 function request_counters_real() {
659 if (offline_mode
) return;
661 debug("requesting counters...");
663 var query
= "backend.php?op=rpc&subop=getAllCounters";
665 if (tagsAreDisplayed()) {
666 query
= query
+ "&omode=tl";
668 query
= query
+ "&omode=flc";
671 new Ajax
.Request(query
, {
672 onComplete: function(transport
) {
674 all_counters_callback2(transport
, true);
676 exception_error("viewfeed/getcounters", e
);
681 exception_error("request_counters_real", e
);
686 function request_counters() {
690 if (getInitParam("bw_limit") == "1") return;
692 var date
= new Date();
693 var timestamp
= Math
.round(date
.getTime() / 1000);
695 // if (getInitParam("sync_counters") == "1" ||
696 // timestamp - counters_last_request > 10) {
698 if (timestamp
- counters_last_request
> 15) {
699 debug("scheduling request of counters...");
700 window
.setTimeout("request_counters_real()", 1000);
701 counters_last_request
= timestamp
;
703 debug("request_counters: rate limit reached: " + (timestamp
- counters_last_request
));
707 exception_error("request_counters", e
);