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", "");
63 exception_error("clean_feed_selections", e
);
67 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
70 loading_set_progress(100);
72 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
74 clean_feed_selections();
76 setActiveFeedId(active_feed_id
);
78 if (is_cat
!= undefined) {
79 active_feed_is_cat
= is_cat
;
83 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
84 if (feedr
&& !feedr
.className
.match("Selected")) {
85 feedr
.className
= feedr
.className
+ "Selected";
89 var f
= document
.getElementById("headlines-frame");
91 if (feed_cur_page
== 0) {
92 debug("resetting headlines scrollTop");
97 if (transport
.responseXML
) {
98 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
99 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
100 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
101 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
103 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
105 var headlines_count
= headlines_count_obj
.getAttribute("value");
106 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
107 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
109 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
111 if (headlines_count
== 0) {
112 _infscroll_disable
= 1;
114 _infscroll_disable
= 0;
117 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
118 var articles
= transport
.responseXML
.getElementsByTagName("article");
119 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
121 if (feed_cur_page
== 0) {
123 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
125 var cache_prefix
= "";
133 cache_invalidate(cache_prefix
+ active_feed_id
);
135 if (!disable_cache
) {
136 cache_inject(cache_prefix
+ active_feed_id
,
137 headlines
.firstChild
.nodeValue
, headlines_unread
);
141 debug("headlines_callback: returned no data");
142 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
147 if (headlines_count
> 0) {
148 debug("adding some more headlines...");
150 var c
= document
.getElementById("headlinesList");
153 c
= document
.getElementById("headlinesInnerContainer");
156 var ids
= getSelectedArticleIds2();
158 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
160 debug("restore selected ids: " + ids
);
162 for (var i
= 0; i
< ids
.length
; i
++) {
163 markHeadline(ids
[i
]);
169 debug("no new headlines received");
172 debug("headlines_callback: returned no data");
173 notify_error("Error while trying to load more headlines");
179 for (var i
= 0; i
< articles
.length
; i
++) {
180 var a_id
= articles
[i
].getAttribute("id");
181 debug("found id: " + a_id
);
182 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
185 debug("no cached articles received");
189 debug("parsing piggybacked counters: " + counters
);
190 parse_counters(counters
, false);
192 debug("counters container not found in reply, requesting...");
197 debug("parsing runtime info: " + runtime_info
[0]);
198 parse_runtime_info(runtime_info
[0]);
200 debug("counters container not found in reply");
204 debug("headlines_callback: returned no XML object");
205 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
208 if (typeof correctPNG
!= 'undefined') {
212 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
214 if (!document
.getElementById("headlinesList") &&
215 getInitParam("cdm_auto_catchup") == 1) {
216 debug("starting CDM watchdog");
217 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
218 _cdm_wd_vishist
= new Array();
220 debug("not in CDM mode or watchdog disabled");
223 if (_tag_cdm_scroll
) {
225 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
226 _tag_cdm_scroll
= false;
227 debug("resetting headlinesInner scrollTop");
232 _feed_cur_page
= feed_cur_page
;
233 _infscroll_request_sent
= 0;
240 exception_error("headlines_callback2", e
);
244 function render_article(article
) {
246 var f
= document
.getElementById("content-frame");
251 f
.innerHTML
= article
;
254 exception_error("render_article", e
);
258 function showArticleInHeadlines(id
) {
262 cleanSelected("headlinesList");
264 var crow
= document
.getElementById("RROW-" + id
);
268 var article_is_unread
= crow
.className
.match("Unread");
270 crow
.className
= crow
.className
.replace("Unread", "");
272 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
274 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
276 var cache_prefix
= "";
278 if (activeFeedIsCat()) {
284 var view_mode
= false;
287 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
288 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
290 exception_error("showArticleInHeadlines/viewmode", e
, true);
293 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
294 upd_img_pic
.src
= "images/blank_icon.gif";
296 cache_invalidate(cache_prefix
+ getActiveFeedId());
298 cache_inject(cache_prefix
+ getActiveFeedId(),
299 document
.getElementById("headlines-frame").innerHTML
,
300 get_feed_unread(getActiveFeedId()));
302 } else if (article_is_unread
&& view_mode
== "all_articles") {
304 cache_invalidate(cache_prefix
+ getActiveFeedId());
306 cache_inject(cache_prefix
+ getActiveFeedId(),
307 document
.getElementById("headlines-frame").innerHTML
,
308 get_feed_unread(getActiveFeedId())-1);
310 } else if (article_is_unread
) {
311 cache_invalidate(cache_prefix
+ getActiveFeedId());
317 exception_error("showArticleInHeadlines", e
);
321 function article_callback2(transport
, id
, feed_id
) {
323 debug("article_callback2 " + id
);
325 if (id
!= last_requested_article
) return;
327 if (transport
.responseXML
) {
329 active_real_feed_id
= feed_id
;
332 showArticleInHeadlines(id
);
334 var reply
= transport
.responseXML
.firstChild
.firstChild
;
336 var articles
= transport
.responseXML
.getElementsByTagName("article");
338 for (var i
= 0; i
< articles
.length
; i
++) {
339 var a_id
= articles
[i
].getAttribute("id");
341 debug("found id: " + a_id
);
343 if (a_id
== active_post_id
) {
344 debug("active article, rendering...");
345 render_article(articles
[i
].firstChild
.nodeValue
);
348 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
352 debug("article_callback: returned no XML object");
353 var f
= document
.getElementById("content-frame");
354 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
357 var date
= new Date();
358 last_article_view
= date
.getTime() / 1000;
360 if (typeof correctPNG
!= 'undefined') {
364 if (_reload_feedlist_after_view
) {
365 setTimeout('updateFeedList(false, false)', 50);
366 _reload_feedlist_after_view
= false;
368 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
371 debug("parsing piggybacked counters: " + counters
);
372 parse_counters(counters
, false);
374 debug("counters container not found in reply, requesting...");
381 exception_error("article_callback2", e
);
385 function view(id
, feed_id
, skip_history
) {
388 debug("loading article: " + id
+ "/" + feed_id
);
390 var cached_article
= cache_find(id
);
392 debug("cache check result: " + (cached_article
!= false));
396 //setActiveFeedId(feed_id);
398 var query
= "backend.php?op=view&id=" + param_escape(id
) +
399 "&feed=" + param_escape(feed_id
);
401 var date
= new Date();
403 var neighbor_ids
= getRelativePostIds(active_post_id
);
405 /* only request uncached articles */
407 var cids_to_request
= Array();
409 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
410 if (!cache_check(neighbor_ids
[i
])) {
411 cids_to_request
.push(neighbor_ids
[i
]);
415 debug("additional ids: " + cids_to_request
.toString());
417 /* additional info for piggyback counters */
419 if (tagsAreDisplayed()) {
420 query
= query
+ "&omode=lt";
422 query
= query
+ "&omode=flc";
425 var date
= new Date();
426 var timestamp
= Math
.round(date
.getTime() / 1000);
427 query
= query
+ "&ts=" + timestamp
;
429 query
= query
+ "&cids=" + cids_to_request
.toString();
431 var crow
= document
.getElementById("RROW-" + id
);
432 var article_is_unread
= crow
.className
.match("Unread");
434 if (!cached_article
) {
436 notify_progress("Loading, please wait...");
438 } else if (cached_article
&& article_is_unread
) {
440 query
= query
+ "&mode=prefetch";
442 showArticleInHeadlines(id
);
443 render_article(cached_article
);
445 } else if (cached_article
) {
447 query
= query
+ "&mode=prefetch_old";
448 render_article(cached_article
);
449 showArticleInHeadlines(id
);
455 last_requested_article
= id
;
457 new Ajax
.Request(query
, {
458 onComplete: function(transport
) {
459 article_callback2(transport
, id
, feed_id
);
463 exception_error("view", e
);
468 return toggleMark(id
);
472 return togglePub(id
);
475 function tMark_afh_off(effect
) {
477 var elem
= effect
.effects
[0].element
;
479 debug("tMark_afh_off : " + elem
.id
);
482 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
483 elem
.alt
= __("Star article");
488 exception_error("tMark_afh_off", e
);
492 function tPub_afh_off(effect
) {
494 var elem
= effect
.effects
[0].element
;
496 debug("tPub_afh_off : " + elem
.id
);
499 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
500 elem
.alt
= __("Publish article");
505 exception_error("tPub_afh_off", e
);
509 function toggleMark(id
, client_only
, no_effects
) {
513 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
515 query
= query
+ "&afid=" + getActiveFeedId();
517 if (tagsAreDisplayed()) {
518 query
= query
+ "&omode=tl";
520 query
= query
+ "&omode=flc";
523 var mark_img
= document
.getElementById("FMPIC-" + id
);
524 var vfeedu
= document
.getElementById("FEEDU--1");
525 var crow
= document
.getElementById("RROW-" + id
);
527 if (mark_img
.src
.match("mark_unset")) {
528 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
529 mark_img
.alt
= __("Unstar article");
530 query
= query
+ "&mark=1";
533 //mark_img.src = "images/mark_unset.png";
534 mark_img
.alt
= __("Please wait...");
535 query
= query
+ "&mark=0";
537 if (document
.getElementById("headlinesList") && !no_effects
) {
538 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
540 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
541 mark_img
.alt
= __("Star article");
548 new Ajax
.Request(query
, {
549 onComplete: function(transport
) {
550 all_counters_callback2(transport
);
556 exception_error("toggleMark", e
);
560 function togglePub(id
, client_only
, no_effects
) {
564 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
566 query
= query
+ "&afid=" + getActiveFeedId();
568 if (tagsAreDisplayed()) {
569 query
= query
+ "&omode=tl";
571 query
= query
+ "&omode=flc";
574 var mark_img
= document
.getElementById("FPPIC-" + id
);
575 var vfeedu
= document
.getElementById("FEEDU--2");
576 var crow
= document
.getElementById("RROW-" + id
);
578 if (mark_img
.src
.match("pub_unset")) {
579 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
580 mark_img
.alt
= __("Unpublish article");
581 query
= query
+ "&pub=1";
585 //mark_img.src = "images/pub_unset.png";
586 mark_img
.alt
= __("Please wait...");
587 query
= query
+ "&pub=0";
589 if (document
.getElementById("headlinesList") && !no_effects
) {
590 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
592 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
593 mark_img
.alt
= __("Publish article");
598 new Ajax
.Request(query
, {
599 onComplete: function(transport
) {
600 all_counters_callback2(transport
);
606 exception_error("togglePub", e
);
610 function correctHeadlinesOffset(id
) {
614 var hlist
= document
.getElementById("headlinesList");
615 var container
= document
.getElementById("headlinesInnerContainer");
616 var row
= document
.getElementById("RROW-" + id
);
618 var viewport
= container
.offsetHeight
;
620 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
621 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
623 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
624 debug("Vport: " + viewport
);
626 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
627 container
.scrollTop
= row
.offsetTop
;
628 } else if (rel_offset_bottom
> viewport
) {
630 /* doesn't properly work with Opera in some cases because
631 Opera fucks up element scrolling */
633 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
637 exception_error("correctHeadlinesOffset", e
);
642 function moveToPost(mode
) {
649 rows
= cdmGetVisibleArticles();
651 rows
= getVisibleHeadlineIds();
657 if (!document
.getElementById('RROW-' + active_post_id
)) {
658 active_post_id
= false;
661 if (active_post_id
== false) {
662 next_id
= getFirstVisibleHeadlineId();
663 prev_id
= getLastVisibleHeadlineId();
665 for (var i
= 0; i
< rows
.length
; i
++) {
666 if (rows
[i
] == active_post_id
) {
673 if (mode
== "next") {
677 if (!cdmArticleIsActuallyVisible(next_id
)) {
678 cdmScrollToArticleId(next_id
);
680 cdmSelectArticles("none");
681 toggleUnread(next_id
, 0, true);
682 toggleSelected(next_id
);
685 correctHeadlinesOffset(next_id
);
686 view(next_id
, getActiveFeedId());
691 if (mode
== "prev") {
694 cdmScrollToArticleId(prev_id
);
695 cdmSelectArticles("none");
696 toggleUnread(prev_id
, 0, true);
697 toggleSelected(prev_id
);
699 correctHeadlinesOffset(prev_id
);
700 view(prev_id
, getActiveFeedId());
706 exception_error("moveToPost", e
);
710 function toggleSelected(id
) {
713 var cb
= document
.getElementById("RCHK-" + id
);
715 var row
= document
.getElementById("RROW-" + id
);
717 var nc
= row
.className
;
719 if (!nc
.match("Selected")) {
720 nc
= nc
+ "Selected";
725 // In CDM basically last selected article == active article
726 if (isCdmMode()) active_post_id
= id
;
728 nc
= nc
.replace("Selected", "");
738 exception_error("toggleSelected", e
);
742 function toggleUnread_afh(effect
) {
745 var elem
= effect
.element
;
746 elem
.style
.backgroundColor
= "";
749 exception_error("toggleUnread_afh", e
);
753 function toggleUnread(id
, cmode
, effect
) {
756 var row
= document
.getElementById("RROW-" + id
);
758 var nc
= row
.className
;
759 var is_selected
= row
.className
.match("Selected");
760 nc
= nc
.replace("Unread", "");
761 nc
= nc
.replace("Selected", "");
763 // since we are removing selection from the object, uncheck
764 // corresponding checkbox
766 var cb
= document
.getElementById("RCHK-" + id
);
771 // NOTE: I'm not sure that resetting selection here is a feature -fox
773 if (cmode
== undefined || cmode
== 2) {
774 if (row
.className
.match("Unread")) {
778 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
779 afterFinish
: toggleUnread_afh
,
780 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
784 row
.className
= nc
+ "Unread";
786 } else if (cmode
== 0) {
790 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
791 afterFinish
: toggleUnread_afh
,
792 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
794 } else if (cmode
== 1) {
795 row
.className
= nc
+ "Unread";
798 // Disable unmarking as selected for the time being (16.05.08) -fox
799 if (is_selected
) row
.className
= row
.className
+ "Selected";
801 if (cmode
== undefined) cmode
= 2;
803 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
804 param_escape(id
) + "&cmode=" + param_escape(cmode
);
806 // notify_progress("Loading, please wait...");
808 new Ajax
.Request(query
, {
809 onComplete: function(transport
) {
810 all_counters_callback2(transport
);
817 exception_error("toggleUnread", e
);
821 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
826 rows
= cdmGetSelectedArticles();
828 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
831 if (rows
.length
== 0 && !no_error
) {
832 alert(__("No articles are selected."));
836 for (i
= 0; i
< rows
.length
; i
++) {
837 var row
= document
.getElementById("RROW-" + rows
[i
]);
839 var nc
= row
.className
;
840 nc
= nc
.replace("Unread", "");
841 nc
= nc
.replace("Selected", "");
843 if (set_state
== undefined) {
844 if (row
.className
.match("Unread")) {
845 row
.className
= nc
+ "Selected";
847 row
.className
= nc
+ "UnreadSelected";
851 if (set_state
== false) {
852 row
.className
= nc
+ "Selected";
855 if (set_state
== true) {
856 row
.className
= nc
+ "UnreadSelected";
861 if (rows
.length
> 0) {
865 if (set_state
== undefined) {
867 } else if (set_state
== true) {
869 } else if (set_state
== false) {
873 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
874 param_escape(rows
.toString()) + "&cmode=" + cmode
;
876 notify_progress("Loading, please wait...");
878 new Ajax
.Request(query
, {
879 onComplete: function(transport
) {
880 catchup_callback2(transport
, callback_func
);
886 exception_error("selectionToggleUnread", e
);
890 function selectionToggleMarked(cdm_mode
) {
896 rows
= cdmGetSelectedArticles();
898 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
901 if (rows
.length
== 0) {
902 alert(__("No articles are selected."));
906 for (i
= 0; i
< rows
.length
; i
++) {
907 toggleMark(rows
[i
], true, true);
910 if (rows
.length
> 0) {
912 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
913 param_escape(rows
.toString()) + "&cmode=2";
915 query
= query
+ "&afid=" + getActiveFeedId();
917 /* if (tagsAreDisplayed()) {
918 query = query + "&omode=tl";
920 query = query + "&omode=flc";
923 query
= query
+ "&omode=lc";
925 new Ajax
.Request(query
, {
926 onComplete: function(transport
) {
927 all_counters_callback2(transport
);
933 exception_error("selectionToggleMarked", e
);
937 function selectionTogglePublished(cdm_mode
) {
943 rows
= cdmGetSelectedArticles();
945 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
948 if (rows
.length
== 0) {
949 alert(__("No articles are selected."));
953 for (i
= 0; i
< rows
.length
; i
++) {
954 togglePub(rows
[i
], true, true);
957 if (rows
.length
> 0) {
959 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
960 param_escape(rows
.toString()) + "&cmode=2";
962 query
= query
+ "&afid=" + getActiveFeedId();
964 /* if (tagsAreDisplayed()) {
965 query = query + "&omode=tl";
967 query = query + "&omode=flc";
970 query
= query
+ "&omode=lc";
972 new Ajax
.Request(query
, {
973 onComplete: function(transport
) {
974 all_counters_callback2(transport
);
980 exception_error("selectionToggleMarked", e
);
984 function cdmGetSelectedArticles() {
985 var sel_articles
= new Array();
986 var container
= document
.getElementById("headlinesInnerContainer");
988 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
989 var child
= container
.childNodes
[i
];
991 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
992 var c_id
= child
.id
.replace("RROW-", "");
993 sel_articles
.push(c_id
);
1000 function cdmGetVisibleArticles() {
1001 var sel_articles
= new Array();
1002 var container
= document
.getElementById("headlinesInnerContainer");
1004 if (!container
) return sel_articles
;
1006 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1007 var child
= container
.childNodes
[i
];
1009 if (child
.id
.match("RROW-")) {
1010 var c_id
= child
.id
.replace("RROW-", "");
1011 sel_articles
.push(c_id
);
1015 return sel_articles
;
1018 function cdmGetUnreadArticles() {
1019 var sel_articles
= new Array();
1020 var container
= document
.getElementById("headlinesInnerContainer");
1022 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1023 var child
= container
.childNodes
[i
];
1025 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1026 var c_id
= child
.id
.replace("RROW-", "");
1027 sel_articles
.push(c_id
);
1031 return sel_articles
;
1035 // mode = all,none,unread
1036 function cdmSelectArticles(mode
) {
1037 var container
= document
.getElementById("headlinesInnerContainer");
1039 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1040 var child
= container
.childNodes
[i
];
1042 if (child
.id
.match("RROW-")) {
1043 var aid
= child
.id
.replace("RROW-", "");
1045 var cb
= document
.getElementById("RCHK-" + aid
);
1047 if (mode
== "all") {
1048 if (!child
.className
.match("Selected")) {
1049 child
.className
= child
.className
+ "Selected";
1052 } else if (mode
== "unread") {
1053 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1054 child
.className
= child
.className
+ "Selected";
1058 child
.className
= child
.className
.replace("Selected", "");
1065 function catchupPage() {
1067 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1069 var str
= __("Mark all visible articles in %s as read?");
1071 str
= str
.replace("%s", fn
);
1073 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1077 if (document
.getElementById("headlinesList")) {
1078 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1079 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1080 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1082 cdmSelectArticles('all');
1083 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1084 cdmSelectArticles('none');
1088 function catchupSelection() {
1094 if (document
.getElementById("headlinesList")) {
1095 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1097 rows
= cdmGetSelectedArticles();
1100 if (rows
.length
== 0) {
1101 alert(__("No articles are selected."));
1106 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1108 var str
= __("Mark %d selected articles in %s as read?");
1110 str
= str
.replace("%d", rows
.length
);
1111 str
= str
.replace("%s", fn
);
1113 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1117 if (document
.getElementById("headlinesList")) {
1118 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1119 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1121 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1122 // cdmSelectArticles('none');
1126 exception_error("catchupSelection", e
);
1131 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1133 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1134 printLockingError();
1137 var title
= prompt(__("Please enter label title:"), "");
1141 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1142 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1143 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1144 "&title=" + param_escape(title
);
1146 debug("LFS: " + query
);
1148 new Ajax
.Request(query
, {
1149 onComplete: function(transport
) {
1150 dlg_frefresh_callback(transport
);
1155 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1156 _tag_active_post_id
= id
;
1157 _tag_active_feed_id
= feed_id
;
1158 _tag_active_cdm
= cdm_enabled
;
1160 cache_invalidate(id
);
1163 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1165 displayDlg('editArticleTags', id
);
1169 function tag_saved_callback(transport
) {
1171 debug("in tag_saved_callback");
1176 if (tagsAreDisplayed()) {
1177 _reload_feedlist_after_view
= true;
1180 if (!_tag_active_cdm
) {
1181 if (active_post_id
== _tag_active_post_id
) {
1182 debug("reloading current article");
1183 view(_tag_active_post_id
, _tag_active_feed_id
);
1186 debug("reloading current feed");
1191 exception_error("catchup_callback", e
);
1195 function editTagsSave() {
1197 notify_progress("Saving article tags...");
1199 var form
= document
.forms
["tag_edit_form"];
1201 var query
= Form
.serialize("tag_edit_form");
1203 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1207 new Ajax
.Request(query
, {
1208 onComplete: function(transport
) {
1209 tag_saved_callback(transport
);
1214 function editTagsInsert() {
1217 var form
= document
.forms
["tag_edit_form"];
1219 var found_tags
= form
.found_tags
;
1220 var tags_str
= form
.tags_str
;
1222 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1224 if (tags_str
.value
.length
> 0 &&
1225 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1227 tags_str
.value
= tags_str
.value
+ ", ";
1230 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1232 found_tags
.selectedIndex
= 0;
1235 exception_error("editTagsInsert", e
);
1239 function cdmScrollViewport(where
) {
1240 debug("cdmScrollViewport: " + where
);
1242 var ctr
= document
.getElementById("headlinesInnerContainer");
1246 if (where
== "bottom") {
1247 ctr
.scrollTop
= ctr
.scrollHeight
;
1249 ctr
.scrollTop
= where
;
1253 function cdmArticleIsBelowViewport(id
) {
1255 var ctr
= document
.getElementById("headlinesInnerContainer");
1256 var e
= document
.getElementById("RROW-" + id
);
1258 if (!e
|| !ctr
) return;
1260 // article starts below viewport
1262 if (ctr
.scrollTop
< e
.offsetTop
) {
1269 exception_error("cdmArticleIsVisible", e
);
1273 function cdmArticleIsAboveViewport(id
) {
1275 var ctr
= document
.getElementById("headlinesInnerContainer");
1276 var e
= document
.getElementById("RROW-" + id
);
1278 if (!e
|| !ctr
) return;
1280 // article starts above viewport
1282 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1289 exception_error("cdmArticleIsVisible", e
);
1293 function cdmScrollToArticleId(id
) {
1295 var ctr
= document
.getElementById("headlinesInnerContainer");
1296 var e
= document
.getElementById("RROW-" + id
);
1298 if (!e
|| !ctr
) return;
1300 ctr
.scrollTop
= e
.offsetTop
;
1303 exception_error("cdmScrollToArticleId", e
);
1307 function cdmArticleIsActuallyVisible(id
) {
1309 var ctr
= document
.getElementById("headlinesInnerContainer");
1310 var e
= document
.getElementById("RROW-" + id
);
1312 if (!e
|| !ctr
) return;
1314 // article fits in viewport OR article is longer than viewport and
1315 // its bottom is visible
1317 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1318 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1322 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1323 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1324 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1333 exception_error("cdmArticleIsVisible", e
);
1337 function cdmWatchdog() {
1341 var ctr
= document
.getElementById("headlinesInnerContainer");
1345 var ids
= new Array();
1347 var e
= ctr
.firstChild
;
1350 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1351 e
.id
.match("RROW-")) {
1353 // article fits in viewport OR article is longer than viewport and
1354 // its bottom is visible
1356 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1357 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1359 // debug(e.id + " is visible " + e.offsetTop + "." +
1360 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1361 // (ctr.scrollTop + ctr.offsetHeight));
1363 ids
.push(e
.id
.replace("RROW-", ""));
1365 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1366 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1367 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1369 ids
.push(e
.id
.replace("RROW-", ""));
1373 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1375 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1376 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1378 ids.push(e.id.replace("RROW-", ""));
1387 debug("cdmWatchdog, ids= " + ids
.toString());
1389 if (ids
.length
> 0) {
1391 for (var i
= 0; i
< ids
.length
; i
++) {
1392 var e
= document
.getElementById("RROW-" + ids
[i
]);
1394 e
.className
= e
.className
.replace("Unread", "");
1398 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1399 param_escape(ids
.toString()) + "&cmode=0";
1401 new Ajax
.Request(query
, {
1402 onComplete: function(transport
) {
1403 all_counters_callback2(transport
);
1408 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1411 exception_error("cdmWatchdog", e
);
1417 function cache_inject(id
, article
, param
) {
1418 if (!cache_check_param(id
, param
)) {
1419 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1421 var cache_obj
= new Array();
1423 cache_obj
["id"] = id
;
1424 cache_obj
["data"] = article
;
1425 cache_obj
["param"] = param
;
1427 article_cache
.push(cache_obj
);
1430 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1434 function cache_find(id
) {
1435 for (var i
= 0; i
< article_cache
.length
; i
++) {
1436 if (article_cache
[i
]["id"] == id
) {
1437 return article_cache
[i
]["data"];
1443 function cache_find_param(id
, param
) {
1444 for (var i
= 0; i
< article_cache
.length
; i
++) {
1445 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1446 return article_cache
[i
]["data"];
1452 function cache_check(id
) {
1453 for (var i
= 0; i
< article_cache
.length
; i
++) {
1454 if (article_cache
[i
]["id"] == id
) {
1461 function cache_check_param(id
, param
) {
1462 for (var i
= 0; i
< article_cache
.length
; i
++) {
1464 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1465 // article_cache[i]["param"] + " vs " + id + ":" + param);
1467 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1474 function cache_expire() {
1475 while (article_cache
.length
> 25) {
1476 article_cache
.shift();
1480 function cache_empty() {
1481 article_cache
= new Array();
1484 function cache_invalidate(id
) {
1489 while (i
< article_cache
.length
) {
1490 if (article_cache
[i
]["id"] == id
) {
1491 debug("cache_invalidate: removed id " + id
);
1492 article_cache
.splice(i
, 1);
1497 debug("cache_invalidate: id not found: " + id
);
1500 exception_error("cache_invalidate", e
);
1504 function getActiveArticleId() {
1505 return active_post_id
;
1508 function cdmClicked(elem
) {
1510 if (elem
.id
&& elem
.id
.match("RROW-")) {
1511 var id
= elem
.id
.replace("RROW-", "");
1512 active_post_id
= id
;
1514 cdmSelectArticles("none");
1515 toggleUnread(id
, 0, true);
1520 exception_error("cdmClicked", e
);
1524 function preload_article_callback(transport
) {
1526 if (transport
.responseXML
) {
1527 var articles
= transport
.responseXML
.getElementsByTagName("article");
1529 for (var i
= 0; i
< articles
.length
; i
++) {
1530 var id
= articles
[i
].getAttribute("id");
1531 if (!cache_check(id
)) {
1532 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1533 debug("preloaded article: " + id
);
1538 exception_error("preload_article_callback", e
);
1542 function preloadArticleUnderPointer(id
) {
1544 if (post_under_pointer
== id
&& !cache_check(id
)) {
1546 debug("trying to preload article " + id
);
1548 var neighbor_ids
= getRelativePostIds(id
, 1);
1550 /* only request uncached articles */
1552 var cids_to_request
= Array();
1554 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1555 if (!cache_check(neighbor_ids
[i
])) {
1556 cids_to_request
.push(neighbor_ids
[i
]);
1559 debug("additional ids: " + cids_to_request
.toString());
1561 cids_to_request
.push(id
);
1563 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1564 cids_to_request
.toString();
1565 new Ajax
.Request(query
, {
1566 onComplete: function(transport
) {
1567 preload_article_callback(transport
);
1571 exception_error("preloadArticleUnderPointer", e
);
1575 function postMouseIn(id
) {
1577 if (post_under_pointer
!= id
) {
1578 post_under_pointer
= id
;
1580 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1585 exception_error("postMouseIn", e
);
1589 function postMouseOut(id
) {
1591 post_under_pointer
= false;
1593 exception_error("postMouseOut", e
);
1597 function headlines_scroll_handler() {
1600 var e
= document
.getElementById("headlinesInnerContainer");
1602 // don't do infinite scrolling when Limit == All
1604 var toolbar_form
= document
.forms
["main_toolbar_form"];
1606 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1607 if (limit
.value
!= 0) {
1609 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1610 _infscroll_disable
);
1612 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1613 if (!_infscroll_disable
) {
1614 debug("more cowbell!");
1621 exception_error("headlines_scroll_handler", e
);
1625 function catchupRelativeToArticle(below
) {
1629 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1630 printLockingError();
1633 if (!getActiveArticleId()) {
1634 alert(__("No article is selected."));
1640 if (document
.getElementById("headlinesList")) {
1641 visible_ids
= getVisibleHeadlineIds();
1643 visible_ids
= cdmGetVisibleArticles();
1646 var ids_to_mark
= new Array();
1649 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1650 if (visible_ids
[i
] != getActiveArticleId()) {
1651 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1653 if (e
&& e
.className
.match("Unread")) {
1654 ids_to_mark
.push(visible_ids
[i
]);
1661 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1662 if (visible_ids
[i
] != getActiveArticleId()) {
1663 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1665 if (e
&& e
.className
.match("Unread")) {
1666 ids_to_mark
.push(visible_ids
[i
]);
1674 if (ids_to_mark
.length
== 0) {
1675 alert(__("No articles found to mark"));
1677 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1681 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1682 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1683 e
.className
= e
.className
.replace("Unread", "");
1686 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1687 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1689 new Ajax
.Request(query
, {
1690 onComplete: function(transport
) {
1691 catchup_callback2(transport
);
1698 exception_error("catchupRelativeToArticle", e
);
1702 function cdmExpandArticle(a_id
) {
1704 var id
= 'CICD-' + a_id
;
1706 Effect
.Appear(id
, {duration
: 0.5,
1707 beforeStart: function(effect
) {
1708 var h_id
= 'CICH-' + a_id
;
1709 var h_elem
= document
.getElementById(h_id
);
1710 if (h_elem
) { h_elem
.style
.display
= "none"; }
1712 toggleUnread(a_id
, 0);
1717 exception_error("appearBlockElementF", e
);
1722 function fixHeadlinesOrder(ids
) {
1724 for (var i
= 0; i
< ids
.length
; i
++) {
1725 var e
= document
.getElementById("RROW-" + ids
[i
]);
1729 e
.className
= e
.className
.replace("even", "odd");
1731 e
.className
= e
.className
.replace("odd", "even");
1736 exception_error("fixHeadlinesOrder", e
);
1740 function subtoolbarSearch() {
1743 var q
= document
.getElementById("subtoolbar_search_box");
1747 q
= q
.value
.toUpperCase();
1750 var vis_ids
= new Array();
1752 if (document
.getElementById("headlinesList")) {
1753 ids
= getVisibleHeadlineIds();
1755 ids
= cdmGetVisibleArticles();
1758 for (var i
= 0; i
< ids
.length
; i
++) {
1759 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1762 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1763 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1765 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1766 vis_ids
.push(ids
[i
]);
1771 fixHeadlinesOrder(vis_ids
);
1774 exception_error("subtoolbarSearch", e
);
1778 function getArticleUnderPointer() {
1779 return post_under_pointer
;