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_callback() {
19 if (xmlhttp_rpc
.readyState
== 4) {
21 debug("catchup_callback");
23 all_counters_callback2(xmlhttp_rpc
);
24 if (_catchup_callback_func
) {
25 setTimeout(_catchup_callback_func
, 10);
28 exception_error("catchup_callback", e
);
33 function catchup_callback2(transport
, callback
) {
35 debug("catchup_callback2 " + transport
+ ", " + callback
);
37 all_counters_callback2(transport
);
39 setTimeout(callback
, 10);
42 exception_error("catchup_callback2", e
, transport
);
46 function clean_feed_selections() {
48 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
50 for (var i
= 0; i
< feeds
.length
; i
++) {
51 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
52 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
54 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
55 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
59 exception_error("clean_feed_selections", e
);
63 function headlines_callback2(transport
, feed_cur_page
) {
66 loading_set_progress(100);
68 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
70 clean_feed_selections();
75 if (transport
.responseXML
) {
76 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
78 is_cat
= headlines
.getAttribute("is_cat");
79 feed_id
= headlines
.getAttribute("id");
80 setActiveFeedId(feed_id
, is_cat
);
85 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
86 if (feedr
&& !feedr
.className
.match("Selected")) {
87 feedr
.className
= feedr
.className
+ "Selected";
90 var feedr
= document
.getElementById("FCAT-" + feed_id
);
91 if (feedr
&& !feedr
.className
.match("Selected")) {
92 feedr
.className
= feedr
.className
+ "Selected";
96 var f
= document
.getElementById("headlines-frame");
98 if (feed_cur_page
== 0) {
99 debug("resetting headlines scrollTop");
104 if (transport
.responseXML
) {
105 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
106 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
107 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
108 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
110 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
112 var headlines_count
= headlines_count_obj
.getAttribute("value");
113 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
114 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
116 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
118 if (headlines_count
== 0) {
119 _infscroll_disable
= 1;
121 _infscroll_disable
= 0;
124 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
125 var articles
= transport
.responseXML
.getElementsByTagName("article");
126 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
128 if (feed_cur_page
== 0) {
130 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
132 var cache_prefix
= "";
140 cache_invalidate(cache_prefix
+ feed_id
);
142 if (!disable_cache
) {
143 cache_inject(cache_prefix
+ feed_id
,
144 headlines
.firstChild
.nodeValue
, headlines_unread
);
148 debug("headlines_callback: returned no data");
149 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
154 if (headlines_count
> 0) {
155 debug("adding some more headlines...");
157 var c
= document
.getElementById("headlinesList");
160 c
= document
.getElementById("headlinesInnerContainer");
163 var ids
= getSelectedArticleIds2();
165 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
167 debug("restore selected ids: " + ids
);
169 for (var i
= 0; i
< ids
.length
; i
++) {
170 markHeadline(ids
[i
]);
174 debug("no new headlines received");
177 debug("headlines_callback: returned no data");
178 notify_error("Error while trying to load more headlines");
184 for (var i
= 0; i
< articles
.length
; i
++) {
185 var a_id
= articles
[i
].getAttribute("id");
186 debug("found id: " + a_id
);
187 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
190 debug("no cached articles received");
194 debug("parsing piggybacked counters: " + counters
);
195 parse_counters(counters
, false);
197 debug("counters container not found in reply, requesting...");
202 debug("parsing runtime info: " + runtime_info
[0]);
203 parse_runtime_info(runtime_info
[0]);
205 debug("counters container not found in reply");
209 debug("headlines_callback: returned no XML object");
210 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
213 if (typeof correctPNG
!= 'undefined') {
217 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
219 if (!document
.getElementById("headlinesList") &&
220 getActiveFeedId() != -3 &&
221 getInitParam("cdm_auto_catchup") == 1) {
222 debug("starting CDM watchdog");
223 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
224 _cdm_wd_vishist
= new Array();
226 debug("not in CDM mode or watchdog disabled");
229 _feed_cur_page
= feed_cur_page
;
230 _infscroll_request_sent
= 0;
237 exception_error("headlines_callback2", e
, transport
);
241 function render_article(article
) {
243 var f
= document
.getElementById("content-frame");
248 var fi
= document
.getElementById("content-insert");
254 fi
.innerHTML
= article
;
257 exception_error("render_article", e
);
261 function showArticleInHeadlines(id
) {
265 cleanSelected("headlinesList");
267 var crow
= document
.getElementById("RROW-" + id
);
271 var article_is_unread
= crow
.className
.match("Unread");
273 crow
.className
= crow
.className
.replace("Unread", "");
275 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
277 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
279 var cache_prefix
= "";
281 if (activeFeedIsCat()) {
287 var view_mode
= false;
290 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
291 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
296 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
297 upd_img_pic
.src
= "images/blank_icon.gif";
299 cache_invalidate(cache_prefix
+ getActiveFeedId());
301 cache_inject(cache_prefix
+ getActiveFeedId(),
302 document
.getElementById("headlines-frame").innerHTML
,
303 get_feed_unread(getActiveFeedId()));
305 } else if (article_is_unread
&& view_mode
== "all_articles") {
307 cache_invalidate(cache_prefix
+ getActiveFeedId());
309 cache_inject(cache_prefix
+ getActiveFeedId(),
310 document
.getElementById("headlines-frame").innerHTML
,
311 get_feed_unread(getActiveFeedId())-1);
313 } else if (article_is_unread
) {
314 cache_invalidate(cache_prefix
+ getActiveFeedId());
320 exception_error("showArticleInHeadlines", e
);
324 function article_callback2(transport
, id
, feed_id
) {
326 debug("article_callback2 " + id
);
328 if (transport
.responseXML
) {
330 debug("looking for articles to cache...");
332 var articles
= transport
.responseXML
.getElementsByTagName("article");
334 for (var i
= 0; i
< articles
.length
; i
++) {
335 var a_id
= articles
[i
].getAttribute("id");
337 debug("found id: " + a_id
);
339 if (a_id
== active_post_id
) {
340 debug("active article, rendering...");
341 render_article(articles
[i
].firstChild
.nodeValue
);
344 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
347 if (id
!= last_requested_article
) {
348 debug("requested article id is out of sequence, aborting");
352 active_real_feed_id
= feed_id
;
355 showArticleInHeadlines(id
);
357 var reply
= transport
.responseXML
.firstChild
.firstChild
;
360 debug("article_callback: returned no XML object");
361 //var f = document.getElementById("content-frame");
362 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
365 var date
= new Date();
366 last_article_view
= date
.getTime() / 1000;
368 if (typeof correctPNG
!= 'undefined') {
372 if (_reload_feedlist_after_view
) {
373 setTimeout('updateFeedList(false, false)', 50);
374 _reload_feedlist_after_view
= false;
376 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
379 debug("parsing piggybacked counters: " + counters
);
380 parse_counters(counters
, false);
382 debug("counters container not found in reply, requesting...");
389 exception_error("article_callback2", e
, transport
);
393 function view(id
, feed_id
, skip_history
) {
396 debug("loading article: " + id
+ "/" + feed_id
);
398 var cached_article
= cache_find(id
);
400 debug("cache check result: " + (cached_article
!= false));
404 //setActiveFeedId(feed_id);
406 var query
= "backend.php?op=view&id=" + param_escape(id
) +
407 "&feed=" + param_escape(feed_id
);
409 var date
= new Date();
411 var neighbor_ids
= getRelativePostIds(active_post_id
);
413 /* only request uncached articles */
415 var cids_to_request
= Array();
417 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
418 if (!cache_check(neighbor_ids
[i
])) {
419 cids_to_request
.push(neighbor_ids
[i
]);
423 debug("additional ids: " + cids_to_request
.toString());
425 /* additional info for piggyback counters */
427 if (tagsAreDisplayed()) {
428 query
= query
+ "&omode=lt";
430 query
= query
+ "&omode=flc";
433 var date
= new Date();
434 var timestamp
= Math
.round(date
.getTime() / 1000);
435 query
= query
+ "&ts=" + timestamp
;
437 query
= query
+ "&cids=" + cids_to_request
.toString();
439 var crow
= document
.getElementById("RROW-" + id
);
440 var article_is_unread
= crow
.className
.match("Unread");
442 if (!async_counters_work
) {
443 query
= query
+ "&csync=true";
446 showArticleInHeadlines(id
);
448 if (!cached_article
) {
450 notify_progress("Loading, please wait...", true);
452 } else if (cached_article
&& article_is_unread
) {
454 query
= query
+ "&mode=prefetch";
456 render_article(cached_article
);
458 } else if (cached_article
) {
460 query
= query
+ "&mode=prefetch_old";
461 render_article(cached_article
);
467 last_requested_article
= id
;
469 new Ajax
.Request(query
, {
470 onComplete: function(transport
) {
471 article_callback2(transport
, id
, feed_id
);
477 exception_error("view", e
);
482 return toggleMark(id
);
486 return togglePub(id
);
489 function tMark_afh_off(effect
) {
491 var elem
= effect
.effects
[0].element
;
493 debug("tMark_afh_off : " + elem
.id
);
496 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
497 elem
.alt
= __("Star article");
502 exception_error("tMark_afh_off", e
);
506 function tPub_afh_off(effect
) {
508 var elem
= effect
.effects
[0].element
;
510 debug("tPub_afh_off : " + elem
.id
);
513 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
514 elem
.alt
= __("Publish article");
519 exception_error("tPub_afh_off", e
);
523 function toggleMark(id
, client_only
, no_effects
) {
527 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
529 query
= query
+ "&afid=" + getActiveFeedId();
531 if (tagsAreDisplayed()) {
532 query
= query
+ "&omode=tl";
534 query
= query
+ "&omode=flc";
537 var mark_img
= document
.getElementById("FMPIC-" + id
);
539 if (!mark_img
) return;
541 var vfeedu
= document
.getElementById("FEEDU--1");
542 var crow
= document
.getElementById("RROW-" + id
);
544 if (mark_img
.src
.match("mark_unset")) {
545 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
546 mark_img
.alt
= __("Unstar article");
547 query
= query
+ "&mark=1";
550 //mark_img.src = "images/mark_unset.png";
551 mark_img
.alt
= __("Please wait...");
552 query
= query
+ "&mark=0";
554 if (document
.getElementById("headlinesList") && !no_effects
) {
555 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
557 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
558 mark_img
.alt
= __("Star article");
565 new Ajax
.Request(query
, {
566 onComplete: function(transport
) {
567 all_counters_callback2(transport
);
573 exception_error("toggleMark", e
);
577 function togglePub(id
, client_only
, no_effects
) {
581 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
583 query
= query
+ "&afid=" + getActiveFeedId();
585 if (tagsAreDisplayed()) {
586 query
= query
+ "&omode=tl";
588 query
= query
+ "&omode=flc";
591 var mark_img
= document
.getElementById("FPPIC-" + id
);
593 if (!mark_img
) return;
595 var vfeedu
= document
.getElementById("FEEDU--2");
596 var crow
= document
.getElementById("RROW-" + id
);
598 if (mark_img
.src
.match("pub_unset")) {
599 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
600 mark_img
.alt
= __("Unpublish article");
601 query
= query
+ "&pub=1";
605 //mark_img.src = "images/pub_unset.png";
606 mark_img
.alt
= __("Please wait...");
607 query
= query
+ "&pub=0";
609 if (document
.getElementById("headlinesList") && !no_effects
) {
610 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
612 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
613 mark_img
.alt
= __("Publish article");
618 new Ajax
.Request(query
, {
619 onComplete: function(transport
) {
620 all_counters_callback2(transport
);
626 exception_error("togglePub", e
);
630 function correctHeadlinesOffset(id
) {
634 var hlist
= document
.getElementById("headlinesList");
635 var container
= document
.getElementById("headlinesInnerContainer");
636 var row
= document
.getElementById("RROW-" + id
);
638 var viewport
= container
.offsetHeight
;
640 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
641 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
643 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
644 debug("Vport: " + viewport
);
646 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
647 container
.scrollTop
= row
.offsetTop
;
648 } else if (rel_offset_bottom
> viewport
) {
650 /* doesn't properly work with Opera in some cases because
651 Opera fucks up element scrolling */
653 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
657 exception_error("correctHeadlinesOffset", e
);
662 function moveToPost(mode
) {
669 rows
= cdmGetVisibleArticles();
671 rows
= getVisibleHeadlineIds();
677 if (!document
.getElementById('RROW-' + active_post_id
)) {
678 active_post_id
= false;
681 if (active_post_id
== false) {
682 next_id
= getFirstVisibleHeadlineId();
683 prev_id
= getLastVisibleHeadlineId();
685 for (var i
= 0; i
< rows
.length
; i
++) {
686 if (rows
[i
] == active_post_id
) {
693 if (mode
== "next") {
697 if (!cdmArticleIsActuallyVisible(next_id
)) {
698 cdmScrollToArticleId(next_id
);
700 cdmSelectArticles("none");
701 toggleUnread(next_id
, 0, true);
702 toggleSelected(next_id
);
705 correctHeadlinesOffset(next_id
);
706 view(next_id
, getActiveFeedId());
711 if (mode
== "prev") {
714 cdmScrollToArticleId(prev_id
);
715 cdmSelectArticles("none");
716 toggleUnread(prev_id
, 0, true);
717 toggleSelected(prev_id
);
719 correctHeadlinesOffset(prev_id
);
720 view(prev_id
, getActiveFeedId());
726 exception_error("moveToPost", e
);
730 function toggleSelected(id
) {
733 var cb
= document
.getElementById("RCHK-" + id
);
735 var row
= document
.getElementById("RROW-" + id
);
737 var nc
= row
.className
;
739 if (!nc
.match("Selected")) {
740 nc
= nc
+ "Selected";
745 // In CDM basically last selected article == active article
746 if (isCdmMode()) active_post_id
= id
;
748 nc
= nc
.replace("Selected", "");
758 exception_error("toggleSelected", e
);
762 function toggleUnread_afh(effect
) {
765 var elem
= effect
.element
;
766 elem
.style
.backgroundColor
= "";
769 exception_error("toggleUnread_afh", e
);
773 function toggleUnread(id
, cmode
, effect
) {
776 var row
= document
.getElementById("RROW-" + id
);
778 var nc
= row
.className
;
779 var is_selected
= row
.className
.match("Selected");
780 nc
= nc
.replace("Unread", "");
781 nc
= nc
.replace("Selected", "");
783 // since we are removing selection from the object, uncheck
784 // corresponding checkbox
786 var cb
= document
.getElementById("RCHK-" + id
);
791 // NOTE: I'm not sure that resetting selection here is a feature -fox
793 if (cmode
== undefined || cmode
== 2) {
794 if (row
.className
.match("Unread")) {
798 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
799 afterFinish
: toggleUnread_afh
,
800 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
804 row
.className
= nc
+ "Unread";
806 } else if (cmode
== 0) {
810 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
811 afterFinish
: toggleUnread_afh
,
812 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
814 } else if (cmode
== 1) {
815 row
.className
= nc
+ "Unread";
818 // Disable unmarking as selected for the time being (16.05.08) -fox
819 if (is_selected
) row
.className
= row
.className
+ "Selected";
821 if (cmode
== undefined) cmode
= 2;
823 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
824 param_escape(id
) + "&cmode=" + param_escape(cmode
);
826 // notify_progress("Loading, please wait...");
828 new Ajax
.Request(query
, {
829 onComplete: function(transport
) {
830 all_counters_callback2(transport
);
837 exception_error("toggleUnread", e
);
841 function selectionRemoveLabel(id
) {
844 var ids
= getSelectedArticleIds2();
846 if (ids
.length
== 0) {
847 alert(__("No articles are selected."));
851 // var ok = confirm(__("Remove selected articles from label?"));
855 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
856 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
858 // notify_progress("Loading, please wait...");
860 cache_invalidate("F:" + (-11 - id
));
862 new Ajax
.Request(query
, {
863 onComplete: function(transport
) {
864 show_labels_in_headlines(transport
);
865 all_counters_callback2(transport
);
871 exception_error("selectionAssignLabel", e
);
876 function selectionAssignLabel(id
) {
879 var ids
= getSelectedArticleIds2();
881 if (ids
.length
== 0) {
882 alert(__("No articles are selected."));
886 // var ok = confirm(__("Assign selected articles to label?"));
890 cache_invalidate("F:" + (-11 - id
));
892 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
893 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
895 // notify_progress("Loading, please wait...");
897 new Ajax
.Request(query
, {
898 onComplete: function(transport
) {
899 show_labels_in_headlines(transport
);
900 all_counters_callback2(transport
);
906 exception_error("selectionAssignLabel", e
);
911 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
916 rows
= cdmGetSelectedArticles();
918 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
921 if (rows
.length
== 0 && !no_error
) {
922 alert(__("No articles are selected."));
926 for (i
= 0; i
< rows
.length
; i
++) {
927 var row
= document
.getElementById("RROW-" + rows
[i
]);
929 var nc
= row
.className
;
930 nc
= nc
.replace("Unread", "");
931 nc
= nc
.replace("Selected", "");
933 if (set_state
== undefined) {
934 if (row
.className
.match("Unread")) {
935 row
.className
= nc
+ "Selected";
937 row
.className
= nc
+ "UnreadSelected";
941 if (set_state
== false) {
942 row
.className
= nc
+ "Selected";
945 if (set_state
== true) {
946 row
.className
= nc
+ "UnreadSelected";
951 if (rows
.length
> 0) {
955 if (set_state
== undefined) {
957 } else if (set_state
== true) {
959 } else if (set_state
== false) {
963 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
964 param_escape(rows
.toString()) + "&cmode=" + cmode
;
966 notify_progress("Loading, please wait...");
968 new Ajax
.Request(query
, {
969 onComplete: function(transport
) {
970 catchup_callback2(transport
, callback_func
);
976 exception_error("selectionToggleUnread", e
);
980 function selectionToggleMarked(cdm_mode
) {
986 rows
= cdmGetSelectedArticles();
988 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
991 if (rows
.length
== 0) {
992 alert(__("No articles are selected."));
996 for (i
= 0; i
< rows
.length
; i
++) {
997 toggleMark(rows
[i
], true, true);
1000 if (rows
.length
> 0) {
1002 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
1003 param_escape(rows
.toString()) + "&cmode=2";
1005 query
= query
+ "&afid=" + getActiveFeedId();
1007 /* if (tagsAreDisplayed()) {
1008 query = query + "&omode=tl";
1010 query = query + "&omode=flc";
1013 query
= query
+ "&omode=lc";
1015 new Ajax
.Request(query
, {
1016 onComplete: function(transport
) {
1017 all_counters_callback2(transport
);
1023 exception_error("selectionToggleMarked", e
);
1027 function selectionTogglePublished(cdm_mode
) {
1033 rows
= cdmGetSelectedArticles();
1035 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1038 if (rows
.length
== 0) {
1039 alert(__("No articles are selected."));
1043 for (i
= 0; i
< rows
.length
; i
++) {
1044 togglePub(rows
[i
], true, true);
1047 if (rows
.length
> 0) {
1049 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1050 param_escape(rows
.toString()) + "&cmode=2";
1052 query
= query
+ "&afid=" + getActiveFeedId();
1054 /* if (tagsAreDisplayed()) {
1055 query = query + "&omode=tl";
1057 query = query + "&omode=flc";
1060 query
= query
+ "&omode=lc";
1062 new Ajax
.Request(query
, {
1063 onComplete: function(transport
) {
1064 all_counters_callback2(transport
);
1070 exception_error("selectionToggleMarked", e
);
1074 function cdmGetSelectedArticles() {
1075 var sel_articles
= new Array();
1076 var container
= document
.getElementById("headlinesInnerContainer");
1078 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1079 var child
= container
.childNodes
[i
];
1081 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1082 var c_id
= child
.id
.replace("RROW-", "");
1083 sel_articles
.push(c_id
);
1087 return sel_articles
;
1090 function cdmGetVisibleArticles() {
1091 var sel_articles
= new Array();
1092 var container
= document
.getElementById("headlinesInnerContainer");
1094 if (!container
) return sel_articles
;
1096 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1097 var child
= container
.childNodes
[i
];
1099 if (child
.id
&& child
.id
.match("RROW-")) {
1100 var c_id
= child
.id
.replace("RROW-", "");
1101 sel_articles
.push(c_id
);
1105 return sel_articles
;
1108 function cdmGetUnreadArticles() {
1109 var sel_articles
= new Array();
1110 var container
= document
.getElementById("headlinesInnerContainer");
1112 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1113 var child
= container
.childNodes
[i
];
1115 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1116 var c_id
= child
.id
.replace("RROW-", "");
1117 sel_articles
.push(c_id
);
1121 return sel_articles
;
1125 // mode = all,none,unread
1126 function cdmSelectArticles(mode
) {
1127 var container
= document
.getElementById("headlinesInnerContainer");
1129 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1130 var child
= container
.childNodes
[i
];
1132 if (child
.id
&& child
.id
.match("RROW-")) {
1133 var aid
= child
.id
.replace("RROW-", "");
1135 var cb
= document
.getElementById("RCHK-" + aid
);
1137 if (mode
== "all") {
1138 if (!child
.className
.match("Selected")) {
1139 child
.className
= child
.className
+ "Selected";
1142 } else if (mode
== "unread") {
1143 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1144 child
.className
= child
.className
+ "Selected";
1148 child
.className
= child
.className
.replace("Selected", "");
1155 function catchupPage() {
1157 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1159 var str
= __("Mark all visible articles in %s as read?");
1161 str
= str
.replace("%s", fn
);
1163 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1167 if (document
.getElementById("headlinesList")) {
1168 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1169 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1170 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1172 cdmSelectArticles('all');
1173 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1174 cdmSelectArticles('none');
1178 function catchupSelection() {
1184 if (document
.getElementById("headlinesList")) {
1185 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1187 rows
= cdmGetSelectedArticles();
1190 if (rows
.length
== 0) {
1191 alert(__("No articles are selected."));
1196 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1198 var str
= __("Mark %d selected articles in %s as read?");
1200 str
= str
.replace("%d", rows
.length
);
1201 str
= str
.replace("%s", fn
);
1203 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1207 if (document
.getElementById("headlinesList")) {
1208 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1209 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1211 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1212 // cdmSelectArticles('none');
1216 exception_error("catchupSelection", e
);
1220 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1221 displayDlg('editArticleTags', id
);
1225 function tag_saved_callback(transport
) {
1227 debug("in tag_saved_callback");
1232 if (tagsAreDisplayed()) {
1233 _reload_feedlist_after_view
= true;
1237 if (transport
.responseXML
) {
1238 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1241 var id
= tags_str
.getAttribute("id");
1244 var tags
= document
.getElementById("ATSTR-" + id
);
1246 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1253 exception_error("tag_saved_callback", e
);
1257 function editTagsSave() {
1259 notify_progress("Saving article tags...");
1261 var form
= document
.forms
["tag_edit_form"];
1263 var query
= Form
.serialize("tag_edit_form");
1265 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1269 new Ajax
.Request(query
, {
1270 onComplete: function(transport
) {
1271 tag_saved_callback(transport
);
1276 function editTagsInsert() {
1279 var form
= document
.forms
["tag_edit_form"];
1281 var found_tags
= form
.found_tags
;
1282 var tags_str
= form
.tags_str
;
1284 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1286 if (tags_str
.value
.length
> 0 &&
1287 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1289 tags_str
.value
= tags_str
.value
+ ", ";
1292 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1294 found_tags
.selectedIndex
= 0;
1297 exception_error("editTagsInsert", e
);
1301 function cdmScrollViewport(where
) {
1302 debug("cdmScrollViewport: " + where
);
1304 var ctr
= document
.getElementById("headlinesInnerContainer");
1308 if (where
== "bottom") {
1309 ctr
.scrollTop
= ctr
.scrollHeight
;
1311 ctr
.scrollTop
= where
;
1315 function cdmArticleIsBelowViewport(id
) {
1317 var ctr
= document
.getElementById("headlinesInnerContainer");
1318 var e
= document
.getElementById("RROW-" + id
);
1320 if (!e
|| !ctr
) return;
1322 // article starts below viewport
1324 if (ctr
.scrollTop
< e
.offsetTop
) {
1331 exception_error("cdmArticleIsVisible", e
);
1335 function cdmArticleIsAboveViewport(id
) {
1337 var ctr
= document
.getElementById("headlinesInnerContainer");
1338 var e
= document
.getElementById("RROW-" + id
);
1340 if (!e
|| !ctr
) return;
1342 // article starts above viewport
1344 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1351 exception_error("cdmArticleIsVisible", e
);
1355 function cdmScrollToArticleId(id
) {
1357 var ctr
= document
.getElementById("headlinesInnerContainer");
1358 var e
= document
.getElementById("RROW-" + id
);
1360 if (!e
|| !ctr
) return;
1362 ctr
.scrollTop
= e
.offsetTop
;
1365 exception_error("cdmScrollToArticleId", e
);
1369 function cdmArticleIsActuallyVisible(id
) {
1371 var ctr
= document
.getElementById("headlinesInnerContainer");
1372 var e
= document
.getElementById("RROW-" + id
);
1374 if (!e
|| !ctr
) return;
1376 // article fits in viewport OR article is longer than viewport and
1377 // its bottom is visible
1379 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1380 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1384 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1385 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1386 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1395 exception_error("cdmArticleIsVisible", e
);
1399 function cdmWatchdog() {
1403 var ctr
= document
.getElementById("headlinesInnerContainer");
1407 var ids
= new Array();
1409 var e
= ctr
.firstChild
;
1412 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1413 e
.id
.match("RROW-")) {
1415 // article fits in viewport OR article is longer than viewport and
1416 // its bottom is visible
1418 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1419 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1421 // debug(e.id + " is visible " + e.offsetTop + "." +
1422 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1423 // (ctr.scrollTop + ctr.offsetHeight));
1425 ids
.push(e
.id
.replace("RROW-", ""));
1427 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1428 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1429 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1431 ids
.push(e
.id
.replace("RROW-", ""));
1435 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1437 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1438 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1440 ids.push(e.id.replace("RROW-", ""));
1449 debug("cdmWatchdog, ids= " + ids
.toString());
1451 if (ids
.length
> 0) {
1453 for (var i
= 0; i
< ids
.length
; i
++) {
1454 var e
= document
.getElementById("RROW-" + ids
[i
]);
1456 e
.className
= e
.className
.replace("Unread", "");
1460 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1461 param_escape(ids
.toString()) + "&cmode=0";
1463 new Ajax
.Request(query
, {
1464 onComplete: function(transport
) {
1465 all_counters_callback2(transport
);
1470 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1473 exception_error("cdmWatchdog", e
);
1479 function cache_inject(id
, article
, param
) {
1480 if (!cache_check_param(id
, param
)) {
1481 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1483 var cache_obj
= new Array();
1485 cache_obj
["id"] = id
;
1486 cache_obj
["data"] = article
;
1487 cache_obj
["param"] = param
;
1489 article_cache
.push(cache_obj
);
1492 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1496 function cache_find(id
) {
1497 for (var i
= 0; i
< article_cache
.length
; i
++) {
1498 if (article_cache
[i
]["id"] == id
) {
1499 return article_cache
[i
]["data"];
1505 function cache_find_param(id
, param
) {
1506 for (var i
= 0; i
< article_cache
.length
; i
++) {
1507 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1508 return article_cache
[i
]["data"];
1514 function cache_check(id
) {
1515 for (var i
= 0; i
< article_cache
.length
; i
++) {
1516 if (article_cache
[i
]["id"] == id
) {
1523 function cache_check_param(id
, param
) {
1524 for (var i
= 0; i
< article_cache
.length
; i
++) {
1526 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1527 // article_cache[i]["param"] + " vs " + id + ":" + param);
1529 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1536 function cache_expire() {
1537 while (article_cache
.length
> 25) {
1538 article_cache
.shift();
1542 function cache_empty() {
1543 article_cache
= new Array();
1546 function cache_invalidate(id
) {
1551 while (i
< article_cache
.length
) {
1552 if (article_cache
[i
]["id"] == id
) {
1553 debug("cache_invalidate: removed id " + id
);
1554 article_cache
.splice(i
, 1);
1559 debug("cache_invalidate: id not found: " + id
);
1562 exception_error("cache_invalidate", e
);
1566 function getActiveArticleId() {
1567 return active_post_id
;
1570 function cdmClicked(id
) {
1572 var elem
= document
.getElementById("RROW-" + id
);
1575 var id
= elem
.id
.replace("RROW-", "");
1576 active_post_id
= id
;
1578 cdmSelectArticles("none");
1579 toggleUnread(id
, 0, true);
1584 exception_error("cdmClicked", e
);
1588 function preload_article_callback(transport
) {
1590 if (transport
.responseXML
) {
1591 var articles
= transport
.responseXML
.getElementsByTagName("article");
1593 for (var i
= 0; i
< articles
.length
; i
++) {
1594 var id
= articles
[i
].getAttribute("id");
1595 if (!cache_check(id
)) {
1596 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1597 debug("preloaded article: " + id
);
1602 exception_error("preload_article_callback", e
);
1606 function preloadArticleUnderPointer(id
) {
1608 if (getInitParam("bw_limit") == "1") return;
1610 if (post_under_pointer
== id
&& !cache_check(id
)) {
1612 debug("trying to preload article " + id
);
1614 var neighbor_ids
= getRelativePostIds(id
, 1);
1616 /* only request uncached articles */
1618 var cids_to_request
= Array();
1620 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1621 if (!cache_check(neighbor_ids
[i
])) {
1622 cids_to_request
.push(neighbor_ids
[i
]);
1625 debug("additional ids: " + cids_to_request
.toString());
1627 cids_to_request
.push(id
);
1629 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1630 cids_to_request
.toString();
1631 new Ajax
.Request(query
, {
1632 onComplete: function(transport
) {
1633 preload_article_callback(transport
);
1637 exception_error("preloadArticleUnderPointer", e
);
1641 function postMouseIn(id
) {
1643 if (post_under_pointer
!= id
) {
1644 post_under_pointer
= id
;
1646 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1651 exception_error("postMouseIn", e
);
1655 function postMouseOut(id
) {
1657 post_under_pointer
= false;
1659 exception_error("postMouseOut", e
);
1663 function headlines_scroll_handler() {
1666 var e
= document
.getElementById("headlinesInnerContainer");
1668 // don't do infinite scrolling when Limit == All
1670 var toolbar_form
= document
.forms
["main_toolbar_form"];
1672 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1673 if (limit
.value
!= 0) {
1675 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1676 _infscroll_disable
);
1678 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1679 if (!_infscroll_disable
) {
1680 debug("more cowbell!");
1687 exception_error("headlines_scroll_handler", e
);
1691 function catchupRelativeToArticle(below
) {
1695 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1696 printLockingError();
1699 if (!getActiveArticleId()) {
1700 alert(__("No article is selected."));
1706 if (document
.getElementById("headlinesList")) {
1707 visible_ids
= getVisibleHeadlineIds();
1709 visible_ids
= cdmGetVisibleArticles();
1712 var ids_to_mark
= new Array();
1715 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1716 if (visible_ids
[i
] != getActiveArticleId()) {
1717 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1719 if (e
&& e
.className
.match("Unread")) {
1720 ids_to_mark
.push(visible_ids
[i
]);
1727 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1728 if (visible_ids
[i
] != getActiveArticleId()) {
1729 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1731 if (e
&& e
.className
.match("Unread")) {
1732 ids_to_mark
.push(visible_ids
[i
]);
1740 if (ids_to_mark
.length
== 0) {
1741 alert(__("No articles found to mark"));
1743 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1747 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1748 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1749 e
.className
= e
.className
.replace("Unread", "");
1752 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1753 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1755 new Ajax
.Request(query
, {
1756 onComplete: function(transport
) {
1757 catchup_callback2(transport
);
1764 exception_error("catchupRelativeToArticle", e
);
1768 function cdmExpandArticle(a_id
) {
1770 var id
= 'CICD-' + a_id
;
1773 Element
.hide("CEXC-" + a_id
);
1776 Effect
.Appear(id
, {duration
: 0.5,
1777 beforeStart: function(effect
) {
1778 var h_id
= 'CICH-' + a_id
;
1779 var h_elem
= document
.getElementById(h_id
);
1780 if (h_elem
) { h_elem
.style
.display
= "none"; }
1782 toggleUnread(a_id
, 0);
1787 exception_error("appearBlockElementF", e
);
1792 function fixHeadlinesOrder(ids
) {
1794 for (var i
= 0; i
< ids
.length
; i
++) {
1795 var e
= document
.getElementById("RROW-" + ids
[i
]);
1799 e
.className
= e
.className
.replace("even", "odd");
1801 e
.className
= e
.className
.replace("odd", "even");
1806 exception_error("fixHeadlinesOrder", e
);
1810 function hideReadHeadlines() {
1814 var vis_ids
= new Array();
1816 if (document
.getElementById("headlinesList")) {
1817 ids
= getVisibleHeadlineIds();
1819 ids
= cdmGetVisibleArticles();
1822 var read_headlines_visible
= true;
1824 for (var i
= 0; i
< ids
.length
; i
++) {
1825 var row
= document
.getElementById("RROW-" + ids
[i
]);
1827 if (row
&& row
.className
) {
1828 if (read_headlines_visible
) {
1829 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1831 vis_ids
.push(ids
[i
]);
1833 //Effect.Fade(row, {duration : 0.3});
1838 vis_ids
.push(ids
[i
]);
1843 fixHeadlinesOrder(vis_ids
);
1845 read_headlines_visible
= !read_headlines_visible
;
1848 exception_error("hideReadHeadlines", e
);
1852 function invertHeadlineSelection() {
1854 var rows
= new Array();
1858 r
= document
.getElementsByTagName("TR");
1860 r
= document
.getElementsByTagName("DIV");
1863 for (var i
= 0; i
< r
.length
; i
++) {
1864 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1869 for (var i
= 0; i
< rows
.length
; i
++) {
1870 var nc
= rows
[i
].className
;
1871 var id
= rows
[i
].id
.replace("RROW-", "");
1872 var cb
= document
.getElementById("RCHK-" + id
);
1874 if (!rows
[i
].className
.match("Selected")) {
1875 nc
= nc
+ "Selected";
1878 nc
= nc
.replace("Selected", "");
1882 rows
[i
].className
= nc
;
1887 exception_error("invertHeadlineSelection", e
);
1891 function getArticleUnderPointer() {
1892 return post_under_pointer
;
1895 function zoomToArticle(id
) {
1897 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1899 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1902 exception_error("zoomToArticle", e
);
1906 function showOriginalArticleInline(id
) {
1909 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1911 notify_progress("Loading, please wait...", true);
1913 new Ajax
.Request(query
, {
1914 onComplete: function(transport
) {
1916 if (transport
.responseXML
) {
1918 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1919 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1924 link
= link
.firstChild
.nodeValue
;
1926 var ci
= document
.getElementById("content-insert");
1928 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1930 render_article(tmp
);
1937 exception_error("showOriginalArticleInline", e
);
1942 function scrollArticle(offset
) {
1945 var ci
= document
.getElementById("content-insert");
1947 ci
.scrollTop
+= offset
;
1950 var hi
= document
.getElementById("headlinesInnerContainer");
1952 hi
.scrollTop
+= offset
;
1957 exception_error("scrollArticle", e
);
1961 function show_labels_in_headlines(transport
) {
1963 if (transport
.responseXML
) {
1964 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1966 var elems
= info
.getElementsByTagName("entry");
1968 for (var l
= 0; l
< elems
.length
; l
++) {
1969 var e_id
= elems
[l
].getAttribute("id");
1973 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
1976 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1984 exception_error("show_labels_in_headlines", e
);
1989 function toggleHeadlineActions() {
1991 var e
= document
.getElementById("headlineActionsBody");
1992 var p
= document
.getElementById("headlineActionsDrop");
1994 if (!Element
.visible(e
)) {
2001 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2002 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2005 exception_error("toggleHeadlineActions", e
);