1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view
= false;
8 var _cdm_wd_timeout
= false;
9 var _cdm_wd_vishist
= new Array();
11 var article_cache
= new Array();
13 var vgroup_last_feed
= false;
14 var post_under_pointer
= false;
16 var last_requested_article
= false;
18 function catchup_callback2(transport
, callback
) {
20 debug("catchup_callback2 " + transport
+ ", " + callback
);
22 all_counters_callback2(transport
);
24 setTimeout(callback
, 10);
27 exception_error("catchup_callback2", e
, transport
);
31 function clean_feed_selections() {
33 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
35 for (var i
= 0; i
< feeds
.length
; i
++) {
36 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
37 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
39 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
40 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
44 exception_error("clean_feed_selections", e
);
48 function headlines_callback2(transport
, feed_cur_page
) {
51 loading_set_progress(100);
53 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
55 if (!transport_error_check(transport
)) return;
57 clean_feed_selections();
62 if (transport
.responseXML
) {
63 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
65 is_cat
= headlines
.getAttribute("is_cat");
66 feed_id
= headlines
.getAttribute("id");
67 setActiveFeedId(feed_id
, is_cat
);
72 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
73 if (feedr
&& !feedr
.className
.match("Selected")) {
74 feedr
.className
= feedr
.className
+ "Selected";
77 var feedr
= document
.getElementById("FCAT-" + feed_id
);
78 if (feedr
&& !feedr
.className
.match("Selected")) {
79 feedr
.className
= feedr
.className
+ "Selected";
83 var f
= document
.getElementById("headlines-frame");
85 if (feed_cur_page
== 0) {
86 debug("resetting headlines scrollTop");
91 if (transport
.responseXML
) {
92 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
93 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
94 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
95 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
97 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
99 var headlines_count
= headlines_count_obj
.getAttribute("value");
100 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
101 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
103 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
105 if (headlines_count
== 0) {
106 _infscroll_disable
= 1;
108 _infscroll_disable
= 0;
111 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
112 var articles
= transport
.responseXML
.getElementsByTagName("article");
113 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
115 if (feed_cur_page
== 0) {
117 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
119 var cache_prefix
= "";
127 cache_invalidate(cache_prefix
+ feed_id
);
129 if (!disable_cache
) {
130 cache_inject(cache_prefix
+ feed_id
,
131 headlines
.firstChild
.nodeValue
, headlines_unread
);
135 debug("headlines_callback: returned no data");
136 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
141 if (headlines_count
> 0) {
142 debug("adding some more headlines...");
144 var c
= document
.getElementById("headlinesList");
147 c
= document
.getElementById("headlinesInnerContainer");
150 var ids
= getSelectedArticleIds2();
152 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
154 debug("restore selected ids: " + ids
);
156 for (var i
= 0; i
< ids
.length
; i
++) {
157 markHeadline(ids
[i
]);
161 debug("no new headlines received");
164 debug("headlines_callback: returned no data");
165 notify_error("Error while trying to load more headlines");
171 for (var i
= 0; i
< articles
.length
; i
++) {
172 var a_id
= articles
[i
].getAttribute("id");
173 debug("found id: " + a_id
);
174 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
177 debug("no cached articles received");
181 debug("parsing piggybacked counters: " + counters
);
182 parse_counters(counters
, false);
184 debug("counters container not found in reply, requesting...");
189 debug("parsing runtime info: " + runtime_info
[0]);
190 parse_runtime_info(runtime_info
[0]);
192 debug("counters container not found in reply");
196 debug("headlines_callback: returned no XML object");
197 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
200 if (typeof correctPNG
!= 'undefined') {
204 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
206 if (!document
.getElementById("headlinesList") &&
207 getActiveFeedId() != -3 &&
208 getInitParam("cdm_auto_catchup") == 1) {
209 debug("starting CDM watchdog");
210 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
211 _cdm_wd_vishist
= new Array();
213 debug("not in CDM mode or watchdog disabled");
216 _feed_cur_page
= feed_cur_page
;
217 _infscroll_request_sent
= 0;
224 exception_error("headlines_callback2", e
, transport
);
228 function render_article(article
) {
230 var f
= document
.getElementById("content-frame");
235 var fi
= document
.getElementById("content-insert");
241 fi
.innerHTML
= article
;
244 exception_error("render_article", e
);
248 function showArticleInHeadlines(id
) {
252 cleanSelected("headlinesList");
254 var crow
= document
.getElementById("RROW-" + id
);
258 var article_is_unread
= crow
.className
.match("Unread");
260 crow
.className
= crow
.className
.replace("Unread", "");
262 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
264 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
266 var cache_prefix
= "";
268 if (activeFeedIsCat()) {
274 var view_mode
= false;
277 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
278 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
283 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
284 upd_img_pic
.src
= "images/blank_icon.gif";
286 cache_invalidate(cache_prefix
+ getActiveFeedId());
288 cache_inject(cache_prefix
+ getActiveFeedId(),
289 document
.getElementById("headlines-frame").innerHTML
,
290 get_feed_unread(getActiveFeedId()));
292 } else if (article_is_unread
&& view_mode
== "all_articles") {
294 cache_invalidate(cache_prefix
+ getActiveFeedId());
296 cache_inject(cache_prefix
+ getActiveFeedId(),
297 document
.getElementById("headlines-frame").innerHTML
,
298 get_feed_unread(getActiveFeedId())-1);
300 } else if (article_is_unread
) {
301 cache_invalidate(cache_prefix
+ getActiveFeedId());
307 exception_error("showArticleInHeadlines", e
);
311 function article_callback2(transport
, id
, feed_id
) {
313 debug("article_callback2 " + id
);
315 if (transport
.responseXML
) {
317 if (!transport_error_check(transport
)) return;
319 debug("looking for articles to cache...");
321 var articles
= transport
.responseXML
.getElementsByTagName("article");
323 for (var i
= 0; i
< articles
.length
; i
++) {
324 var a_id
= articles
[i
].getAttribute("id");
326 debug("found id: " + a_id
);
328 if (a_id
== active_post_id
) {
329 debug("active article, rendering...");
330 render_article(articles
[i
].firstChild
.nodeValue
);
333 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
336 if (id
!= last_requested_article
) {
337 debug("requested article id is out of sequence, aborting");
341 active_real_feed_id
= feed_id
;
344 showArticleInHeadlines(id
);
346 var reply
= transport
.responseXML
.firstChild
.firstChild
;
349 debug("article_callback: returned no XML object");
350 //var f = document.getElementById("content-frame");
351 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
354 var date
= new Date();
355 last_article_view
= date
.getTime() / 1000;
357 if (typeof correctPNG
!= 'undefined') {
361 if (_reload_feedlist_after_view
) {
362 setTimeout('updateFeedList(false, false)', 50);
363 _reload_feedlist_after_view
= false;
365 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
368 debug("parsing piggybacked counters: " + counters
);
369 parse_counters(counters
, false);
371 debug("counters container not found in reply, requesting...");
378 exception_error("article_callback2", e
, transport
);
382 function view(id
, feed_id
, skip_history
) {
385 debug("loading article: " + id
+ "/" + feed_id
);
387 var cached_article
= cache_find(id
);
389 debug("cache check result: " + (cached_article
!= false));
393 //setActiveFeedId(feed_id);
395 var query
= "backend.php?op=view&id=" + param_escape(id
) +
396 "&feed=" + param_escape(feed_id
);
398 var date
= new Date();
400 var neighbor_ids
= getRelativePostIds(active_post_id
);
402 /* only request uncached articles */
404 var cids_to_request
= Array();
406 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
407 if (!cache_check(neighbor_ids
[i
])) {
408 cids_to_request
.push(neighbor_ids
[i
]);
412 debug("additional ids: " + cids_to_request
.toString());
414 /* additional info for piggyback counters */
416 if (tagsAreDisplayed()) {
417 query
= query
+ "&omode=lt";
419 query
= query
+ "&omode=flc";
422 var date
= new Date();
423 var timestamp
= Math
.round(date
.getTime() / 1000);
424 query
= query
+ "&ts=" + timestamp
;
426 query
= query
+ "&cids=" + cids_to_request
.toString();
428 var crow
= document
.getElementById("RROW-" + id
);
429 var article_is_unread
= crow
.className
.match("Unread");
431 if (!async_counters_work
) {
432 query
= query
+ "&csync=true";
435 showArticleInHeadlines(id
);
437 if (!cached_article
) {
439 notify_progress("Loading, please wait...", true);
441 } else if (cached_article
&& article_is_unread
) {
443 query
= query
+ "&mode=prefetch";
445 render_article(cached_article
);
447 } else if (cached_article
) {
449 query
= query
+ "&mode=prefetch_old";
450 render_article(cached_article
);
456 last_requested_article
= id
;
458 new Ajax
.Request(query
, {
459 onComplete: function(transport
) {
460 article_callback2(transport
, id
, feed_id
);
466 exception_error("view", e
);
471 return toggleMark(id
);
475 return togglePub(id
);
478 function tMark_afh_off(effect
) {
480 var elem
= effect
.effects
[0].element
;
482 debug("tMark_afh_off : " + elem
.id
);
485 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
486 elem
.alt
= __("Star article");
491 exception_error("tMark_afh_off", e
);
495 function tPub_afh_off(effect
) {
497 var elem
= effect
.effects
[0].element
;
499 debug("tPub_afh_off : " + elem
.id
);
502 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
503 elem
.alt
= __("Publish article");
508 exception_error("tPub_afh_off", e
);
512 function toggleMark(id
, client_only
, no_effects
) {
516 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
518 query
= query
+ "&afid=" + getActiveFeedId();
520 if (tagsAreDisplayed()) {
521 query
= query
+ "&omode=tl";
523 query
= query
+ "&omode=flc";
526 var mark_img
= document
.getElementById("FMPIC-" + id
);
528 if (!mark_img
) return;
530 var vfeedu
= document
.getElementById("FEEDU--1");
531 var crow
= document
.getElementById("RROW-" + id
);
533 if (mark_img
.src
.match("mark_unset")) {
534 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
535 mark_img
.alt
= __("Unstar article");
536 query
= query
+ "&mark=1";
539 //mark_img.src = "images/mark_unset.png";
540 mark_img
.alt
= __("Please wait...");
541 query
= query
+ "&mark=0";
543 if (document
.getElementById("headlinesList") && !no_effects
) {
544 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
546 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
547 mark_img
.alt
= __("Star article");
554 new Ajax
.Request(query
, {
555 onComplete: function(transport
) {
556 all_counters_callback2(transport
);
562 exception_error("toggleMark", e
);
566 function togglePub(id
, client_only
, no_effects
) {
570 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
572 query
= query
+ "&afid=" + getActiveFeedId();
574 if (tagsAreDisplayed()) {
575 query
= query
+ "&omode=tl";
577 query
= query
+ "&omode=flc";
580 var mark_img
= document
.getElementById("FPPIC-" + id
);
582 if (!mark_img
) return;
584 var vfeedu
= document
.getElementById("FEEDU--2");
585 var crow
= document
.getElementById("RROW-" + id
);
587 if (mark_img
.src
.match("pub_unset")) {
588 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
589 mark_img
.alt
= __("Unpublish article");
590 query
= query
+ "&pub=1";
594 //mark_img.src = "images/pub_unset.png";
595 mark_img
.alt
= __("Please wait...");
596 query
= query
+ "&pub=0";
598 if (document
.getElementById("headlinesList") && !no_effects
) {
599 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
601 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
602 mark_img
.alt
= __("Publish article");
607 new Ajax
.Request(query
, {
608 onComplete: function(transport
) {
609 all_counters_callback2(transport
);
615 exception_error("togglePub", e
);
619 function correctHeadlinesOffset(id
) {
623 var hlist
= document
.getElementById("headlinesList");
624 var container
= document
.getElementById("headlinesInnerContainer");
625 var row
= document
.getElementById("RROW-" + id
);
627 var viewport
= container
.offsetHeight
;
629 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
630 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
632 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
633 debug("Vport: " + viewport
);
635 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
636 container
.scrollTop
= row
.offsetTop
;
637 } else if (rel_offset_bottom
> viewport
) {
639 /* doesn't properly work with Opera in some cases because
640 Opera fucks up element scrolling */
642 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
646 exception_error("correctHeadlinesOffset", e
);
651 function moveToPost(mode
) {
658 rows
= cdmGetVisibleArticles();
660 rows
= getVisibleHeadlineIds();
666 if (!document
.getElementById('RROW-' + active_post_id
)) {
667 active_post_id
= false;
670 if (active_post_id
== false) {
671 next_id
= getFirstVisibleHeadlineId();
672 prev_id
= getLastVisibleHeadlineId();
674 for (var i
= 0; i
< rows
.length
; i
++) {
675 if (rows
[i
] == active_post_id
) {
682 if (mode
== "next") {
686 if (!cdmArticleIsActuallyVisible(next_id
)) {
687 cdmScrollToArticleId(next_id
);
689 cdmSelectArticles("none");
690 toggleUnread(next_id
, 0, true);
691 toggleSelected(next_id
);
694 correctHeadlinesOffset(next_id
);
695 view(next_id
, getActiveFeedId());
700 if (mode
== "prev") {
703 cdmScrollToArticleId(prev_id
);
704 cdmSelectArticles("none");
705 toggleUnread(prev_id
, 0, true);
706 toggleSelected(prev_id
);
708 correctHeadlinesOffset(prev_id
);
709 view(prev_id
, getActiveFeedId());
715 exception_error("moveToPost", e
);
719 function toggleSelected(id
) {
722 var cb
= document
.getElementById("RCHK-" + id
);
724 var row
= document
.getElementById("RROW-" + id
);
726 var nc
= row
.className
;
728 if (!nc
.match("Selected")) {
729 nc
= nc
+ "Selected";
734 // In CDM basically last selected article == active article
735 if (isCdmMode()) active_post_id
= id
;
737 nc
= nc
.replace("Selected", "");
747 exception_error("toggleSelected", e
);
751 function toggleUnread_afh(effect
) {
754 var elem
= effect
.element
;
755 elem
.style
.backgroundColor
= "";
758 exception_error("toggleUnread_afh", e
);
762 function toggleUnread(id
, cmode
, effect
) {
765 var row
= document
.getElementById("RROW-" + id
);
767 var nc
= row
.className
;
768 var is_selected
= row
.className
.match("Selected");
769 nc
= nc
.replace("Unread", "");
770 nc
= nc
.replace("Selected", "");
772 // since we are removing selection from the object, uncheck
773 // corresponding checkbox
775 var cb
= document
.getElementById("RCHK-" + id
);
780 // NOTE: I'm not sure that resetting selection here is a feature -fox
782 if (cmode
== undefined || cmode
== 2) {
783 if (row
.className
.match("Unread")) {
787 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
788 afterFinish
: toggleUnread_afh
,
789 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
793 row
.className
= nc
+ "Unread";
795 } else if (cmode
== 0) {
799 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
800 afterFinish
: toggleUnread_afh
,
801 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
803 } else if (cmode
== 1) {
804 row
.className
= nc
+ "Unread";
807 // Disable unmarking as selected for the time being (16.05.08) -fox
808 if (is_selected
) row
.className
= row
.className
+ "Selected";
810 if (cmode
== undefined) cmode
= 2;
812 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
813 param_escape(id
) + "&cmode=" + param_escape(cmode
);
815 // notify_progress("Loading, please wait...");
817 new Ajax
.Request(query
, {
818 onComplete: function(transport
) {
819 all_counters_callback2(transport
);
826 exception_error("toggleUnread", e
);
830 function selectionRemoveLabel(id
) {
833 var ids
= getSelectedArticleIds2();
835 if (ids
.length
== 0) {
836 alert(__("No articles are selected."));
840 // var ok = confirm(__("Remove selected articles from label?"));
844 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
845 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
847 // notify_progress("Loading, please wait...");
849 cache_invalidate("F:" + (-11 - id
));
851 new Ajax
.Request(query
, {
852 onComplete: function(transport
) {
853 show_labels_in_headlines(transport
);
854 all_counters_callback2(transport
);
860 exception_error("selectionAssignLabel", e
);
865 function selectionAssignLabel(id
) {
868 var ids
= getSelectedArticleIds2();
870 if (ids
.length
== 0) {
871 alert(__("No articles are selected."));
875 // var ok = confirm(__("Assign selected articles to label?"));
879 cache_invalidate("F:" + (-11 - id
));
881 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
882 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
884 // notify_progress("Loading, please wait...");
886 new Ajax
.Request(query
, {
887 onComplete: function(transport
) {
888 show_labels_in_headlines(transport
);
889 all_counters_callback2(transport
);
895 exception_error("selectionAssignLabel", e
);
900 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
905 rows
= cdmGetSelectedArticles();
907 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
910 if (rows
.length
== 0 && !no_error
) {
911 alert(__("No articles are selected."));
915 for (i
= 0; i
< rows
.length
; i
++) {
916 var row
= document
.getElementById("RROW-" + rows
[i
]);
918 var nc
= row
.className
;
919 nc
= nc
.replace("Unread", "");
920 nc
= nc
.replace("Selected", "");
922 if (set_state
== undefined) {
923 if (row
.className
.match("Unread")) {
924 row
.className
= nc
+ "Selected";
926 row
.className
= nc
+ "UnreadSelected";
930 if (set_state
== false) {
931 row
.className
= nc
+ "Selected";
934 if (set_state
== true) {
935 row
.className
= nc
+ "UnreadSelected";
940 if (rows
.length
> 0) {
944 if (set_state
== undefined) {
946 } else if (set_state
== true) {
948 } else if (set_state
== false) {
952 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
953 param_escape(rows
.toString()) + "&cmode=" + cmode
;
955 notify_progress("Loading, please wait...");
957 new Ajax
.Request(query
, {
958 onComplete: function(transport
) {
959 catchup_callback2(transport
, callback_func
);
965 exception_error("selectionToggleUnread", e
);
969 function selectionToggleMarked(cdm_mode
) {
975 rows
= cdmGetSelectedArticles();
977 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
980 if (rows
.length
== 0) {
981 alert(__("No articles are selected."));
985 for (i
= 0; i
< rows
.length
; i
++) {
986 toggleMark(rows
[i
], true, true);
989 if (rows
.length
> 0) {
991 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
992 param_escape(rows
.toString()) + "&cmode=2";
994 query
= query
+ "&afid=" + getActiveFeedId();
996 /* if (tagsAreDisplayed()) {
997 query = query + "&omode=tl";
999 query = query + "&omode=flc";
1002 query
= query
+ "&omode=lc";
1004 new Ajax
.Request(query
, {
1005 onComplete: function(transport
) {
1006 all_counters_callback2(transport
);
1012 exception_error("selectionToggleMarked", e
);
1016 function selectionTogglePublished(cdm_mode
) {
1022 rows
= cdmGetSelectedArticles();
1024 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1027 if (rows
.length
== 0) {
1028 alert(__("No articles are selected."));
1032 for (i
= 0; i
< rows
.length
; i
++) {
1033 togglePub(rows
[i
], true, true);
1036 if (rows
.length
> 0) {
1038 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1039 param_escape(rows
.toString()) + "&cmode=2";
1041 query
= query
+ "&afid=" + getActiveFeedId();
1043 /* if (tagsAreDisplayed()) {
1044 query = query + "&omode=tl";
1046 query = query + "&omode=flc";
1049 query
= query
+ "&omode=lc";
1051 new Ajax
.Request(query
, {
1052 onComplete: function(transport
) {
1053 all_counters_callback2(transport
);
1059 exception_error("selectionToggleMarked", e
);
1063 function cdmGetSelectedArticles() {
1064 var sel_articles
= new Array();
1065 var container
= document
.getElementById("headlinesInnerContainer");
1067 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1068 var child
= container
.childNodes
[i
];
1070 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1071 var c_id
= child
.id
.replace("RROW-", "");
1072 sel_articles
.push(c_id
);
1076 return sel_articles
;
1079 function cdmGetVisibleArticles() {
1080 var sel_articles
= new Array();
1081 var container
= document
.getElementById("headlinesInnerContainer");
1083 if (!container
) return sel_articles
;
1085 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1086 var child
= container
.childNodes
[i
];
1088 if (child
.id
&& child
.id
.match("RROW-")) {
1089 var c_id
= child
.id
.replace("RROW-", "");
1090 sel_articles
.push(c_id
);
1094 return sel_articles
;
1097 function cdmGetUnreadArticles() {
1098 var sel_articles
= new Array();
1099 var container
= document
.getElementById("headlinesInnerContainer");
1101 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1102 var child
= container
.childNodes
[i
];
1104 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1105 var c_id
= child
.id
.replace("RROW-", "");
1106 sel_articles
.push(c_id
);
1110 return sel_articles
;
1114 // mode = all,none,unread
1115 function cdmSelectArticles(mode
) {
1116 var container
= document
.getElementById("headlinesInnerContainer");
1118 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1119 var child
= container
.childNodes
[i
];
1121 if (child
.id
&& child
.id
.match("RROW-")) {
1122 var aid
= child
.id
.replace("RROW-", "");
1124 var cb
= document
.getElementById("RCHK-" + aid
);
1126 if (mode
== "all") {
1127 if (!child
.className
.match("Selected")) {
1128 child
.className
= child
.className
+ "Selected";
1131 } else if (mode
== "unread") {
1132 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1133 child
.className
= child
.className
+ "Selected";
1137 child
.className
= child
.className
.replace("Selected", "");
1144 function catchupPage() {
1146 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1148 var str
= __("Mark all visible articles in %s as read?");
1150 str
= str
.replace("%s", fn
);
1152 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1156 if (document
.getElementById("headlinesList")) {
1157 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1158 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1159 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1161 cdmSelectArticles('all');
1162 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1163 cdmSelectArticles('none');
1167 function catchupSelection() {
1173 if (document
.getElementById("headlinesList")) {
1174 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1176 rows
= cdmGetSelectedArticles();
1179 if (rows
.length
== 0) {
1180 alert(__("No articles are selected."));
1185 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1187 var str
= __("Mark %d selected articles in %s as read?");
1189 str
= str
.replace("%d", rows
.length
);
1190 str
= str
.replace("%s", fn
);
1192 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1196 if (document
.getElementById("headlinesList")) {
1197 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1198 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1200 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1201 // cdmSelectArticles('none');
1205 exception_error("catchupSelection", e
);
1209 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1210 displayDlg('editArticleTags', id
);
1214 function tag_saved_callback(transport
) {
1216 debug("in tag_saved_callback");
1221 if (tagsAreDisplayed()) {
1222 _reload_feedlist_after_view
= true;
1226 if (transport
.responseXML
) {
1227 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1230 var id
= tags_str
.getAttribute("id");
1233 var tags
= document
.getElementById("ATSTR-" + id
);
1235 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1242 exception_error("tag_saved_callback", e
);
1246 function editTagsSave() {
1248 notify_progress("Saving article tags...");
1250 var form
= document
.forms
["tag_edit_form"];
1252 var query
= Form
.serialize("tag_edit_form");
1254 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1258 new Ajax
.Request(query
, {
1259 onComplete: function(transport
) {
1260 tag_saved_callback(transport
);
1265 function editTagsInsert() {
1268 var form
= document
.forms
["tag_edit_form"];
1270 var found_tags
= form
.found_tags
;
1271 var tags_str
= form
.tags_str
;
1273 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1275 if (tags_str
.value
.length
> 0 &&
1276 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1278 tags_str
.value
= tags_str
.value
+ ", ";
1281 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1283 found_tags
.selectedIndex
= 0;
1286 exception_error("editTagsInsert", e
);
1290 function cdmScrollViewport(where
) {
1291 debug("cdmScrollViewport: " + where
);
1293 var ctr
= document
.getElementById("headlinesInnerContainer");
1297 if (where
== "bottom") {
1298 ctr
.scrollTop
= ctr
.scrollHeight
;
1300 ctr
.scrollTop
= where
;
1304 function cdmArticleIsBelowViewport(id
) {
1306 var ctr
= document
.getElementById("headlinesInnerContainer");
1307 var e
= document
.getElementById("RROW-" + id
);
1309 if (!e
|| !ctr
) return;
1311 // article starts below viewport
1313 if (ctr
.scrollTop
< e
.offsetTop
) {
1320 exception_error("cdmArticleIsVisible", e
);
1324 function cdmArticleIsAboveViewport(id
) {
1326 var ctr
= document
.getElementById("headlinesInnerContainer");
1327 var e
= document
.getElementById("RROW-" + id
);
1329 if (!e
|| !ctr
) return;
1331 // article starts above viewport
1333 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1340 exception_error("cdmArticleIsVisible", e
);
1344 function cdmScrollToArticleId(id
) {
1346 var ctr
= document
.getElementById("headlinesInnerContainer");
1347 var e
= document
.getElementById("RROW-" + id
);
1349 if (!e
|| !ctr
) return;
1351 ctr
.scrollTop
= e
.offsetTop
;
1354 exception_error("cdmScrollToArticleId", e
);
1358 function cdmArticleIsActuallyVisible(id
) {
1360 var ctr
= document
.getElementById("headlinesInnerContainer");
1361 var e
= document
.getElementById("RROW-" + id
);
1363 if (!e
|| !ctr
) return;
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
) {
1373 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1374 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1375 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1384 exception_error("cdmArticleIsVisible", e
);
1388 function cdmWatchdog() {
1392 var ctr
= document
.getElementById("headlinesInnerContainer");
1396 var ids
= new Array();
1398 var e
= ctr
.firstChild
;
1401 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1402 e
.id
.match("RROW-")) {
1404 // article fits in viewport OR article is longer than viewport and
1405 // its bottom is visible
1407 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1408 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1410 // debug(e.id + " is visible " + e.offsetTop + "." +
1411 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1412 // (ctr.scrollTop + ctr.offsetHeight));
1414 ids
.push(e
.id
.replace("RROW-", ""));
1416 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1417 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1418 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1420 ids
.push(e
.id
.replace("RROW-", ""));
1424 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1426 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1427 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1429 ids.push(e.id.replace("RROW-", ""));
1438 debug("cdmWatchdog, ids= " + ids
.toString());
1440 if (ids
.length
> 0) {
1442 for (var i
= 0; i
< ids
.length
; i
++) {
1443 var e
= document
.getElementById("RROW-" + ids
[i
]);
1445 e
.className
= e
.className
.replace("Unread", "");
1449 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1450 param_escape(ids
.toString()) + "&cmode=0";
1452 new Ajax
.Request(query
, {
1453 onComplete: function(transport
) {
1454 all_counters_callback2(transport
);
1459 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1462 exception_error("cdmWatchdog", e
);
1468 function cache_inject(id
, article
, param
) {
1469 if (!cache_check_param(id
, param
)) {
1470 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1472 var cache_obj
= new Array();
1474 cache_obj
["id"] = id
;
1475 cache_obj
["data"] = article
;
1476 cache_obj
["param"] = param
;
1478 article_cache
.push(cache_obj
);
1481 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1485 function cache_find(id
) {
1486 for (var i
= 0; i
< article_cache
.length
; i
++) {
1487 if (article_cache
[i
]["id"] == id
) {
1488 return article_cache
[i
]["data"];
1494 function cache_find_param(id
, param
) {
1495 for (var i
= 0; i
< article_cache
.length
; i
++) {
1496 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1497 return article_cache
[i
]["data"];
1503 function cache_check(id
) {
1504 for (var i
= 0; i
< article_cache
.length
; i
++) {
1505 if (article_cache
[i
]["id"] == id
) {
1512 function cache_check_param(id
, param
) {
1513 for (var i
= 0; i
< article_cache
.length
; i
++) {
1515 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1516 // article_cache[i]["param"] + " vs " + id + ":" + param);
1518 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1525 function cache_expire() {
1526 while (article_cache
.length
> 25) {
1527 article_cache
.shift();
1531 function cache_empty() {
1532 article_cache
= new Array();
1535 function cache_invalidate(id
) {
1540 while (i
< article_cache
.length
) {
1541 if (article_cache
[i
]["id"] == id
) {
1542 debug("cache_invalidate: removed id " + id
);
1543 article_cache
.splice(i
, 1);
1548 debug("cache_invalidate: id not found: " + id
);
1551 exception_error("cache_invalidate", e
);
1555 function getActiveArticleId() {
1556 return active_post_id
;
1559 function cdmClicked(id
) {
1561 var elem
= document
.getElementById("RROW-" + id
);
1564 var id
= elem
.id
.replace("RROW-", "");
1565 active_post_id
= id
;
1567 // cdmSelectArticles("none");
1568 toggleUnread(id
, 0, true);
1569 // toggleSelected(id);
1573 exception_error("cdmClicked", e
);
1577 function preload_article_callback(transport
) {
1579 if (transport
.responseXML
) {
1580 var articles
= transport
.responseXML
.getElementsByTagName("article");
1582 for (var i
= 0; i
< articles
.length
; i
++) {
1583 var id
= articles
[i
].getAttribute("id");
1584 if (!cache_check(id
)) {
1585 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1586 debug("preloaded article: " + id
);
1591 exception_error("preload_article_callback", e
);
1595 function preloadArticleUnderPointer(id
) {
1597 if (getInitParam("bw_limit") == "1") return;
1599 if (post_under_pointer
== id
&& !cache_check(id
)) {
1601 debug("trying to preload article " + id
);
1603 var neighbor_ids
= getRelativePostIds(id
, 1);
1605 /* only request uncached articles */
1607 var cids_to_request
= Array();
1609 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1610 if (!cache_check(neighbor_ids
[i
])) {
1611 cids_to_request
.push(neighbor_ids
[i
]);
1614 debug("additional ids: " + cids_to_request
.toString());
1616 cids_to_request
.push(id
);
1618 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1619 cids_to_request
.toString();
1620 new Ajax
.Request(query
, {
1621 onComplete: function(transport
) {
1622 preload_article_callback(transport
);
1626 exception_error("preloadArticleUnderPointer", e
);
1630 function postMouseIn(id
) {
1632 if (post_under_pointer
!= id
) {
1633 post_under_pointer
= id
;
1635 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1640 exception_error("postMouseIn", e
);
1644 function postMouseOut(id
) {
1646 post_under_pointer
= false;
1648 exception_error("postMouseOut", e
);
1652 function headlines_scroll_handler() {
1655 var e
= document
.getElementById("headlinesInnerContainer");
1657 // don't do infinite scrolling when Limit == All
1659 var toolbar_form
= document
.forms
["main_toolbar_form"];
1661 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1662 if (limit
.value
!= 0) {
1664 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1665 _infscroll_disable
);
1667 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1668 if (!_infscroll_disable
) {
1669 debug("more cowbell!");
1676 exception_error("headlines_scroll_handler", e
);
1680 function catchupRelativeToArticle(below
) {
1685 if (!getActiveArticleId()) {
1686 alert(__("No article is selected."));
1692 if (document
.getElementById("headlinesList")) {
1693 visible_ids
= getVisibleHeadlineIds();
1695 visible_ids
= cdmGetVisibleArticles();
1698 var ids_to_mark
= new Array();
1701 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1702 if (visible_ids
[i
] != getActiveArticleId()) {
1703 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1705 if (e
&& e
.className
.match("Unread")) {
1706 ids_to_mark
.push(visible_ids
[i
]);
1713 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1714 if (visible_ids
[i
] != getActiveArticleId()) {
1715 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1717 if (e
&& e
.className
.match("Unread")) {
1718 ids_to_mark
.push(visible_ids
[i
]);
1726 if (ids_to_mark
.length
== 0) {
1727 alert(__("No articles found to mark"));
1729 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1733 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1734 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1735 e
.className
= e
.className
.replace("Unread", "");
1738 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1739 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1741 new Ajax
.Request(query
, {
1742 onComplete: function(transport
) {
1743 catchup_callback2(transport
);
1750 exception_error("catchupRelativeToArticle", e
);
1754 function cdmExpandArticle(a_id
) {
1756 var id
= 'CICD-' + a_id
;
1759 Element
.hide("CEXC-" + a_id
);
1762 Effect
.Appear(id
, {duration
: 0.5,
1763 beforeStart: function(effect
) {
1764 var h_id
= 'CICH-' + a_id
;
1765 var h_elem
= document
.getElementById(h_id
);
1766 if (h_elem
) { h_elem
.style
.display
= "none"; }
1768 toggleUnread(a_id
, 0);
1773 exception_error("appearBlockElementF", e
);
1778 function fixHeadlinesOrder(ids
) {
1780 for (var i
= 0; i
< ids
.length
; i
++) {
1781 var e
= document
.getElementById("RROW-" + ids
[i
]);
1785 e
.className
= e
.className
.replace("even", "odd");
1787 e
.className
= e
.className
.replace("odd", "even");
1792 exception_error("fixHeadlinesOrder", e
);
1796 function hideReadHeadlines() {
1800 var vis_ids
= new Array();
1802 if (document
.getElementById("headlinesList")) {
1803 ids
= getVisibleHeadlineIds();
1805 ids
= cdmGetVisibleArticles();
1808 var read_headlines_visible
= true;
1810 for (var i
= 0; i
< ids
.length
; i
++) {
1811 var row
= document
.getElementById("RROW-" + ids
[i
]);
1813 if (row
&& row
.className
) {
1814 if (read_headlines_visible
) {
1815 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1817 vis_ids
.push(ids
[i
]);
1819 //Effect.Fade(row, {duration : 0.3});
1824 vis_ids
.push(ids
[i
]);
1829 fixHeadlinesOrder(vis_ids
);
1831 read_headlines_visible
= !read_headlines_visible
;
1834 exception_error("hideReadHeadlines", e
);
1838 function invertHeadlineSelection() {
1840 var rows
= new Array();
1844 r
= document
.getElementsByTagName("TR");
1846 r
= document
.getElementsByTagName("DIV");
1849 for (var i
= 0; i
< r
.length
; i
++) {
1850 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1855 for (var i
= 0; i
< rows
.length
; i
++) {
1856 var nc
= rows
[i
].className
;
1857 var id
= rows
[i
].id
.replace("RROW-", "");
1858 var cb
= document
.getElementById("RCHK-" + id
);
1860 if (!rows
[i
].className
.match("Selected")) {
1861 nc
= nc
+ "Selected";
1864 nc
= nc
.replace("Selected", "");
1868 rows
[i
].className
= nc
;
1873 exception_error("invertHeadlineSelection", e
);
1877 function getArticleUnderPointer() {
1878 return post_under_pointer
;
1881 function zoomToArticle(id
) {
1883 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1885 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1888 exception_error("zoomToArticle", e
);
1892 function showOriginalArticleInline(id
) {
1895 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1897 notify_progress("Loading, please wait...", true);
1899 new Ajax
.Request(query
, {
1900 onComplete: function(transport
) {
1902 if (transport
.responseXML
) {
1904 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1905 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1910 link
= link
.firstChild
.nodeValue
;
1912 var ci
= document
.getElementById("content-insert");
1914 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1916 render_article(tmp
);
1923 exception_error("showOriginalArticleInline", e
);
1928 function scrollArticle(offset
) {
1931 var ci
= document
.getElementById("content-insert");
1933 ci
.scrollTop
+= offset
;
1936 var hi
= document
.getElementById("headlinesInnerContainer");
1938 hi
.scrollTop
+= offset
;
1943 exception_error("scrollArticle", e
);
1947 function show_labels_in_headlines(transport
) {
1949 if (transport
.responseXML
) {
1950 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1952 var elems
= info
.getElementsByTagName("entry");
1954 for (var l
= 0; l
< elems
.length
; l
++) {
1955 var e_id
= elems
[l
].getAttribute("id");
1959 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
1962 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1970 exception_error("show_labels_in_headlines", e
);
1975 function toggleHeadlineActions() {
1977 var e
= document
.getElementById("headlineActionsBody");
1978 var p
= document
.getElementById("headlineActionsDrop");
1980 if (!Element
.visible(e
)) {
1987 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1988 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
1991 exception_error("toggleHeadlineActions", e
);