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;
25 function catchup_callback() {
26 if (xmlhttp_rpc
.readyState
== 4) {
28 debug("catchup_callback");
30 all_counters_callback2(xmlhttp_rpc
);
31 if (_catchup_callback_func
) {
32 setTimeout(_catchup_callback_func
, 10);
35 exception_error("catchup_callback", e
);
40 function catchup_callback2(transport
, callback
) {
42 debug("catchup_callback2 " + transport
+ ", " + callback
);
44 all_counters_callback2(transport
);
46 setTimeout(callback
, 10);
49 exception_error("catchup_callback2", e
);
53 function clean_feed_selections() {
55 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
57 for (var i
= 0; i
< feeds
.length
; i
++) {
58 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
59 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
62 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
66 exception_error("clean_feed_selections", e
);
70 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
73 loading_set_progress(100);
75 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
77 clean_feed_selections();
79 setActiveFeedId(active_feed_id
);
81 if (is_cat
!= undefined) {
82 active_feed_is_cat
= is_cat
;
86 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
87 if (feedr
&& !feedr
.className
.match("Selected")) {
88 feedr
.className
= feedr
.className
+ "Selected";
91 var feedr
= document
.getElementById("FCAT-" + active_feed_id
);
92 if (feedr
&& !feedr
.className
.match("Selected")) {
93 feedr
.className
= feedr
.className
+ "Selected";
97 var f
= document
.getElementById("headlines-frame");
99 if (feed_cur_page
== 0) {
100 debug("resetting headlines scrollTop");
105 if (transport
.responseXML
) {
106 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
107 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
108 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
109 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
111 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
113 var headlines_count
= headlines_count_obj
.getAttribute("value");
114 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
115 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
117 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
119 if (headlines_count
== 0) {
120 _infscroll_disable
= 1;
122 _infscroll_disable
= 0;
125 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
126 var articles
= transport
.responseXML
.getElementsByTagName("article");
127 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
129 if (feed_cur_page
== 0) {
131 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
133 var cache_prefix
= "";
141 cache_invalidate(cache_prefix
+ active_feed_id
);
143 if (!disable_cache
) {
144 cache_inject(cache_prefix
+ active_feed_id
,
145 headlines
.firstChild
.nodeValue
, headlines_unread
);
149 debug("headlines_callback: returned no data");
150 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
155 if (headlines_count
> 0) {
156 debug("adding some more headlines...");
158 var c
= document
.getElementById("headlinesList");
161 c
= document
.getElementById("headlinesInnerContainer");
164 var ids
= getSelectedArticleIds2();
166 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
168 debug("restore selected ids: " + ids
);
170 for (var i
= 0; i
< ids
.length
; i
++) {
171 markHeadline(ids
[i
]);
177 debug("no new headlines received");
180 debug("headlines_callback: returned no data");
181 notify_error("Error while trying to load more headlines");
187 for (var i
= 0; i
< articles
.length
; i
++) {
188 var a_id
= articles
[i
].getAttribute("id");
189 debug("found id: " + a_id
);
190 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
193 debug("no cached articles received");
197 debug("parsing piggybacked counters: " + counters
);
198 parse_counters(counters
, false);
200 debug("counters container not found in reply, requesting...");
205 debug("parsing runtime info: " + runtime_info
[0]);
206 parse_runtime_info(runtime_info
[0]);
208 debug("counters container not found in reply");
212 debug("headlines_callback: returned no XML object");
213 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
216 if (typeof correctPNG
!= 'undefined') {
220 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
222 if (!document
.getElementById("headlinesList") &&
223 getInitParam("cdm_auto_catchup") == 1) {
224 debug("starting CDM watchdog");
225 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
226 _cdm_wd_vishist
= new Array();
228 debug("not in CDM mode or watchdog disabled");
231 if (_tag_cdm_scroll
) {
233 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
234 _tag_cdm_scroll
= false;
235 debug("resetting headlinesInner scrollTop");
240 _feed_cur_page
= feed_cur_page
;
241 _infscroll_request_sent
= 0;
248 exception_error("headlines_callback2", e
);
252 function render_article(article
) {
254 var f
= document
.getElementById("content-frame");
259 var fi
= document
.getElementById("content-insert");
261 fi
.innerHTML
= article
;
264 exception_error("render_article", e
);
268 function showArticleInHeadlines(id
) {
272 cleanSelected("headlinesList");
274 var crow
= document
.getElementById("RROW-" + id
);
278 var article_is_unread
= crow
.className
.match("Unread");
280 crow
.className
= crow
.className
.replace("Unread", "");
282 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
284 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
286 var cache_prefix
= "";
288 if (activeFeedIsCat()) {
294 var view_mode
= false;
297 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
298 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
300 exception_error("showArticleInHeadlines/viewmode", e
, true);
303 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
304 upd_img_pic
.src
= "images/blank_icon.gif";
306 cache_invalidate(cache_prefix
+ getActiveFeedId());
308 cache_inject(cache_prefix
+ getActiveFeedId(),
309 document
.getElementById("headlines-frame").innerHTML
,
310 get_feed_unread(getActiveFeedId()));
312 } else if (article_is_unread
&& view_mode
== "all_articles") {
314 cache_invalidate(cache_prefix
+ getActiveFeedId());
316 cache_inject(cache_prefix
+ getActiveFeedId(),
317 document
.getElementById("headlines-frame").innerHTML
,
318 get_feed_unread(getActiveFeedId())-1);
320 } else if (article_is_unread
) {
321 cache_invalidate(cache_prefix
+ getActiveFeedId());
327 exception_error("showArticleInHeadlines", e
);
331 function article_callback2(transport
, id
, feed_id
) {
333 debug("article_callback2 " + id
);
335 if (transport
.responseXML
) {
337 debug("looking for articles to cache...");
339 var articles
= transport
.responseXML
.getElementsByTagName("article");
341 for (var i
= 0; i
< articles
.length
; i
++) {
342 var a_id
= articles
[i
].getAttribute("id");
344 debug("found id: " + a_id
);
346 if (a_id
== active_post_id
) {
347 debug("active article, rendering...");
348 render_article(articles
[i
].firstChild
.nodeValue
);
351 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
354 if (id
!= last_requested_article
) {
355 debug("requested article id is out of sequence, aborting");
359 active_real_feed_id
= feed_id
;
362 showArticleInHeadlines(id
);
364 var reply
= transport
.responseXML
.firstChild
.firstChild
;
367 debug("article_callback: returned no XML object");
368 //var f = document.getElementById("content-frame");
369 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
372 var date
= new Date();
373 last_article_view
= date
.getTime() / 1000;
375 if (typeof correctPNG
!= 'undefined') {
379 if (_reload_feedlist_after_view
) {
380 setTimeout('updateFeedList(false, false)', 50);
381 _reload_feedlist_after_view
= false;
383 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
386 debug("parsing piggybacked counters: " + counters
);
387 parse_counters(counters
, false);
389 debug("counters container not found in reply, requesting...");
396 exception_error("article_callback2", e
);
400 function view(id
, feed_id
, skip_history
) {
403 debug("loading article: " + id
+ "/" + feed_id
);
405 var cached_article
= cache_find(id
);
407 debug("cache check result: " + (cached_article
!= false));
411 //setActiveFeedId(feed_id);
413 var query
= "backend.php?op=view&id=" + param_escape(id
) +
414 "&feed=" + param_escape(feed_id
);
416 var date
= new Date();
418 var neighbor_ids
= getRelativePostIds(active_post_id
);
420 /* only request uncached articles */
422 var cids_to_request
= Array();
424 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
425 if (!cache_check(neighbor_ids
[i
])) {
426 cids_to_request
.push(neighbor_ids
[i
]);
430 debug("additional ids: " + cids_to_request
.toString());
432 /* additional info for piggyback counters */
434 if (tagsAreDisplayed()) {
435 query
= query
+ "&omode=lt";
437 query
= query
+ "&omode=flc";
440 var date
= new Date();
441 var timestamp
= Math
.round(date
.getTime() / 1000);
442 query
= query
+ "&ts=" + timestamp
;
444 query
= query
+ "&cids=" + cids_to_request
.toString();
446 var crow
= document
.getElementById("RROW-" + id
);
447 var article_is_unread
= crow
.className
.match("Unread");
449 if (!async_counters_work
) {
450 query
= query
+ "&csync=true";
453 showArticleInHeadlines(id
);
455 if (!cached_article
) {
457 notify_progress("Loading, please wait...", true);
459 } else if (cached_article
&& article_is_unread
) {
461 query
= query
+ "&mode=prefetch";
463 render_article(cached_article
);
465 } else if (cached_article
) {
467 query
= query
+ "&mode=prefetch_old";
468 render_article(cached_article
);
474 last_requested_article
= id
;
476 new Ajax
.Request(query
, {
477 onComplete: function(transport
) {
478 article_callback2(transport
, id
, feed_id
);
484 exception_error("view", e
);
489 return toggleMark(id
);
493 return togglePub(id
);
496 function tMark_afh_off(effect
) {
498 var elem
= effect
.effects
[0].element
;
500 debug("tMark_afh_off : " + elem
.id
);
503 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
504 elem
.alt
= __("Star article");
509 exception_error("tMark_afh_off", e
);
513 function tPub_afh_off(effect
) {
515 var elem
= effect
.effects
[0].element
;
517 debug("tPub_afh_off : " + elem
.id
);
520 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
521 elem
.alt
= __("Publish article");
526 exception_error("tPub_afh_off", e
);
530 function toggleMark(id
, client_only
, no_effects
) {
534 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
536 query
= query
+ "&afid=" + getActiveFeedId();
538 if (tagsAreDisplayed()) {
539 query
= query
+ "&omode=tl";
541 query
= query
+ "&omode=flc";
544 var mark_img
= document
.getElementById("FMPIC-" + id
);
545 var vfeedu
= document
.getElementById("FEEDU--1");
546 var crow
= document
.getElementById("RROW-" + id
);
548 if (mark_img
.src
.match("mark_unset")) {
549 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
550 mark_img
.alt
= __("Unstar article");
551 query
= query
+ "&mark=1";
554 //mark_img.src = "images/mark_unset.png";
555 mark_img
.alt
= __("Please wait...");
556 query
= query
+ "&mark=0";
558 if (document
.getElementById("headlinesList") && !no_effects
) {
559 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
561 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
562 mark_img
.alt
= __("Star article");
569 new Ajax
.Request(query
, {
570 onComplete: function(transport
) {
571 all_counters_callback2(transport
);
577 exception_error("toggleMark", e
);
581 function togglePub(id
, client_only
, no_effects
) {
585 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
587 query
= query
+ "&afid=" + getActiveFeedId();
589 if (tagsAreDisplayed()) {
590 query
= query
+ "&omode=tl";
592 query
= query
+ "&omode=flc";
595 var mark_img
= document
.getElementById("FPPIC-" + id
);
596 var vfeedu
= document
.getElementById("FEEDU--2");
597 var crow
= document
.getElementById("RROW-" + id
);
599 if (mark_img
.src
.match("pub_unset")) {
600 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
601 mark_img
.alt
= __("Unpublish article");
602 query
= query
+ "&pub=1";
606 //mark_img.src = "images/pub_unset.png";
607 mark_img
.alt
= __("Please wait...");
608 query
= query
+ "&pub=0";
610 if (document
.getElementById("headlinesList") && !no_effects
) {
611 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
613 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
614 mark_img
.alt
= __("Publish article");
619 new Ajax
.Request(query
, {
620 onComplete: function(transport
) {
621 all_counters_callback2(transport
);
627 exception_error("togglePub", e
);
631 function correctHeadlinesOffset(id
) {
635 var hlist
= document
.getElementById("headlinesList");
636 var container
= document
.getElementById("headlinesInnerContainer");
637 var row
= document
.getElementById("RROW-" + id
);
639 var viewport
= container
.offsetHeight
;
641 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
642 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
644 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
645 debug("Vport: " + viewport
);
647 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
648 container
.scrollTop
= row
.offsetTop
;
649 } else if (rel_offset_bottom
> viewport
) {
651 /* doesn't properly work with Opera in some cases because
652 Opera fucks up element scrolling */
654 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
658 exception_error("correctHeadlinesOffset", e
);
663 function moveToPost(mode
) {
670 rows
= cdmGetVisibleArticles();
672 rows
= getVisibleHeadlineIds();
678 if (!document
.getElementById('RROW-' + active_post_id
)) {
679 active_post_id
= false;
682 if (active_post_id
== false) {
683 next_id
= getFirstVisibleHeadlineId();
684 prev_id
= getLastVisibleHeadlineId();
686 for (var i
= 0; i
< rows
.length
; i
++) {
687 if (rows
[i
] == active_post_id
) {
694 if (mode
== "next") {
698 if (!cdmArticleIsActuallyVisible(next_id
)) {
699 cdmScrollToArticleId(next_id
);
701 cdmSelectArticles("none");
702 toggleUnread(next_id
, 0, true);
703 toggleSelected(next_id
);
706 correctHeadlinesOffset(next_id
);
707 view(next_id
, getActiveFeedId());
712 if (mode
== "prev") {
715 cdmScrollToArticleId(prev_id
);
716 cdmSelectArticles("none");
717 toggleUnread(prev_id
, 0, true);
718 toggleSelected(prev_id
);
720 correctHeadlinesOffset(prev_id
);
721 view(prev_id
, getActiveFeedId());
727 exception_error("moveToPost", e
);
731 function toggleSelected(id
) {
734 var cb
= document
.getElementById("RCHK-" + id
);
736 var row
= document
.getElementById("RROW-" + id
);
738 var nc
= row
.className
;
740 if (!nc
.match("Selected")) {
741 nc
= nc
+ "Selected";
746 // In CDM basically last selected article == active article
747 if (isCdmMode()) active_post_id
= id
;
749 nc
= nc
.replace("Selected", "");
759 exception_error("toggleSelected", e
);
763 function toggleUnread_afh(effect
) {
766 var elem
= effect
.element
;
767 elem
.style
.backgroundColor
= "";
770 exception_error("toggleUnread_afh", e
);
774 function toggleUnread(id
, cmode
, effect
) {
777 var row
= document
.getElementById("RROW-" + id
);
779 var nc
= row
.className
;
780 var is_selected
= row
.className
.match("Selected");
781 nc
= nc
.replace("Unread", "");
782 nc
= nc
.replace("Selected", "");
784 // since we are removing selection from the object, uncheck
785 // corresponding checkbox
787 var cb
= document
.getElementById("RCHK-" + id
);
792 // NOTE: I'm not sure that resetting selection here is a feature -fox
794 if (cmode
== undefined || cmode
== 2) {
795 if (row
.className
.match("Unread")) {
799 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
800 afterFinish
: toggleUnread_afh
,
801 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
805 row
.className
= nc
+ "Unread";
807 } else if (cmode
== 0) {
811 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
812 afterFinish
: toggleUnread_afh
,
813 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
815 } else if (cmode
== 1) {
816 row
.className
= nc
+ "Unread";
819 // Disable unmarking as selected for the time being (16.05.08) -fox
820 if (is_selected
) row
.className
= row
.className
+ "Selected";
822 if (cmode
== undefined) cmode
= 2;
824 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
825 param_escape(id
) + "&cmode=" + param_escape(cmode
);
827 // notify_progress("Loading, please wait...");
829 new Ajax
.Request(query
, {
830 onComplete: function(transport
) {
831 all_counters_callback2(transport
);
838 exception_error("toggleUnread", e
);
842 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
847 rows
= cdmGetSelectedArticles();
849 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
852 if (rows
.length
== 0 && !no_error
) {
853 alert(__("No articles are selected."));
857 for (i
= 0; i
< rows
.length
; i
++) {
858 var row
= document
.getElementById("RROW-" + rows
[i
]);
860 var nc
= row
.className
;
861 nc
= nc
.replace("Unread", "");
862 nc
= nc
.replace("Selected", "");
864 if (set_state
== undefined) {
865 if (row
.className
.match("Unread")) {
866 row
.className
= nc
+ "Selected";
868 row
.className
= nc
+ "UnreadSelected";
872 if (set_state
== false) {
873 row
.className
= nc
+ "Selected";
876 if (set_state
== true) {
877 row
.className
= nc
+ "UnreadSelected";
882 if (rows
.length
> 0) {
886 if (set_state
== undefined) {
888 } else if (set_state
== true) {
890 } else if (set_state
== false) {
894 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
895 param_escape(rows
.toString()) + "&cmode=" + cmode
;
897 notify_progress("Loading, please wait...");
899 new Ajax
.Request(query
, {
900 onComplete: function(transport
) {
901 catchup_callback2(transport
, callback_func
);
907 exception_error("selectionToggleUnread", e
);
911 function selectionToggleMarked(cdm_mode
) {
917 rows
= cdmGetSelectedArticles();
919 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
922 if (rows
.length
== 0) {
923 alert(__("No articles are selected."));
927 for (i
= 0; i
< rows
.length
; i
++) {
928 toggleMark(rows
[i
], true, true);
931 if (rows
.length
> 0) {
933 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
934 param_escape(rows
.toString()) + "&cmode=2";
936 query
= query
+ "&afid=" + getActiveFeedId();
938 /* if (tagsAreDisplayed()) {
939 query = query + "&omode=tl";
941 query = query + "&omode=flc";
944 query
= query
+ "&omode=lc";
946 new Ajax
.Request(query
, {
947 onComplete: function(transport
) {
948 all_counters_callback2(transport
);
954 exception_error("selectionToggleMarked", e
);
958 function selectionTogglePublished(cdm_mode
) {
964 rows
= cdmGetSelectedArticles();
966 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
969 if (rows
.length
== 0) {
970 alert(__("No articles are selected."));
974 for (i
= 0; i
< rows
.length
; i
++) {
975 togglePub(rows
[i
], true, true);
978 if (rows
.length
> 0) {
980 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
981 param_escape(rows
.toString()) + "&cmode=2";
983 query
= query
+ "&afid=" + getActiveFeedId();
985 /* if (tagsAreDisplayed()) {
986 query = query + "&omode=tl";
988 query = query + "&omode=flc";
991 query
= query
+ "&omode=lc";
993 new Ajax
.Request(query
, {
994 onComplete: function(transport
) {
995 all_counters_callback2(transport
);
1001 exception_error("selectionToggleMarked", e
);
1005 function cdmGetSelectedArticles() {
1006 var sel_articles
= new Array();
1007 var container
= document
.getElementById("headlinesInnerContainer");
1009 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1010 var child
= container
.childNodes
[i
];
1012 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1013 var c_id
= child
.id
.replace("RROW-", "");
1014 sel_articles
.push(c_id
);
1018 return sel_articles
;
1021 function cdmGetVisibleArticles() {
1022 var sel_articles
= new Array();
1023 var container
= document
.getElementById("headlinesInnerContainer");
1025 if (!container
) return sel_articles
;
1027 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1028 var child
= container
.childNodes
[i
];
1030 if (child
.id
&& child
.id
.match("RROW-")) {
1031 var c_id
= child
.id
.replace("RROW-", "");
1032 sel_articles
.push(c_id
);
1036 return sel_articles
;
1039 function cdmGetUnreadArticles() {
1040 var sel_articles
= new Array();
1041 var container
= document
.getElementById("headlinesInnerContainer");
1043 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1044 var child
= container
.childNodes
[i
];
1046 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1047 var c_id
= child
.id
.replace("RROW-", "");
1048 sel_articles
.push(c_id
);
1052 return sel_articles
;
1056 // mode = all,none,unread
1057 function cdmSelectArticles(mode
) {
1058 var container
= document
.getElementById("headlinesInnerContainer");
1060 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1061 var child
= container
.childNodes
[i
];
1063 if (child
.id
&& child
.id
.match("RROW-")) {
1064 var aid
= child
.id
.replace("RROW-", "");
1066 var cb
= document
.getElementById("RCHK-" + aid
);
1068 if (mode
== "all") {
1069 if (!child
.className
.match("Selected")) {
1070 child
.className
= child
.className
+ "Selected";
1073 } else if (mode
== "unread") {
1074 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1075 child
.className
= child
.className
+ "Selected";
1079 child
.className
= child
.className
.replace("Selected", "");
1086 function catchupPage() {
1088 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1090 var str
= __("Mark all visible articles in %s as read?");
1092 str
= str
.replace("%s", fn
);
1094 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1098 if (document
.getElementById("headlinesList")) {
1099 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1100 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1101 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1103 cdmSelectArticles('all');
1104 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1105 cdmSelectArticles('none');
1109 function catchupSelection() {
1115 if (document
.getElementById("headlinesList")) {
1116 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1118 rows
= cdmGetSelectedArticles();
1121 if (rows
.length
== 0) {
1122 alert(__("No articles are selected."));
1127 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1129 var str
= __("Mark %d selected articles in %s as read?");
1131 str
= str
.replace("%d", rows
.length
);
1132 str
= str
.replace("%s", fn
);
1134 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1138 if (document
.getElementById("headlinesList")) {
1139 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1140 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1142 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1143 // cdmSelectArticles('none');
1147 exception_error("catchupSelection", e
);
1152 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1154 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1155 printLockingError();
1158 var title
= prompt(__("Please enter label title:"), "");
1162 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1163 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1164 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1165 "&title=" + param_escape(title
);
1167 debug("LFS: " + query
);
1169 new Ajax
.Request(query
, {
1170 onComplete: function(transport
) {
1171 dlg_frefresh_callback(transport
);
1176 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1177 _tag_active_post_id
= id
;
1178 _tag_active_feed_id
= feed_id
;
1179 _tag_active_cdm
= cdm_enabled
;
1181 cache_invalidate(id
);
1184 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1186 displayDlg('editArticleTags', id
);
1190 function tag_saved_callback(transport
) {
1192 debug("in tag_saved_callback");
1197 if (tagsAreDisplayed()) {
1198 _reload_feedlist_after_view
= true;
1201 if (!_tag_active_cdm
) {
1202 if (active_post_id
== _tag_active_post_id
) {
1203 debug("reloading current article");
1204 view(_tag_active_post_id
, _tag_active_feed_id
);
1207 debug("reloading current feed");
1212 exception_error("catchup_callback", e
);
1216 function editTagsSave() {
1218 notify_progress("Saving article tags...");
1220 var form
= document
.forms
["tag_edit_form"];
1222 var query
= Form
.serialize("tag_edit_form");
1224 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1228 new Ajax
.Request(query
, {
1229 onComplete: function(transport
) {
1230 tag_saved_callback(transport
);
1235 function editTagsInsert() {
1238 var form
= document
.forms
["tag_edit_form"];
1240 var found_tags
= form
.found_tags
;
1241 var tags_str
= form
.tags_str
;
1243 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1245 if (tags_str
.value
.length
> 0 &&
1246 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1248 tags_str
.value
= tags_str
.value
+ ", ";
1251 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1253 found_tags
.selectedIndex
= 0;
1256 exception_error("editTagsInsert", e
);
1260 function cdmScrollViewport(where
) {
1261 debug("cdmScrollViewport: " + where
);
1263 var ctr
= document
.getElementById("headlinesInnerContainer");
1267 if (where
== "bottom") {
1268 ctr
.scrollTop
= ctr
.scrollHeight
;
1270 ctr
.scrollTop
= where
;
1274 function cdmArticleIsBelowViewport(id
) {
1276 var ctr
= document
.getElementById("headlinesInnerContainer");
1277 var e
= document
.getElementById("RROW-" + id
);
1279 if (!e
|| !ctr
) return;
1281 // article starts below viewport
1283 if (ctr
.scrollTop
< e
.offsetTop
) {
1290 exception_error("cdmArticleIsVisible", e
);
1294 function cdmArticleIsAboveViewport(id
) {
1296 var ctr
= document
.getElementById("headlinesInnerContainer");
1297 var e
= document
.getElementById("RROW-" + id
);
1299 if (!e
|| !ctr
) return;
1301 // article starts above viewport
1303 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1310 exception_error("cdmArticleIsVisible", e
);
1314 function cdmScrollToArticleId(id
) {
1316 var ctr
= document
.getElementById("headlinesInnerContainer");
1317 var e
= document
.getElementById("RROW-" + id
);
1319 if (!e
|| !ctr
) return;
1321 ctr
.scrollTop
= e
.offsetTop
;
1324 exception_error("cdmScrollToArticleId", e
);
1328 function cdmArticleIsActuallyVisible(id
) {
1330 var ctr
= document
.getElementById("headlinesInnerContainer");
1331 var e
= document
.getElementById("RROW-" + id
);
1333 if (!e
|| !ctr
) return;
1335 // article fits in viewport OR article is longer than viewport and
1336 // its bottom is visible
1338 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1339 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1343 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1344 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1345 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1354 exception_error("cdmArticleIsVisible", e
);
1358 function cdmWatchdog() {
1362 var ctr
= document
.getElementById("headlinesInnerContainer");
1366 var ids
= new Array();
1368 var e
= ctr
.firstChild
;
1371 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1372 e
.id
.match("RROW-")) {
1374 // article fits in viewport OR article is longer than viewport and
1375 // its bottom is visible
1377 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1378 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1380 // debug(e.id + " is visible " + e.offsetTop + "." +
1381 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1382 // (ctr.scrollTop + ctr.offsetHeight));
1384 ids
.push(e
.id
.replace("RROW-", ""));
1386 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1387 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1388 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1390 ids
.push(e
.id
.replace("RROW-", ""));
1394 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1396 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1397 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1399 ids.push(e.id.replace("RROW-", ""));
1408 debug("cdmWatchdog, ids= " + ids
.toString());
1410 if (ids
.length
> 0) {
1412 for (var i
= 0; i
< ids
.length
; i
++) {
1413 var e
= document
.getElementById("RROW-" + ids
[i
]);
1415 e
.className
= e
.className
.replace("Unread", "");
1419 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1420 param_escape(ids
.toString()) + "&cmode=0";
1422 new Ajax
.Request(query
, {
1423 onComplete: function(transport
) {
1424 all_counters_callback2(transport
);
1429 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1432 exception_error("cdmWatchdog", e
);
1438 function cache_inject(id
, article
, param
) {
1439 if (!cache_check_param(id
, param
)) {
1440 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1442 var cache_obj
= new Array();
1444 cache_obj
["id"] = id
;
1445 cache_obj
["data"] = article
;
1446 cache_obj
["param"] = param
;
1448 article_cache
.push(cache_obj
);
1451 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1455 function cache_find(id
) {
1456 for (var i
= 0; i
< article_cache
.length
; i
++) {
1457 if (article_cache
[i
]["id"] == id
) {
1458 return article_cache
[i
]["data"];
1464 function cache_find_param(id
, param
) {
1465 for (var i
= 0; i
< article_cache
.length
; i
++) {
1466 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1467 return article_cache
[i
]["data"];
1473 function cache_check(id
) {
1474 for (var i
= 0; i
< article_cache
.length
; i
++) {
1475 if (article_cache
[i
]["id"] == id
) {
1482 function cache_check_param(id
, param
) {
1483 for (var i
= 0; i
< article_cache
.length
; i
++) {
1485 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1486 // article_cache[i]["param"] + " vs " + id + ":" + param);
1488 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1495 function cache_expire() {
1496 while (article_cache
.length
> 25) {
1497 article_cache
.shift();
1501 function cache_empty() {
1502 article_cache
= new Array();
1505 function cache_invalidate(id
) {
1510 while (i
< article_cache
.length
) {
1511 if (article_cache
[i
]["id"] == id
) {
1512 debug("cache_invalidate: removed id " + id
);
1513 article_cache
.splice(i
, 1);
1518 debug("cache_invalidate: id not found: " + id
);
1521 exception_error("cache_invalidate", e
);
1525 function getActiveArticleId() {
1526 return active_post_id
;
1529 function cdmClicked(id
) {
1531 var elem
= document
.getElementById("RROW-" + id
);
1534 var id
= elem
.id
.replace("RROW-", "");
1535 active_post_id
= id
;
1537 cdmSelectArticles("none");
1538 toggleUnread(id
, 0, true);
1543 exception_error("cdmClicked", e
);
1547 function preload_article_callback(transport
) {
1549 if (transport
.responseXML
) {
1550 var articles
= transport
.responseXML
.getElementsByTagName("article");
1552 for (var i
= 0; i
< articles
.length
; i
++) {
1553 var id
= articles
[i
].getAttribute("id");
1554 if (!cache_check(id
)) {
1555 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1556 debug("preloaded article: " + id
);
1561 exception_error("preload_article_callback", e
);
1565 function preloadArticleUnderPointer(id
) {
1567 if (getInitParam("bw_limit") == "1") return;
1569 if (post_under_pointer
== id
&& !cache_check(id
)) {
1571 debug("trying to preload article " + id
);
1573 var neighbor_ids
= getRelativePostIds(id
, 1);
1575 /* only request uncached articles */
1577 var cids_to_request
= Array();
1579 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1580 if (!cache_check(neighbor_ids
[i
])) {
1581 cids_to_request
.push(neighbor_ids
[i
]);
1584 debug("additional ids: " + cids_to_request
.toString());
1586 cids_to_request
.push(id
);
1588 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1589 cids_to_request
.toString();
1590 new Ajax
.Request(query
, {
1591 onComplete: function(transport
) {
1592 preload_article_callback(transport
);
1596 exception_error("preloadArticleUnderPointer", e
);
1600 function postMouseIn(id
) {
1602 if (post_under_pointer
!= id
) {
1603 post_under_pointer
= id
;
1605 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1610 exception_error("postMouseIn", e
);
1614 function postMouseOut(id
) {
1616 post_under_pointer
= false;
1618 exception_error("postMouseOut", e
);
1622 function headlines_scroll_handler() {
1625 var e
= document
.getElementById("headlinesInnerContainer");
1627 // don't do infinite scrolling when Limit == All
1629 var toolbar_form
= document
.forms
["main_toolbar_form"];
1631 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1632 if (limit
.value
!= 0) {
1634 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1635 _infscroll_disable
);
1637 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1638 if (!_infscroll_disable
) {
1639 debug("more cowbell!");
1646 exception_error("headlines_scroll_handler", e
);
1650 function catchupRelativeToArticle(below
) {
1654 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1655 printLockingError();
1658 if (!getActiveArticleId()) {
1659 alert(__("No article is selected."));
1665 if (document
.getElementById("headlinesList")) {
1666 visible_ids
= getVisibleHeadlineIds();
1668 visible_ids
= cdmGetVisibleArticles();
1671 var ids_to_mark
= new Array();
1674 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1675 if (visible_ids
[i
] != getActiveArticleId()) {
1676 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1678 if (e
&& e
.className
.match("Unread")) {
1679 ids_to_mark
.push(visible_ids
[i
]);
1686 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1687 if (visible_ids
[i
] != getActiveArticleId()) {
1688 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1690 if (e
&& e
.className
.match("Unread")) {
1691 ids_to_mark
.push(visible_ids
[i
]);
1699 if (ids_to_mark
.length
== 0) {
1700 alert(__("No articles found to mark"));
1702 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1706 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1707 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1708 e
.className
= e
.className
.replace("Unread", "");
1711 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1712 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1714 new Ajax
.Request(query
, {
1715 onComplete: function(transport
) {
1716 catchup_callback2(transport
);
1723 exception_error("catchupRelativeToArticle", e
);
1727 function cdmExpandArticle(a_id
) {
1729 var id
= 'CICD-' + a_id
;
1732 Element
.hide("CEXC-" + a_id
);
1735 Effect
.Appear(id
, {duration
: 0.5,
1736 beforeStart: function(effect
) {
1737 var h_id
= 'CICH-' + a_id
;
1738 var h_elem
= document
.getElementById(h_id
);
1739 if (h_elem
) { h_elem
.style
.display
= "none"; }
1741 toggleUnread(a_id
, 0);
1746 exception_error("appearBlockElementF", e
);
1751 function fixHeadlinesOrder(ids
) {
1753 for (var i
= 0; i
< ids
.length
; i
++) {
1754 var e
= document
.getElementById("RROW-" + ids
[i
]);
1758 e
.className
= e
.className
.replace("even", "odd");
1760 e
.className
= e
.className
.replace("odd", "even");
1765 exception_error("fixHeadlinesOrder", e
);
1769 function subtoolbarSearch() {
1772 var q
= document
.getElementById("subtoolbar_search_box");
1776 q
= q
.value
.toUpperCase();
1779 var vis_ids
= new Array();
1781 if (document
.getElementById("headlinesList")) {
1782 ids
= getVisibleHeadlineIds();
1784 ids
= cdmGetVisibleArticles();
1787 for (var i
= 0; i
< ids
.length
; i
++) {
1788 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1791 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1792 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1794 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1795 vis_ids
.push(ids
[i
]);
1800 fixHeadlinesOrder(vis_ids
);
1803 exception_error("subtoolbarSearch", e
);
1807 function hideReadHeadlines() {
1811 var vis_ids
= new Array();
1813 if (document
.getElementById("headlinesList")) {
1814 ids
= getVisibleHeadlineIds();
1816 ids
= cdmGetVisibleArticles();
1819 var read_headlines_visible
= true;
1821 for (var i
= 0; i
< ids
.length
; i
++) {
1822 var row
= document
.getElementById("RROW-" + ids
[i
]);
1824 if (row
&& row
.className
) {
1825 if (read_headlines_visible
) {
1826 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1828 vis_ids
.push(ids
[i
]);
1830 //Effect.Fade(row, {duration : 0.3});
1835 vis_ids
.push(ids
[i
]);
1840 fixHeadlinesOrder(vis_ids
);
1842 read_headlines_visible
= !read_headlines_visible
;
1845 exception_error("hideReadHeadlines", e
);
1849 function getArticleUnderPointer() {
1850 return post_under_pointer
;