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
]);
183 debug("no new headlines received");
186 debug("headlines_callback: returned no data");
187 notify_error("Error while trying to load more headlines");
193 for (var i
= 0; i
< articles
.length
; i
++) {
194 var a_id
= articles
[i
].getAttribute("id");
195 debug("found id: " + a_id
);
196 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
199 debug("no cached articles received");
203 debug("parsing piggybacked counters: " + counters
);
204 parse_counters(counters
, false);
206 debug("counters container not found in reply, requesting...");
211 debug("parsing runtime info: " + runtime_info
[0]);
212 parse_runtime_info(runtime_info
[0]);
214 debug("counters container not found in reply");
218 debug("headlines_callback: returned no XML object");
219 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
222 if (typeof correctPNG
!= 'undefined') {
226 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
228 if (!document
.getElementById("headlinesList") &&
229 getActiveFeedId() != -3 &&
230 getInitParam("cdm_auto_catchup") == 1) {
231 debug("starting CDM watchdog");
232 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
233 _cdm_wd_vishist
= new Array();
235 debug("not in CDM mode or watchdog disabled");
238 if (_tag_cdm_scroll
) {
240 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
241 _tag_cdm_scroll
= false;
242 debug("resetting headlinesInner scrollTop");
247 _feed_cur_page
= feed_cur_page
;
248 _infscroll_request_sent
= 0;
255 exception_error("headlines_callback2", e
);
259 function render_article(article
) {
261 var f
= document
.getElementById("content-frame");
266 var fi
= document
.getElementById("content-insert");
272 fi
.innerHTML
= article
;
275 exception_error("render_article", e
);
279 function showArticleInHeadlines(id
) {
283 cleanSelected("headlinesList");
285 var crow
= document
.getElementById("RROW-" + id
);
289 var article_is_unread
= crow
.className
.match("Unread");
291 crow
.className
= crow
.className
.replace("Unread", "");
293 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
295 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
297 var cache_prefix
= "";
299 if (activeFeedIsCat()) {
305 var view_mode
= false;
308 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
309 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
311 exception_error("showArticleInHeadlines/viewmode", e
, true);
314 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
315 upd_img_pic
.src
= "images/blank_icon.gif";
317 cache_invalidate(cache_prefix
+ getActiveFeedId());
319 cache_inject(cache_prefix
+ getActiveFeedId(),
320 document
.getElementById("headlines-frame").innerHTML
,
321 get_feed_unread(getActiveFeedId()));
323 } else if (article_is_unread
&& view_mode
== "all_articles") {
325 cache_invalidate(cache_prefix
+ getActiveFeedId());
327 cache_inject(cache_prefix
+ getActiveFeedId(),
328 document
.getElementById("headlines-frame").innerHTML
,
329 get_feed_unread(getActiveFeedId())-1);
331 } else if (article_is_unread
) {
332 cache_invalidate(cache_prefix
+ getActiveFeedId());
338 exception_error("showArticleInHeadlines", e
);
342 function article_callback2(transport
, id
, feed_id
) {
344 debug("article_callback2 " + id
);
346 if (transport
.responseXML
) {
348 debug("looking for articles to cache...");
350 var articles
= transport
.responseXML
.getElementsByTagName("article");
352 for (var i
= 0; i
< articles
.length
; i
++) {
353 var a_id
= articles
[i
].getAttribute("id");
355 debug("found id: " + a_id
);
357 if (a_id
== active_post_id
) {
358 debug("active article, rendering...");
359 render_article(articles
[i
].firstChild
.nodeValue
);
362 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
365 if (id
!= last_requested_article
) {
366 debug("requested article id is out of sequence, aborting");
370 active_real_feed_id
= feed_id
;
373 showArticleInHeadlines(id
);
375 var reply
= transport
.responseXML
.firstChild
.firstChild
;
378 debug("article_callback: returned no XML object");
379 //var f = document.getElementById("content-frame");
380 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
383 var date
= new Date();
384 last_article_view
= date
.getTime() / 1000;
386 if (typeof correctPNG
!= 'undefined') {
390 if (_reload_feedlist_after_view
) {
391 setTimeout('updateFeedList(false, false)', 50);
392 _reload_feedlist_after_view
= false;
394 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
397 debug("parsing piggybacked counters: " + counters
);
398 parse_counters(counters
, false);
400 debug("counters container not found in reply, requesting...");
407 exception_error("article_callback2", e
);
411 function view(id
, feed_id
, skip_history
) {
414 debug("loading article: " + id
+ "/" + feed_id
);
416 var cached_article
= cache_find(id
);
418 debug("cache check result: " + (cached_article
!= false));
422 //setActiveFeedId(feed_id);
424 var query
= "backend.php?op=view&id=" + param_escape(id
) +
425 "&feed=" + param_escape(feed_id
);
427 var date
= new Date();
429 var neighbor_ids
= getRelativePostIds(active_post_id
);
431 /* only request uncached articles */
433 var cids_to_request
= Array();
435 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
436 if (!cache_check(neighbor_ids
[i
])) {
437 cids_to_request
.push(neighbor_ids
[i
]);
441 debug("additional ids: " + cids_to_request
.toString());
443 /* additional info for piggyback counters */
445 if (tagsAreDisplayed()) {
446 query
= query
+ "&omode=lt";
448 query
= query
+ "&omode=flc";
451 var date
= new Date();
452 var timestamp
= Math
.round(date
.getTime() / 1000);
453 query
= query
+ "&ts=" + timestamp
;
455 query
= query
+ "&cids=" + cids_to_request
.toString();
457 var crow
= document
.getElementById("RROW-" + id
);
458 var article_is_unread
= crow
.className
.match("Unread");
460 if (!async_counters_work
) {
461 query
= query
+ "&csync=true";
464 showArticleInHeadlines(id
);
466 if (!cached_article
) {
468 notify_progress("Loading, please wait...", true);
470 } else if (cached_article
&& article_is_unread
) {
472 query
= query
+ "&mode=prefetch";
474 render_article(cached_article
);
476 } else if (cached_article
) {
478 query
= query
+ "&mode=prefetch_old";
479 render_article(cached_article
);
485 last_requested_article
= id
;
487 new Ajax
.Request(query
, {
488 onComplete: function(transport
) {
489 article_callback2(transport
, id
, feed_id
);
495 exception_error("view", e
);
500 return toggleMark(id
);
504 return togglePub(id
);
507 function tMark_afh_off(effect
) {
509 var elem
= effect
.effects
[0].element
;
511 debug("tMark_afh_off : " + elem
.id
);
514 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
515 elem
.alt
= __("Star article");
520 exception_error("tMark_afh_off", e
);
524 function tPub_afh_off(effect
) {
526 var elem
= effect
.effects
[0].element
;
528 debug("tPub_afh_off : " + elem
.id
);
531 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
532 elem
.alt
= __("Publish article");
537 exception_error("tPub_afh_off", e
);
541 function toggleMark(id
, client_only
, no_effects
) {
545 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
547 query
= query
+ "&afid=" + getActiveFeedId();
549 if (tagsAreDisplayed()) {
550 query
= query
+ "&omode=tl";
552 query
= query
+ "&omode=flc";
555 var mark_img
= document
.getElementById("FMPIC-" + id
);
556 var vfeedu
= document
.getElementById("FEEDU--1");
557 var crow
= document
.getElementById("RROW-" + id
);
559 if (mark_img
.src
.match("mark_unset")) {
560 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
561 mark_img
.alt
= __("Unstar article");
562 query
= query
+ "&mark=1";
565 //mark_img.src = "images/mark_unset.png";
566 mark_img
.alt
= __("Please wait...");
567 query
= query
+ "&mark=0";
569 if (document
.getElementById("headlinesList") && !no_effects
) {
570 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
572 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
573 mark_img
.alt
= __("Star article");
580 new Ajax
.Request(query
, {
581 onComplete: function(transport
) {
582 all_counters_callback2(transport
);
588 exception_error("toggleMark", e
);
592 function togglePub(id
, client_only
, no_effects
) {
596 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
598 query
= query
+ "&afid=" + getActiveFeedId();
600 if (tagsAreDisplayed()) {
601 query
= query
+ "&omode=tl";
603 query
= query
+ "&omode=flc";
606 var mark_img
= document
.getElementById("FPPIC-" + id
);
607 var vfeedu
= document
.getElementById("FEEDU--2");
608 var crow
= document
.getElementById("RROW-" + id
);
610 if (mark_img
.src
.match("pub_unset")) {
611 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
612 mark_img
.alt
= __("Unpublish article");
613 query
= query
+ "&pub=1";
617 //mark_img.src = "images/pub_unset.png";
618 mark_img
.alt
= __("Please wait...");
619 query
= query
+ "&pub=0";
621 if (document
.getElementById("headlinesList") && !no_effects
) {
622 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
624 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
625 mark_img
.alt
= __("Publish article");
630 new Ajax
.Request(query
, {
631 onComplete: function(transport
) {
632 all_counters_callback2(transport
);
638 exception_error("togglePub", e
);
642 function correctHeadlinesOffset(id
) {
646 var hlist
= document
.getElementById("headlinesList");
647 var container
= document
.getElementById("headlinesInnerContainer");
648 var row
= document
.getElementById("RROW-" + id
);
650 var viewport
= container
.offsetHeight
;
652 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
653 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
655 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
656 debug("Vport: " + viewport
);
658 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
659 container
.scrollTop
= row
.offsetTop
;
660 } else if (rel_offset_bottom
> viewport
) {
662 /* doesn't properly work with Opera in some cases because
663 Opera fucks up element scrolling */
665 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
669 exception_error("correctHeadlinesOffset", e
);
674 function moveToPost(mode
) {
681 rows
= cdmGetVisibleArticles();
683 rows
= getVisibleHeadlineIds();
689 if (!document
.getElementById('RROW-' + active_post_id
)) {
690 active_post_id
= false;
693 if (active_post_id
== false) {
694 next_id
= getFirstVisibleHeadlineId();
695 prev_id
= getLastVisibleHeadlineId();
697 for (var i
= 0; i
< rows
.length
; i
++) {
698 if (rows
[i
] == active_post_id
) {
705 if (mode
== "next") {
709 if (!cdmArticleIsActuallyVisible(next_id
)) {
710 cdmScrollToArticleId(next_id
);
712 cdmSelectArticles("none");
713 toggleUnread(next_id
, 0, true);
714 toggleSelected(next_id
);
717 correctHeadlinesOffset(next_id
);
718 view(next_id
, getActiveFeedId());
723 if (mode
== "prev") {
726 cdmScrollToArticleId(prev_id
);
727 cdmSelectArticles("none");
728 toggleUnread(prev_id
, 0, true);
729 toggleSelected(prev_id
);
731 correctHeadlinesOffset(prev_id
);
732 view(prev_id
, getActiveFeedId());
738 exception_error("moveToPost", e
);
742 function toggleSelected(id
) {
745 var cb
= document
.getElementById("RCHK-" + id
);
747 var row
= document
.getElementById("RROW-" + id
);
749 var nc
= row
.className
;
751 if (!nc
.match("Selected")) {
752 nc
= nc
+ "Selected";
757 // In CDM basically last selected article == active article
758 if (isCdmMode()) active_post_id
= id
;
760 nc
= nc
.replace("Selected", "");
770 exception_error("toggleSelected", e
);
774 function toggleUnread_afh(effect
) {
777 var elem
= effect
.element
;
778 elem
.style
.backgroundColor
= "";
781 exception_error("toggleUnread_afh", e
);
785 function toggleUnread(id
, cmode
, effect
) {
788 var row
= document
.getElementById("RROW-" + id
);
790 var nc
= row
.className
;
791 var is_selected
= row
.className
.match("Selected");
792 nc
= nc
.replace("Unread", "");
793 nc
= nc
.replace("Selected", "");
795 // since we are removing selection from the object, uncheck
796 // corresponding checkbox
798 var cb
= document
.getElementById("RCHK-" + id
);
803 // NOTE: I'm not sure that resetting selection here is a feature -fox
805 if (cmode
== undefined || cmode
== 2) {
806 if (row
.className
.match("Unread")) {
810 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
811 afterFinish
: toggleUnread_afh
,
812 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
816 row
.className
= nc
+ "Unread";
818 } else if (cmode
== 0) {
822 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
823 afterFinish
: toggleUnread_afh
,
824 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
826 } else if (cmode
== 1) {
827 row
.className
= nc
+ "Unread";
830 // Disable unmarking as selected for the time being (16.05.08) -fox
831 if (is_selected
) row
.className
= row
.className
+ "Selected";
833 if (cmode
== undefined) cmode
= 2;
835 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
836 param_escape(id
) + "&cmode=" + param_escape(cmode
);
838 // notify_progress("Loading, please wait...");
840 new Ajax
.Request(query
, {
841 onComplete: function(transport
) {
842 all_counters_callback2(transport
);
849 exception_error("toggleUnread", e
);
853 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
858 rows
= cdmGetSelectedArticles();
860 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
863 if (rows
.length
== 0 && !no_error
) {
864 alert(__("No articles are selected."));
868 for (i
= 0; i
< rows
.length
; i
++) {
869 var row
= document
.getElementById("RROW-" + rows
[i
]);
871 var nc
= row
.className
;
872 nc
= nc
.replace("Unread", "");
873 nc
= nc
.replace("Selected", "");
875 if (set_state
== undefined) {
876 if (row
.className
.match("Unread")) {
877 row
.className
= nc
+ "Selected";
879 row
.className
= nc
+ "UnreadSelected";
883 if (set_state
== false) {
884 row
.className
= nc
+ "Selected";
887 if (set_state
== true) {
888 row
.className
= nc
+ "UnreadSelected";
893 if (rows
.length
> 0) {
897 if (set_state
== undefined) {
899 } else if (set_state
== true) {
901 } else if (set_state
== false) {
905 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
906 param_escape(rows
.toString()) + "&cmode=" + cmode
;
908 notify_progress("Loading, please wait...");
910 new Ajax
.Request(query
, {
911 onComplete: function(transport
) {
912 catchup_callback2(transport
, callback_func
);
918 exception_error("selectionToggleUnread", e
);
922 function selectionToggleMarked(cdm_mode
) {
928 rows
= cdmGetSelectedArticles();
930 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
933 if (rows
.length
== 0) {
934 alert(__("No articles are selected."));
938 for (i
= 0; i
< rows
.length
; i
++) {
939 toggleMark(rows
[i
], true, true);
942 if (rows
.length
> 0) {
944 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
945 param_escape(rows
.toString()) + "&cmode=2";
947 query
= query
+ "&afid=" + getActiveFeedId();
949 /* if (tagsAreDisplayed()) {
950 query = query + "&omode=tl";
952 query = query + "&omode=flc";
955 query
= query
+ "&omode=lc";
957 new Ajax
.Request(query
, {
958 onComplete: function(transport
) {
959 all_counters_callback2(transport
);
965 exception_error("selectionToggleMarked", e
);
969 function selectionTogglePublished(cdm_mode
) {
975 rows
= cdmGetSelectedArticles();
977 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
980 if (rows
.length
== 0) {
981 alert(__("No articles are selected."));
985 for (i
= 0; i
< rows
.length
; i
++) {
986 togglePub(rows
[i
], true, true);
989 if (rows
.length
> 0) {
991 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
992 param_escape(rows
.toString()) + "&cmode=2";
994 query
= query
+ "&afid=" + getActiveFeedId();
996 /* if (tagsAreDisplayed()) {
997 query = query + "&omode=tl";
999 query = query + "&omode=flc";
1002 query
= query
+ "&omode=lc";
1004 new Ajax
.Request(query
, {
1005 onComplete: function(transport
) {
1006 all_counters_callback2(transport
);
1012 exception_error("selectionToggleMarked", e
);
1016 function cdmGetSelectedArticles() {
1017 var sel_articles
= new Array();
1018 var container
= document
.getElementById("headlinesInnerContainer");
1020 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1021 var child
= container
.childNodes
[i
];
1023 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1024 var c_id
= child
.id
.replace("RROW-", "");
1025 sel_articles
.push(c_id
);
1029 return sel_articles
;
1032 function cdmGetVisibleArticles() {
1033 var sel_articles
= new Array();
1034 var container
= document
.getElementById("headlinesInnerContainer");
1036 if (!container
) return sel_articles
;
1038 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1039 var child
= container
.childNodes
[i
];
1041 if (child
.id
&& child
.id
.match("RROW-")) {
1042 var c_id
= child
.id
.replace("RROW-", "");
1043 sel_articles
.push(c_id
);
1047 return sel_articles
;
1050 function cdmGetUnreadArticles() {
1051 var sel_articles
= new Array();
1052 var container
= document
.getElementById("headlinesInnerContainer");
1054 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1055 var child
= container
.childNodes
[i
];
1057 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1058 var c_id
= child
.id
.replace("RROW-", "");
1059 sel_articles
.push(c_id
);
1063 return sel_articles
;
1067 // mode = all,none,unread
1068 function cdmSelectArticles(mode
) {
1069 var container
= document
.getElementById("headlinesInnerContainer");
1071 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1072 var child
= container
.childNodes
[i
];
1074 if (child
.id
&& child
.id
.match("RROW-")) {
1075 var aid
= child
.id
.replace("RROW-", "");
1077 var cb
= document
.getElementById("RCHK-" + aid
);
1079 if (mode
== "all") {
1080 if (!child
.className
.match("Selected")) {
1081 child
.className
= child
.className
+ "Selected";
1084 } else if (mode
== "unread") {
1085 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1086 child
.className
= child
.className
+ "Selected";
1090 child
.className
= child
.className
.replace("Selected", "");
1097 function catchupPage() {
1099 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1101 var str
= __("Mark all visible articles in %s as read?");
1103 str
= str
.replace("%s", fn
);
1105 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1109 if (document
.getElementById("headlinesList")) {
1110 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1111 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1112 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1114 cdmSelectArticles('all');
1115 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1116 cdmSelectArticles('none');
1120 function catchupSelection() {
1126 if (document
.getElementById("headlinesList")) {
1127 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1129 rows
= cdmGetSelectedArticles();
1132 if (rows
.length
== 0) {
1133 alert(__("No articles are selected."));
1138 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1140 var str
= __("Mark %d selected articles in %s as read?");
1142 str
= str
.replace("%d", rows
.length
);
1143 str
= str
.replace("%s", fn
);
1145 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1149 if (document
.getElementById("headlinesList")) {
1150 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1151 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1153 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1154 // cdmSelectArticles('none');
1158 exception_error("catchupSelection", e
);
1163 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1165 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1166 printLockingError();
1169 var title
= prompt(__("Please enter label title:"), "");
1173 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1174 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1175 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1176 "&title=" + param_escape(title
);
1178 debug("LFS: " + query
);
1180 new Ajax
.Request(query
, {
1181 onComplete: function(transport
) {
1182 dlg_frefresh_callback(transport
);
1187 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1188 _tag_active_post_id
= id
;
1189 _tag_active_feed_id
= feed_id
;
1190 _tag_active_cdm
= cdm_enabled
;
1192 cache_invalidate(id
);
1195 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1197 displayDlg('editArticleTags', id
);
1201 function tag_saved_callback(transport
) {
1203 debug("in tag_saved_callback");
1208 if (tagsAreDisplayed()) {
1209 _reload_feedlist_after_view
= true;
1212 if (!_tag_active_cdm
) {
1213 if (active_post_id
== _tag_active_post_id
) {
1214 debug("reloading current article");
1215 view(_tag_active_post_id
, _tag_active_feed_id
);
1218 debug("reloading current feed");
1223 exception_error("catchup_callback", e
);
1227 function editTagsSave() {
1229 notify_progress("Saving article tags...");
1231 var form
= document
.forms
["tag_edit_form"];
1233 var query
= Form
.serialize("tag_edit_form");
1235 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1239 new Ajax
.Request(query
, {
1240 onComplete: function(transport
) {
1241 tag_saved_callback(transport
);
1246 function editTagsInsert() {
1249 var form
= document
.forms
["tag_edit_form"];
1251 var found_tags
= form
.found_tags
;
1252 var tags_str
= form
.tags_str
;
1254 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1256 if (tags_str
.value
.length
> 0 &&
1257 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1259 tags_str
.value
= tags_str
.value
+ ", ";
1262 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1264 found_tags
.selectedIndex
= 0;
1267 exception_error("editTagsInsert", e
);
1271 function cdmScrollViewport(where
) {
1272 debug("cdmScrollViewport: " + where
);
1274 var ctr
= document
.getElementById("headlinesInnerContainer");
1278 if (where
== "bottom") {
1279 ctr
.scrollTop
= ctr
.scrollHeight
;
1281 ctr
.scrollTop
= where
;
1285 function cdmArticleIsBelowViewport(id
) {
1287 var ctr
= document
.getElementById("headlinesInnerContainer");
1288 var e
= document
.getElementById("RROW-" + id
);
1290 if (!e
|| !ctr
) return;
1292 // article starts below viewport
1294 if (ctr
.scrollTop
< e
.offsetTop
) {
1301 exception_error("cdmArticleIsVisible", e
);
1305 function cdmArticleIsAboveViewport(id
) {
1307 var ctr
= document
.getElementById("headlinesInnerContainer");
1308 var e
= document
.getElementById("RROW-" + id
);
1310 if (!e
|| !ctr
) return;
1312 // article starts above viewport
1314 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1321 exception_error("cdmArticleIsVisible", e
);
1325 function cdmScrollToArticleId(id
) {
1327 var ctr
= document
.getElementById("headlinesInnerContainer");
1328 var e
= document
.getElementById("RROW-" + id
);
1330 if (!e
|| !ctr
) return;
1332 ctr
.scrollTop
= e
.offsetTop
;
1335 exception_error("cdmScrollToArticleId", e
);
1339 function cdmArticleIsActuallyVisible(id
) {
1341 var ctr
= document
.getElementById("headlinesInnerContainer");
1342 var e
= document
.getElementById("RROW-" + id
);
1344 if (!e
|| !ctr
) return;
1346 // article fits in viewport OR article is longer than viewport and
1347 // its bottom is visible
1349 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1350 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1354 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1355 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1356 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1365 exception_error("cdmArticleIsVisible", e
);
1369 function cdmWatchdog() {
1373 var ctr
= document
.getElementById("headlinesInnerContainer");
1377 var ids
= new Array();
1379 var e
= ctr
.firstChild
;
1382 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1383 e
.id
.match("RROW-")) {
1385 // article fits in viewport OR article is longer than viewport and
1386 // its bottom is visible
1388 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1389 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1391 // debug(e.id + " is visible " + e.offsetTop + "." +
1392 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1393 // (ctr.scrollTop + ctr.offsetHeight));
1395 ids
.push(e
.id
.replace("RROW-", ""));
1397 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1398 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1399 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1401 ids
.push(e
.id
.replace("RROW-", ""));
1405 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1407 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1408 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1410 ids.push(e.id.replace("RROW-", ""));
1419 debug("cdmWatchdog, ids= " + ids
.toString());
1421 if (ids
.length
> 0) {
1423 for (var i
= 0; i
< ids
.length
; i
++) {
1424 var e
= document
.getElementById("RROW-" + ids
[i
]);
1426 e
.className
= e
.className
.replace("Unread", "");
1430 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1431 param_escape(ids
.toString()) + "&cmode=0";
1433 new Ajax
.Request(query
, {
1434 onComplete: function(transport
) {
1435 all_counters_callback2(transport
);
1440 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1443 exception_error("cdmWatchdog", e
);
1449 function cache_inject(id
, article
, param
) {
1450 if (!cache_check_param(id
, param
)) {
1451 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1453 var cache_obj
= new Array();
1455 cache_obj
["id"] = id
;
1456 cache_obj
["data"] = article
;
1457 cache_obj
["param"] = param
;
1459 article_cache
.push(cache_obj
);
1462 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1466 function cache_find(id
) {
1467 for (var i
= 0; i
< article_cache
.length
; i
++) {
1468 if (article_cache
[i
]["id"] == id
) {
1469 return article_cache
[i
]["data"];
1475 function cache_find_param(id
, param
) {
1476 for (var i
= 0; i
< article_cache
.length
; i
++) {
1477 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1478 return article_cache
[i
]["data"];
1484 function cache_check(id
) {
1485 for (var i
= 0; i
< article_cache
.length
; i
++) {
1486 if (article_cache
[i
]["id"] == id
) {
1493 function cache_check_param(id
, param
) {
1494 for (var i
= 0; i
< article_cache
.length
; i
++) {
1496 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1497 // article_cache[i]["param"] + " vs " + id + ":" + param);
1499 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1506 function cache_expire() {
1507 while (article_cache
.length
> 25) {
1508 article_cache
.shift();
1512 function cache_empty() {
1513 article_cache
= new Array();
1516 function cache_invalidate(id
) {
1521 while (i
< article_cache
.length
) {
1522 if (article_cache
[i
]["id"] == id
) {
1523 debug("cache_invalidate: removed id " + id
);
1524 article_cache
.splice(i
, 1);
1529 debug("cache_invalidate: id not found: " + id
);
1532 exception_error("cache_invalidate", e
);
1536 function getActiveArticleId() {
1537 return active_post_id
;
1540 function cdmClicked(id
) {
1542 var elem
= document
.getElementById("RROW-" + id
);
1545 var id
= elem
.id
.replace("RROW-", "");
1546 active_post_id
= id
;
1548 cdmSelectArticles("none");
1549 toggleUnread(id
, 0, true);
1554 exception_error("cdmClicked", e
);
1558 function preload_article_callback(transport
) {
1560 if (transport
.responseXML
) {
1561 var articles
= transport
.responseXML
.getElementsByTagName("article");
1563 for (var i
= 0; i
< articles
.length
; i
++) {
1564 var id
= articles
[i
].getAttribute("id");
1565 if (!cache_check(id
)) {
1566 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1567 debug("preloaded article: " + id
);
1572 exception_error("preload_article_callback", e
);
1576 function preloadArticleUnderPointer(id
) {
1578 if (getInitParam("bw_limit") == "1") return;
1580 if (post_under_pointer
== id
&& !cache_check(id
)) {
1582 debug("trying to preload article " + id
);
1584 var neighbor_ids
= getRelativePostIds(id
, 1);
1586 /* only request uncached articles */
1588 var cids_to_request
= Array();
1590 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1591 if (!cache_check(neighbor_ids
[i
])) {
1592 cids_to_request
.push(neighbor_ids
[i
]);
1595 debug("additional ids: " + cids_to_request
.toString());
1597 cids_to_request
.push(id
);
1599 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1600 cids_to_request
.toString();
1601 new Ajax
.Request(query
, {
1602 onComplete: function(transport
) {
1603 preload_article_callback(transport
);
1607 exception_error("preloadArticleUnderPointer", e
);
1611 function postMouseIn(id
) {
1613 if (post_under_pointer
!= id
) {
1614 post_under_pointer
= id
;
1616 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1621 exception_error("postMouseIn", e
);
1625 function postMouseOut(id
) {
1627 post_under_pointer
= false;
1629 exception_error("postMouseOut", e
);
1633 function headlines_scroll_handler() {
1636 var e
= document
.getElementById("headlinesInnerContainer");
1638 // don't do infinite scrolling when Limit == All
1640 var toolbar_form
= document
.forms
["main_toolbar_form"];
1642 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1643 if (limit
.value
!= 0) {
1645 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1646 _infscroll_disable
);
1648 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1649 if (!_infscroll_disable
) {
1650 debug("more cowbell!");
1657 exception_error("headlines_scroll_handler", e
);
1661 function catchupRelativeToArticle(below
) {
1665 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1666 printLockingError();
1669 if (!getActiveArticleId()) {
1670 alert(__("No article is selected."));
1676 if (document
.getElementById("headlinesList")) {
1677 visible_ids
= getVisibleHeadlineIds();
1679 visible_ids
= cdmGetVisibleArticles();
1682 var ids_to_mark
= new Array();
1685 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1686 if (visible_ids
[i
] != getActiveArticleId()) {
1687 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1689 if (e
&& e
.className
.match("Unread")) {
1690 ids_to_mark
.push(visible_ids
[i
]);
1697 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1698 if (visible_ids
[i
] != getActiveArticleId()) {
1699 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1701 if (e
&& e
.className
.match("Unread")) {
1702 ids_to_mark
.push(visible_ids
[i
]);
1710 if (ids_to_mark
.length
== 0) {
1711 alert(__("No articles found to mark"));
1713 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1717 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1718 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1719 e
.className
= e
.className
.replace("Unread", "");
1722 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1723 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1725 new Ajax
.Request(query
, {
1726 onComplete: function(transport
) {
1727 catchup_callback2(transport
);
1734 exception_error("catchupRelativeToArticle", e
);
1738 function cdmExpandArticle(a_id
) {
1740 var id
= 'CICD-' + a_id
;
1743 Element
.hide("CEXC-" + a_id
);
1746 Effect
.Appear(id
, {duration
: 0.5,
1747 beforeStart: function(effect
) {
1748 var h_id
= 'CICH-' + a_id
;
1749 var h_elem
= document
.getElementById(h_id
);
1750 if (h_elem
) { h_elem
.style
.display
= "none"; }
1752 toggleUnread(a_id
, 0);
1757 exception_error("appearBlockElementF", e
);
1762 function fixHeadlinesOrder(ids
) {
1764 for (var i
= 0; i
< ids
.length
; i
++) {
1765 var e
= document
.getElementById("RROW-" + ids
[i
]);
1769 e
.className
= e
.className
.replace("even", "odd");
1771 e
.className
= e
.className
.replace("odd", "even");
1776 exception_error("fixHeadlinesOrder", e
);
1780 function subtoolbarSearch() {
1783 var q
= document
.getElementById("subtoolbar_search_box");
1787 q
= q
.value
.toUpperCase();
1790 var vis_ids
= new Array();
1792 if (document
.getElementById("headlinesList")) {
1793 ids
= getVisibleHeadlineIds();
1795 ids
= cdmGetVisibleArticles();
1798 for (var i
= 0; i
< ids
.length
; i
++) {
1799 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1802 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1803 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1805 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1806 vis_ids
.push(ids
[i
]);
1811 fixHeadlinesOrder(vis_ids
);
1814 exception_error("subtoolbarSearch", e
);
1818 function hideReadHeadlines() {
1822 var vis_ids
= new Array();
1824 if (document
.getElementById("headlinesList")) {
1825 ids
= getVisibleHeadlineIds();
1827 ids
= cdmGetVisibleArticles();
1830 var read_headlines_visible
= true;
1832 for (var i
= 0; i
< ids
.length
; i
++) {
1833 var row
= document
.getElementById("RROW-" + ids
[i
]);
1835 if (row
&& row
.className
) {
1836 if (read_headlines_visible
) {
1837 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1839 vis_ids
.push(ids
[i
]);
1841 //Effect.Fade(row, {duration : 0.3});
1846 vis_ids
.push(ids
[i
]);
1851 fixHeadlinesOrder(vis_ids
);
1853 read_headlines_visible
= !read_headlines_visible
;
1856 exception_error("hideReadHeadlines", e
);
1860 function invertHeadlineSelection() {
1862 var rows
= new Array();
1866 r
= document
.getElementsByTagName("TR");
1868 r
= document
.getElementsByTagName("DIV");
1871 for (var i
= 0; i
< r
.length
; i
++) {
1872 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1877 for (var i
= 0; i
< rows
.length
; i
++) {
1878 var nc
= rows
[i
].className
;
1879 var id
= rows
[i
].id
.replace("RROW-", "");
1880 var cb
= document
.getElementById("RCHK-" + id
);
1882 if (!rows
[i
].className
.match("Selected")) {
1883 nc
= nc
+ "Selected";
1886 nc
= nc
.replace("Selected", "");
1890 rows
[i
].className
= nc
;
1895 exception_error("invertHeadlineSelection", e
);
1899 function getArticleUnderPointer() {
1900 return post_under_pointer
;
1903 function zoomToArticle(id
) {
1905 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1907 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1910 exception_error("zoomToArticle", e
);
1914 function showOriginalArticleInline(id
) {
1917 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1919 notify_progress("Loading, please wait...", true);
1921 new Ajax
.Request(query
, {
1922 onComplete: function(transport
) {
1924 if (transport
.responseXML
) {
1926 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1927 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1932 link
= link
.firstChild
.nodeValue
;
1934 var ci
= document
.getElementById("content-insert");
1936 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
1938 render_article(tmp
);
1945 exception_error("showOriginalArticleInline", e
);
1950 function scrollArticle(offset
) {
1953 var ci
= document
.getElementById("content-insert");
1955 ci
.scrollTop
+= offset
;
1958 var hi
= document
.getElementById("headlinesInnerContainer");
1960 hi
.scrollTop
+= offset
;
1965 exception_error("scrollArticle", e
);