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 if (!transport_error_check(transport
)) return;
72 clean_feed_selections();
77 if (transport
.responseXML
) {
78 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
80 is_cat
= headlines
.getAttribute("is_cat");
81 feed_id
= headlines
.getAttribute("id");
82 setActiveFeedId(feed_id
, is_cat
);
87 var feedr
= document
.getElementById("FEEDR-" + feed_id
);
88 if (feedr
&& !feedr
.className
.match("Selected")) {
89 feedr
.className
= feedr
.className
+ "Selected";
92 var feedr
= document
.getElementById("FCAT-" + feed_id
);
93 if (feedr
&& !feedr
.className
.match("Selected")) {
94 feedr
.className
= feedr
.className
+ "Selected";
98 var f
= document
.getElementById("headlines-frame");
100 if (feed_cur_page
== 0) {
101 debug("resetting headlines scrollTop");
106 if (transport
.responseXML
) {
107 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
108 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
109 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
110 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
112 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
114 var headlines_count
= headlines_count_obj
.getAttribute("value");
115 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
116 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
118 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
120 if (headlines_count
== 0) {
121 _infscroll_disable
= 1;
123 _infscroll_disable
= 0;
126 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
127 var articles
= transport
.responseXML
.getElementsByTagName("article");
128 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
130 if (feed_cur_page
== 0) {
132 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
134 var cache_prefix
= "";
142 cache_invalidate(cache_prefix
+ feed_id
);
144 if (!disable_cache
) {
145 cache_inject(cache_prefix
+ feed_id
,
146 headlines
.firstChild
.nodeValue
, headlines_unread
);
150 debug("headlines_callback: returned no data");
151 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
156 if (headlines_count
> 0) {
157 debug("adding some more headlines...");
159 var c
= document
.getElementById("headlinesList");
162 c
= document
.getElementById("headlinesInnerContainer");
165 var ids
= getSelectedArticleIds2();
167 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
169 debug("restore selected ids: " + ids
);
171 for (var i
= 0; i
< ids
.length
; i
++) {
172 markHeadline(ids
[i
]);
176 debug("no new headlines received");
179 debug("headlines_callback: returned no data");
180 notify_error("Error while trying to load more headlines");
186 for (var i
= 0; i
< articles
.length
; i
++) {
187 var a_id
= articles
[i
].getAttribute("id");
188 debug("found id: " + a_id
);
189 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
192 debug("no cached articles received");
196 debug("parsing piggybacked counters: " + counters
);
197 parse_counters(counters
, false);
199 debug("counters container not found in reply, requesting...");
204 debug("parsing runtime info: " + runtime_info
[0]);
205 parse_runtime_info(runtime_info
[0]);
207 debug("counters container not found in reply");
211 debug("headlines_callback: returned no XML object");
212 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
215 if (typeof correctPNG
!= 'undefined') {
219 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
221 if (!document
.getElementById("headlinesList") &&
222 getActiveFeedId() != -3 &&
223 getInitParam("cdm_auto_catchup") == 1) {
224 debug("starting CDM watchdog");
225 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
226 _cdm_wd_vishist
= new Array();
228 debug("not in CDM mode or watchdog disabled");
231 _feed_cur_page
= feed_cur_page
;
232 _infscroll_request_sent
= 0;
239 exception_error("headlines_callback2", e
, transport
);
243 function render_article(article
) {
245 var f
= document
.getElementById("content-frame");
250 var fi
= document
.getElementById("content-insert");
256 fi
.innerHTML
= article
;
259 exception_error("render_article", e
);
263 function showArticleInHeadlines(id
) {
267 cleanSelected("headlinesList");
269 var crow
= document
.getElementById("RROW-" + id
);
273 var article_is_unread
= crow
.className
.match("Unread");
275 crow
.className
= crow
.className
.replace("Unread", "");
277 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
279 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
281 var cache_prefix
= "";
283 if (activeFeedIsCat()) {
289 var view_mode
= false;
292 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
293 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
298 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
299 upd_img_pic
.src
= "images/blank_icon.gif";
301 cache_invalidate(cache_prefix
+ getActiveFeedId());
303 cache_inject(cache_prefix
+ getActiveFeedId(),
304 document
.getElementById("headlines-frame").innerHTML
,
305 get_feed_unread(getActiveFeedId()));
307 } else if (article_is_unread
&& view_mode
== "all_articles") {
309 cache_invalidate(cache_prefix
+ getActiveFeedId());
311 cache_inject(cache_prefix
+ getActiveFeedId(),
312 document
.getElementById("headlines-frame").innerHTML
,
313 get_feed_unread(getActiveFeedId())-1);
315 } else if (article_is_unread
) {
316 cache_invalidate(cache_prefix
+ getActiveFeedId());
322 exception_error("showArticleInHeadlines", e
);
326 function article_callback2(transport
, id
, feed_id
) {
328 debug("article_callback2 " + id
);
330 if (transport
.responseXML
) {
332 if (!transport_error_check(transport
)) return;
334 debug("looking for articles to cache...");
336 var articles
= transport
.responseXML
.getElementsByTagName("article");
338 for (var i
= 0; i
< articles
.length
; i
++) {
339 var a_id
= articles
[i
].getAttribute("id");
341 debug("found id: " + a_id
);
343 if (a_id
== active_post_id
) {
344 debug("active article, rendering...");
345 render_article(articles
[i
].firstChild
.nodeValue
);
348 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
351 if (id
!= last_requested_article
) {
352 debug("requested article id is out of sequence, aborting");
356 active_real_feed_id
= feed_id
;
359 showArticleInHeadlines(id
);
361 var reply
= transport
.responseXML
.firstChild
.firstChild
;
364 debug("article_callback: returned no XML object");
365 //var f = document.getElementById("content-frame");
366 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
369 var date
= new Date();
370 last_article_view
= date
.getTime() / 1000;
372 if (typeof correctPNG
!= 'undefined') {
376 if (_reload_feedlist_after_view
) {
377 setTimeout('updateFeedList(false, false)', 50);
378 _reload_feedlist_after_view
= false;
380 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
383 debug("parsing piggybacked counters: " + counters
);
384 parse_counters(counters
, false);
386 debug("counters container not found in reply, requesting...");
393 exception_error("article_callback2", e
, transport
);
397 function view(id
, feed_id
, skip_history
) {
400 debug("loading article: " + id
+ "/" + feed_id
);
402 var cached_article
= cache_find(id
);
404 debug("cache check result: " + (cached_article
!= false));
408 //setActiveFeedId(feed_id);
410 var query
= "backend.php?op=view&id=" + param_escape(id
) +
411 "&feed=" + param_escape(feed_id
);
413 var date
= new Date();
415 var neighbor_ids
= getRelativePostIds(active_post_id
);
417 /* only request uncached articles */
419 var cids_to_request
= Array();
421 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
422 if (!cache_check(neighbor_ids
[i
])) {
423 cids_to_request
.push(neighbor_ids
[i
]);
427 debug("additional ids: " + cids_to_request
.toString());
429 /* additional info for piggyback counters */
431 if (tagsAreDisplayed()) {
432 query
= query
+ "&omode=lt";
434 query
= query
+ "&omode=flc";
437 var date
= new Date();
438 var timestamp
= Math
.round(date
.getTime() / 1000);
439 query
= query
+ "&ts=" + timestamp
;
441 query
= query
+ "&cids=" + cids_to_request
.toString();
443 var crow
= document
.getElementById("RROW-" + id
);
444 var article_is_unread
= crow
.className
.match("Unread");
446 if (!async_counters_work
) {
447 query
= query
+ "&csync=true";
450 showArticleInHeadlines(id
);
452 if (!cached_article
) {
454 notify_progress("Loading, please wait...", true);
456 } else if (cached_article
&& article_is_unread
) {
458 query
= query
+ "&mode=prefetch";
460 render_article(cached_article
);
462 } else if (cached_article
) {
464 query
= query
+ "&mode=prefetch_old";
465 render_article(cached_article
);
471 last_requested_article
= id
;
473 new Ajax
.Request(query
, {
474 onComplete: function(transport
) {
475 article_callback2(transport
, id
, feed_id
);
481 exception_error("view", e
);
486 return toggleMark(id
);
490 return togglePub(id
);
493 function tMark_afh_off(effect
) {
495 var elem
= effect
.effects
[0].element
;
497 debug("tMark_afh_off : " + elem
.id
);
500 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
501 elem
.alt
= __("Star article");
506 exception_error("tMark_afh_off", e
);
510 function tPub_afh_off(effect
) {
512 var elem
= effect
.effects
[0].element
;
514 debug("tPub_afh_off : " + elem
.id
);
517 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
518 elem
.alt
= __("Publish article");
523 exception_error("tPub_afh_off", e
);
527 function toggleMark(id
, client_only
, no_effects
) {
531 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
533 query
= query
+ "&afid=" + getActiveFeedId();
535 if (tagsAreDisplayed()) {
536 query
= query
+ "&omode=tl";
538 query
= query
+ "&omode=flc";
541 var mark_img
= document
.getElementById("FMPIC-" + id
);
543 if (!mark_img
) return;
545 var vfeedu
= document
.getElementById("FEEDU--1");
546 var crow
= document
.getElementById("RROW-" + id
);
548 if (mark_img
.src
.match("mark_unset")) {
549 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
550 mark_img
.alt
= __("Unstar article");
551 query
= query
+ "&mark=1";
554 //mark_img.src = "images/mark_unset.png";
555 mark_img
.alt
= __("Please wait...");
556 query
= query
+ "&mark=0";
558 if (document
.getElementById("headlinesList") && !no_effects
) {
559 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
561 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
562 mark_img
.alt
= __("Star article");
569 new Ajax
.Request(query
, {
570 onComplete: function(transport
) {
571 all_counters_callback2(transport
);
577 exception_error("toggleMark", e
);
581 function togglePub(id
, client_only
, no_effects
) {
585 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
587 query
= query
+ "&afid=" + getActiveFeedId();
589 if (tagsAreDisplayed()) {
590 query
= query
+ "&omode=tl";
592 query
= query
+ "&omode=flc";
595 var mark_img
= document
.getElementById("FPPIC-" + id
);
597 if (!mark_img
) return;
599 var vfeedu
= document
.getElementById("FEEDU--2");
600 var crow
= document
.getElementById("RROW-" + id
);
602 if (mark_img
.src
.match("pub_unset")) {
603 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
604 mark_img
.alt
= __("Unpublish article");
605 query
= query
+ "&pub=1";
609 //mark_img.src = "images/pub_unset.png";
610 mark_img
.alt
= __("Please wait...");
611 query
= query
+ "&pub=0";
613 if (document
.getElementById("headlinesList") && !no_effects
) {
614 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
616 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
617 mark_img
.alt
= __("Publish article");
622 new Ajax
.Request(query
, {
623 onComplete: function(transport
) {
624 all_counters_callback2(transport
);
630 exception_error("togglePub", e
);
634 function correctHeadlinesOffset(id
) {
638 var hlist
= document
.getElementById("headlinesList");
639 var container
= document
.getElementById("headlinesInnerContainer");
640 var row
= document
.getElementById("RROW-" + id
);
642 var viewport
= container
.offsetHeight
;
644 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
645 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
647 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
648 debug("Vport: " + viewport
);
650 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
651 container
.scrollTop
= row
.offsetTop
;
652 } else if (rel_offset_bottom
> viewport
) {
654 /* doesn't properly work with Opera in some cases because
655 Opera fucks up element scrolling */
657 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
661 exception_error("correctHeadlinesOffset", e
);
666 function moveToPost(mode
) {
673 rows
= cdmGetVisibleArticles();
675 rows
= getVisibleHeadlineIds();
681 if (!document
.getElementById('RROW-' + active_post_id
)) {
682 active_post_id
= false;
685 if (active_post_id
== false) {
686 next_id
= getFirstVisibleHeadlineId();
687 prev_id
= getLastVisibleHeadlineId();
689 for (var i
= 0; i
< rows
.length
; i
++) {
690 if (rows
[i
] == active_post_id
) {
697 if (mode
== "next") {
701 if (!cdmArticleIsActuallyVisible(next_id
)) {
702 cdmScrollToArticleId(next_id
);
704 cdmSelectArticles("none");
705 toggleUnread(next_id
, 0, true);
706 toggleSelected(next_id
);
709 correctHeadlinesOffset(next_id
);
710 view(next_id
, getActiveFeedId());
715 if (mode
== "prev") {
718 cdmScrollToArticleId(prev_id
);
719 cdmSelectArticles("none");
720 toggleUnread(prev_id
, 0, true);
721 toggleSelected(prev_id
);
723 correctHeadlinesOffset(prev_id
);
724 view(prev_id
, getActiveFeedId());
730 exception_error("moveToPost", e
);
734 function toggleSelected(id
) {
737 var cb
= document
.getElementById("RCHK-" + id
);
739 var row
= document
.getElementById("RROW-" + id
);
741 var nc
= row
.className
;
743 if (!nc
.match("Selected")) {
744 nc
= nc
+ "Selected";
749 // In CDM basically last selected article == active article
750 if (isCdmMode()) active_post_id
= id
;
752 nc
= nc
.replace("Selected", "");
762 exception_error("toggleSelected", e
);
766 function toggleUnread_afh(effect
) {
769 var elem
= effect
.element
;
770 elem
.style
.backgroundColor
= "";
773 exception_error("toggleUnread_afh", e
);
777 function toggleUnread(id
, cmode
, effect
) {
780 var row
= document
.getElementById("RROW-" + id
);
782 var nc
= row
.className
;
783 var is_selected
= row
.className
.match("Selected");
784 nc
= nc
.replace("Unread", "");
785 nc
= nc
.replace("Selected", "");
787 // since we are removing selection from the object, uncheck
788 // corresponding checkbox
790 var cb
= document
.getElementById("RCHK-" + id
);
795 // NOTE: I'm not sure that resetting selection here is a feature -fox
797 if (cmode
== undefined || cmode
== 2) {
798 if (row
.className
.match("Unread")) {
802 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
803 afterFinish
: toggleUnread_afh
,
804 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
808 row
.className
= nc
+ "Unread";
810 } else if (cmode
== 0) {
814 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
815 afterFinish
: toggleUnread_afh
,
816 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
818 } else if (cmode
== 1) {
819 row
.className
= nc
+ "Unread";
822 // Disable unmarking as selected for the time being (16.05.08) -fox
823 if (is_selected
) row
.className
= row
.className
+ "Selected";
825 if (cmode
== undefined) cmode
= 2;
827 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
828 param_escape(id
) + "&cmode=" + param_escape(cmode
);
830 // notify_progress("Loading, please wait...");
832 new Ajax
.Request(query
, {
833 onComplete: function(transport
) {
834 all_counters_callback2(transport
);
841 exception_error("toggleUnread", e
);
845 function selectionRemoveLabel(id
) {
848 var ids
= getSelectedArticleIds2();
850 if (ids
.length
== 0) {
851 alert(__("No articles are selected."));
855 // var ok = confirm(__("Remove selected articles from label?"));
859 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
860 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
862 // notify_progress("Loading, please wait...");
864 cache_invalidate("F:" + (-11 - id
));
866 new Ajax
.Request(query
, {
867 onComplete: function(transport
) {
868 show_labels_in_headlines(transport
);
869 all_counters_callback2(transport
);
875 exception_error("selectionAssignLabel", e
);
880 function selectionAssignLabel(id
) {
883 var ids
= getSelectedArticleIds2();
885 if (ids
.length
== 0) {
886 alert(__("No articles are selected."));
890 // var ok = confirm(__("Assign selected articles to label?"));
894 cache_invalidate("F:" + (-11 - id
));
896 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
897 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
899 // notify_progress("Loading, please wait...");
901 new Ajax
.Request(query
, {
902 onComplete: function(transport
) {
903 show_labels_in_headlines(transport
);
904 all_counters_callback2(transport
);
910 exception_error("selectionAssignLabel", e
);
915 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
920 rows
= cdmGetSelectedArticles();
922 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
925 if (rows
.length
== 0 && !no_error
) {
926 alert(__("No articles are selected."));
930 for (i
= 0; i
< rows
.length
; i
++) {
931 var row
= document
.getElementById("RROW-" + rows
[i
]);
933 var nc
= row
.className
;
934 nc
= nc
.replace("Unread", "");
935 nc
= nc
.replace("Selected", "");
937 if (set_state
== undefined) {
938 if (row
.className
.match("Unread")) {
939 row
.className
= nc
+ "Selected";
941 row
.className
= nc
+ "UnreadSelected";
945 if (set_state
== false) {
946 row
.className
= nc
+ "Selected";
949 if (set_state
== true) {
950 row
.className
= nc
+ "UnreadSelected";
955 if (rows
.length
> 0) {
959 if (set_state
== undefined) {
961 } else if (set_state
== true) {
963 } else if (set_state
== false) {
967 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
968 param_escape(rows
.toString()) + "&cmode=" + cmode
;
970 notify_progress("Loading, please wait...");
972 new Ajax
.Request(query
, {
973 onComplete: function(transport
) {
974 catchup_callback2(transport
, callback_func
);
980 exception_error("selectionToggleUnread", e
);
984 function selectionToggleMarked(cdm_mode
) {
990 rows
= cdmGetSelectedArticles();
992 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
995 if (rows
.length
== 0) {
996 alert(__("No articles are selected."));
1000 for (i
= 0; i
< rows
.length
; i
++) {
1001 toggleMark(rows
[i
], true, true);
1004 if (rows
.length
> 0) {
1006 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
1007 param_escape(rows
.toString()) + "&cmode=2";
1009 query
= query
+ "&afid=" + getActiveFeedId();
1011 /* if (tagsAreDisplayed()) {
1012 query = query + "&omode=tl";
1014 query = query + "&omode=flc";
1017 query
= query
+ "&omode=lc";
1019 new Ajax
.Request(query
, {
1020 onComplete: function(transport
) {
1021 all_counters_callback2(transport
);
1027 exception_error("selectionToggleMarked", e
);
1031 function selectionTogglePublished(cdm_mode
) {
1037 rows
= cdmGetSelectedArticles();
1039 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1042 if (rows
.length
== 0) {
1043 alert(__("No articles are selected."));
1047 for (i
= 0; i
< rows
.length
; i
++) {
1048 togglePub(rows
[i
], true, true);
1051 if (rows
.length
> 0) {
1053 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1054 param_escape(rows
.toString()) + "&cmode=2";
1056 query
= query
+ "&afid=" + getActiveFeedId();
1058 /* if (tagsAreDisplayed()) {
1059 query = query + "&omode=tl";
1061 query = query + "&omode=flc";
1064 query
= query
+ "&omode=lc";
1066 new Ajax
.Request(query
, {
1067 onComplete: function(transport
) {
1068 all_counters_callback2(transport
);
1074 exception_error("selectionToggleMarked", e
);
1078 function cdmGetSelectedArticles() {
1079 var sel_articles
= new Array();
1080 var container
= document
.getElementById("headlinesInnerContainer");
1082 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1083 var child
= container
.childNodes
[i
];
1085 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1086 var c_id
= child
.id
.replace("RROW-", "");
1087 sel_articles
.push(c_id
);
1091 return sel_articles
;
1094 function cdmGetVisibleArticles() {
1095 var sel_articles
= new Array();
1096 var container
= document
.getElementById("headlinesInnerContainer");
1098 if (!container
) return sel_articles
;
1100 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1101 var child
= container
.childNodes
[i
];
1103 if (child
.id
&& child
.id
.match("RROW-")) {
1104 var c_id
= child
.id
.replace("RROW-", "");
1105 sel_articles
.push(c_id
);
1109 return sel_articles
;
1112 function cdmGetUnreadArticles() {
1113 var sel_articles
= new Array();
1114 var container
= document
.getElementById("headlinesInnerContainer");
1116 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1117 var child
= container
.childNodes
[i
];
1119 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1120 var c_id
= child
.id
.replace("RROW-", "");
1121 sel_articles
.push(c_id
);
1125 return sel_articles
;
1129 // mode = all,none,unread
1130 function cdmSelectArticles(mode
) {
1131 var container
= document
.getElementById("headlinesInnerContainer");
1133 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1134 var child
= container
.childNodes
[i
];
1136 if (child
.id
&& child
.id
.match("RROW-")) {
1137 var aid
= child
.id
.replace("RROW-", "");
1139 var cb
= document
.getElementById("RCHK-" + aid
);
1141 if (mode
== "all") {
1142 if (!child
.className
.match("Selected")) {
1143 child
.className
= child
.className
+ "Selected";
1146 } else if (mode
== "unread") {
1147 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1148 child
.className
= child
.className
+ "Selected";
1152 child
.className
= child
.className
.replace("Selected", "");
1159 function catchupPage() {
1161 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1163 var str
= __("Mark all visible articles in %s as read?");
1165 str
= str
.replace("%s", fn
);
1167 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1171 if (document
.getElementById("headlinesList")) {
1172 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1173 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1174 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1176 cdmSelectArticles('all');
1177 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1178 cdmSelectArticles('none');
1182 function catchupSelection() {
1188 if (document
.getElementById("headlinesList")) {
1189 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1191 rows
= cdmGetSelectedArticles();
1194 if (rows
.length
== 0) {
1195 alert(__("No articles are selected."));
1200 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1202 var str
= __("Mark %d selected articles in %s as read?");
1204 str
= str
.replace("%d", rows
.length
);
1205 str
= str
.replace("%s", fn
);
1207 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1211 if (document
.getElementById("headlinesList")) {
1212 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1213 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1215 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1216 // cdmSelectArticles('none');
1220 exception_error("catchupSelection", e
);
1224 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1225 displayDlg('editArticleTags', id
);
1229 function tag_saved_callback(transport
) {
1231 debug("in tag_saved_callback");
1236 if (tagsAreDisplayed()) {
1237 _reload_feedlist_after_view
= true;
1241 if (transport
.responseXML
) {
1242 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1245 var id
= tags_str
.getAttribute("id");
1248 var tags
= document
.getElementById("ATSTR-" + id
);
1250 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1257 exception_error("tag_saved_callback", e
);
1261 function editTagsSave() {
1263 notify_progress("Saving article tags...");
1265 var form
= document
.forms
["tag_edit_form"];
1267 var query
= Form
.serialize("tag_edit_form");
1269 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1273 new Ajax
.Request(query
, {
1274 onComplete: function(transport
) {
1275 tag_saved_callback(transport
);
1280 function editTagsInsert() {
1283 var form
= document
.forms
["tag_edit_form"];
1285 var found_tags
= form
.found_tags
;
1286 var tags_str
= form
.tags_str
;
1288 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1290 if (tags_str
.value
.length
> 0 &&
1291 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1293 tags_str
.value
= tags_str
.value
+ ", ";
1296 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1298 found_tags
.selectedIndex
= 0;
1301 exception_error("editTagsInsert", e
);
1305 function cdmScrollViewport(where
) {
1306 debug("cdmScrollViewport: " + where
);
1308 var ctr
= document
.getElementById("headlinesInnerContainer");
1312 if (where
== "bottom") {
1313 ctr
.scrollTop
= ctr
.scrollHeight
;
1315 ctr
.scrollTop
= where
;
1319 function cdmArticleIsBelowViewport(id
) {
1321 var ctr
= document
.getElementById("headlinesInnerContainer");
1322 var e
= document
.getElementById("RROW-" + id
);
1324 if (!e
|| !ctr
) return;
1326 // article starts below viewport
1328 if (ctr
.scrollTop
< e
.offsetTop
) {
1335 exception_error("cdmArticleIsVisible", e
);
1339 function cdmArticleIsAboveViewport(id
) {
1341 var ctr
= document
.getElementById("headlinesInnerContainer");
1342 var e
= document
.getElementById("RROW-" + id
);
1344 if (!e
|| !ctr
) return;
1346 // article starts above viewport
1348 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1355 exception_error("cdmArticleIsVisible", e
);
1359 function cdmScrollToArticleId(id
) {
1361 var ctr
= document
.getElementById("headlinesInnerContainer");
1362 var e
= document
.getElementById("RROW-" + id
);
1364 if (!e
|| !ctr
) return;
1366 ctr
.scrollTop
= e
.offsetTop
;
1369 exception_error("cdmScrollToArticleId", e
);
1373 function cdmArticleIsActuallyVisible(id
) {
1375 var ctr
= document
.getElementById("headlinesInnerContainer");
1376 var e
= document
.getElementById("RROW-" + id
);
1378 if (!e
|| !ctr
) return;
1380 // article fits in viewport OR article is longer than viewport and
1381 // its bottom is visible
1383 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1384 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1388 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1389 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1390 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1399 exception_error("cdmArticleIsVisible", e
);
1403 function cdmWatchdog() {
1407 var ctr
= document
.getElementById("headlinesInnerContainer");
1411 var ids
= new Array();
1413 var e
= ctr
.firstChild
;
1416 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1417 e
.id
.match("RROW-")) {
1419 // article fits in viewport OR article is longer than viewport and
1420 // its bottom is visible
1422 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1423 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1425 // debug(e.id + " is visible " + e.offsetTop + "." +
1426 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1427 // (ctr.scrollTop + ctr.offsetHeight));
1429 ids
.push(e
.id
.replace("RROW-", ""));
1431 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1432 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1433 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1435 ids
.push(e
.id
.replace("RROW-", ""));
1439 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1441 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1442 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1444 ids.push(e.id.replace("RROW-", ""));
1453 debug("cdmWatchdog, ids= " + ids
.toString());
1455 if (ids
.length
> 0) {
1457 for (var i
= 0; i
< ids
.length
; i
++) {
1458 var e
= document
.getElementById("RROW-" + ids
[i
]);
1460 e
.className
= e
.className
.replace("Unread", "");
1464 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1465 param_escape(ids
.toString()) + "&cmode=0";
1467 new Ajax
.Request(query
, {
1468 onComplete: function(transport
) {
1469 all_counters_callback2(transport
);
1474 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1477 exception_error("cdmWatchdog", e
);
1483 function cache_inject(id
, article
, param
) {
1484 if (!cache_check_param(id
, param
)) {
1485 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1487 var cache_obj
= new Array();
1489 cache_obj
["id"] = id
;
1490 cache_obj
["data"] = article
;
1491 cache_obj
["param"] = param
;
1493 article_cache
.push(cache_obj
);
1496 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1500 function cache_find(id
) {
1501 for (var i
= 0; i
< article_cache
.length
; i
++) {
1502 if (article_cache
[i
]["id"] == id
) {
1503 return article_cache
[i
]["data"];
1509 function cache_find_param(id
, param
) {
1510 for (var i
= 0; i
< article_cache
.length
; i
++) {
1511 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1512 return article_cache
[i
]["data"];
1518 function cache_check(id
) {
1519 for (var i
= 0; i
< article_cache
.length
; i
++) {
1520 if (article_cache
[i
]["id"] == id
) {
1527 function cache_check_param(id
, param
) {
1528 for (var i
= 0; i
< article_cache
.length
; i
++) {
1530 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1531 // article_cache[i]["param"] + " vs " + id + ":" + param);
1533 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1540 function cache_expire() {
1541 while (article_cache
.length
> 25) {
1542 article_cache
.shift();
1546 function cache_empty() {
1547 article_cache
= new Array();
1550 function cache_invalidate(id
) {
1555 while (i
< article_cache
.length
) {
1556 if (article_cache
[i
]["id"] == id
) {
1557 debug("cache_invalidate: removed id " + id
);
1558 article_cache
.splice(i
, 1);
1563 debug("cache_invalidate: id not found: " + id
);
1566 exception_error("cache_invalidate", e
);
1570 function getActiveArticleId() {
1571 return active_post_id
;
1574 function cdmClicked(id
) {
1576 var elem
= document
.getElementById("RROW-" + id
);
1579 var id
= elem
.id
.replace("RROW-", "");
1580 active_post_id
= id
;
1582 cdmSelectArticles("none");
1583 toggleUnread(id
, 0, true);
1588 exception_error("cdmClicked", e
);
1592 function preload_article_callback(transport
) {
1594 if (transport
.responseXML
) {
1595 var articles
= transport
.responseXML
.getElementsByTagName("article");
1597 for (var i
= 0; i
< articles
.length
; i
++) {
1598 var id
= articles
[i
].getAttribute("id");
1599 if (!cache_check(id
)) {
1600 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1601 debug("preloaded article: " + id
);
1606 exception_error("preload_article_callback", e
);
1610 function preloadArticleUnderPointer(id
) {
1612 if (getInitParam("bw_limit") == "1") return;
1614 if (post_under_pointer
== id
&& !cache_check(id
)) {
1616 debug("trying to preload article " + id
);
1618 var neighbor_ids
= getRelativePostIds(id
, 1);
1620 /* only request uncached articles */
1622 var cids_to_request
= Array();
1624 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1625 if (!cache_check(neighbor_ids
[i
])) {
1626 cids_to_request
.push(neighbor_ids
[i
]);
1629 debug("additional ids: " + cids_to_request
.toString());
1631 cids_to_request
.push(id
);
1633 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1634 cids_to_request
.toString();
1635 new Ajax
.Request(query
, {
1636 onComplete: function(transport
) {
1637 preload_article_callback(transport
);
1641 exception_error("preloadArticleUnderPointer", e
);
1645 function postMouseIn(id
) {
1647 if (post_under_pointer
!= id
) {
1648 post_under_pointer
= id
;
1650 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1655 exception_error("postMouseIn", e
);
1659 function postMouseOut(id
) {
1661 post_under_pointer
= false;
1663 exception_error("postMouseOut", e
);
1667 function headlines_scroll_handler() {
1670 var e
= document
.getElementById("headlinesInnerContainer");
1672 // don't do infinite scrolling when Limit == All
1674 var toolbar_form
= document
.forms
["main_toolbar_form"];
1676 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1677 if (limit
.value
!= 0) {
1679 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1680 _infscroll_disable
);
1682 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1683 if (!_infscroll_disable
) {
1684 debug("more cowbell!");
1691 exception_error("headlines_scroll_handler", e
);
1695 function catchupRelativeToArticle(below
) {
1699 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1700 printLockingError();
1703 if (!getActiveArticleId()) {
1704 alert(__("No article is selected."));
1710 if (document
.getElementById("headlinesList")) {
1711 visible_ids
= getVisibleHeadlineIds();
1713 visible_ids
= cdmGetVisibleArticles();
1716 var ids_to_mark
= new Array();
1719 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1720 if (visible_ids
[i
] != getActiveArticleId()) {
1721 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1723 if (e
&& e
.className
.match("Unread")) {
1724 ids_to_mark
.push(visible_ids
[i
]);
1731 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1732 if (visible_ids
[i
] != getActiveArticleId()) {
1733 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1735 if (e
&& e
.className
.match("Unread")) {
1736 ids_to_mark
.push(visible_ids
[i
]);
1744 if (ids_to_mark
.length
== 0) {
1745 alert(__("No articles found to mark"));
1747 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1751 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1752 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1753 e
.className
= e
.className
.replace("Unread", "");
1756 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1757 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1759 new Ajax
.Request(query
, {
1760 onComplete: function(transport
) {
1761 catchup_callback2(transport
);
1768 exception_error("catchupRelativeToArticle", e
);
1772 function cdmExpandArticle(a_id
) {
1774 var id
= 'CICD-' + a_id
;
1777 Element
.hide("CEXC-" + a_id
);
1780 Effect
.Appear(id
, {duration
: 0.5,
1781 beforeStart: function(effect
) {
1782 var h_id
= 'CICH-' + a_id
;
1783 var h_elem
= document
.getElementById(h_id
);
1784 if (h_elem
) { h_elem
.style
.display
= "none"; }
1786 toggleUnread(a_id
, 0);
1791 exception_error("appearBlockElementF", e
);
1796 function fixHeadlinesOrder(ids
) {
1798 for (var i
= 0; i
< ids
.length
; i
++) {
1799 var e
= document
.getElementById("RROW-" + ids
[i
]);
1803 e
.className
= e
.className
.replace("even", "odd");
1805 e
.className
= e
.className
.replace("odd", "even");
1810 exception_error("fixHeadlinesOrder", e
);
1814 function hideReadHeadlines() {
1818 var vis_ids
= new Array();
1820 if (document
.getElementById("headlinesList")) {
1821 ids
= getVisibleHeadlineIds();
1823 ids
= cdmGetVisibleArticles();
1826 var read_headlines_visible
= true;
1828 for (var i
= 0; i
< ids
.length
; i
++) {
1829 var row
= document
.getElementById("RROW-" + ids
[i
]);
1831 if (row
&& row
.className
) {
1832 if (read_headlines_visible
) {
1833 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1835 vis_ids
.push(ids
[i
]);
1837 //Effect.Fade(row, {duration : 0.3});
1842 vis_ids
.push(ids
[i
]);
1847 fixHeadlinesOrder(vis_ids
);
1849 read_headlines_visible
= !read_headlines_visible
;
1852 exception_error("hideReadHeadlines", e
);
1856 function invertHeadlineSelection() {
1858 var rows
= new Array();
1862 r
= document
.getElementsByTagName("TR");
1864 r
= document
.getElementsByTagName("DIV");
1867 for (var i
= 0; i
< r
.length
; i
++) {
1868 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1873 for (var i
= 0; i
< rows
.length
; i
++) {
1874 var nc
= rows
[i
].className
;
1875 var id
= rows
[i
].id
.replace("RROW-", "");
1876 var cb
= document
.getElementById("RCHK-" + id
);
1878 if (!rows
[i
].className
.match("Selected")) {
1879 nc
= nc
+ "Selected";
1882 nc
= nc
.replace("Selected", "");
1886 rows
[i
].className
= nc
;
1891 exception_error("invertHeadlineSelection", e
);
1895 function getArticleUnderPointer() {
1896 return post_under_pointer
;
1899 function zoomToArticle(id
) {
1901 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1903 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1906 exception_error("zoomToArticle", e
);
1910 function showOriginalArticleInline(id
) {
1913 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1915 notify_progress("Loading, please wait...", true);
1917 new Ajax
.Request(query
, {
1918 onComplete: function(transport
) {
1920 if (transport
.responseXML
) {
1922 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1923 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1928 link
= link
.firstChild
.nodeValue
;
1930 var ci
= document
.getElementById("content-insert");
1932 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1934 render_article(tmp
);
1941 exception_error("showOriginalArticleInline", e
);
1946 function scrollArticle(offset
) {
1949 var ci
= document
.getElementById("content-insert");
1951 ci
.scrollTop
+= offset
;
1954 var hi
= document
.getElementById("headlinesInnerContainer");
1956 hi
.scrollTop
+= offset
;
1961 exception_error("scrollArticle", e
);
1965 function show_labels_in_headlines(transport
) {
1967 if (transport
.responseXML
) {
1968 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1970 var elems
= info
.getElementsByTagName("entry");
1972 for (var l
= 0; l
< elems
.length
; l
++) {
1973 var e_id
= elems
[l
].getAttribute("id");
1977 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
1980 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1988 exception_error("show_labels_in_headlines", e
);
1993 function toggleHeadlineActions() {
1995 var e
= document
.getElementById("headlineActionsBody");
1996 var p
= document
.getElementById("headlineActionsDrop");
1998 if (!Element
.visible(e
)) {
2005 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2006 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2009 exception_error("toggleHeadlineActions", e
);