1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _tag_active_post_id
= false;
6 var _tag_active_feed_id
= false;
7 var _tag_active_cdm
= false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll
= false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view
= false;
15 var _cdm_wd_timeout
= false;
16 var _cdm_wd_vishist
= new Array();
18 var article_cache
= new Array();
20 function catchup_callback() {
21 if (xmlhttp_rpc
.readyState
== 4) {
23 debug("catchup_callback");
25 all_counters_callback2(xmlhttp_rpc
);
26 if (_catchup_callback_func
) {
27 setTimeout(_catchup_callback_func
, 10);
30 exception_error("catchup_callback", e
);
35 function catchup_callback2(transport
, callback
) {
37 debug("catchup_callback2 " + transport
+ ", " + callback
);
39 all_counters_callback2(transport
);
41 setTimeout(callback
, 10);
44 exception_error("catchup_callback2", e
);
48 function clean_feed_selections() {
50 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
52 for (var i
= 0; i
< feeds
.length
; i
++) {
53 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
54 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
58 exception_error("clean_feed_selections", e
);
62 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
65 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
67 clean_feed_selections();
69 setActiveFeedId(active_feed_id
);
71 if (is_cat
!= undefined) {
72 active_feed_is_cat
= is_cat
;
76 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
77 if (feedr
&& !feedr
.className
.match("Selected")) {
78 feedr
.className
= feedr
.className
+ "Selected";
82 var f
= document
.getElementById("headlines-frame");
84 if (feed_cur_page
== 0) {
85 debug("resetting headlines scrollTop");
90 if (transport
.responseXML
) {
91 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
92 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
93 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
94 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
96 var headlines_count
= headlines_count_obj
.getAttribute("value");
97 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
98 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
100 if (headlines_count
== 0) _infscroll_disable
= 1;
102 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
103 var articles
= transport
.responseXML
.getElementsByTagName("article");
104 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
106 if (feed_cur_page
== 0) {
108 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
110 var cache_prefix
= "";
118 cache_invalidate(cache_prefix
+ active_feed_id
);
120 if (!disable_cache
) {
121 cache_inject(cache_prefix
+ active_feed_id
,
122 headlines
.firstChild
.nodeValue
, headlines_unread
);
126 debug("headlines_callback: returned no data");
127 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
132 if (headlines_count
> 0) {
133 debug("adding some more headlines...");
135 var c
= document
.getElementById("headlinesList");
138 c
= document
.getElementById("headlinesInnerContainer");
141 var ids
= getSelectedArticleIds2();
143 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
145 debug("restore selected ids: " + ids
);
147 for (var i
= 0; i
< ids
.length
; i
++) {
148 markHeadline(ids
[i
]);
152 debug("no new headlines received");
155 debug("headlines_callback: returned no data");
156 notify_error("Error while trying to load more headlines");
162 for (var i
= 0; i
< articles
.length
; i
++) {
163 var a_id
= articles
[i
].getAttribute("id");
164 debug("found id: " + a_id
);
165 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
168 debug("no cached articles received");
172 debug("parsing piggybacked counters: " + counters
);
173 parse_counters(counters
, false);
175 debug("counters container not found in reply");
179 debug("parsing runtime info: " + runtime_info
[0]);
180 parse_runtime_info(runtime_info
[0]);
182 debug("counters container not found in reply");
186 debug("headlines_callback: returned no XML object");
187 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
190 if (typeof correctPNG
!= 'undefined') {
194 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
196 if (!document
.getElementById("headlinesList") &&
197 getInitParam("cdm_auto_catchup") == 1) {
198 debug("starting CDM watchdog");
199 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
200 _cdm_wd_vishist
= new Array();
202 debug("not in CDM mode or watchdog disabled");
205 if (_tag_cdm_scroll
) {
207 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
208 _tag_cdm_scroll
= false;
209 debug("resetting headlinesInner scrollTop");
214 _feed_cur_page
= feed_cur_page
;
215 _infscroll_request_sent
= 0;
219 exception_error("headlines_callback2", e
);
223 function render_article(article
) {
225 var f
= document
.getElementById("content-frame");
230 f
.innerHTML
= article
;
233 exception_error("render_article", e
);
237 function showArticleInHeadlines(id
) {
241 cleanSelected("headlinesList");
243 var crow
= document
.getElementById("RROW-" + id
);
247 var article_is_unread
= crow
.className
.match("Unread");
249 crow
.className
= crow
.className
.replace("Unread", "");
251 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
254 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
256 var cache_prefix
= "";
258 if (activeFeedIsCat()) {
264 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
265 upd_img_pic
.src
= "images/blank_icon.gif";
267 cache_invalidate(cache_prefix
+ getActiveFeedId());
269 cache_inject(cache_prefix
+ getActiveFeedId(),
270 document
.getElementById("headlines-frame").innerHTML
,
271 get_feed_unread(getActiveFeedId()));
273 } else if (article_is_unread
) {
275 cache_invalidate(cache_prefix
+ getActiveFeedId());
277 cache_inject(cache_prefix
+ getActiveFeedId(),
278 document
.getElementById("headlines-frame").innerHTML
,
279 get_feed_unread(getActiveFeedId())-1);
284 exception_error("showArticleInHeadlines", e
);
288 function article_callback2(transport
, id
, feed_id
) {
290 debug("article_callback2 " + id
);
292 if (transport
.responseXML
) {
294 active_real_feed_id
= feed_id
;
297 showArticleInHeadlines(id
);
299 var reply
= transport
.responseXML
.firstChild
.firstChild
;
301 var articles
= transport
.responseXML
.getElementsByTagName("article");
303 for (var i
= 0; i
< articles
.length
; i
++) {
304 var a_id
= articles
[i
].getAttribute("id");
306 debug("found id: " + a_id
);
308 if (a_id
== active_post_id
) {
309 debug("active article, rendering...");
310 render_article(articles
[i
].firstChild
.nodeValue
);
313 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
317 debug("article_callback: returned no XML object");
318 var f
= document
.getElementById("content-frame");
319 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
322 var date
= new Date();
323 last_article_view
= date
.getTime() / 1000;
325 if (typeof correctPNG
!= 'undefined') {
329 if (_reload_feedlist_after_view
) {
330 setTimeout('updateFeedList(false, false)', 50);
331 _reload_feedlist_after_view
= false;
333 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
336 debug("parsing piggybacked counters: " + counters
);
337 parse_counters(counters
, false);
339 debug("counters container not found in reply");
345 exception_error("article_callback2", e
);
349 function view(id
, feed_id
, skip_history
) {
352 debug("loading article: " + id
+ "/" + feed_id
);
354 var cached_article
= cache_find(id
);
356 debug("cache check result: " + (cached_article
!= false));
360 //setActiveFeedId(feed_id);
362 var query
= "backend.php?op=view&id=" + param_escape(id
) +
363 "&feed=" + param_escape(feed_id
);
365 var date
= new Date();
367 var neighbor_ids
= getRelativePostIds(active_post_id
);
369 /* only request uncached articles */
371 var cids_to_request
= Array();
373 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
374 if (!cache_check(neighbor_ids
[i
])) {
375 cids_to_request
.push(neighbor_ids
[i
]);
379 debug("additional ids: " + cids_to_request
.toString());
381 /* additional info for piggyback counters */
383 if (tagsAreDisplayed()) {
384 query
= query
+ "&omode=lt";
386 query
= query
+ "&omode=flc";
389 var date
= new Date();
390 var timestamp
= Math
.round(date
.getTime() / 1000);
391 query
= query
+ "&ts=" + timestamp
;
393 query
= query
+ "&cids=" + cids_to_request
.toString();
395 var crow
= document
.getElementById("RROW-" + id
);
396 var article_is_unread
= crow
.className
.match("Unread");
398 showArticleInHeadlines(id
);
400 if (!cached_article
) {
402 notify_progress("Loading, please wait...");
404 } else if (cached_article
&& article_is_unread
) {
406 query
= query
+ "&mode=prefetch";
408 render_article(cached_article
);
410 } else if (cached_article
) {
412 query
= query
+ "&mode=prefetch_old";
413 render_article(cached_article
);
418 new Ajax
.Request(query
, {
419 onComplete: function(transport
) {
420 article_callback2(transport
, id
, feed_id
);
424 exception_error("view", e
);
429 return toggleMark(id
);
433 return togglePub(id
);
436 function tMark_afh_off(effect
) {
438 var elem
= effect
.effects
[0].element
;
440 debug("tMark_afh_off : " + elem
.id
);
443 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
444 elem
.alt
= __("Star article");
449 exception_error("tMark_afh_off", e
);
453 function tPub_afh_off(effect
) {
455 var elem
= effect
.effects
[0].element
;
457 debug("tPub_afh_off : " + elem
.id
);
460 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
461 elem
.alt
= __("Publish article");
466 exception_error("tPub_afh_off", e
);
470 function toggleMark(id
, client_only
, no_effects
) {
474 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
476 query
= query
+ "&afid=" + getActiveFeedId();
478 if (tagsAreDisplayed()) {
479 query
= query
+ "&omode=tl";
481 query
= query
+ "&omode=flc";
484 var mark_img
= document
.getElementById("FMPIC-" + id
);
485 var vfeedu
= document
.getElementById("FEEDU--1");
486 var crow
= document
.getElementById("RROW-" + id
);
488 if (mark_img
.src
.match("mark_unset")) {
489 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
490 mark_img
.alt
= __("Unstar article");
491 query
= query
+ "&mark=1";
493 /* if (vfeedu && crow.className.match("Unread")) {
494 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
498 //mark_img.src = "images/mark_unset.png";
499 mark_img
.alt
= __("Please wait...");
500 query
= query
+ "&mark=0";
502 /* if (vfeedu && crow.className.match("Unread")) {
503 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
506 if (document
.getElementById("headlinesList") && !no_effects
) {
507 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
509 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
510 mark_img
.alt
= __("Star article");
514 /* var vfeedctr = document.getElementById("FEEDCTR--1");
515 var vfeedr = document.getElementById("FEEDR--1");
517 if (vfeedu && vfeedctr) {
518 if ((+vfeedu.innerHTML) > 0) {
519 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
520 vfeedr.className = vfeedr.className + "Unread";
521 vfeedctr.className = "odd";
524 vfeedctr.className = "invisible";
525 vfeedr.className = vfeedr.className.replace("Unread", "");
529 debug("toggle starred for aid " + id);
531 //new Ajax.Request(query); */
536 new Ajax
.Request(query
, {
537 onComplete: function(transport
) {
538 all_counters_callback2(transport
);
544 exception_error("toggleMark", e
);
548 function togglePub(id
, client_only
, no_effects
) {
552 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
554 query
= query
+ "&afid=" + getActiveFeedId();
556 if (tagsAreDisplayed()) {
557 query
= query
+ "&omode=tl";
559 query
= query
+ "&omode=flc";
562 var mark_img
= document
.getElementById("FPPIC-" + id
);
563 var vfeedu
= document
.getElementById("FEEDU--2");
564 var crow
= document
.getElementById("RROW-" + id
);
566 if (mark_img
.src
.match("pub_unset")) {
567 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
568 mark_img
.alt
= __("Unpublish article");
569 query
= query
+ "&pub=1";
571 /* if (vfeedu && crow.className.match("Unread")) {
572 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
576 //mark_img.src = "images/pub_unset.png";
577 mark_img
.alt
= __("Please wait...");
578 query
= query
+ "&pub=0";
580 /* if (vfeedu && crow.className.match("Unread")) {
581 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
584 if (document
.getElementById("headlinesList") && !no_effects
) {
585 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
587 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
588 mark_img
.alt
= __("Publish article");
592 /* var vfeedctr = document.getElementById("FEEDCTR--2");
593 var vfeedr = document.getElementById("FEEDR--2");
595 if (vfeedu && vfeedctr) {
596 if ((+vfeedu.innerHTML) > 0) {
597 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
598 vfeedr.className = vfeedr.className + "Unread";
599 vfeedctr.className = "odd";
602 vfeedctr.className = "invisible";
603 vfeedr.className = vfeedr.className.replace("Unread", "");
607 debug("toggle published for aid " + id);
609 new Ajax.Request(query); */
612 new Ajax
.Request(query
, {
613 onComplete: function(transport
) {
614 all_counters_callback2(transport
);
620 exception_error("togglePub", e
);
624 function correctHeadlinesOffset(id
) {
628 var hlist
= document
.getElementById("headlinesList");
629 var container
= document
.getElementById("headlinesInnerContainer");
630 var row
= document
.getElementById("RROW-" + id
);
632 var viewport
= container
.offsetHeight
;
634 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
635 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
637 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
638 debug("Vport: " + viewport
);
640 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
641 container
.scrollTop
= row
.offsetTop
;
642 } else if (rel_offset_bottom
> viewport
) {
644 /* doesn't properly work with Opera in some cases because
645 Opera fucks up element scrolling */
647 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
651 exception_error("correctHeadlinesOffset", e
);
656 function moveToPost(mode
) {
658 // check for combined mode
659 if (!document
.getElementById("headlinesList"))
662 var rows
= getVisibleHeadlineIds();
667 if (!document
.getElementById('RROW-' + active_post_id
)) {
668 active_post_id
= false;
671 if (active_post_id
== false) {
672 next_id
= getFirstVisibleHeadlineId();
673 prev_id
= getLastVisibleHeadlineId();
675 for (var i
= 0; i
< rows
.length
; i
++) {
676 if (rows
[i
] == active_post_id
) {
683 if (mode
== "next") {
685 correctHeadlinesOffset(next_id
);
686 view(next_id
, getActiveFeedId());
690 if (mode
== "prev") {
692 correctHeadlinesOffset(prev_id
);
693 view(prev_id
, getActiveFeedId());
698 function toggleUnread(id
, cmode
) {
701 var row
= document
.getElementById("RROW-" + id
);
703 var nc
= row
.className
;
704 nc
= nc
.replace("Unread", "");
705 nc
= nc
.replace("Selected", "");
707 if (cmode
== undefined || cmode
== 2) {
708 if (row
.className
.match("Unread")) {
711 row
.className
= nc
+ "Unread";
713 } else if (cmode
== 0) {
715 } else if (cmode
== 1) {
716 row
.className
= nc
+ "Unread";
719 if (cmode
== undefined) cmode
= 2;
721 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
722 param_escape(id
) + "&cmode=" + param_escape(cmode
);
724 // notify_progress("Loading, please wait...");
726 new Ajax
.Request(query
, {
727 onComplete: function(transport
) {
728 all_counters_callback2(transport
);
735 exception_error("toggleUnread", e
);
739 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
744 rows
= cdmGetSelectedArticles();
746 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
749 if (rows
.length
== 0 && !no_error
) {
750 alert(__("No articles are selected."));
754 for (i
= 0; i
< rows
.length
; i
++) {
755 var row
= document
.getElementById("RROW-" + rows
[i
]);
757 var nc
= row
.className
;
758 nc
= nc
.replace("Unread", "");
759 nc
= nc
.replace("Selected", "");
761 if (set_state
== undefined) {
762 if (row
.className
.match("Unread")) {
763 row
.className
= nc
+ "Selected";
765 row
.className
= nc
+ "UnreadSelected";
769 if (set_state
== false) {
770 row
.className
= nc
+ "Selected";
773 if (set_state
== true) {
774 row
.className
= nc
+ "UnreadSelected";
779 if (rows
.length
> 0) {
783 if (set_state
== undefined) {
785 } else if (set_state
== true) {
787 } else if (set_state
== false) {
791 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
792 param_escape(rows
.toString()) + "&cmode=" + cmode
;
794 notify_progress("Loading, please wait...");
796 new Ajax
.Request(query
, {
797 onComplete: function(transport
) {
798 catchup_callback2(transport
, callback_func
);
804 exception_error("selectionToggleUnread", e
);
808 function selectionToggleMarked(cdm_mode
) {
814 rows
= cdmGetSelectedArticles();
816 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
819 if (rows
.length
== 0) {
820 alert(__("No articles are selected."));
824 for (i
= 0; i
< rows
.length
; i
++) {
825 toggleMark(rows
[i
], true, true);
828 if (rows
.length
> 0) {
830 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
831 param_escape(rows
.toString()) + "&cmode=2";
833 query
= query
+ "&afid=" + getActiveFeedId();
835 /* if (tagsAreDisplayed()) {
836 query = query + "&omode=tl";
838 query = query + "&omode=flc";
841 query
= query
+ "&omode=lc";
843 new Ajax
.Request(query
, {
844 onComplete: function(transport
) {
845 all_counters_callback2(transport
);
851 exception_error("selectionToggleMarked", e
);
855 function selectionTogglePublished(cdm_mode
) {
861 rows
= cdmGetSelectedArticles();
863 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
866 if (rows
.length
== 0) {
867 alert(__("No articles are selected."));
871 for (i
= 0; i
< rows
.length
; i
++) {
872 togglePub(rows
[i
], true, true);
875 if (rows
.length
> 0) {
877 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
878 param_escape(rows
.toString()) + "&cmode=2";
880 query
= query
+ "&afid=" + getActiveFeedId();
882 /* if (tagsAreDisplayed()) {
883 query = query + "&omode=tl";
885 query = query + "&omode=flc";
888 query
= query
+ "&omode=lc";
890 new Ajax
.Request(query
, {
891 onComplete: function(transport
) {
892 all_counters_callback2(transport
);
898 exception_error("selectionToggleMarked", e
);
902 function cdmGetSelectedArticles() {
903 var sel_articles
= new Array();
904 var container
= document
.getElementById("headlinesInnerContainer");
906 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
907 var child
= container
.childNodes
[i
];
909 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
910 var c_id
= child
.id
.replace("RROW-", "");
911 sel_articles
.push(c_id
);
918 function cdmGetVisibleArticles() {
919 var sel_articles
= new Array();
920 var container
= document
.getElementById("headlinesInnerContainer");
922 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
923 var child
= container
.childNodes
[i
];
925 if (child
.id
.match("RROW-")) {
926 var c_id
= child
.id
.replace("RROW-", "");
927 sel_articles
.push(c_id
);
934 function cdmGetUnreadArticles() {
935 var sel_articles
= new Array();
936 var container
= document
.getElementById("headlinesInnerContainer");
938 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
939 var child
= container
.childNodes
[i
];
941 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
942 var c_id
= child
.id
.replace("RROW-", "");
943 sel_articles
.push(c_id
);
951 // mode = all,none,unread
952 function cdmSelectArticles(mode
) {
953 var container
= document
.getElementById("headlinesInnerContainer");
955 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
956 var child
= container
.childNodes
[i
];
958 if (child
.id
.match("RROW-")) {
959 var aid
= child
.id
.replace("RROW-", "");
961 var cb
= document
.getElementById("RCHK-" + aid
);
964 if (!child
.className
.match("Selected")) {
965 child
.className
= child
.className
+ "Selected";
968 } else if (mode
== "unread") {
969 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
970 child
.className
= child
.className
+ "Selected";
974 child
.className
= child
.className
.replace("Selected", "");
981 function catchupPage() {
983 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
985 var str
= __("Mark all visible articles in %s as read?");
987 str
= str
.replace("%s", fn
);
989 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
993 if (document
.getElementById("headlinesList")) {
994 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
995 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
996 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
998 cdmSelectArticles('all');
999 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1000 cdmSelectArticles('none');
1004 function catchupSelection() {
1010 if (document
.getElementById("headlinesList")) {
1011 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1013 rows
= cdmGetSelectedArticles();
1016 if (rows
.length
== 0) {
1017 alert(__("No articles are selected."));
1022 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1024 var str
= __("Mark %d selected articles in %s as read?");
1026 str
= str
.replace("%d", rows
.length
);
1027 str
= str
.replace("%s", fn
);
1029 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1033 if (document
.getElementById("headlinesList")) {
1034 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1035 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1037 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1038 // cdmSelectArticles('none');
1042 exception_error("catchupSelection", e
);
1047 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1049 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1050 printLockingError();
1053 var title
= prompt(__("Please enter label title:"), "");
1057 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1058 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1059 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1060 "&title=" + param_escape(title
);
1062 debug("LFS: " + query
);
1064 new Ajax
.Request(query
, {
1065 onComplete: function(transport
) {
1066 dlg_frefresh_callback(transport
);
1071 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1072 _tag_active_post_id
= id
;
1073 _tag_active_feed_id
= feed_id
;
1074 _tag_active_cdm
= cdm_enabled
;
1076 cache_invalidate(id
);
1079 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1081 displayDlg('editArticleTags', id
);
1085 function tag_saved_callback(transport
) {
1087 debug("in tag_saved_callback");
1092 if (tagsAreDisplayed()) {
1093 _reload_feedlist_after_view
= true;
1096 if (!_tag_active_cdm
) {
1097 if (active_post_id
== _tag_active_post_id
) {
1098 debug("reloading current article");
1099 view(_tag_active_post_id
, _tag_active_feed_id
);
1102 debug("reloading current feed");
1107 exception_error("catchup_callback", e
);
1111 function editTagsSave() {
1113 notify_progress("Saving article tags...");
1115 var form
= document
.forms
["tag_edit_form"];
1117 var query
= Form
.serialize("tag_edit_form");
1119 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1123 new Ajax
.Request(query
, {
1124 onComplete: function(transport
) {
1125 tag_saved_callback(transport
);
1130 function editTagsInsert() {
1133 var form
= document
.forms
["tag_edit_form"];
1135 var found_tags
= form
.found_tags
;
1136 var tags_str
= form
.tags_str
;
1138 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1140 if (tags_str
.value
.length
> 0 &&
1141 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1143 tags_str
.value
= tags_str
.value
+ ", ";
1146 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1148 found_tags
.selectedIndex
= 0;
1151 exception_error(e
, "editTagsInsert");
1155 function cdmWatchdog() {
1159 var ctr
= document
.getElementById("headlinesInnerContainer");
1163 var ids
= new Array();
1165 var e
= ctr
.firstChild
;
1168 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1169 e
.id
.match("RROW-")) {
1171 // article fits in viewport OR article is longer than viewport and
1172 // its bottom is visible
1174 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1175 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1177 // debug(e.id + " is visible " + e.offsetTop + "." +
1178 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1179 // (ctr.scrollTop + ctr.offsetHeight));
1181 ids
.push(e
.id
.replace("RROW-", ""));
1183 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1184 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1185 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1187 ids
.push(e
.id
.replace("RROW-", ""));
1191 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1193 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1194 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1196 ids.push(e.id.replace("RROW-", ""));
1205 debug("cdmWatchdog, ids= " + ids
.toString());
1207 if (ids
.length
> 0) {
1209 for (var i
= 0; i
< ids
.length
; i
++) {
1210 var e
= document
.getElementById("RROW-" + ids
[i
]);
1212 e
.className
= e
.className
.replace("Unread", "");
1216 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1217 param_escape(ids
.toString()) + "&cmode=0";
1219 new Ajax
.Request(query
, {
1220 onComplete: function(transport
) {
1221 all_counters_callback2(transport
);
1226 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1229 exception_error(e
, "cdmWatchdog");
1235 function cache_inject(id
, article
, param
) {
1236 if (!cache_check_param(id
, param
)) {
1237 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1239 var cache_obj
= new Array();
1241 cache_obj
["id"] = id
;
1242 cache_obj
["data"] = article
;
1243 cache_obj
["param"] = param
;
1245 article_cache
.push(cache_obj
);
1248 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1252 function cache_find(id
) {
1253 for (var i
= 0; i
< article_cache
.length
; i
++) {
1254 if (article_cache
[i
]["id"] == id
) {
1255 return article_cache
[i
]["data"];
1261 function cache_find_param(id
, param
) {
1262 for (var i
= 0; i
< article_cache
.length
; i
++) {
1263 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1264 return article_cache
[i
]["data"];
1270 function cache_check(id
) {
1271 for (var i
= 0; i
< article_cache
.length
; i
++) {
1272 if (article_cache
[i
]["id"] == id
) {
1279 function cache_check_param(id
, param
) {
1280 for (var i
= 0; i
< article_cache
.length
; i
++) {
1282 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1283 // article_cache[i]["param"] + " vs " + id + ":" + param);
1285 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1292 function cache_expire() {
1293 while (article_cache
.length
> 20) {
1294 article_cache
.shift();
1298 function cache_invalidate(id
) {
1303 while (i
< article_cache
.length
) {
1304 if (article_cache
[i
]["id"] == id
) {
1305 debug("cache_invalidate: removed id " + id
);
1306 article_cache
.splice(i
, 1);
1311 debug("cache_invalidate: id not found: " + id
);
1314 exception_error("cache_invalidate", e
);
1318 function getActiveArticleId() {
1319 return active_post_id
;
1322 function cdmMouseIn(elem
) {
1324 if (elem
.id
&& elem
.id
.match("RROW-")) {
1325 var id
= elem
.id
.replace("RROW-", "");
1326 active_post_id
= id
;
1329 exception_error("cdmMouseIn", e
);
1334 function cdmMouseOut(elem
) {
1335 active_post_id
= false;
1338 function headlines_scroll_handler() {
1341 var e
= document
.getElementById("headlinesInnerContainer");
1343 // don't do infinite scrolling when Limit == All
1345 var toolbar_form
= document
.forms
["main_toolbar_form"];
1347 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1348 if (limit
.value
!= 0) {
1349 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1350 if (!_infscroll_disable
) {
1351 debug("more cowbell!");
1358 exception_error("headlines_scroll_handler", e
);
1362 function catchupRelativeToArticle(below
) {
1366 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1367 printLockingError();
1370 if (!getActiveArticleId()) {
1371 alert(__("No article is selected."));
1377 if (document
.getElementById("headlinesList")) {
1378 visible_ids
= getVisibleHeadlineIds();
1380 visible_ids
= cdmGetVisibleArticles();
1383 var ids_to_mark
= new Array();
1386 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1387 if (visible_ids
[i
] != getActiveArticleId()) {
1388 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1390 if (e
&& e
.className
.match("Unread")) {
1391 ids_to_mark
.push(visible_ids
[i
]);
1398 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1399 if (visible_ids
[i
] != getActiveArticleId()) {
1400 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1402 if (e
&& e
.className
.match("Unread")) {
1403 ids_to_mark
.push(visible_ids
[i
]);
1411 if (ids_to_mark
.length
== 0) {
1412 alert(__("No articles found to mark"));
1414 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1418 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1419 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1420 e
.className
= e
.className
.replace("Unread", "");
1423 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1424 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1426 new Ajax
.Request(query
, {
1427 onComplete: function(transport
) {
1428 catchup_callback2(transport
);
1435 exception_error("catchupRelativeToArticle", e
);
1439 function cdmExpandArticle(a_id
) {
1441 var id
= 'CICD-' + a_id
;
1443 Effect
.Appear(id
, {duration
: 0.5,
1444 beforeStart: function(effect
) {
1445 var h_id
= 'CICH-' + a_id
;
1446 var h_elem
= document
.getElementById(h_id
);
1447 if (h_elem
) { h_elem
.style
.display
= "none"; }
1449 toggleUnread(a_id
, 0);
1454 exception_error("appearBlockElementF", e
);