1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _tag_active_post_id
= false;
6 var _tag_active_feed_id
= false;
7 var _tag_active_cdm
= false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll
= false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view
= false;
15 var _cdm_wd_timeout
= false;
16 var _cdm_wd_vishist
= new Array();
18 var article_cache
= new Array();
20 var vgroup_last_feed
= false;
21 var post_under_pointer
= false;
23 var last_requested_article
= false;
25 function catchup_callback() {
26 if (xmlhttp_rpc
.readyState
== 4) {
28 debug("catchup_callback");
30 all_counters_callback2(xmlhttp_rpc
);
31 if (_catchup_callback_func
) {
32 setTimeout(_catchup_callback_func
, 10);
35 exception_error("catchup_callback", e
);
40 function catchup_callback2(transport
, callback
) {
42 debug("catchup_callback2 " + transport
+ ", " + callback
);
44 all_counters_callback2(transport
);
46 setTimeout(callback
, 10);
49 exception_error("catchup_callback2", e
);
53 function clean_feed_selections() {
55 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
57 for (var i
= 0; i
< feeds
.length
; i
++) {
58 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
59 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
62 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
66 exception_error("clean_feed_selections", e
);
70 function headlines_callback2(transport
, feed_cur_page
) {
73 loading_set_progress(100);
75 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
77 clean_feed_selections();
82 if (transport
.responseXML
) {
83 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
85 is_cat
= headlines
.getAttribute("is_cat");
86 feed_id
= headlines
.getAttribute("id");
87 setActiveFeedId(feed_id
, is_cat
);
92 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
93 if (feedr
&& !feedr
.className
.match("Selected")) {
94 feedr
.className
= feedr
.className
+ "Selected";
97 var feedr
= document
.getElementById("FCAT-" + feed_id
);
98 if (feedr
&& !feedr
.className
.match("Selected")) {
99 feedr
.className
= feedr
.className
+ "Selected";
103 var f
= document
.getElementById("headlines-frame");
105 if (feed_cur_page
== 0) {
106 debug("resetting headlines scrollTop");
111 if (transport
.responseXML
) {
112 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
113 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
114 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
115 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
117 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
119 var headlines_count
= headlines_count_obj
.getAttribute("value");
120 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
121 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
123 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
125 if (headlines_count
== 0) {
126 _infscroll_disable
= 1;
128 _infscroll_disable
= 0;
131 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
132 var articles
= transport
.responseXML
.getElementsByTagName("article");
133 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
135 if (feed_cur_page
== 0) {
137 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
139 var cache_prefix
= "";
147 cache_invalidate(cache_prefix
+ feed_id
);
149 if (!disable_cache
) {
150 cache_inject(cache_prefix
+ feed_id
,
151 headlines
.firstChild
.nodeValue
, headlines_unread
);
155 debug("headlines_callback: returned no data");
156 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
161 if (headlines_count
> 0) {
162 debug("adding some more headlines...");
164 var c
= document
.getElementById("headlinesList");
167 c
= document
.getElementById("headlinesInnerContainer");
170 var ids
= getSelectedArticleIds2();
172 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
174 debug("restore selected ids: " + ids
);
176 for (var i
= 0; i
< ids
.length
; i
++) {
177 markHeadline(ids
[i
]);
181 debug("no new headlines received");
184 debug("headlines_callback: returned no data");
185 notify_error("Error while trying to load more headlines");
191 for (var i
= 0; i
< articles
.length
; i
++) {
192 var a_id
= articles
[i
].getAttribute("id");
193 debug("found id: " + a_id
);
194 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
197 debug("no cached articles received");
201 debug("parsing piggybacked counters: " + counters
);
202 parse_counters(counters
, false);
204 debug("counters container not found in reply, requesting...");
209 debug("parsing runtime info: " + runtime_info
[0]);
210 parse_runtime_info(runtime_info
[0]);
212 debug("counters container not found in reply");
216 debug("headlines_callback: returned no XML object");
217 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
220 if (typeof correctPNG
!= 'undefined') {
224 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
226 if (!document
.getElementById("headlinesList") &&
227 getActiveFeedId() != -3 &&
228 getInitParam("cdm_auto_catchup") == 1) {
229 debug("starting CDM watchdog");
230 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
231 _cdm_wd_vishist
= new Array();
233 debug("not in CDM mode or watchdog disabled");
236 if (_tag_cdm_scroll
) {
238 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
239 _tag_cdm_scroll
= false;
240 debug("resetting headlinesInner scrollTop");
245 _feed_cur_page
= feed_cur_page
;
246 _infscroll_request_sent
= 0;
253 exception_error("headlines_callback2", e
);
257 function render_article(article
) {
259 var f
= document
.getElementById("content-frame");
264 var fi
= document
.getElementById("content-insert");
270 fi
.innerHTML
= article
;
273 exception_error("render_article", e
);
277 function showArticleInHeadlines(id
) {
281 cleanSelected("headlinesList");
283 var crow
= document
.getElementById("RROW-" + id
);
287 var article_is_unread
= crow
.className
.match("Unread");
289 crow
.className
= crow
.className
.replace("Unread", "");
291 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
293 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
295 var cache_prefix
= "";
297 if (activeFeedIsCat()) {
303 var view_mode
= false;
306 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
307 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
309 exception_error("showArticleInHeadlines/viewmode", e
, true);
312 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
313 upd_img_pic
.src
= "images/blank_icon.gif";
315 cache_invalidate(cache_prefix
+ getActiveFeedId());
317 cache_inject(cache_prefix
+ getActiveFeedId(),
318 document
.getElementById("headlines-frame").innerHTML
,
319 get_feed_unread(getActiveFeedId()));
321 } else if (article_is_unread
&& view_mode
== "all_articles") {
323 cache_invalidate(cache_prefix
+ getActiveFeedId());
325 cache_inject(cache_prefix
+ getActiveFeedId(),
326 document
.getElementById("headlines-frame").innerHTML
,
327 get_feed_unread(getActiveFeedId())-1);
329 } else if (article_is_unread
) {
330 cache_invalidate(cache_prefix
+ getActiveFeedId());
336 exception_error("showArticleInHeadlines", e
);
340 function article_callback2(transport
, id
, feed_id
) {
342 debug("article_callback2 " + id
);
344 if (transport
.responseXML
) {
346 debug("looking for articles to cache...");
348 var articles
= transport
.responseXML
.getElementsByTagName("article");
350 for (var i
= 0; i
< articles
.length
; i
++) {
351 var a_id
= articles
[i
].getAttribute("id");
353 debug("found id: " + a_id
);
355 if (a_id
== active_post_id
) {
356 debug("active article, rendering...");
357 render_article(articles
[i
].firstChild
.nodeValue
);
360 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
363 if (id
!= last_requested_article
) {
364 debug("requested article id is out of sequence, aborting");
368 active_real_feed_id
= feed_id
;
371 showArticleInHeadlines(id
);
373 var reply
= transport
.responseXML
.firstChild
.firstChild
;
376 debug("article_callback: returned no XML object");
377 //var f = document.getElementById("content-frame");
378 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
381 var date
= new Date();
382 last_article_view
= date
.getTime() / 1000;
384 if (typeof correctPNG
!= 'undefined') {
388 if (_reload_feedlist_after_view
) {
389 setTimeout('updateFeedList(false, false)', 50);
390 _reload_feedlist_after_view
= false;
392 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
395 debug("parsing piggybacked counters: " + counters
);
396 parse_counters(counters
, false);
398 debug("counters container not found in reply, requesting...");
405 exception_error("article_callback2", e
);
409 function view(id
, feed_id
, skip_history
) {
412 debug("loading article: " + id
+ "/" + feed_id
);
414 var cached_article
= cache_find(id
);
416 debug("cache check result: " + (cached_article
!= false));
420 //setActiveFeedId(feed_id);
422 var query
= "backend.php?op=view&id=" + param_escape(id
) +
423 "&feed=" + param_escape(feed_id
);
425 var date
= new Date();
427 var neighbor_ids
= getRelativePostIds(active_post_id
);
429 /* only request uncached articles */
431 var cids_to_request
= Array();
433 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
434 if (!cache_check(neighbor_ids
[i
])) {
435 cids_to_request
.push(neighbor_ids
[i
]);
439 debug("additional ids: " + cids_to_request
.toString());
441 /* additional info for piggyback counters */
443 if (tagsAreDisplayed()) {
444 query
= query
+ "&omode=lt";
446 query
= query
+ "&omode=flc";
449 var date
= new Date();
450 var timestamp
= Math
.round(date
.getTime() / 1000);
451 query
= query
+ "&ts=" + timestamp
;
453 query
= query
+ "&cids=" + cids_to_request
.toString();
455 var crow
= document
.getElementById("RROW-" + id
);
456 var article_is_unread
= crow
.className
.match("Unread");
458 if (!async_counters_work
) {
459 query
= query
+ "&csync=true";
462 showArticleInHeadlines(id
);
464 if (!cached_article
) {
466 notify_progress("Loading, please wait...", true);
468 } else if (cached_article
&& article_is_unread
) {
470 query
= query
+ "&mode=prefetch";
472 render_article(cached_article
);
474 } else if (cached_article
) {
476 query
= query
+ "&mode=prefetch_old";
477 render_article(cached_article
);
483 last_requested_article
= id
;
485 new Ajax
.Request(query
, {
486 onComplete: function(transport
) {
487 article_callback2(transport
, id
, feed_id
);
493 exception_error("view", e
);
498 return toggleMark(id
);
502 return togglePub(id
);
505 function tMark_afh_off(effect
) {
507 var elem
= effect
.effects
[0].element
;
509 debug("tMark_afh_off : " + elem
.id
);
512 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
513 elem
.alt
= __("Star article");
518 exception_error("tMark_afh_off", e
);
522 function tPub_afh_off(effect
) {
524 var elem
= effect
.effects
[0].element
;
526 debug("tPub_afh_off : " + elem
.id
);
529 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
530 elem
.alt
= __("Publish article");
535 exception_error("tPub_afh_off", e
);
539 function toggleMark(id
, client_only
, no_effects
) {
543 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
545 query
= query
+ "&afid=" + getActiveFeedId();
547 if (tagsAreDisplayed()) {
548 query
= query
+ "&omode=tl";
550 query
= query
+ "&omode=flc";
553 var mark_img
= document
.getElementById("FMPIC-" + id
);
554 var vfeedu
= document
.getElementById("FEEDU--1");
555 var crow
= document
.getElementById("RROW-" + id
);
557 if (mark_img
.src
.match("mark_unset")) {
558 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
559 mark_img
.alt
= __("Unstar article");
560 query
= query
+ "&mark=1";
563 //mark_img.src = "images/mark_unset.png";
564 mark_img
.alt
= __("Please wait...");
565 query
= query
+ "&mark=0";
567 if (document
.getElementById("headlinesList") && !no_effects
) {
568 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
570 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
571 mark_img
.alt
= __("Star article");
578 new Ajax
.Request(query
, {
579 onComplete: function(transport
) {
580 all_counters_callback2(transport
);
586 exception_error("toggleMark", e
);
590 function togglePub(id
, client_only
, no_effects
) {
594 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
596 query
= query
+ "&afid=" + getActiveFeedId();
598 if (tagsAreDisplayed()) {
599 query
= query
+ "&omode=tl";
601 query
= query
+ "&omode=flc";
604 var mark_img
= document
.getElementById("FPPIC-" + id
);
605 var vfeedu
= document
.getElementById("FEEDU--2");
606 var crow
= document
.getElementById("RROW-" + id
);
608 if (mark_img
.src
.match("pub_unset")) {
609 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
610 mark_img
.alt
= __("Unpublish article");
611 query
= query
+ "&pub=1";
615 //mark_img.src = "images/pub_unset.png";
616 mark_img
.alt
= __("Please wait...");
617 query
= query
+ "&pub=0";
619 if (document
.getElementById("headlinesList") && !no_effects
) {
620 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
622 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
623 mark_img
.alt
= __("Publish article");
628 new Ajax
.Request(query
, {
629 onComplete: function(transport
) {
630 all_counters_callback2(transport
);
636 exception_error("togglePub", e
);
640 function correctHeadlinesOffset(id
) {
644 var hlist
= document
.getElementById("headlinesList");
645 var container
= document
.getElementById("headlinesInnerContainer");
646 var row
= document
.getElementById("RROW-" + id
);
648 var viewport
= container
.offsetHeight
;
650 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
651 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
653 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
654 debug("Vport: " + viewport
);
656 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
657 container
.scrollTop
= row
.offsetTop
;
658 } else if (rel_offset_bottom
> viewport
) {
660 /* doesn't properly work with Opera in some cases because
661 Opera fucks up element scrolling */
663 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
667 exception_error("correctHeadlinesOffset", e
);
672 function moveToPost(mode
) {
679 rows
= cdmGetVisibleArticles();
681 rows
= getVisibleHeadlineIds();
687 if (!document
.getElementById('RROW-' + active_post_id
)) {
688 active_post_id
= false;
691 if (active_post_id
== false) {
692 next_id
= getFirstVisibleHeadlineId();
693 prev_id
= getLastVisibleHeadlineId();
695 for (var i
= 0; i
< rows
.length
; i
++) {
696 if (rows
[i
] == active_post_id
) {
703 if (mode
== "next") {
707 if (!cdmArticleIsActuallyVisible(next_id
)) {
708 cdmScrollToArticleId(next_id
);
710 cdmSelectArticles("none");
711 toggleUnread(next_id
, 0, true);
712 toggleSelected(next_id
);
715 correctHeadlinesOffset(next_id
);
716 view(next_id
, getActiveFeedId());
721 if (mode
== "prev") {
724 cdmScrollToArticleId(prev_id
);
725 cdmSelectArticles("none");
726 toggleUnread(prev_id
, 0, true);
727 toggleSelected(prev_id
);
729 correctHeadlinesOffset(prev_id
);
730 view(prev_id
, getActiveFeedId());
736 exception_error("moveToPost", e
);
740 function toggleSelected(id
) {
743 var cb
= document
.getElementById("RCHK-" + id
);
745 var row
= document
.getElementById("RROW-" + id
);
747 var nc
= row
.className
;
749 if (!nc
.match("Selected")) {
750 nc
= nc
+ "Selected";
755 // In CDM basically last selected article == active article
756 if (isCdmMode()) active_post_id
= id
;
758 nc
= nc
.replace("Selected", "");
768 exception_error("toggleSelected", e
);
772 function toggleUnread_afh(effect
) {
775 var elem
= effect
.element
;
776 elem
.style
.backgroundColor
= "";
779 exception_error("toggleUnread_afh", e
);
783 function toggleUnread(id
, cmode
, effect
) {
786 var row
= document
.getElementById("RROW-" + id
);
788 var nc
= row
.className
;
789 var is_selected
= row
.className
.match("Selected");
790 nc
= nc
.replace("Unread", "");
791 nc
= nc
.replace("Selected", "");
793 // since we are removing selection from the object, uncheck
794 // corresponding checkbox
796 var cb
= document
.getElementById("RCHK-" + id
);
801 // NOTE: I'm not sure that resetting selection here is a feature -fox
803 if (cmode
== undefined || cmode
== 2) {
804 if (row
.className
.match("Unread")) {
808 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
809 afterFinish
: toggleUnread_afh
,
810 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
814 row
.className
= nc
+ "Unread";
816 } else if (cmode
== 0) {
820 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
821 afterFinish
: toggleUnread_afh
,
822 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
824 } else if (cmode
== 1) {
825 row
.className
= nc
+ "Unread";
828 // Disable unmarking as selected for the time being (16.05.08) -fox
829 if (is_selected
) row
.className
= row
.className
+ "Selected";
831 if (cmode
== undefined) cmode
= 2;
833 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
834 param_escape(id
) + "&cmode=" + param_escape(cmode
);
836 // notify_progress("Loading, please wait...");
838 new Ajax
.Request(query
, {
839 onComplete: function(transport
) {
840 all_counters_callback2(transport
);
847 exception_error("toggleUnread", e
);
851 function selectionRemoveLabel(id
) {
854 var ids
= getSelectedArticleIds2();
856 if (ids
.length
== 0) {
857 alert(__("No articles are selected."));
861 // var ok = confirm(__("Remove selected articles from label?"));
865 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
866 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
868 // notify_progress("Loading, please wait...");
870 cache_invalidate("F:" + (-11 - id
));
872 new Ajax
.Request(query
, {
873 onComplete: function(transport
) {
874 show_labels_in_headlines(transport
);
875 all_counters_callback2(transport
);
881 exception_error("selectionAssignLabel", e
);
886 function selectionAssignLabel(id
) {
889 var ids
= getSelectedArticleIds2();
891 if (ids
.length
== 0) {
892 alert(__("No articles are selected."));
896 // var ok = confirm(__("Assign selected articles to label?"));
900 cache_invalidate("F:" + (-11 - id
));
902 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
903 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
905 // notify_progress("Loading, please wait...");
907 new Ajax
.Request(query
, {
908 onComplete: function(transport
) {
909 show_labels_in_headlines(transport
);
910 all_counters_callback2(transport
);
916 exception_error("selectionAssignLabel", e
);
921 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
926 rows
= cdmGetSelectedArticles();
928 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
931 if (rows
.length
== 0 && !no_error
) {
932 alert(__("No articles are selected."));
936 for (i
= 0; i
< rows
.length
; i
++) {
937 var row
= document
.getElementById("RROW-" + rows
[i
]);
939 var nc
= row
.className
;
940 nc
= nc
.replace("Unread", "");
941 nc
= nc
.replace("Selected", "");
943 if (set_state
== undefined) {
944 if (row
.className
.match("Unread")) {
945 row
.className
= nc
+ "Selected";
947 row
.className
= nc
+ "UnreadSelected";
951 if (set_state
== false) {
952 row
.className
= nc
+ "Selected";
955 if (set_state
== true) {
956 row
.className
= nc
+ "UnreadSelected";
961 if (rows
.length
> 0) {
965 if (set_state
== undefined) {
967 } else if (set_state
== true) {
969 } else if (set_state
== false) {
973 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
974 param_escape(rows
.toString()) + "&cmode=" + cmode
;
976 notify_progress("Loading, please wait...");
978 new Ajax
.Request(query
, {
979 onComplete: function(transport
) {
980 catchup_callback2(transport
, callback_func
);
986 exception_error("selectionToggleUnread", e
);
990 function selectionToggleMarked(cdm_mode
) {
996 rows
= cdmGetSelectedArticles();
998 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1001 if (rows
.length
== 0) {
1002 alert(__("No articles are selected."));
1006 for (i
= 0; i
< rows
.length
; i
++) {
1007 toggleMark(rows
[i
], true, true);
1010 if (rows
.length
> 0) {
1012 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
1013 param_escape(rows
.toString()) + "&cmode=2";
1015 query
= query
+ "&afid=" + getActiveFeedId();
1017 /* if (tagsAreDisplayed()) {
1018 query = query + "&omode=tl";
1020 query = query + "&omode=flc";
1023 query
= query
+ "&omode=lc";
1025 new Ajax
.Request(query
, {
1026 onComplete: function(transport
) {
1027 all_counters_callback2(transport
);
1033 exception_error("selectionToggleMarked", e
);
1037 function selectionTogglePublished(cdm_mode
) {
1043 rows
= cdmGetSelectedArticles();
1045 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1048 if (rows
.length
== 0) {
1049 alert(__("No articles are selected."));
1053 for (i
= 0; i
< rows
.length
; i
++) {
1054 togglePub(rows
[i
], true, true);
1057 if (rows
.length
> 0) {
1059 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1060 param_escape(rows
.toString()) + "&cmode=2";
1062 query
= query
+ "&afid=" + getActiveFeedId();
1064 /* if (tagsAreDisplayed()) {
1065 query = query + "&omode=tl";
1067 query = query + "&omode=flc";
1070 query
= query
+ "&omode=lc";
1072 new Ajax
.Request(query
, {
1073 onComplete: function(transport
) {
1074 all_counters_callback2(transport
);
1080 exception_error("selectionToggleMarked", e
);
1084 function cdmGetSelectedArticles() {
1085 var sel_articles
= new Array();
1086 var container
= document
.getElementById("headlinesInnerContainer");
1088 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1089 var child
= container
.childNodes
[i
];
1091 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1092 var c_id
= child
.id
.replace("RROW-", "");
1093 sel_articles
.push(c_id
);
1097 return sel_articles
;
1100 function cdmGetVisibleArticles() {
1101 var sel_articles
= new Array();
1102 var container
= document
.getElementById("headlinesInnerContainer");
1104 if (!container
) return sel_articles
;
1106 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1107 var child
= container
.childNodes
[i
];
1109 if (child
.id
&& child
.id
.match("RROW-")) {
1110 var c_id
= child
.id
.replace("RROW-", "");
1111 sel_articles
.push(c_id
);
1115 return sel_articles
;
1118 function cdmGetUnreadArticles() {
1119 var sel_articles
= new Array();
1120 var container
= document
.getElementById("headlinesInnerContainer");
1122 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1123 var child
= container
.childNodes
[i
];
1125 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1126 var c_id
= child
.id
.replace("RROW-", "");
1127 sel_articles
.push(c_id
);
1131 return sel_articles
;
1135 // mode = all,none,unread
1136 function cdmSelectArticles(mode
) {
1137 var container
= document
.getElementById("headlinesInnerContainer");
1139 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1140 var child
= container
.childNodes
[i
];
1142 if (child
.id
&& child
.id
.match("RROW-")) {
1143 var aid
= child
.id
.replace("RROW-", "");
1145 var cb
= document
.getElementById("RCHK-" + aid
);
1147 if (mode
== "all") {
1148 if (!child
.className
.match("Selected")) {
1149 child
.className
= child
.className
+ "Selected";
1152 } else if (mode
== "unread") {
1153 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1154 child
.className
= child
.className
+ "Selected";
1158 child
.className
= child
.className
.replace("Selected", "");
1165 function catchupPage() {
1167 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1169 var str
= __("Mark all visible articles in %s as read?");
1171 str
= str
.replace("%s", fn
);
1173 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1177 if (document
.getElementById("headlinesList")) {
1178 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1179 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1180 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1182 cdmSelectArticles('all');
1183 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1184 cdmSelectArticles('none');
1188 function catchupSelection() {
1194 if (document
.getElementById("headlinesList")) {
1195 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1197 rows
= cdmGetSelectedArticles();
1200 if (rows
.length
== 0) {
1201 alert(__("No articles are selected."));
1206 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1208 var str
= __("Mark %d selected articles in %s as read?");
1210 str
= str
.replace("%d", rows
.length
);
1211 str
= str
.replace("%s", fn
);
1213 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1217 if (document
.getElementById("headlinesList")) {
1218 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1219 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1221 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1222 // cdmSelectArticles('none');
1226 exception_error("catchupSelection", e
);
1230 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1231 _tag_active_post_id
= id
;
1232 _tag_active_feed_id
= feed_id
;
1233 _tag_active_cdm
= cdm_enabled
;
1235 cache_invalidate(id
);
1238 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1240 displayDlg('editArticleTags', id
);
1244 function tag_saved_callback(transport
) {
1246 debug("in tag_saved_callback");
1251 if (tagsAreDisplayed()) {
1252 _reload_feedlist_after_view
= true;
1255 if (!_tag_active_cdm
) {
1256 if (active_post_id
== _tag_active_post_id
) {
1257 debug("reloading current article");
1258 view(_tag_active_post_id
, _tag_active_feed_id
);
1261 debug("reloading current feed");
1266 exception_error("catchup_callback", e
);
1270 function editTagsSave() {
1272 notify_progress("Saving article tags...");
1274 var form
= document
.forms
["tag_edit_form"];
1276 var query
= Form
.serialize("tag_edit_form");
1278 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1282 new Ajax
.Request(query
, {
1283 onComplete: function(transport
) {
1284 tag_saved_callback(transport
);
1289 function editTagsInsert() {
1292 var form
= document
.forms
["tag_edit_form"];
1294 var found_tags
= form
.found_tags
;
1295 var tags_str
= form
.tags_str
;
1297 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1299 if (tags_str
.value
.length
> 0 &&
1300 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1302 tags_str
.value
= tags_str
.value
+ ", ";
1305 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1307 found_tags
.selectedIndex
= 0;
1310 exception_error("editTagsInsert", e
);
1314 function cdmScrollViewport(where
) {
1315 debug("cdmScrollViewport: " + where
);
1317 var ctr
= document
.getElementById("headlinesInnerContainer");
1321 if (where
== "bottom") {
1322 ctr
.scrollTop
= ctr
.scrollHeight
;
1324 ctr
.scrollTop
= where
;
1328 function cdmArticleIsBelowViewport(id
) {
1330 var ctr
= document
.getElementById("headlinesInnerContainer");
1331 var e
= document
.getElementById("RROW-" + id
);
1333 if (!e
|| !ctr
) return;
1335 // article starts below viewport
1337 if (ctr
.scrollTop
< e
.offsetTop
) {
1344 exception_error("cdmArticleIsVisible", e
);
1348 function cdmArticleIsAboveViewport(id
) {
1350 var ctr
= document
.getElementById("headlinesInnerContainer");
1351 var e
= document
.getElementById("RROW-" + id
);
1353 if (!e
|| !ctr
) return;
1355 // article starts above viewport
1357 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1364 exception_error("cdmArticleIsVisible", e
);
1368 function cdmScrollToArticleId(id
) {
1370 var ctr
= document
.getElementById("headlinesInnerContainer");
1371 var e
= document
.getElementById("RROW-" + id
);
1373 if (!e
|| !ctr
) return;
1375 ctr
.scrollTop
= e
.offsetTop
;
1378 exception_error("cdmScrollToArticleId", e
);
1382 function cdmArticleIsActuallyVisible(id
) {
1384 var ctr
= document
.getElementById("headlinesInnerContainer");
1385 var e
= document
.getElementById("RROW-" + id
);
1387 if (!e
|| !ctr
) return;
1389 // article fits in viewport OR article is longer than viewport and
1390 // its bottom is visible
1392 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1393 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1397 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1398 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1399 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1408 exception_error("cdmArticleIsVisible", e
);
1412 function cdmWatchdog() {
1416 var ctr
= document
.getElementById("headlinesInnerContainer");
1420 var ids
= new Array();
1422 var e
= ctr
.firstChild
;
1425 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1426 e
.id
.match("RROW-")) {
1428 // article fits in viewport OR article is longer than viewport and
1429 // its bottom is visible
1431 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1432 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1434 // debug(e.id + " is visible " + e.offsetTop + "." +
1435 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1436 // (ctr.scrollTop + ctr.offsetHeight));
1438 ids
.push(e
.id
.replace("RROW-", ""));
1440 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1441 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1442 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1444 ids
.push(e
.id
.replace("RROW-", ""));
1448 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1450 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1451 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1453 ids.push(e.id.replace("RROW-", ""));
1462 debug("cdmWatchdog, ids= " + ids
.toString());
1464 if (ids
.length
> 0) {
1466 for (var i
= 0; i
< ids
.length
; i
++) {
1467 var e
= document
.getElementById("RROW-" + ids
[i
]);
1469 e
.className
= e
.className
.replace("Unread", "");
1473 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1474 param_escape(ids
.toString()) + "&cmode=0";
1476 new Ajax
.Request(query
, {
1477 onComplete: function(transport
) {
1478 all_counters_callback2(transport
);
1483 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1486 exception_error("cdmWatchdog", e
);
1492 function cache_inject(id
, article
, param
) {
1493 if (!cache_check_param(id
, param
)) {
1494 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1496 var cache_obj
= new Array();
1498 cache_obj
["id"] = id
;
1499 cache_obj
["data"] = article
;
1500 cache_obj
["param"] = param
;
1502 article_cache
.push(cache_obj
);
1505 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1509 function cache_find(id
) {
1510 for (var i
= 0; i
< article_cache
.length
; i
++) {
1511 if (article_cache
[i
]["id"] == id
) {
1512 return article_cache
[i
]["data"];
1518 function cache_find_param(id
, param
) {
1519 for (var i
= 0; i
< article_cache
.length
; i
++) {
1520 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1521 return article_cache
[i
]["data"];
1527 function cache_check(id
) {
1528 for (var i
= 0; i
< article_cache
.length
; i
++) {
1529 if (article_cache
[i
]["id"] == id
) {
1536 function cache_check_param(id
, param
) {
1537 for (var i
= 0; i
< article_cache
.length
; i
++) {
1539 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1540 // article_cache[i]["param"] + " vs " + id + ":" + param);
1542 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1549 function cache_expire() {
1550 while (article_cache
.length
> 25) {
1551 article_cache
.shift();
1555 function cache_empty() {
1556 article_cache
= new Array();
1559 function cache_invalidate(id
) {
1564 while (i
< article_cache
.length
) {
1565 if (article_cache
[i
]["id"] == id
) {
1566 debug("cache_invalidate: removed id " + id
);
1567 article_cache
.splice(i
, 1);
1572 debug("cache_invalidate: id not found: " + id
);
1575 exception_error("cache_invalidate", e
);
1579 function getActiveArticleId() {
1580 return active_post_id
;
1583 function cdmClicked(id
) {
1585 var elem
= document
.getElementById("RROW-" + id
);
1588 var id
= elem
.id
.replace("RROW-", "");
1589 active_post_id
= id
;
1591 cdmSelectArticles("none");
1592 toggleUnread(id
, 0, true);
1597 exception_error("cdmClicked", e
);
1601 function preload_article_callback(transport
) {
1603 if (transport
.responseXML
) {
1604 var articles
= transport
.responseXML
.getElementsByTagName("article");
1606 for (var i
= 0; i
< articles
.length
; i
++) {
1607 var id
= articles
[i
].getAttribute("id");
1608 if (!cache_check(id
)) {
1609 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1610 debug("preloaded article: " + id
);
1615 exception_error("preload_article_callback", e
);
1619 function preloadArticleUnderPointer(id
) {
1621 if (getInitParam("bw_limit") == "1") return;
1623 if (post_under_pointer
== id
&& !cache_check(id
)) {
1625 debug("trying to preload article " + id
);
1627 var neighbor_ids
= getRelativePostIds(id
, 1);
1629 /* only request uncached articles */
1631 var cids_to_request
= Array();
1633 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1634 if (!cache_check(neighbor_ids
[i
])) {
1635 cids_to_request
.push(neighbor_ids
[i
]);
1638 debug("additional ids: " + cids_to_request
.toString());
1640 cids_to_request
.push(id
);
1642 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1643 cids_to_request
.toString();
1644 new Ajax
.Request(query
, {
1645 onComplete: function(transport
) {
1646 preload_article_callback(transport
);
1650 exception_error("preloadArticleUnderPointer", e
);
1654 function postMouseIn(id
) {
1656 if (post_under_pointer
!= id
) {
1657 post_under_pointer
= id
;
1659 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1664 exception_error("postMouseIn", e
);
1668 function postMouseOut(id
) {
1670 post_under_pointer
= false;
1672 exception_error("postMouseOut", e
);
1676 function headlines_scroll_handler() {
1679 var e
= document
.getElementById("headlinesInnerContainer");
1681 // don't do infinite scrolling when Limit == All
1683 var toolbar_form
= document
.forms
["main_toolbar_form"];
1685 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1686 if (limit
.value
!= 0) {
1688 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1689 _infscroll_disable
);
1691 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1692 if (!_infscroll_disable
) {
1693 debug("more cowbell!");
1700 exception_error("headlines_scroll_handler", e
);
1704 function catchupRelativeToArticle(below
) {
1708 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1709 printLockingError();
1712 if (!getActiveArticleId()) {
1713 alert(__("No article is selected."));
1719 if (document
.getElementById("headlinesList")) {
1720 visible_ids
= getVisibleHeadlineIds();
1722 visible_ids
= cdmGetVisibleArticles();
1725 var ids_to_mark
= new Array();
1728 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1729 if (visible_ids
[i
] != getActiveArticleId()) {
1730 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1732 if (e
&& e
.className
.match("Unread")) {
1733 ids_to_mark
.push(visible_ids
[i
]);
1740 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1741 if (visible_ids
[i
] != getActiveArticleId()) {
1742 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1744 if (e
&& e
.className
.match("Unread")) {
1745 ids_to_mark
.push(visible_ids
[i
]);
1753 if (ids_to_mark
.length
== 0) {
1754 alert(__("No articles found to mark"));
1756 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1760 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1761 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1762 e
.className
= e
.className
.replace("Unread", "");
1765 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1766 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1768 new Ajax
.Request(query
, {
1769 onComplete: function(transport
) {
1770 catchup_callback2(transport
);
1777 exception_error("catchupRelativeToArticle", e
);
1781 function cdmExpandArticle(a_id
) {
1783 var id
= 'CICD-' + a_id
;
1786 Element
.hide("CEXC-" + a_id
);
1789 Effect
.Appear(id
, {duration
: 0.5,
1790 beforeStart: function(effect
) {
1791 var h_id
= 'CICH-' + a_id
;
1792 var h_elem
= document
.getElementById(h_id
);
1793 if (h_elem
) { h_elem
.style
.display
= "none"; }
1795 toggleUnread(a_id
, 0);
1800 exception_error("appearBlockElementF", e
);
1805 function fixHeadlinesOrder(ids
) {
1807 for (var i
= 0; i
< ids
.length
; i
++) {
1808 var e
= document
.getElementById("RROW-" + ids
[i
]);
1812 e
.className
= e
.className
.replace("even", "odd");
1814 e
.className
= e
.className
.replace("odd", "even");
1819 exception_error("fixHeadlinesOrder", e
);
1823 function hideReadHeadlines() {
1827 var vis_ids
= new Array();
1829 if (document
.getElementById("headlinesList")) {
1830 ids
= getVisibleHeadlineIds();
1832 ids
= cdmGetVisibleArticles();
1835 var read_headlines_visible
= true;
1837 for (var i
= 0; i
< ids
.length
; i
++) {
1838 var row
= document
.getElementById("RROW-" + ids
[i
]);
1840 if (row
&& row
.className
) {
1841 if (read_headlines_visible
) {
1842 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1844 vis_ids
.push(ids
[i
]);
1846 //Effect.Fade(row, {duration : 0.3});
1851 vis_ids
.push(ids
[i
]);
1856 fixHeadlinesOrder(vis_ids
);
1858 read_headlines_visible
= !read_headlines_visible
;
1861 exception_error("hideReadHeadlines", e
);
1865 function invertHeadlineSelection() {
1867 var rows
= new Array();
1871 r
= document
.getElementsByTagName("TR");
1873 r
= document
.getElementsByTagName("DIV");
1876 for (var i
= 0; i
< r
.length
; i
++) {
1877 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1882 for (var i
= 0; i
< rows
.length
; i
++) {
1883 var nc
= rows
[i
].className
;
1884 var id
= rows
[i
].id
.replace("RROW-", "");
1885 var cb
= document
.getElementById("RCHK-" + id
);
1887 if (!rows
[i
].className
.match("Selected")) {
1888 nc
= nc
+ "Selected";
1891 nc
= nc
.replace("Selected", "");
1895 rows
[i
].className
= nc
;
1900 exception_error("invertHeadlineSelection", e
);
1904 function getArticleUnderPointer() {
1905 return post_under_pointer
;
1908 function zoomToArticle(id
) {
1910 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1912 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1915 exception_error("zoomToArticle", e
);
1919 function showOriginalArticleInline(id
) {
1922 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1924 notify_progress("Loading, please wait...", true);
1926 new Ajax
.Request(query
, {
1927 onComplete: function(transport
) {
1929 if (transport
.responseXML
) {
1931 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1932 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1937 link
= link
.firstChild
.nodeValue
;
1939 var ci
= document
.getElementById("content-insert");
1941 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1943 render_article(tmp
);
1950 exception_error("showOriginalArticleInline", e
);
1955 function scrollArticle(offset
) {
1958 var ci
= document
.getElementById("content-insert");
1960 ci
.scrollTop
+= offset
;
1963 var hi
= document
.getElementById("headlinesInnerContainer");
1965 hi
.scrollTop
+= offset
;
1970 exception_error("scrollArticle", e
);
1974 function show_labels_in_headlines(transport
) {
1976 if (transport
.responseXML
) {
1977 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1979 var elems
= info
.getElementsByTagName("entry");
1981 for (var l
= 0; l
< elems
.length
; l
++) {
1982 var e_id
= elems
[l
].getAttribute("id");
1986 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
1989 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1997 exception_error("show_labels_in_headlines", e
);
2002 function toggleHeadlineActions() {
2004 var e
= document
.getElementById("headlineActionsBody");
2005 var p
= document
.getElementById("headlineActionsDrop");
2007 if (!Element
.visible(e
)) {
2014 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2015 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2018 exception_error("toggleHeadlineActions", e
);