1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view
= false;
8 var _cdm_wd_timeout
= false;
9 var _cdm_wd_vishist
= new Array();
11 var article_cache
= new Array();
13 var vgroup_last_feed
= false;
14 var post_under_pointer
= false;
16 var last_requested_article
= false;
18 function catchup_callback2(transport
, callback
) {
20 debug("catchup_callback2 " + transport
+ ", " + callback
);
22 all_counters_callback2(transport
);
24 setTimeout(callback
, 10);
27 exception_error("catchup_callback2", e
, transport
);
31 function clean_feed_selections() {
33 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
35 for (var i
= 0; i
< feeds
.length
; i
++) {
36 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
37 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
39 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
40 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
44 exception_error("clean_feed_selections", e
);
48 function headlines_callback2(transport
, feed_cur_page
) {
51 loading_set_progress(100);
53 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
55 if (!transport_error_check(transport
)) return;
57 clean_feed_selections();
62 if (transport
.responseXML
) {
63 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
65 is_cat
= headlines
.getAttribute("is_cat");
66 feed_id
= headlines
.getAttribute("id");
67 setActiveFeedId(feed_id
, is_cat
);
72 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
73 if (feedr
&& !feedr
.className
.match("Selected")) {
74 feedr
.className
= feedr
.className
+ "Selected";
77 var feedr
= document
.getElementById("FCAT-" + feed_id
);
78 if (feedr
&& !feedr
.className
.match("Selected")) {
79 feedr
.className
= feedr
.className
+ "Selected";
83 var f
= document
.getElementById("headlines-frame");
85 if (feed_cur_page
== 0) {
86 debug("resetting headlines scrollTop");
91 if (transport
.responseXML
) {
92 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
93 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
94 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
95 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
97 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
99 var headlines_count
= headlines_count_obj
.getAttribute("value");
100 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
101 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
103 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
105 if (headlines_count
== 0) {
106 _infscroll_disable
= 1;
108 _infscroll_disable
= 0;
111 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
112 var articles
= transport
.responseXML
.getElementsByTagName("article");
113 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
115 if (feed_cur_page
== 0) {
117 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
119 var cache_prefix
= "";
127 cache_invalidate(cache_prefix
+ feed_id
);
129 if (!disable_cache
) {
130 cache_inject(cache_prefix
+ feed_id
,
131 headlines
.firstChild
.nodeValue
, headlines_unread
);
135 debug("headlines_callback: returned no data");
136 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
141 if (headlines_count
> 0) {
142 debug("adding some more headlines...");
144 var c
= document
.getElementById("headlinesList");
147 c
= document
.getElementById("headlinesInnerContainer");
150 var ids
= getSelectedArticleIds2();
152 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
154 debug("restore selected ids: " + ids
);
156 for (var i
= 0; i
< ids
.length
; i
++) {
157 markHeadline(ids
[i
]);
161 debug("no new headlines received");
164 debug("headlines_callback: returned no data");
165 notify_error("Error while trying to load more headlines");
171 for (var i
= 0; i
< articles
.length
; i
++) {
172 var a_id
= articles
[i
].getAttribute("id");
173 debug("found id: " + a_id
);
174 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
177 debug("no cached articles received");
181 debug("parsing piggybacked counters: " + counters
);
182 parse_counters(counters
, false);
184 debug("counters container not found in reply, requesting...");
189 debug("parsing runtime info: " + runtime_info
[0]);
190 parse_runtime_info(runtime_info
[0]);
192 debug("counters container not found in reply");
196 debug("headlines_callback: returned no XML object");
197 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
200 if (typeof correctPNG
!= 'undefined') {
204 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
206 if (!document
.getElementById("headlinesList") &&
207 getActiveFeedId() != -3 &&
208 getInitParam("cdm_auto_catchup") == 1) {
209 debug("starting CDM watchdog");
210 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
211 _cdm_wd_vishist
= new Array();
213 debug("not in CDM mode or watchdog disabled");
216 _feed_cur_page
= feed_cur_page
;
217 _infscroll_request_sent
= 0;
224 exception_error("headlines_callback2", e
, transport
);
228 function render_article(article
) {
230 var f
= document
.getElementById("content-frame");
235 var fi
= document
.getElementById("content-insert");
241 fi
.innerHTML
= article
;
244 exception_error("render_article", e
);
248 function showArticleInHeadlines(id
) {
252 cleanSelected("headlinesList");
254 var crow
= document
.getElementById("RROW-" + id
);
258 var article_is_unread
= crow
.className
.match("Unread");
260 crow
.className
= crow
.className
.replace("Unread", "");
262 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
264 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
266 var cache_prefix
= "";
268 if (activeFeedIsCat()) {
274 var view_mode
= false;
277 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
278 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
283 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
284 upd_img_pic
.src
= "images/blank_icon.gif";
286 cache_invalidate(cache_prefix
+ getActiveFeedId());
288 cache_inject(cache_prefix
+ getActiveFeedId(),
289 document
.getElementById("headlines-frame").innerHTML
,
290 get_feed_unread(getActiveFeedId()));
292 } else if (article_is_unread
&& view_mode
== "all_articles") {
294 cache_invalidate(cache_prefix
+ getActiveFeedId());
296 cache_inject(cache_prefix
+ getActiveFeedId(),
297 document
.getElementById("headlines-frame").innerHTML
,
298 get_feed_unread(getActiveFeedId())-1);
300 } else if (article_is_unread
) {
301 cache_invalidate(cache_prefix
+ getActiveFeedId());
307 exception_error("showArticleInHeadlines", e
);
311 function article_callback2(transport
, id
, feed_id
) {
313 debug("article_callback2 " + id
);
315 if (transport
.responseXML
) {
317 if (!transport_error_check(transport
)) return;
319 debug("looking for articles to cache...");
321 var articles
= transport
.responseXML
.getElementsByTagName("article");
323 for (var i
= 0; i
< articles
.length
; i
++) {
324 var a_id
= articles
[i
].getAttribute("id");
326 debug("found id: " + a_id
);
328 if (a_id
== active_post_id
) {
329 debug("active article, rendering...");
330 render_article(articles
[i
].firstChild
.nodeValue
);
333 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
336 if (id
!= last_requested_article
) {
337 debug("requested article id is out of sequence, aborting");
341 active_real_feed_id
= feed_id
;
344 showArticleInHeadlines(id
);
346 var reply
= transport
.responseXML
.firstChild
.firstChild
;
349 debug("article_callback: returned no XML object");
350 //var f = document.getElementById("content-frame");
351 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
354 var date
= new Date();
355 last_article_view
= date
.getTime() / 1000;
357 if (typeof correctPNG
!= 'undefined') {
361 if (_reload_feedlist_after_view
) {
362 setTimeout('updateFeedList(false, false)', 50);
363 _reload_feedlist_after_view
= false;
365 if (transport
.responseXML
) {
366 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
369 debug("parsing piggybacked counters: " + counters
);
370 parse_counters(counters
, false);
372 debug("counters container not found in reply, requesting...");
380 exception_error("article_callback2", e
, transport
);
384 function view(id
, feed_id
, skip_history
) {
387 debug("loading article: " + id
+ "/" + feed_id
);
389 var cached_article
= cache_find(id
);
391 debug("cache check result: " + (cached_article
!= false));
395 //setActiveFeedId(feed_id);
397 var query
= "backend.php?op=view&id=" + param_escape(id
) +
398 "&feed=" + param_escape(feed_id
);
400 var date
= new Date();
402 var neighbor_ids
= getRelativePostIds(active_post_id
);
404 /* only request uncached articles */
406 var cids_to_request
= Array();
408 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
409 if (!cache_check(neighbor_ids
[i
])) {
410 cids_to_request
.push(neighbor_ids
[i
]);
414 debug("additional ids: " + cids_to_request
.toString());
416 /* additional info for piggyback counters */
418 if (tagsAreDisplayed()) {
419 query
= query
+ "&omode=lt";
421 query
= query
+ "&omode=flc";
424 var date
= new Date();
425 var timestamp
= Math
.round(date
.getTime() / 1000);
426 query
= query
+ "&ts=" + timestamp
;
428 query
= query
+ "&cids=" + cids_to_request
.toString();
430 var crow
= document
.getElementById("RROW-" + id
);
431 var article_is_unread
= crow
.className
.match("Unread");
433 if (!async_counters_work
) {
434 query
= query
+ "&csync=true";
437 showArticleInHeadlines(id
);
439 if (!cached_article
) {
441 notify_progress("Loading, please wait...", true);
443 } else if (cached_article
&& article_is_unread
) {
445 query
= query
+ "&mode=prefetch";
447 render_article(cached_article
);
449 } else if (cached_article
) {
451 query
= query
+ "&mode=prefetch_old";
452 render_article(cached_article
);
458 last_requested_article
= id
;
460 new Ajax
.Request(query
, {
461 onComplete: function(transport
) {
462 article_callback2(transport
, id
, feed_id
);
468 exception_error("view", e
);
473 return toggleMark(id
);
477 return togglePub(id
);
480 function tMark_afh_off(effect
) {
482 var elem
= effect
.effects
[0].element
;
484 debug("tMark_afh_off : " + elem
.id
);
487 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
488 elem
.alt
= __("Star article");
493 exception_error("tMark_afh_off", e
);
497 function tPub_afh_off(effect
) {
499 var elem
= effect
.effects
[0].element
;
501 debug("tPub_afh_off : " + elem
.id
);
504 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
505 elem
.alt
= __("Publish article");
510 exception_error("tPub_afh_off", e
);
514 function toggleMark(id
, client_only
, no_effects
) {
518 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
520 query
= query
+ "&afid=" + getActiveFeedId();
522 if (tagsAreDisplayed()) {
523 query
= query
+ "&omode=tl";
525 query
= query
+ "&omode=flc";
528 var mark_img
= document
.getElementById("FMPIC-" + id
);
530 if (!mark_img
) return;
532 var vfeedu
= document
.getElementById("FEEDU--1");
533 var crow
= document
.getElementById("RROW-" + id
);
535 if (mark_img
.src
.match("mark_unset")) {
536 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
537 mark_img
.alt
= __("Unstar article");
538 query
= query
+ "&mark=1";
541 //mark_img.src = "images/mark_unset.png";
542 mark_img
.alt
= __("Please wait...");
543 query
= query
+ "&mark=0";
545 if (document
.getElementById("headlinesList") && !no_effects
) {
546 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
548 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
549 mark_img
.alt
= __("Star article");
556 new Ajax
.Request(query
, {
557 onComplete: function(transport
) {
558 all_counters_callback2(transport
);
564 exception_error("toggleMark", e
);
568 function togglePub(id
, client_only
, no_effects
) {
572 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
574 query
= query
+ "&afid=" + getActiveFeedId();
576 if (tagsAreDisplayed()) {
577 query
= query
+ "&omode=tl";
579 query
= query
+ "&omode=flc";
582 var mark_img
= document
.getElementById("FPPIC-" + id
);
584 if (!mark_img
) return;
586 var vfeedu
= document
.getElementById("FEEDU--2");
587 var crow
= document
.getElementById("RROW-" + id
);
589 if (mark_img
.src
.match("pub_unset")) {
590 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
591 mark_img
.alt
= __("Unpublish article");
592 query
= query
+ "&pub=1";
596 //mark_img.src = "images/pub_unset.png";
597 mark_img
.alt
= __("Please wait...");
598 query
= query
+ "&pub=0";
600 if (document
.getElementById("headlinesList") && !no_effects
) {
601 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
603 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
604 mark_img
.alt
= __("Publish article");
609 new Ajax
.Request(query
, {
610 onComplete: function(transport
) {
611 all_counters_callback2(transport
);
617 exception_error("togglePub", e
);
621 function correctHeadlinesOffset(id
) {
625 var hlist
= document
.getElementById("headlinesList");
626 var container
= document
.getElementById("headlinesInnerContainer");
627 var row
= document
.getElementById("RROW-" + id
);
629 var viewport
= container
.offsetHeight
;
631 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
632 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
634 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
635 debug("Vport: " + viewport
);
637 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
638 container
.scrollTop
= row
.offsetTop
;
639 } else if (rel_offset_bottom
> viewport
) {
641 /* doesn't properly work with Opera in some cases because
642 Opera fucks up element scrolling */
644 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
648 exception_error("correctHeadlinesOffset", e
);
653 function moveToPost(mode
) {
660 rows
= cdmGetVisibleArticles();
662 rows
= getVisibleHeadlineIds();
668 if (!document
.getElementById('RROW-' + active_post_id
)) {
669 active_post_id
= false;
672 if (active_post_id
== false) {
673 next_id
= getFirstVisibleHeadlineId();
674 prev_id
= getLastVisibleHeadlineId();
676 for (var i
= 0; i
< rows
.length
; i
++) {
677 if (rows
[i
] == active_post_id
) {
684 if (mode
== "next") {
688 if (!cdmArticleIsActuallyVisible(next_id
)) {
689 cdmScrollToArticleId(next_id
);
691 cdmSelectArticles("none");
692 toggleUnread(next_id
, 0, true);
693 toggleSelected(next_id
);
696 correctHeadlinesOffset(next_id
);
697 view(next_id
, getActiveFeedId());
702 if (mode
== "prev") {
705 cdmScrollToArticleId(prev_id
);
706 cdmSelectArticles("none");
707 toggleUnread(prev_id
, 0, true);
708 toggleSelected(prev_id
);
710 correctHeadlinesOffset(prev_id
);
711 view(prev_id
, getActiveFeedId());
717 exception_error("moveToPost", e
);
721 function toggleSelected(id
) {
724 var cb
= document
.getElementById("RCHK-" + id
);
726 var row
= document
.getElementById("RROW-" + id
);
728 var nc
= row
.className
;
730 if (!nc
.match("Selected")) {
731 nc
= nc
+ "Selected";
736 // In CDM basically last selected article == active article
737 if (isCdmMode()) active_post_id
= id
;
739 nc
= nc
.replace("Selected", "");
749 exception_error("toggleSelected", e
);
753 function toggleUnread_afh(effect
) {
756 var elem
= effect
.element
;
757 elem
.style
.backgroundColor
= "";
760 exception_error("toggleUnread_afh", e
);
764 function toggleUnread(id
, cmode
, effect
) {
767 var row
= document
.getElementById("RROW-" + id
);
769 var nc
= row
.className
;
770 var is_selected
= row
.className
.match("Selected");
771 nc
= nc
.replace("Unread", "");
772 nc
= nc
.replace("Selected", "");
774 // since we are removing selection from the object, uncheck
775 // corresponding checkbox
777 var cb
= document
.getElementById("RCHK-" + id
);
782 // NOTE: I'm not sure that resetting selection here is a feature -fox
784 if (cmode
== undefined || cmode
== 2) {
785 if (row
.className
.match("Unread")) {
789 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
790 afterFinish
: toggleUnread_afh
,
791 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
795 row
.className
= nc
+ "Unread";
797 } else if (cmode
== 0) {
801 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
802 afterFinish
: toggleUnread_afh
,
803 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
805 } else if (cmode
== 1) {
806 row
.className
= nc
+ "Unread";
809 // Disable unmarking as selected for the time being (16.05.08) -fox
810 if (is_selected
) row
.className
= row
.className
+ "Selected";
812 if (cmode
== undefined) cmode
= 2;
814 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
815 param_escape(id
) + "&cmode=" + param_escape(cmode
);
817 // notify_progress("Loading, please wait...");
819 new Ajax
.Request(query
, {
820 onComplete: function(transport
) {
821 all_counters_callback2(transport
);
828 exception_error("toggleUnread", e
);
832 function selectionRemoveLabel(id
) {
835 var ids
= getSelectedArticleIds2();
837 if (ids
.length
== 0) {
838 alert(__("No articles are selected."));
842 // var ok = confirm(__("Remove selected articles from label?"));
846 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
847 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
849 // notify_progress("Loading, please wait...");
851 cache_invalidate("F:" + (-11 - id
));
853 new Ajax
.Request(query
, {
854 onComplete: function(transport
) {
855 show_labels_in_headlines(transport
);
856 all_counters_callback2(transport
);
862 exception_error("selectionAssignLabel", e
);
867 function selectionAssignLabel(id
) {
870 var ids
= getSelectedArticleIds2();
872 if (ids
.length
== 0) {
873 alert(__("No articles are selected."));
877 // var ok = confirm(__("Assign selected articles to label?"));
881 cache_invalidate("F:" + (-11 - id
));
883 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
884 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
886 // notify_progress("Loading, please wait...");
888 new Ajax
.Request(query
, {
889 onComplete: function(transport
) {
890 show_labels_in_headlines(transport
);
891 all_counters_callback2(transport
);
897 exception_error("selectionAssignLabel", e
);
902 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
907 rows
= cdmGetSelectedArticles();
909 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
912 if (rows
.length
== 0 && !no_error
) {
913 alert(__("No articles are selected."));
917 for (i
= 0; i
< rows
.length
; i
++) {
918 var row
= document
.getElementById("RROW-" + rows
[i
]);
920 var nc
= row
.className
;
921 nc
= nc
.replace("Unread", "");
922 nc
= nc
.replace("Selected", "");
924 if (set_state
== undefined) {
925 if (row
.className
.match("Unread")) {
926 row
.className
= nc
+ "Selected";
928 row
.className
= nc
+ "UnreadSelected";
932 if (set_state
== false) {
933 row
.className
= nc
+ "Selected";
936 if (set_state
== true) {
937 row
.className
= nc
+ "UnreadSelected";
942 if (rows
.length
> 0) {
946 if (set_state
== undefined) {
948 } else if (set_state
== true) {
950 } else if (set_state
== false) {
954 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
955 param_escape(rows
.toString()) + "&cmode=" + cmode
;
957 notify_progress("Loading, please wait...");
959 new Ajax
.Request(query
, {
960 onComplete: function(transport
) {
961 catchup_callback2(transport
, callback_func
);
967 exception_error("selectionToggleUnread", e
);
971 function selectionToggleMarked(cdm_mode
) {
977 rows
= cdmGetSelectedArticles();
979 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
982 if (rows
.length
== 0) {
983 alert(__("No articles are selected."));
987 for (i
= 0; i
< rows
.length
; i
++) {
988 toggleMark(rows
[i
], true, true);
991 if (rows
.length
> 0) {
993 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
994 param_escape(rows
.toString()) + "&cmode=2";
996 query
= query
+ "&afid=" + getActiveFeedId();
998 /* if (tagsAreDisplayed()) {
999 query = query + "&omode=tl";
1001 query = query + "&omode=flc";
1004 query
= query
+ "&omode=lc";
1006 new Ajax
.Request(query
, {
1007 onComplete: function(transport
) {
1008 all_counters_callback2(transport
);
1014 exception_error("selectionToggleMarked", e
);
1018 function selectionTogglePublished(cdm_mode
) {
1024 rows
= cdmGetSelectedArticles();
1026 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1029 if (rows
.length
== 0) {
1030 alert(__("No articles are selected."));
1034 for (i
= 0; i
< rows
.length
; i
++) {
1035 togglePub(rows
[i
], true, true);
1038 if (rows
.length
> 0) {
1040 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1041 param_escape(rows
.toString()) + "&cmode=2";
1043 query
= query
+ "&afid=" + getActiveFeedId();
1045 /* if (tagsAreDisplayed()) {
1046 query = query + "&omode=tl";
1048 query = query + "&omode=flc";
1051 query
= query
+ "&omode=lc";
1053 new Ajax
.Request(query
, {
1054 onComplete: function(transport
) {
1055 all_counters_callback2(transport
);
1061 exception_error("selectionToggleMarked", e
);
1065 function cdmGetSelectedArticles() {
1066 var sel_articles
= new Array();
1067 var container
= document
.getElementById("headlinesInnerContainer");
1069 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1070 var child
= container
.childNodes
[i
];
1072 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1073 var c_id
= child
.id
.replace("RROW-", "");
1074 sel_articles
.push(c_id
);
1078 return sel_articles
;
1081 function cdmGetVisibleArticles() {
1082 var sel_articles
= new Array();
1083 var container
= document
.getElementById("headlinesInnerContainer");
1085 if (!container
) return sel_articles
;
1087 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1088 var child
= container
.childNodes
[i
];
1090 if (child
.id
&& child
.id
.match("RROW-")) {
1091 var c_id
= child
.id
.replace("RROW-", "");
1092 sel_articles
.push(c_id
);
1096 return sel_articles
;
1099 function cdmGetUnreadArticles() {
1100 var sel_articles
= new Array();
1101 var container
= document
.getElementById("headlinesInnerContainer");
1103 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1104 var child
= container
.childNodes
[i
];
1106 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1107 var c_id
= child
.id
.replace("RROW-", "");
1108 sel_articles
.push(c_id
);
1112 return sel_articles
;
1116 // mode = all,none,unread
1117 function cdmSelectArticles(mode
) {
1118 var container
= document
.getElementById("headlinesInnerContainer");
1120 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1121 var child
= container
.childNodes
[i
];
1123 if (child
.id
&& child
.id
.match("RROW-")) {
1124 var aid
= child
.id
.replace("RROW-", "");
1126 var cb
= document
.getElementById("RCHK-" + aid
);
1128 if (mode
== "all") {
1129 if (!child
.className
.match("Selected")) {
1130 child
.className
= child
.className
+ "Selected";
1133 } else if (mode
== "unread") {
1134 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1135 child
.className
= child
.className
+ "Selected";
1139 child
.className
= child
.className
.replace("Selected", "");
1146 function catchupPage() {
1148 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1150 var str
= __("Mark all visible articles in %s as read?");
1152 str
= str
.replace("%s", fn
);
1154 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1158 if (document
.getElementById("headlinesList")) {
1159 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1160 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1161 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1163 cdmSelectArticles('all');
1164 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1165 cdmSelectArticles('none');
1169 function catchupSelection() {
1175 if (document
.getElementById("headlinesList")) {
1176 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1178 rows
= cdmGetSelectedArticles();
1181 if (rows
.length
== 0) {
1182 alert(__("No articles are selected."));
1187 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1189 var str
= __("Mark %d selected articles in %s as read?");
1191 str
= str
.replace("%d", rows
.length
);
1192 str
= str
.replace("%s", fn
);
1194 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1198 if (document
.getElementById("headlinesList")) {
1199 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1200 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1202 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1203 // cdmSelectArticles('none');
1207 exception_error("catchupSelection", e
);
1211 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1212 displayDlg('editArticleTags', id
);
1216 function tag_saved_callback(transport
) {
1218 debug("in tag_saved_callback");
1223 if (tagsAreDisplayed()) {
1224 _reload_feedlist_after_view
= true;
1228 if (transport
.responseXML
) {
1229 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1232 var id
= tags_str
.getAttribute("id");
1235 var tags
= document
.getElementById("ATSTR-" + id
);
1237 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1244 exception_error("tag_saved_callback", e
);
1248 function editTagsSave() {
1250 notify_progress("Saving article tags...");
1252 var form
= document
.forms
["tag_edit_form"];
1254 var query
= Form
.serialize("tag_edit_form");
1256 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1260 new Ajax
.Request(query
, {
1261 onComplete: function(transport
) {
1262 tag_saved_callback(transport
);
1267 function editTagsInsert() {
1270 var form
= document
.forms
["tag_edit_form"];
1272 var found_tags
= form
.found_tags
;
1273 var tags_str
= form
.tags_str
;
1275 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1277 if (tags_str
.value
.length
> 0 &&
1278 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1280 tags_str
.value
= tags_str
.value
+ ", ";
1283 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1285 found_tags
.selectedIndex
= 0;
1288 exception_error("editTagsInsert", e
);
1292 function cdmScrollViewport(where
) {
1293 debug("cdmScrollViewport: " + where
);
1295 var ctr
= document
.getElementById("headlinesInnerContainer");
1299 if (where
== "bottom") {
1300 ctr
.scrollTop
= ctr
.scrollHeight
;
1302 ctr
.scrollTop
= where
;
1306 function cdmArticleIsBelowViewport(id
) {
1308 var ctr
= document
.getElementById("headlinesInnerContainer");
1309 var e
= document
.getElementById("RROW-" + id
);
1311 if (!e
|| !ctr
) return;
1313 // article starts below viewport
1315 if (ctr
.scrollTop
< e
.offsetTop
) {
1322 exception_error("cdmArticleIsVisible", e
);
1326 function cdmArticleIsAboveViewport(id
) {
1328 var ctr
= document
.getElementById("headlinesInnerContainer");
1329 var e
= document
.getElementById("RROW-" + id
);
1331 if (!e
|| !ctr
) return;
1333 // article starts above viewport
1335 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1342 exception_error("cdmArticleIsVisible", e
);
1346 function cdmScrollToArticleId(id
) {
1348 var ctr
= document
.getElementById("headlinesInnerContainer");
1349 var e
= document
.getElementById("RROW-" + id
);
1351 if (!e
|| !ctr
) return;
1353 ctr
.scrollTop
= e
.offsetTop
;
1356 exception_error("cdmScrollToArticleId", e
);
1360 function cdmArticleIsActuallyVisible(id
) {
1362 var ctr
= document
.getElementById("headlinesInnerContainer");
1363 var e
= document
.getElementById("RROW-" + id
);
1365 if (!e
|| !ctr
) return;
1367 // article fits in viewport OR article is longer than viewport and
1368 // its bottom is visible
1370 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1371 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1375 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1376 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1377 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1386 exception_error("cdmArticleIsVisible", e
);
1390 function cdmWatchdog() {
1394 var ctr
= document
.getElementById("headlinesInnerContainer");
1398 var ids
= new Array();
1400 var e
= ctr
.firstChild
;
1403 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1404 e
.id
.match("RROW-")) {
1406 // article fits in viewport OR article is longer than viewport and
1407 // its bottom is visible
1409 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1410 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1412 // debug(e.id + " is visible " + e.offsetTop + "." +
1413 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1414 // (ctr.scrollTop + ctr.offsetHeight));
1416 ids
.push(e
.id
.replace("RROW-", ""));
1418 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1419 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1420 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1422 ids
.push(e
.id
.replace("RROW-", ""));
1426 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1428 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1429 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1431 ids.push(e.id.replace("RROW-", ""));
1440 debug("cdmWatchdog, ids= " + ids
.toString());
1442 if (ids
.length
> 0) {
1444 for (var i
= 0; i
< ids
.length
; i
++) {
1445 var e
= document
.getElementById("RROW-" + ids
[i
]);
1447 e
.className
= e
.className
.replace("Unread", "");
1451 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1452 param_escape(ids
.toString()) + "&cmode=0";
1454 new Ajax
.Request(query
, {
1455 onComplete: function(transport
) {
1456 all_counters_callback2(transport
);
1461 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1464 exception_error("cdmWatchdog", e
);
1470 function cache_inject(id
, article
, param
) {
1472 if (!cache_check_param(id
, param
)) {
1473 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1478 var date
= new Date();
1479 var ts
= Math
.round(date
.getTime() / 1000);
1481 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1482 [id
, article
, param
, ts
]);
1485 var cache_obj
= new Array();
1487 cache_obj
["id"] = id
;
1488 cache_obj
["data"] = article
;
1489 cache_obj
["param"] = param
;
1491 article_cache
.push(cache_obj
);
1495 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1498 exception_error("cache_inject", e
);
1502 function cache_find(id
) {
1505 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1507 if (rs
.isValidRow()) {
1512 for (var i
= 0; i
< article_cache
.length
; i
++) {
1513 if (article_cache
[i
]["id"] == id
) {
1514 return article_cache
[i
]["data"];
1521 function cache_find_param(id
, param
) {
1524 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1527 if (rs
.isValidRow()) {
1532 for (var i
= 0; i
< article_cache
.length
; i
++) {
1533 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1534 return article_cache
[i
]["data"];
1541 function cache_check(id
) {
1544 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1547 if (rs
.isValidRow()) {
1548 return rs
.field(0) != "0";
1552 for (var i
= 0; i
< article_cache
.length
; i
++) {
1553 if (article_cache
[i
]["id"] == id
) {
1561 function cache_check_param(id
, param
) {
1564 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1567 if (rs
.isValidRow()) {
1568 return rs
.field(0) != "0";
1572 for (var i
= 0; i
< article_cache
.length
; i
++) {
1573 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1581 function cache_expire() {
1583 var date
= new Date();
1584 var ts
= Math
.round(date
.getTime() / 1000);
1586 db
.execute("DELETE FROM cache WHERE added < ? - 600", [ts
]);
1589 while (article_cache
.length
> 25) {
1590 article_cache
.shift();
1595 function cache_empty() {
1596 article_cache
= new Array();
1599 function cache_invalidate(id
) {
1603 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1604 return rs
.rowsAffected
!= 0;
1609 while (i
< article_cache
.length
) {
1610 if (article_cache
[i
]["id"] == id
) {
1611 debug("cache_invalidate: removed id " + id
);
1612 article_cache
.splice(i
, 1);
1619 debug("cache_invalidate: id not found: " + id
);
1622 exception_error("cache_invalidate", e
);
1626 function getActiveArticleId() {
1627 return active_post_id
;
1630 function cdmClicked(id
) {
1632 var elem
= document
.getElementById("RROW-" + id
);
1635 var id
= elem
.id
.replace("RROW-", "");
1636 active_post_id
= id
;
1638 cdmSelectArticles("none");
1639 toggleUnread(id
, 0, true);
1644 exception_error("cdmClicked", e
);
1648 function preload_article_callback(transport
) {
1650 if (transport
.responseXML
) {
1651 var articles
= transport
.responseXML
.getElementsByTagName("article");
1653 for (var i
= 0; i
< articles
.length
; i
++) {
1654 var id
= articles
[i
].getAttribute("id");
1655 if (!cache_check(id
)) {
1656 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1657 debug("preloaded article: " + id
);
1662 exception_error("preload_article_callback", e
);
1666 function preloadArticleUnderPointer(id
) {
1668 if (getInitParam("bw_limit") == "1") return;
1670 if (post_under_pointer
== id
&& !cache_check(id
)) {
1672 debug("trying to preload article " + id
);
1674 var neighbor_ids
= getRelativePostIds(id
, 1);
1676 /* only request uncached articles */
1678 var cids_to_request
= Array();
1680 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1681 if (!cache_check(neighbor_ids
[i
])) {
1682 cids_to_request
.push(neighbor_ids
[i
]);
1685 debug("additional ids: " + cids_to_request
.toString());
1687 cids_to_request
.push(id
);
1689 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1690 cids_to_request
.toString();
1691 new Ajax
.Request(query
, {
1692 onComplete: function(transport
) {
1693 preload_article_callback(transport
);
1697 exception_error("preloadArticleUnderPointer", e
);
1701 function postMouseIn(id
) {
1703 if (post_under_pointer
!= id
) {
1704 post_under_pointer
= id
;
1706 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1711 exception_error("postMouseIn", e
);
1715 function postMouseOut(id
) {
1717 post_under_pointer
= false;
1719 exception_error("postMouseOut", e
);
1723 function headlines_scroll_handler() {
1726 var e
= document
.getElementById("headlinesInnerContainer");
1728 // don't do infinite scrolling when Limit == All
1730 var toolbar_form
= document
.forms
["main_toolbar_form"];
1732 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1733 if (limit
.value
!= 0) {
1735 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1736 _infscroll_disable
);
1738 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1739 if (!_infscroll_disable
) {
1740 debug("more cowbell!");
1747 exception_error("headlines_scroll_handler", e
);
1751 function catchupRelativeToArticle(below
) {
1756 if (!getActiveArticleId()) {
1757 alert(__("No article is selected."));
1763 if (document
.getElementById("headlinesList")) {
1764 visible_ids
= getVisibleHeadlineIds();
1766 visible_ids
= cdmGetVisibleArticles();
1769 var ids_to_mark
= new Array();
1772 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1773 if (visible_ids
[i
] != getActiveArticleId()) {
1774 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1776 if (e
&& e
.className
.match("Unread")) {
1777 ids_to_mark
.push(visible_ids
[i
]);
1784 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1785 if (visible_ids
[i
] != getActiveArticleId()) {
1786 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1788 if (e
&& e
.className
.match("Unread")) {
1789 ids_to_mark
.push(visible_ids
[i
]);
1797 if (ids_to_mark
.length
== 0) {
1798 alert(__("No articles found to mark"));
1800 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1804 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1805 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1806 e
.className
= e
.className
.replace("Unread", "");
1809 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1810 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1812 new Ajax
.Request(query
, {
1813 onComplete: function(transport
) {
1814 catchup_callback2(transport
);
1821 exception_error("catchupRelativeToArticle", e
);
1825 function cdmExpandArticle(a_id
) {
1827 var id
= 'CICD-' + a_id
;
1830 Element
.hide("CEXC-" + a_id
);
1833 Effect
.Appear(id
, {duration
: 0.5,
1834 beforeStart: function(effect
) {
1835 var h_id
= 'CICH-' + a_id
;
1836 var h_elem
= document
.getElementById(h_id
);
1837 if (h_elem
) { h_elem
.style
.display
= "none"; }
1839 toggleUnread(a_id
, 0);
1844 exception_error("appearBlockElementF", e
);
1849 function fixHeadlinesOrder(ids
) {
1851 for (var i
= 0; i
< ids
.length
; i
++) {
1852 var e
= document
.getElementById("RROW-" + ids
[i
]);
1856 e
.className
= e
.className
.replace("even", "odd");
1858 e
.className
= e
.className
.replace("odd", "even");
1863 exception_error("fixHeadlinesOrder", e
);
1867 function hideReadHeadlines() {
1871 var vis_ids
= new Array();
1873 if (document
.getElementById("headlinesList")) {
1874 ids
= getVisibleHeadlineIds();
1876 ids
= cdmGetVisibleArticles();
1879 var read_headlines_visible
= true;
1881 for (var i
= 0; i
< ids
.length
; i
++) {
1882 var row
= document
.getElementById("RROW-" + ids
[i
]);
1884 if (row
&& row
.className
) {
1885 if (read_headlines_visible
) {
1886 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1888 vis_ids
.push(ids
[i
]);
1890 //Effect.Fade(row, {duration : 0.3});
1895 vis_ids
.push(ids
[i
]);
1900 fixHeadlinesOrder(vis_ids
);
1902 read_headlines_visible
= !read_headlines_visible
;
1905 exception_error("hideReadHeadlines", e
);
1909 function invertHeadlineSelection() {
1911 var rows
= new Array();
1915 r
= document
.getElementsByTagName("TR");
1917 r
= document
.getElementsByTagName("DIV");
1920 for (var i
= 0; i
< r
.length
; i
++) {
1921 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1926 for (var i
= 0; i
< rows
.length
; i
++) {
1927 var nc
= rows
[i
].className
;
1928 var id
= rows
[i
].id
.replace("RROW-", "");
1929 var cb
= document
.getElementById("RCHK-" + id
);
1931 if (!rows
[i
].className
.match("Selected")) {
1932 nc
= nc
+ "Selected";
1935 nc
= nc
.replace("Selected", "");
1939 rows
[i
].className
= nc
;
1944 exception_error("invertHeadlineSelection", e
);
1948 function getArticleUnderPointer() {
1949 return post_under_pointer
;
1952 function zoomToArticle(id
) {
1954 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1956 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1959 exception_error("zoomToArticle", e
);
1963 function showOriginalArticleInline(id
) {
1966 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1968 notify_progress("Loading, please wait...", true);
1970 new Ajax
.Request(query
, {
1971 onComplete: function(transport
) {
1973 if (transport
.responseXML
) {
1975 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1976 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1981 link
= link
.firstChild
.nodeValue
;
1983 var ci
= document
.getElementById("content-insert");
1985 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1987 render_article(tmp
);
1994 exception_error("showOriginalArticleInline", e
);
1999 function scrollArticle(offset
) {
2002 var ci
= document
.getElementById("content-insert");
2004 ci
.scrollTop
+= offset
;
2007 var hi
= document
.getElementById("headlinesInnerContainer");
2009 hi
.scrollTop
+= offset
;
2014 exception_error("scrollArticle", e
);
2018 function show_labels_in_headlines(transport
) {
2020 if (transport
.responseXML
) {
2021 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2023 var elems
= info
.getElementsByTagName("entry");
2025 for (var l
= 0; l
< elems
.length
; l
++) {
2026 var e_id
= elems
[l
].getAttribute("id");
2030 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
2033 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2041 exception_error("show_labels_in_headlines", e
);
2046 function toggleHeadlineActions() {
2048 var e
= document
.getElementById("headlineActionsBody");
2049 var p
= document
.getElementById("headlineActionsDrop");
2051 if (!Element
.visible(e
)) {
2058 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2059 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2062 exception_error("toggleHeadlineActions", e
);