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 (!async_counters_work
) {
435 query
= query
+ "&csync=true";
438 if (!cached_article
) {
440 notify_progress("Loading, please wait...");
442 } else if (cached_article
&& article_is_unread
) {
444 query
= query
+ "&mode=prefetch";
446 showArticleInHeadlines(id
);
447 render_article(cached_article
);
449 } else if (cached_article
) {
451 query
= query
+ "&mode=prefetch_old";
452 render_article(cached_article
);
453 showArticleInHeadlines(id
);
459 last_requested_article
= id
;
461 new Ajax
.Request(query
, {
462 onComplete: function(transport
) {
463 article_callback2(transport
, id
, feed_id
);
469 exception_error("view", e
);
474 return toggleMark(id
);
478 return togglePub(id
);
481 function tMark_afh_off(effect
) {
483 var elem
= effect
.effects
[0].element
;
485 debug("tMark_afh_off : " + elem
.id
);
488 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
489 elem
.alt
= __("Star article");
494 exception_error("tMark_afh_off", e
);
498 function tPub_afh_off(effect
) {
500 var elem
= effect
.effects
[0].element
;
502 debug("tPub_afh_off : " + elem
.id
);
505 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
506 elem
.alt
= __("Publish article");
511 exception_error("tPub_afh_off", e
);
515 function toggleMark(id
, client_only
, no_effects
) {
519 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
521 query
= query
+ "&afid=" + getActiveFeedId();
523 if (tagsAreDisplayed()) {
524 query
= query
+ "&omode=tl";
526 query
= query
+ "&omode=flc";
529 var mark_img
= document
.getElementById("FMPIC-" + id
);
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
);
581 var vfeedu
= document
.getElementById("FEEDU--2");
582 var crow
= document
.getElementById("RROW-" + id
);
584 if (mark_img
.src
.match("pub_unset")) {
585 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
586 mark_img
.alt
= __("Unpublish article");
587 query
= query
+ "&pub=1";
591 //mark_img.src = "images/pub_unset.png";
592 mark_img
.alt
= __("Please wait...");
593 query
= query
+ "&pub=0";
595 if (document
.getElementById("headlinesList") && !no_effects
) {
596 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
598 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
599 mark_img
.alt
= __("Publish article");
604 new Ajax
.Request(query
, {
605 onComplete: function(transport
) {
606 all_counters_callback2(transport
);
612 exception_error("togglePub", e
);
616 function correctHeadlinesOffset(id
) {
620 var hlist
= document
.getElementById("headlinesList");
621 var container
= document
.getElementById("headlinesInnerContainer");
622 var row
= document
.getElementById("RROW-" + id
);
624 var viewport
= container
.offsetHeight
;
626 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
627 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
629 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
630 debug("Vport: " + viewport
);
632 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
633 container
.scrollTop
= row
.offsetTop
;
634 } else if (rel_offset_bottom
> viewport
) {
636 /* doesn't properly work with Opera in some cases because
637 Opera fucks up element scrolling */
639 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
643 exception_error("correctHeadlinesOffset", e
);
648 function moveToPost(mode
) {
655 rows
= cdmGetVisibleArticles();
657 rows
= getVisibleHeadlineIds();
663 if (!document
.getElementById('RROW-' + active_post_id
)) {
664 active_post_id
= false;
667 if (active_post_id
== false) {
668 next_id
= getFirstVisibleHeadlineId();
669 prev_id
= getLastVisibleHeadlineId();
671 for (var i
= 0; i
< rows
.length
; i
++) {
672 if (rows
[i
] == active_post_id
) {
679 if (mode
== "next") {
683 if (!cdmArticleIsActuallyVisible(next_id
)) {
684 cdmScrollToArticleId(next_id
);
686 cdmSelectArticles("none");
687 toggleUnread(next_id
, 0, true);
688 toggleSelected(next_id
);
691 correctHeadlinesOffset(next_id
);
692 view(next_id
, getActiveFeedId());
697 if (mode
== "prev") {
700 cdmScrollToArticleId(prev_id
);
701 cdmSelectArticles("none");
702 toggleUnread(prev_id
, 0, true);
703 toggleSelected(prev_id
);
705 correctHeadlinesOffset(prev_id
);
706 view(prev_id
, getActiveFeedId());
712 exception_error("moveToPost", e
);
716 function toggleSelected(id
) {
719 var cb
= document
.getElementById("RCHK-" + id
);
721 var row
= document
.getElementById("RROW-" + id
);
723 var nc
= row
.className
;
725 if (!nc
.match("Selected")) {
726 nc
= nc
+ "Selected";
731 // In CDM basically last selected article == active article
732 if (isCdmMode()) active_post_id
= id
;
734 nc
= nc
.replace("Selected", "");
744 exception_error("toggleSelected", e
);
748 function toggleUnread_afh(effect
) {
751 var elem
= effect
.element
;
752 elem
.style
.backgroundColor
= "";
755 exception_error("toggleUnread_afh", e
);
759 function toggleUnread(id
, cmode
, effect
) {
762 var row
= document
.getElementById("RROW-" + id
);
764 var nc
= row
.className
;
765 var is_selected
= row
.className
.match("Selected");
766 nc
= nc
.replace("Unread", "");
767 nc
= nc
.replace("Selected", "");
769 // since we are removing selection from the object, uncheck
770 // corresponding checkbox
772 var cb
= document
.getElementById("RCHK-" + id
);
777 // NOTE: I'm not sure that resetting selection here is a feature -fox
779 if (cmode
== undefined || cmode
== 2) {
780 if (row
.className
.match("Unread")) {
784 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
785 afterFinish
: toggleUnread_afh
,
786 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
790 row
.className
= nc
+ "Unread";
792 } else if (cmode
== 0) {
796 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
797 afterFinish
: toggleUnread_afh
,
798 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
800 } else if (cmode
== 1) {
801 row
.className
= nc
+ "Unread";
804 // Disable unmarking as selected for the time being (16.05.08) -fox
805 if (is_selected
) row
.className
= row
.className
+ "Selected";
807 if (cmode
== undefined) cmode
= 2;
809 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
810 param_escape(id
) + "&cmode=" + param_escape(cmode
);
812 // notify_progress("Loading, please wait...");
814 new Ajax
.Request(query
, {
815 onComplete: function(transport
) {
816 all_counters_callback2(transport
);
823 exception_error("toggleUnread", e
);
827 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
832 rows
= cdmGetSelectedArticles();
834 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
837 if (rows
.length
== 0 && !no_error
) {
838 alert(__("No articles are selected."));
842 for (i
= 0; i
< rows
.length
; i
++) {
843 var row
= document
.getElementById("RROW-" + rows
[i
]);
845 var nc
= row
.className
;
846 nc
= nc
.replace("Unread", "");
847 nc
= nc
.replace("Selected", "");
849 if (set_state
== undefined) {
850 if (row
.className
.match("Unread")) {
851 row
.className
= nc
+ "Selected";
853 row
.className
= nc
+ "UnreadSelected";
857 if (set_state
== false) {
858 row
.className
= nc
+ "Selected";
861 if (set_state
== true) {
862 row
.className
= nc
+ "UnreadSelected";
867 if (rows
.length
> 0) {
871 if (set_state
== undefined) {
873 } else if (set_state
== true) {
875 } else if (set_state
== false) {
879 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
880 param_escape(rows
.toString()) + "&cmode=" + cmode
;
882 notify_progress("Loading, please wait...");
884 new Ajax
.Request(query
, {
885 onComplete: function(transport
) {
886 catchup_callback2(transport
, callback_func
);
892 exception_error("selectionToggleUnread", e
);
896 function selectionToggleMarked(cdm_mode
) {
902 rows
= cdmGetSelectedArticles();
904 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
907 if (rows
.length
== 0) {
908 alert(__("No articles are selected."));
912 for (i
= 0; i
< rows
.length
; i
++) {
913 toggleMark(rows
[i
], true, true);
916 if (rows
.length
> 0) {
918 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
919 param_escape(rows
.toString()) + "&cmode=2";
921 query
= query
+ "&afid=" + getActiveFeedId();
923 /* if (tagsAreDisplayed()) {
924 query = query + "&omode=tl";
926 query = query + "&omode=flc";
929 query
= query
+ "&omode=lc";
931 new Ajax
.Request(query
, {
932 onComplete: function(transport
) {
933 all_counters_callback2(transport
);
939 exception_error("selectionToggleMarked", e
);
943 function selectionTogglePublished(cdm_mode
) {
949 rows
= cdmGetSelectedArticles();
951 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
954 if (rows
.length
== 0) {
955 alert(__("No articles are selected."));
959 for (i
= 0; i
< rows
.length
; i
++) {
960 togglePub(rows
[i
], true, true);
963 if (rows
.length
> 0) {
965 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
966 param_escape(rows
.toString()) + "&cmode=2";
968 query
= query
+ "&afid=" + getActiveFeedId();
970 /* if (tagsAreDisplayed()) {
971 query = query + "&omode=tl";
973 query = query + "&omode=flc";
976 query
= query
+ "&omode=lc";
978 new Ajax
.Request(query
, {
979 onComplete: function(transport
) {
980 all_counters_callback2(transport
);
986 exception_error("selectionToggleMarked", e
);
990 function cdmGetSelectedArticles() {
991 var sel_articles
= new Array();
992 var container
= document
.getElementById("headlinesInnerContainer");
994 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
995 var child
= container
.childNodes
[i
];
997 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
998 var c_id
= child
.id
.replace("RROW-", "");
999 sel_articles
.push(c_id
);
1003 return sel_articles
;
1006 function cdmGetVisibleArticles() {
1007 var sel_articles
= new Array();
1008 var container
= document
.getElementById("headlinesInnerContainer");
1010 if (!container
) return sel_articles
;
1012 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1013 var child
= container
.childNodes
[i
];
1015 if (child
.id
.match("RROW-")) {
1016 var c_id
= child
.id
.replace("RROW-", "");
1017 sel_articles
.push(c_id
);
1021 return sel_articles
;
1024 function cdmGetUnreadArticles() {
1025 var sel_articles
= new Array();
1026 var container
= document
.getElementById("headlinesInnerContainer");
1028 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1029 var child
= container
.childNodes
[i
];
1031 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1032 var c_id
= child
.id
.replace("RROW-", "");
1033 sel_articles
.push(c_id
);
1037 return sel_articles
;
1041 // mode = all,none,unread
1042 function cdmSelectArticles(mode
) {
1043 var container
= document
.getElementById("headlinesInnerContainer");
1045 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1046 var child
= container
.childNodes
[i
];
1048 if (child
.id
.match("RROW-")) {
1049 var aid
= child
.id
.replace("RROW-", "");
1051 var cb
= document
.getElementById("RCHK-" + aid
);
1053 if (mode
== "all") {
1054 if (!child
.className
.match("Selected")) {
1055 child
.className
= child
.className
+ "Selected";
1058 } else if (mode
== "unread") {
1059 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1060 child
.className
= child
.className
+ "Selected";
1064 child
.className
= child
.className
.replace("Selected", "");
1071 function catchupPage() {
1073 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1075 var str
= __("Mark all visible articles in %s as read?");
1077 str
= str
.replace("%s", fn
);
1079 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1083 if (document
.getElementById("headlinesList")) {
1084 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1085 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1086 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1088 cdmSelectArticles('all');
1089 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1090 cdmSelectArticles('none');
1094 function catchupSelection() {
1100 if (document
.getElementById("headlinesList")) {
1101 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1103 rows
= cdmGetSelectedArticles();
1106 if (rows
.length
== 0) {
1107 alert(__("No articles are selected."));
1112 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1114 var str
= __("Mark %d selected articles in %s as read?");
1116 str
= str
.replace("%d", rows
.length
);
1117 str
= str
.replace("%s", fn
);
1119 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1123 if (document
.getElementById("headlinesList")) {
1124 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1125 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1127 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1128 // cdmSelectArticles('none');
1132 exception_error("catchupSelection", e
);
1137 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1139 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1140 printLockingError();
1143 var title
= prompt(__("Please enter label title:"), "");
1147 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1148 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1149 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1150 "&title=" + param_escape(title
);
1152 debug("LFS: " + query
);
1154 new Ajax
.Request(query
, {
1155 onComplete: function(transport
) {
1156 dlg_frefresh_callback(transport
);
1161 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1162 _tag_active_post_id
= id
;
1163 _tag_active_feed_id
= feed_id
;
1164 _tag_active_cdm
= cdm_enabled
;
1166 cache_invalidate(id
);
1169 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1171 displayDlg('editArticleTags', id
);
1175 function tag_saved_callback(transport
) {
1177 debug("in tag_saved_callback");
1182 if (tagsAreDisplayed()) {
1183 _reload_feedlist_after_view
= true;
1186 if (!_tag_active_cdm
) {
1187 if (active_post_id
== _tag_active_post_id
) {
1188 debug("reloading current article");
1189 view(_tag_active_post_id
, _tag_active_feed_id
);
1192 debug("reloading current feed");
1197 exception_error("catchup_callback", e
);
1201 function editTagsSave() {
1203 notify_progress("Saving article tags...");
1205 var form
= document
.forms
["tag_edit_form"];
1207 var query
= Form
.serialize("tag_edit_form");
1209 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1213 new Ajax
.Request(query
, {
1214 onComplete: function(transport
) {
1215 tag_saved_callback(transport
);
1220 function editTagsInsert() {
1223 var form
= document
.forms
["tag_edit_form"];
1225 var found_tags
= form
.found_tags
;
1226 var tags_str
= form
.tags_str
;
1228 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1230 if (tags_str
.value
.length
> 0 &&
1231 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1233 tags_str
.value
= tags_str
.value
+ ", ";
1236 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1238 found_tags
.selectedIndex
= 0;
1241 exception_error("editTagsInsert", e
);
1245 function cdmScrollViewport(where
) {
1246 debug("cdmScrollViewport: " + where
);
1248 var ctr
= document
.getElementById("headlinesInnerContainer");
1252 if (where
== "bottom") {
1253 ctr
.scrollTop
= ctr
.scrollHeight
;
1255 ctr
.scrollTop
= where
;
1259 function cdmArticleIsBelowViewport(id
) {
1261 var ctr
= document
.getElementById("headlinesInnerContainer");
1262 var e
= document
.getElementById("RROW-" + id
);
1264 if (!e
|| !ctr
) return;
1266 // article starts below viewport
1268 if (ctr
.scrollTop
< e
.offsetTop
) {
1275 exception_error("cdmArticleIsVisible", e
);
1279 function cdmArticleIsAboveViewport(id
) {
1281 var ctr
= document
.getElementById("headlinesInnerContainer");
1282 var e
= document
.getElementById("RROW-" + id
);
1284 if (!e
|| !ctr
) return;
1286 // article starts above viewport
1288 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1295 exception_error("cdmArticleIsVisible", e
);
1299 function cdmScrollToArticleId(id
) {
1301 var ctr
= document
.getElementById("headlinesInnerContainer");
1302 var e
= document
.getElementById("RROW-" + id
);
1304 if (!e
|| !ctr
) return;
1306 ctr
.scrollTop
= e
.offsetTop
;
1309 exception_error("cdmScrollToArticleId", e
);
1313 function cdmArticleIsActuallyVisible(id
) {
1315 var ctr
= document
.getElementById("headlinesInnerContainer");
1316 var e
= document
.getElementById("RROW-" + id
);
1318 if (!e
|| !ctr
) return;
1320 // article fits in viewport OR article is longer than viewport and
1321 // its bottom is visible
1323 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1324 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1328 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1329 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1330 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1339 exception_error("cdmArticleIsVisible", e
);
1343 function cdmWatchdog() {
1347 var ctr
= document
.getElementById("headlinesInnerContainer");
1351 var ids
= new Array();
1353 var e
= ctr
.firstChild
;
1356 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1357 e
.id
.match("RROW-")) {
1359 // article fits in viewport OR article is longer than viewport and
1360 // its bottom is visible
1362 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1363 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1365 // debug(e.id + " is visible " + e.offsetTop + "." +
1366 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1367 // (ctr.scrollTop + ctr.offsetHeight));
1369 ids
.push(e
.id
.replace("RROW-", ""));
1371 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1372 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1373 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1375 ids
.push(e
.id
.replace("RROW-", ""));
1379 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1381 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1382 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1384 ids.push(e.id.replace("RROW-", ""));
1393 debug("cdmWatchdog, ids= " + ids
.toString());
1395 if (ids
.length
> 0) {
1397 for (var i
= 0; i
< ids
.length
; i
++) {
1398 var e
= document
.getElementById("RROW-" + ids
[i
]);
1400 e
.className
= e
.className
.replace("Unread", "");
1404 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1405 param_escape(ids
.toString()) + "&cmode=0";
1407 new Ajax
.Request(query
, {
1408 onComplete: function(transport
) {
1409 all_counters_callback2(transport
);
1414 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1417 exception_error("cdmWatchdog", e
);
1423 function cache_inject(id
, article
, param
) {
1424 if (!cache_check_param(id
, param
)) {
1425 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1427 var cache_obj
= new Array();
1429 cache_obj
["id"] = id
;
1430 cache_obj
["data"] = article
;
1431 cache_obj
["param"] = param
;
1433 article_cache
.push(cache_obj
);
1436 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1440 function cache_find(id
) {
1441 for (var i
= 0; i
< article_cache
.length
; i
++) {
1442 if (article_cache
[i
]["id"] == id
) {
1443 return article_cache
[i
]["data"];
1449 function cache_find_param(id
, param
) {
1450 for (var i
= 0; i
< article_cache
.length
; i
++) {
1451 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1452 return article_cache
[i
]["data"];
1458 function cache_check(id
) {
1459 for (var i
= 0; i
< article_cache
.length
; i
++) {
1460 if (article_cache
[i
]["id"] == id
) {
1467 function cache_check_param(id
, param
) {
1468 for (var i
= 0; i
< article_cache
.length
; i
++) {
1470 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1471 // article_cache[i]["param"] + " vs " + id + ":" + param);
1473 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1480 function cache_expire() {
1481 while (article_cache
.length
> 25) {
1482 article_cache
.shift();
1486 function cache_empty() {
1487 article_cache
= new Array();
1490 function cache_invalidate(id
) {
1495 while (i
< article_cache
.length
) {
1496 if (article_cache
[i
]["id"] == id
) {
1497 debug("cache_invalidate: removed id " + id
);
1498 article_cache
.splice(i
, 1);
1503 debug("cache_invalidate: id not found: " + id
);
1506 exception_error("cache_invalidate", e
);
1510 function getActiveArticleId() {
1511 return active_post_id
;
1514 function cdmClicked(id
) {
1516 var elem
= document
.getElementById("RROW-" + id
);
1519 var id
= elem
.id
.replace("RROW-", "");
1520 active_post_id
= id
;
1522 cdmSelectArticles("none");
1523 toggleUnread(id
, 0, true);
1528 exception_error("cdmClicked", e
);
1532 function preload_article_callback(transport
) {
1534 if (transport
.responseXML
) {
1535 var articles
= transport
.responseXML
.getElementsByTagName("article");
1537 for (var i
= 0; i
< articles
.length
; i
++) {
1538 var id
= articles
[i
].getAttribute("id");
1539 if (!cache_check(id
)) {
1540 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1541 debug("preloaded article: " + id
);
1546 exception_error("preload_article_callback", e
);
1550 function preloadArticleUnderPointer(id
) {
1552 if (post_under_pointer
== id
&& !cache_check(id
)) {
1554 debug("trying to preload article " + id
);
1556 var neighbor_ids
= getRelativePostIds(id
, 1);
1558 /* only request uncached articles */
1560 var cids_to_request
= Array();
1562 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1563 if (!cache_check(neighbor_ids
[i
])) {
1564 cids_to_request
.push(neighbor_ids
[i
]);
1567 debug("additional ids: " + cids_to_request
.toString());
1569 cids_to_request
.push(id
);
1571 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1572 cids_to_request
.toString();
1573 new Ajax
.Request(query
, {
1574 onComplete: function(transport
) {
1575 preload_article_callback(transport
);
1579 exception_error("preloadArticleUnderPointer", e
);
1583 function postMouseIn(id
) {
1585 if (post_under_pointer
!= id
) {
1586 post_under_pointer
= id
;
1588 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1593 exception_error("postMouseIn", e
);
1597 function postMouseOut(id
) {
1599 post_under_pointer
= false;
1601 exception_error("postMouseOut", e
);
1605 function headlines_scroll_handler() {
1608 var e
= document
.getElementById("headlinesInnerContainer");
1610 // don't do infinite scrolling when Limit == All
1612 var toolbar_form
= document
.forms
["main_toolbar_form"];
1614 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1615 if (limit
.value
!= 0) {
1617 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1618 _infscroll_disable
);
1620 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1621 if (!_infscroll_disable
) {
1622 debug("more cowbell!");
1629 exception_error("headlines_scroll_handler", e
);
1633 function catchupRelativeToArticle(below
) {
1637 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1638 printLockingError();
1641 if (!getActiveArticleId()) {
1642 alert(__("No article is selected."));
1648 if (document
.getElementById("headlinesList")) {
1649 visible_ids
= getVisibleHeadlineIds();
1651 visible_ids
= cdmGetVisibleArticles();
1654 var ids_to_mark
= new Array();
1657 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1658 if (visible_ids
[i
] != getActiveArticleId()) {
1659 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1661 if (e
&& e
.className
.match("Unread")) {
1662 ids_to_mark
.push(visible_ids
[i
]);
1669 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1670 if (visible_ids
[i
] != getActiveArticleId()) {
1671 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1673 if (e
&& e
.className
.match("Unread")) {
1674 ids_to_mark
.push(visible_ids
[i
]);
1682 if (ids_to_mark
.length
== 0) {
1683 alert(__("No articles found to mark"));
1685 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1689 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1690 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1691 e
.className
= e
.className
.replace("Unread", "");
1694 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1695 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1697 new Ajax
.Request(query
, {
1698 onComplete: function(transport
) {
1699 catchup_callback2(transport
);
1706 exception_error("catchupRelativeToArticle", e
);
1710 function cdmExpandArticle(a_id
) {
1712 var id
= 'CICD-' + a_id
;
1715 Element
.hide("CEXC-" + a_id
);
1718 Effect
.Appear(id
, {duration
: 0.5,
1719 beforeStart: function(effect
) {
1720 var h_id
= 'CICH-' + a_id
;
1721 var h_elem
= document
.getElementById(h_id
);
1722 if (h_elem
) { h_elem
.style
.display
= "none"; }
1724 toggleUnread(a_id
, 0);
1729 exception_error("appearBlockElementF", e
);
1734 function fixHeadlinesOrder(ids
) {
1736 for (var i
= 0; i
< ids
.length
; i
++) {
1737 var e
= document
.getElementById("RROW-" + ids
[i
]);
1741 e
.className
= e
.className
.replace("even", "odd");
1743 e
.className
= e
.className
.replace("odd", "even");
1748 exception_error("fixHeadlinesOrder", e
);
1752 function subtoolbarSearch() {
1755 var q
= document
.getElementById("subtoolbar_search_box");
1759 q
= q
.value
.toUpperCase();
1762 var vis_ids
= new Array();
1764 if (document
.getElementById("headlinesList")) {
1765 ids
= getVisibleHeadlineIds();
1767 ids
= cdmGetVisibleArticles();
1770 for (var i
= 0; i
< ids
.length
; i
++) {
1771 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1774 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1775 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1777 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1778 vis_ids
.push(ids
[i
]);
1783 fixHeadlinesOrder(vis_ids
);
1786 exception_error("subtoolbarSearch", e
);
1790 function getArticleUnderPointer() {
1791 return post_under_pointer
;