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 var vgroup_last_feed
= false;
21 var post_under_pointer
= false;
23 var last_requested_article
= false;
24 var read_headlines_visible
= true;
26 function catchup_callback() {
27 if (xmlhttp_rpc
.readyState
== 4) {
29 debug("catchup_callback");
31 all_counters_callback2(xmlhttp_rpc
);
32 if (_catchup_callback_func
) {
33 setTimeout(_catchup_callback_func
, 10);
36 exception_error("catchup_callback", e
);
41 function catchup_callback2(transport
, callback
) {
43 debug("catchup_callback2 " + transport
+ ", " + callback
);
45 all_counters_callback2(transport
);
47 setTimeout(callback
, 10);
50 exception_error("catchup_callback2", e
);
54 function clean_feed_selections() {
56 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
58 for (var i
= 0; i
< feeds
.length
; i
++) {
59 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
60 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
64 exception_error("clean_feed_selections", e
);
68 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
71 loading_set_progress(100);
73 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
75 clean_feed_selections();
77 setActiveFeedId(active_feed_id
);
79 if (is_cat
!= undefined) {
80 active_feed_is_cat
= is_cat
;
84 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
85 if (feedr
&& !feedr
.className
.match("Selected")) {
86 feedr
.className
= feedr
.className
+ "Selected";
90 var f
= document
.getElementById("headlines-frame");
92 if (feed_cur_page
== 0) {
93 debug("resetting headlines scrollTop");
98 if (transport
.responseXML
) {
99 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
100 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
101 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
102 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
104 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
106 var headlines_count
= headlines_count_obj
.getAttribute("value");
107 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
108 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
110 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
112 if (headlines_count
== 0) {
113 _infscroll_disable
= 1;
115 _infscroll_disable
= 0;
118 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
119 var articles
= transport
.responseXML
.getElementsByTagName("article");
120 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
122 if (feed_cur_page
== 0) {
124 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
126 var cache_prefix
= "";
134 cache_invalidate(cache_prefix
+ active_feed_id
);
136 if (!disable_cache
) {
137 cache_inject(cache_prefix
+ active_feed_id
,
138 headlines
.firstChild
.nodeValue
, headlines_unread
);
142 debug("headlines_callback: returned no data");
143 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
148 if (headlines_count
> 0) {
149 debug("adding some more headlines...");
151 var c
= document
.getElementById("headlinesList");
154 c
= document
.getElementById("headlinesInnerContainer");
157 var ids
= getSelectedArticleIds2();
159 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
161 debug("restore selected ids: " + ids
);
163 for (var i
= 0; i
< ids
.length
; i
++) {
164 markHeadline(ids
[i
]);
170 debug("no new headlines received");
173 debug("headlines_callback: returned no data");
174 notify_error("Error while trying to load more headlines");
180 for (var i
= 0; i
< articles
.length
; i
++) {
181 var a_id
= articles
[i
].getAttribute("id");
182 debug("found id: " + a_id
);
183 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
186 debug("no cached articles received");
190 debug("parsing piggybacked counters: " + counters
);
191 parse_counters(counters
, false);
193 debug("counters container not found in reply, requesting...");
198 debug("parsing runtime info: " + runtime_info
[0]);
199 parse_runtime_info(runtime_info
[0]);
201 debug("counters container not found in reply");
205 debug("headlines_callback: returned no XML object");
206 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
209 if (typeof correctPNG
!= 'undefined') {
213 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
215 if (!document
.getElementById("headlinesList") &&
216 getInitParam("cdm_auto_catchup") == 1) {
217 debug("starting CDM watchdog");
218 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
219 _cdm_wd_vishist
= new Array();
221 debug("not in CDM mode or watchdog disabled");
224 if (_tag_cdm_scroll
) {
226 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
227 _tag_cdm_scroll
= false;
228 debug("resetting headlinesInner scrollTop");
233 _feed_cur_page
= feed_cur_page
;
234 _infscroll_request_sent
= 0;
241 exception_error("headlines_callback2", e
);
245 function render_article(article
) {
247 var f
= document
.getElementById("content-frame");
252 f
.innerHTML
= article
;
255 exception_error("render_article", e
);
259 function showArticleInHeadlines(id
) {
263 cleanSelected("headlinesList");
265 var crow
= document
.getElementById("RROW-" + id
);
269 var article_is_unread
= crow
.className
.match("Unread");
271 crow
.className
= crow
.className
.replace("Unread", "");
273 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
275 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
277 var cache_prefix
= "";
279 if (activeFeedIsCat()) {
285 var view_mode
= false;
288 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
289 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
291 exception_error("showArticleInHeadlines/viewmode", e
, true);
294 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
295 upd_img_pic
.src
= "images/blank_icon.gif";
297 cache_invalidate(cache_prefix
+ getActiveFeedId());
299 cache_inject(cache_prefix
+ getActiveFeedId(),
300 document
.getElementById("headlines-frame").innerHTML
,
301 get_feed_unread(getActiveFeedId()));
303 } else if (article_is_unread
&& view_mode
== "all_articles") {
305 cache_invalidate(cache_prefix
+ getActiveFeedId());
307 cache_inject(cache_prefix
+ getActiveFeedId(),
308 document
.getElementById("headlines-frame").innerHTML
,
309 get_feed_unread(getActiveFeedId())-1);
311 } else if (article_is_unread
) {
312 cache_invalidate(cache_prefix
+ getActiveFeedId());
318 exception_error("showArticleInHeadlines", e
);
322 function article_callback2(transport
, id
, feed_id
) {
324 debug("article_callback2 " + id
);
326 if (transport
.responseXML
) {
328 debug("looking for articles to cache...");
330 var articles
= transport
.responseXML
.getElementsByTagName("article");
332 for (var i
= 0; i
< articles
.length
; i
++) {
333 var a_id
= articles
[i
].getAttribute("id");
335 debug("found id: " + a_id
);
337 if (a_id
== active_post_id
) {
338 debug("active article, rendering...");
339 render_article(articles
[i
].firstChild
.nodeValue
);
342 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
345 if (id
!= last_requested_article
) {
346 debug("requested article id is out of sequence, aborting");
350 active_real_feed_id
= feed_id
;
353 showArticleInHeadlines(id
);
355 var reply
= transport
.responseXML
.firstChild
.firstChild
;
358 debug("article_callback: returned no XML object");
359 var f
= document
.getElementById("content-frame");
360 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
363 var date
= new Date();
364 last_article_view
= date
.getTime() / 1000;
366 if (typeof correctPNG
!= 'undefined') {
370 if (_reload_feedlist_after_view
) {
371 setTimeout('updateFeedList(false, false)', 50);
372 _reload_feedlist_after_view
= false;
374 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
377 debug("parsing piggybacked counters: " + counters
);
378 parse_counters(counters
, false);
380 debug("counters container not found in reply, requesting...");
387 exception_error("article_callback2", e
);
391 function view(id
, feed_id
, skip_history
) {
394 debug("loading article: " + id
+ "/" + feed_id
);
396 var cached_article
= cache_find(id
);
398 debug("cache check result: " + (cached_article
!= false));
402 //setActiveFeedId(feed_id);
404 var query
= "backend.php?op=view&id=" + param_escape(id
) +
405 "&feed=" + param_escape(feed_id
);
407 var date
= new Date();
409 var neighbor_ids
= getRelativePostIds(active_post_id
);
411 /* only request uncached articles */
413 var cids_to_request
= Array();
415 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
416 if (!cache_check(neighbor_ids
[i
])) {
417 cids_to_request
.push(neighbor_ids
[i
]);
421 debug("additional ids: " + cids_to_request
.toString());
423 /* additional info for piggyback counters */
425 if (tagsAreDisplayed()) {
426 query
= query
+ "&omode=lt";
428 query
= query
+ "&omode=flc";
431 var date
= new Date();
432 var timestamp
= Math
.round(date
.getTime() / 1000);
433 query
= query
+ "&ts=" + timestamp
;
435 query
= query
+ "&cids=" + cids_to_request
.toString();
437 var crow
= document
.getElementById("RROW-" + id
);
438 var article_is_unread
= crow
.className
.match("Unread");
440 if (!async_counters_work
) {
441 query
= query
+ "&csync=true";
444 showArticleInHeadlines(id
);
446 if (!cached_article
) {
448 notify_progress("Loading, please wait...", true);
450 } else if (cached_article
&& article_is_unread
) {
452 query
= query
+ "&mode=prefetch";
454 render_article(cached_article
);
456 } else if (cached_article
) {
458 query
= query
+ "&mode=prefetch_old";
459 render_article(cached_article
);
465 last_requested_article
= id
;
467 new Ajax
.Request(query
, {
468 onComplete: function(transport
) {
469 article_callback2(transport
, id
, feed_id
);
475 exception_error("view", e
);
480 return toggleMark(id
);
484 return togglePub(id
);
487 function tMark_afh_off(effect
) {
489 var elem
= effect
.effects
[0].element
;
491 debug("tMark_afh_off : " + elem
.id
);
494 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
495 elem
.alt
= __("Star article");
500 exception_error("tMark_afh_off", e
);
504 function tPub_afh_off(effect
) {
506 var elem
= effect
.effects
[0].element
;
508 debug("tPub_afh_off : " + elem
.id
);
511 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
512 elem
.alt
= __("Publish article");
517 exception_error("tPub_afh_off", e
);
521 function toggleMark(id
, client_only
, no_effects
) {
525 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
527 query
= query
+ "&afid=" + getActiveFeedId();
529 if (tagsAreDisplayed()) {
530 query
= query
+ "&omode=tl";
532 query
= query
+ "&omode=flc";
535 var mark_img
= document
.getElementById("FMPIC-" + id
);
536 var vfeedu
= document
.getElementById("FEEDU--1");
537 var crow
= document
.getElementById("RROW-" + id
);
539 if (mark_img
.src
.match("mark_unset")) {
540 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
541 mark_img
.alt
= __("Unstar article");
542 query
= query
+ "&mark=1";
545 //mark_img.src = "images/mark_unset.png";
546 mark_img
.alt
= __("Please wait...");
547 query
= query
+ "&mark=0";
549 if (document
.getElementById("headlinesList") && !no_effects
) {
550 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
552 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
553 mark_img
.alt
= __("Star article");
560 new Ajax
.Request(query
, {
561 onComplete: function(transport
) {
562 all_counters_callback2(transport
);
568 exception_error("toggleMark", e
);
572 function togglePub(id
, client_only
, no_effects
) {
576 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
578 query
= query
+ "&afid=" + getActiveFeedId();
580 if (tagsAreDisplayed()) {
581 query
= query
+ "&omode=tl";
583 query
= query
+ "&omode=flc";
586 var mark_img
= document
.getElementById("FPPIC-" + id
);
587 var vfeedu
= document
.getElementById("FEEDU--2");
588 var crow
= document
.getElementById("RROW-" + id
);
590 if (mark_img
.src
.match("pub_unset")) {
591 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
592 mark_img
.alt
= __("Unpublish article");
593 query
= query
+ "&pub=1";
597 //mark_img.src = "images/pub_unset.png";
598 mark_img
.alt
= __("Please wait...");
599 query
= query
+ "&pub=0";
601 if (document
.getElementById("headlinesList") && !no_effects
) {
602 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
604 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
605 mark_img
.alt
= __("Publish article");
610 new Ajax
.Request(query
, {
611 onComplete: function(transport
) {
612 all_counters_callback2(transport
);
618 exception_error("togglePub", e
);
622 function correctHeadlinesOffset(id
) {
626 var hlist
= document
.getElementById("headlinesList");
627 var container
= document
.getElementById("headlinesInnerContainer");
628 var row
= document
.getElementById("RROW-" + id
);
630 var viewport
= container
.offsetHeight
;
632 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
633 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
635 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
636 debug("Vport: " + viewport
);
638 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
639 container
.scrollTop
= row
.offsetTop
;
640 } else if (rel_offset_bottom
> viewport
) {
642 /* doesn't properly work with Opera in some cases because
643 Opera fucks up element scrolling */
645 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
649 exception_error("correctHeadlinesOffset", e
);
654 function moveToPost(mode
) {
661 rows
= cdmGetVisibleArticles();
663 rows
= getVisibleHeadlineIds();
669 if (!document
.getElementById('RROW-' + active_post_id
)) {
670 active_post_id
= false;
673 if (active_post_id
== false) {
674 next_id
= getFirstVisibleHeadlineId();
675 prev_id
= getLastVisibleHeadlineId();
677 for (var i
= 0; i
< rows
.length
; i
++) {
678 if (rows
[i
] == active_post_id
) {
685 if (mode
== "next") {
689 if (!cdmArticleIsActuallyVisible(next_id
)) {
690 cdmScrollToArticleId(next_id
);
692 cdmSelectArticles("none");
693 toggleUnread(next_id
, 0, true);
694 toggleSelected(next_id
);
697 correctHeadlinesOffset(next_id
);
698 view(next_id
, getActiveFeedId());
703 if (mode
== "prev") {
706 cdmScrollToArticleId(prev_id
);
707 cdmSelectArticles("none");
708 toggleUnread(prev_id
, 0, true);
709 toggleSelected(prev_id
);
711 correctHeadlinesOffset(prev_id
);
712 view(prev_id
, getActiveFeedId());
718 exception_error("moveToPost", e
);
722 function toggleSelected(id
) {
725 var cb
= document
.getElementById("RCHK-" + id
);
727 var row
= document
.getElementById("RROW-" + id
);
729 var nc
= row
.className
;
731 if (!nc
.match("Selected")) {
732 nc
= nc
+ "Selected";
737 // In CDM basically last selected article == active article
738 if (isCdmMode()) active_post_id
= id
;
740 nc
= nc
.replace("Selected", "");
750 exception_error("toggleSelected", e
);
754 function toggleUnread_afh(effect
) {
757 var elem
= effect
.element
;
758 elem
.style
.backgroundColor
= "";
761 exception_error("toggleUnread_afh", e
);
765 function toggleUnread(id
, cmode
, effect
) {
768 var row
= document
.getElementById("RROW-" + id
);
770 var nc
= row
.className
;
771 var is_selected
= row
.className
.match("Selected");
772 nc
= nc
.replace("Unread", "");
773 nc
= nc
.replace("Selected", "");
775 // since we are removing selection from the object, uncheck
776 // corresponding checkbox
778 var cb
= document
.getElementById("RCHK-" + id
);
783 // NOTE: I'm not sure that resetting selection here is a feature -fox
785 if (cmode
== undefined || cmode
== 2) {
786 if (row
.className
.match("Unread")) {
790 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
791 afterFinish
: toggleUnread_afh
,
792 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
796 row
.className
= nc
+ "Unread";
798 } else if (cmode
== 0) {
802 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
803 afterFinish
: toggleUnread_afh
,
804 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
806 } else if (cmode
== 1) {
807 row
.className
= nc
+ "Unread";
810 // Disable unmarking as selected for the time being (16.05.08) -fox
811 if (is_selected
) row
.className
= row
.className
+ "Selected";
813 if (cmode
== undefined) cmode
= 2;
815 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
816 param_escape(id
) + "&cmode=" + param_escape(cmode
);
818 // notify_progress("Loading, please wait...");
820 new Ajax
.Request(query
, {
821 onComplete: function(transport
) {
822 all_counters_callback2(transport
);
829 exception_error("toggleUnread", e
);
833 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
838 rows
= cdmGetSelectedArticles();
840 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
843 if (rows
.length
== 0 && !no_error
) {
844 alert(__("No articles are selected."));
848 for (i
= 0; i
< rows
.length
; i
++) {
849 var row
= document
.getElementById("RROW-" + rows
[i
]);
851 var nc
= row
.className
;
852 nc
= nc
.replace("Unread", "");
853 nc
= nc
.replace("Selected", "");
855 if (set_state
== undefined) {
856 if (row
.className
.match("Unread")) {
857 row
.className
= nc
+ "Selected";
859 row
.className
= nc
+ "UnreadSelected";
863 if (set_state
== false) {
864 row
.className
= nc
+ "Selected";
867 if (set_state
== true) {
868 row
.className
= nc
+ "UnreadSelected";
873 if (rows
.length
> 0) {
877 if (set_state
== undefined) {
879 } else if (set_state
== true) {
881 } else if (set_state
== false) {
885 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
886 param_escape(rows
.toString()) + "&cmode=" + cmode
;
888 notify_progress("Loading, please wait...");
890 new Ajax
.Request(query
, {
891 onComplete: function(transport
) {
892 catchup_callback2(transport
, callback_func
);
898 exception_error("selectionToggleUnread", e
);
902 function selectionToggleMarked(cdm_mode
) {
908 rows
= cdmGetSelectedArticles();
910 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
913 if (rows
.length
== 0) {
914 alert(__("No articles are selected."));
918 for (i
= 0; i
< rows
.length
; i
++) {
919 toggleMark(rows
[i
], true, true);
922 if (rows
.length
> 0) {
924 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
925 param_escape(rows
.toString()) + "&cmode=2";
927 query
= query
+ "&afid=" + getActiveFeedId();
929 /* if (tagsAreDisplayed()) {
930 query = query + "&omode=tl";
932 query = query + "&omode=flc";
935 query
= query
+ "&omode=lc";
937 new Ajax
.Request(query
, {
938 onComplete: function(transport
) {
939 all_counters_callback2(transport
);
945 exception_error("selectionToggleMarked", e
);
949 function selectionTogglePublished(cdm_mode
) {
955 rows
= cdmGetSelectedArticles();
957 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
960 if (rows
.length
== 0) {
961 alert(__("No articles are selected."));
965 for (i
= 0; i
< rows
.length
; i
++) {
966 togglePub(rows
[i
], true, true);
969 if (rows
.length
> 0) {
971 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
972 param_escape(rows
.toString()) + "&cmode=2";
974 query
= query
+ "&afid=" + getActiveFeedId();
976 /* if (tagsAreDisplayed()) {
977 query = query + "&omode=tl";
979 query = query + "&omode=flc";
982 query
= query
+ "&omode=lc";
984 new Ajax
.Request(query
, {
985 onComplete: function(transport
) {
986 all_counters_callback2(transport
);
992 exception_error("selectionToggleMarked", e
);
996 function cdmGetSelectedArticles() {
997 var sel_articles
= new Array();
998 var container
= document
.getElementById("headlinesInnerContainer");
1000 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1001 var child
= container
.childNodes
[i
];
1003 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1004 var c_id
= child
.id
.replace("RROW-", "");
1005 sel_articles
.push(c_id
);
1009 return sel_articles
;
1012 function cdmGetVisibleArticles() {
1013 var sel_articles
= new Array();
1014 var container
= document
.getElementById("headlinesInnerContainer");
1016 if (!container
) return sel_articles
;
1018 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1019 var child
= container
.childNodes
[i
];
1021 if (child
.id
.match("RROW-")) {
1022 var c_id
= child
.id
.replace("RROW-", "");
1023 sel_articles
.push(c_id
);
1027 return sel_articles
;
1030 function cdmGetUnreadArticles() {
1031 var sel_articles
= new Array();
1032 var container
= document
.getElementById("headlinesInnerContainer");
1034 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1035 var child
= container
.childNodes
[i
];
1037 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1038 var c_id
= child
.id
.replace("RROW-", "");
1039 sel_articles
.push(c_id
);
1043 return sel_articles
;
1047 // mode = all,none,unread
1048 function cdmSelectArticles(mode
) {
1049 var container
= document
.getElementById("headlinesInnerContainer");
1051 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1052 var child
= container
.childNodes
[i
];
1054 if (child
.id
.match("RROW-")) {
1055 var aid
= child
.id
.replace("RROW-", "");
1057 var cb
= document
.getElementById("RCHK-" + aid
);
1059 if (mode
== "all") {
1060 if (!child
.className
.match("Selected")) {
1061 child
.className
= child
.className
+ "Selected";
1064 } else if (mode
== "unread") {
1065 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1066 child
.className
= child
.className
+ "Selected";
1070 child
.className
= child
.className
.replace("Selected", "");
1077 function catchupPage() {
1079 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1081 var str
= __("Mark all visible articles in %s as read?");
1083 str
= str
.replace("%s", fn
);
1085 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1089 if (document
.getElementById("headlinesList")) {
1090 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1091 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1092 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1094 cdmSelectArticles('all');
1095 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1096 cdmSelectArticles('none');
1100 function catchupSelection() {
1106 if (document
.getElementById("headlinesList")) {
1107 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1109 rows
= cdmGetSelectedArticles();
1112 if (rows
.length
== 0) {
1113 alert(__("No articles are selected."));
1118 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1120 var str
= __("Mark %d selected articles in %s as read?");
1122 str
= str
.replace("%d", rows
.length
);
1123 str
= str
.replace("%s", fn
);
1125 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1129 if (document
.getElementById("headlinesList")) {
1130 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1131 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1133 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1134 // cdmSelectArticles('none');
1138 exception_error("catchupSelection", e
);
1143 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1145 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1146 printLockingError();
1149 var title
= prompt(__("Please enter label title:"), "");
1153 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1154 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1155 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1156 "&title=" + param_escape(title
);
1158 debug("LFS: " + query
);
1160 new Ajax
.Request(query
, {
1161 onComplete: function(transport
) {
1162 dlg_frefresh_callback(transport
);
1167 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1168 _tag_active_post_id
= id
;
1169 _tag_active_feed_id
= feed_id
;
1170 _tag_active_cdm
= cdm_enabled
;
1172 cache_invalidate(id
);
1175 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1177 displayDlg('editArticleTags', id
);
1181 function tag_saved_callback(transport
) {
1183 debug("in tag_saved_callback");
1188 if (tagsAreDisplayed()) {
1189 _reload_feedlist_after_view
= true;
1192 if (!_tag_active_cdm
) {
1193 if (active_post_id
== _tag_active_post_id
) {
1194 debug("reloading current article");
1195 view(_tag_active_post_id
, _tag_active_feed_id
);
1198 debug("reloading current feed");
1203 exception_error("catchup_callback", e
);
1207 function editTagsSave() {
1209 notify_progress("Saving article tags...");
1211 var form
= document
.forms
["tag_edit_form"];
1213 var query
= Form
.serialize("tag_edit_form");
1215 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1219 new Ajax
.Request(query
, {
1220 onComplete: function(transport
) {
1221 tag_saved_callback(transport
);
1226 function editTagsInsert() {
1229 var form
= document
.forms
["tag_edit_form"];
1231 var found_tags
= form
.found_tags
;
1232 var tags_str
= form
.tags_str
;
1234 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1236 if (tags_str
.value
.length
> 0 &&
1237 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1239 tags_str
.value
= tags_str
.value
+ ", ";
1242 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1244 found_tags
.selectedIndex
= 0;
1247 exception_error("editTagsInsert", e
);
1251 function cdmScrollViewport(where
) {
1252 debug("cdmScrollViewport: " + where
);
1254 var ctr
= document
.getElementById("headlinesInnerContainer");
1258 if (where
== "bottom") {
1259 ctr
.scrollTop
= ctr
.scrollHeight
;
1261 ctr
.scrollTop
= where
;
1265 function cdmArticleIsBelowViewport(id
) {
1267 var ctr
= document
.getElementById("headlinesInnerContainer");
1268 var e
= document
.getElementById("RROW-" + id
);
1270 if (!e
|| !ctr
) return;
1272 // article starts below viewport
1274 if (ctr
.scrollTop
< e
.offsetTop
) {
1281 exception_error("cdmArticleIsVisible", e
);
1285 function cdmArticleIsAboveViewport(id
) {
1287 var ctr
= document
.getElementById("headlinesInnerContainer");
1288 var e
= document
.getElementById("RROW-" + id
);
1290 if (!e
|| !ctr
) return;
1292 // article starts above viewport
1294 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1301 exception_error("cdmArticleIsVisible", e
);
1305 function cdmScrollToArticleId(id
) {
1307 var ctr
= document
.getElementById("headlinesInnerContainer");
1308 var e
= document
.getElementById("RROW-" + id
);
1310 if (!e
|| !ctr
) return;
1312 ctr
.scrollTop
= e
.offsetTop
;
1315 exception_error("cdmScrollToArticleId", e
);
1319 function cdmArticleIsActuallyVisible(id
) {
1321 var ctr
= document
.getElementById("headlinesInnerContainer");
1322 var e
= document
.getElementById("RROW-" + id
);
1324 if (!e
|| !ctr
) return;
1326 // article fits in viewport OR article is longer than viewport and
1327 // its bottom is visible
1329 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1330 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1334 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1335 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1336 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1345 exception_error("cdmArticleIsVisible", e
);
1349 function cdmWatchdog() {
1353 var ctr
= document
.getElementById("headlinesInnerContainer");
1357 var ids
= new Array();
1359 var e
= ctr
.firstChild
;
1362 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1363 e
.id
.match("RROW-")) {
1365 // article fits in viewport OR article is longer than viewport and
1366 // its bottom is visible
1368 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1369 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1371 // debug(e.id + " is visible " + e.offsetTop + "." +
1372 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1373 // (ctr.scrollTop + ctr.offsetHeight));
1375 ids
.push(e
.id
.replace("RROW-", ""));
1377 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1378 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1379 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1381 ids
.push(e
.id
.replace("RROW-", ""));
1385 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1387 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1388 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1390 ids.push(e.id.replace("RROW-", ""));
1399 debug("cdmWatchdog, ids= " + ids
.toString());
1401 if (ids
.length
> 0) {
1403 for (var i
= 0; i
< ids
.length
; i
++) {
1404 var e
= document
.getElementById("RROW-" + ids
[i
]);
1406 e
.className
= e
.className
.replace("Unread", "");
1410 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1411 param_escape(ids
.toString()) + "&cmode=0";
1413 new Ajax
.Request(query
, {
1414 onComplete: function(transport
) {
1415 all_counters_callback2(transport
);
1420 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1423 exception_error("cdmWatchdog", e
);
1429 function cache_inject(id
, article
, param
) {
1430 if (!cache_check_param(id
, param
)) {
1431 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1433 var cache_obj
= new Array();
1435 cache_obj
["id"] = id
;
1436 cache_obj
["data"] = article
;
1437 cache_obj
["param"] = param
;
1439 article_cache
.push(cache_obj
);
1442 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1446 function cache_find(id
) {
1447 for (var i
= 0; i
< article_cache
.length
; i
++) {
1448 if (article_cache
[i
]["id"] == id
) {
1449 return article_cache
[i
]["data"];
1455 function cache_find_param(id
, param
) {
1456 for (var i
= 0; i
< article_cache
.length
; i
++) {
1457 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1458 return article_cache
[i
]["data"];
1464 function cache_check(id
) {
1465 for (var i
= 0; i
< article_cache
.length
; i
++) {
1466 if (article_cache
[i
]["id"] == id
) {
1473 function cache_check_param(id
, param
) {
1474 for (var i
= 0; i
< article_cache
.length
; i
++) {
1476 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1477 // article_cache[i]["param"] + " vs " + id + ":" + param);
1479 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1486 function cache_expire() {
1487 while (article_cache
.length
> 25) {
1488 article_cache
.shift();
1492 function cache_empty() {
1493 article_cache
= new Array();
1496 function cache_invalidate(id
) {
1501 while (i
< article_cache
.length
) {
1502 if (article_cache
[i
]["id"] == id
) {
1503 debug("cache_invalidate: removed id " + id
);
1504 article_cache
.splice(i
, 1);
1509 debug("cache_invalidate: id not found: " + id
);
1512 exception_error("cache_invalidate", e
);
1516 function getActiveArticleId() {
1517 return active_post_id
;
1520 function cdmClicked(id
) {
1522 var elem
= document
.getElementById("RROW-" + id
);
1525 var id
= elem
.id
.replace("RROW-", "");
1526 active_post_id
= id
;
1528 cdmSelectArticles("none");
1529 toggleUnread(id
, 0, true);
1534 exception_error("cdmClicked", e
);
1538 function preload_article_callback(transport
) {
1540 if (transport
.responseXML
) {
1541 var articles
= transport
.responseXML
.getElementsByTagName("article");
1543 for (var i
= 0; i
< articles
.length
; i
++) {
1544 var id
= articles
[i
].getAttribute("id");
1545 if (!cache_check(id
)) {
1546 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1547 debug("preloaded article: " + id
);
1552 exception_error("preload_article_callback", e
);
1556 function preloadArticleUnderPointer(id
) {
1558 if (post_under_pointer
== id
&& !cache_check(id
)) {
1560 debug("trying to preload article " + id
);
1562 var neighbor_ids
= getRelativePostIds(id
, 1);
1564 /* only request uncached articles */
1566 var cids_to_request
= Array();
1568 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1569 if (!cache_check(neighbor_ids
[i
])) {
1570 cids_to_request
.push(neighbor_ids
[i
]);
1573 debug("additional ids: " + cids_to_request
.toString());
1575 cids_to_request
.push(id
);
1577 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1578 cids_to_request
.toString();
1579 new Ajax
.Request(query
, {
1580 onComplete: function(transport
) {
1581 preload_article_callback(transport
);
1585 exception_error("preloadArticleUnderPointer", e
);
1589 function postMouseIn(id
) {
1591 if (post_under_pointer
!= id
) {
1592 post_under_pointer
= id
;
1594 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1599 exception_error("postMouseIn", e
);
1603 function postMouseOut(id
) {
1605 post_under_pointer
= false;
1607 exception_error("postMouseOut", e
);
1611 function headlines_scroll_handler() {
1614 var e
= document
.getElementById("headlinesInnerContainer");
1616 // don't do infinite scrolling when Limit == All
1618 var toolbar_form
= document
.forms
["main_toolbar_form"];
1620 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1621 if (limit
.value
!= 0) {
1623 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1624 _infscroll_disable
);
1626 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1627 if (!_infscroll_disable
) {
1628 debug("more cowbell!");
1635 exception_error("headlines_scroll_handler", e
);
1639 function catchupRelativeToArticle(below
) {
1643 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1644 printLockingError();
1647 if (!getActiveArticleId()) {
1648 alert(__("No article is selected."));
1654 if (document
.getElementById("headlinesList")) {
1655 visible_ids
= getVisibleHeadlineIds();
1657 visible_ids
= cdmGetVisibleArticles();
1660 var ids_to_mark
= new Array();
1663 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1664 if (visible_ids
[i
] != getActiveArticleId()) {
1665 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1667 if (e
&& e
.className
.match("Unread")) {
1668 ids_to_mark
.push(visible_ids
[i
]);
1675 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1676 if (visible_ids
[i
] != getActiveArticleId()) {
1677 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1679 if (e
&& e
.className
.match("Unread")) {
1680 ids_to_mark
.push(visible_ids
[i
]);
1688 if (ids_to_mark
.length
== 0) {
1689 alert(__("No articles found to mark"));
1691 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1695 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1696 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1697 e
.className
= e
.className
.replace("Unread", "");
1700 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1701 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1703 new Ajax
.Request(query
, {
1704 onComplete: function(transport
) {
1705 catchup_callback2(transport
);
1712 exception_error("catchupRelativeToArticle", e
);
1716 function cdmExpandArticle(a_id
) {
1718 var id
= 'CICD-' + a_id
;
1721 Element
.hide("CEXC-" + a_id
);
1724 Effect
.Appear(id
, {duration
: 0.5,
1725 beforeStart: function(effect
) {
1726 var h_id
= 'CICH-' + a_id
;
1727 var h_elem
= document
.getElementById(h_id
);
1728 if (h_elem
) { h_elem
.style
.display
= "none"; }
1730 toggleUnread(a_id
, 0);
1735 exception_error("appearBlockElementF", e
);
1740 function fixHeadlinesOrder(ids
) {
1742 for (var i
= 0; i
< ids
.length
; i
++) {
1743 var e
= document
.getElementById("RROW-" + ids
[i
]);
1747 e
.className
= e
.className
.replace("even", "odd");
1749 e
.className
= e
.className
.replace("odd", "even");
1754 exception_error("fixHeadlinesOrder", e
);
1758 function subtoolbarSearch() {
1761 var q
= document
.getElementById("subtoolbar_search_box");
1765 q
= q
.value
.toUpperCase();
1768 var vis_ids
= new Array();
1770 if (document
.getElementById("headlinesList")) {
1771 ids
= getVisibleHeadlineIds();
1773 ids
= cdmGetVisibleArticles();
1776 for (var i
= 0; i
< ids
.length
; i
++) {
1777 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1780 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1781 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1783 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1784 vis_ids
.push(ids
[i
]);
1789 fixHeadlinesOrder(vis_ids
);
1792 exception_error("subtoolbarSearch", e
);
1796 function hideReadHeadlines() {
1800 var vis_ids
= new Array();
1802 if (document
.getElementById("headlinesList")) {
1803 ids
= getVisibleHeadlineIds();
1805 ids
= cdmGetVisibleArticles();
1808 for (var i
= 0; i
< ids
.length
; i
++) {
1809 var row
= document
.getElementById("RROW-" + ids
[i
]);
1811 if (row
&& row
.className
) {
1812 if (read_headlines_visible
) {
1813 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1815 vis_ids
.push(ids
[i
]);
1817 //Effect.Fade(row, {duration : 0.3});
1822 vis_ids
.push(ids
[i
]);
1827 fixHeadlinesOrder(vis_ids
);
1829 read_headlines_visible
= !read_headlines_visible
;
1832 exception_error("hideReadHeadlines", e
);
1836 function getArticleUnderPointer() {
1837 return post_under_pointer
;