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 function catchup_callback() {
24 if (xmlhttp_rpc
.readyState
== 4) {
26 debug("catchup_callback");
28 all_counters_callback2(xmlhttp_rpc
);
29 if (_catchup_callback_func
) {
30 setTimeout(_catchup_callback_func
, 10);
33 exception_error("catchup_callback", e
);
38 function catchup_callback2(transport
, callback
) {
40 debug("catchup_callback2 " + transport
+ ", " + callback
);
42 all_counters_callback2(transport
);
44 setTimeout(callback
, 10);
47 exception_error("catchup_callback2", e
);
51 function clean_feed_selections() {
53 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
55 for (var i
= 0; i
< feeds
.length
; i
++) {
56 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
57 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 exception_error("clean_feed_selections", e
);
65 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
68 loading_set_progress(100);
70 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
72 clean_feed_selections();
74 setActiveFeedId(active_feed_id
);
76 if (is_cat
!= undefined) {
77 active_feed_is_cat
= is_cat
;
81 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
82 if (feedr
&& !feedr
.className
.match("Selected")) {
83 feedr
.className
= feedr
.className
+ "Selected";
87 var f
= document
.getElementById("headlines-frame");
89 if (feed_cur_page
== 0) {
90 debug("resetting headlines scrollTop");
95 if (transport
.responseXML
) {
96 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
97 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
98 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
99 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
101 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
103 var headlines_count
= headlines_count_obj
.getAttribute("value");
104 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
105 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
107 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
109 if (headlines_count
== 0) {
110 _infscroll_disable
= 1;
112 _infscroll_disable
= 0;
115 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
116 var articles
= transport
.responseXML
.getElementsByTagName("article");
117 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
119 if (feed_cur_page
== 0) {
121 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
123 var cache_prefix
= "";
131 cache_invalidate(cache_prefix
+ active_feed_id
);
133 if (!disable_cache
) {
134 cache_inject(cache_prefix
+ active_feed_id
,
135 headlines
.firstChild
.nodeValue
, headlines_unread
);
139 debug("headlines_callback: returned no data");
140 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
145 if (headlines_count
> 0) {
146 debug("adding some more headlines...");
148 var c
= document
.getElementById("headlinesList");
151 c
= document
.getElementById("headlinesInnerContainer");
154 var ids
= getSelectedArticleIds2();
156 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
158 debug("restore selected ids: " + ids
);
160 for (var i
= 0; i
< ids
.length
; i
++) {
161 markHeadline(ids
[i
]);
167 debug("no new headlines received");
170 debug("headlines_callback: returned no data");
171 notify_error("Error while trying to load more headlines");
177 for (var i
= 0; i
< articles
.length
; i
++) {
178 var a_id
= articles
[i
].getAttribute("id");
179 debug("found id: " + a_id
);
180 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
183 debug("no cached articles received");
187 debug("parsing piggybacked counters: " + counters
);
188 parse_counters(counters
, false);
190 debug("counters container not found in reply, requesting...");
195 debug("parsing runtime info: " + runtime_info
[0]);
196 parse_runtime_info(runtime_info
[0]);
198 debug("counters container not found in reply");
202 debug("headlines_callback: returned no XML object");
203 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
206 if (typeof correctPNG
!= 'undefined') {
210 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
212 if (!document
.getElementById("headlinesList") &&
213 getInitParam("cdm_auto_catchup") == 1) {
214 debug("starting CDM watchdog");
215 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
216 _cdm_wd_vishist
= new Array();
218 debug("not in CDM mode or watchdog disabled");
221 if (_tag_cdm_scroll
) {
223 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
224 _tag_cdm_scroll
= false;
225 debug("resetting headlinesInner scrollTop");
230 _feed_cur_page
= feed_cur_page
;
231 _infscroll_request_sent
= 0;
238 exception_error("headlines_callback2", e
);
242 function render_article(article
) {
244 var f
= document
.getElementById("content-frame");
249 f
.innerHTML
= article
;
252 exception_error("render_article", e
);
256 function showArticleInHeadlines(id
) {
260 cleanSelected("headlinesList");
262 var crow
= document
.getElementById("RROW-" + id
);
266 var article_is_unread
= crow
.className
.match("Unread");
268 crow
.className
= crow
.className
.replace("Unread", "");
270 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
272 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
274 var cache_prefix
= "";
276 if (activeFeedIsCat()) {
282 var view_mode
= false;
285 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
286 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
288 exception_error("showArticleInHeadlines/viewmode", e
, true);
291 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
292 upd_img_pic
.src
= "images/blank_icon.gif";
294 cache_invalidate(cache_prefix
+ getActiveFeedId());
296 cache_inject(cache_prefix
+ getActiveFeedId(),
297 document
.getElementById("headlines-frame").innerHTML
,
298 get_feed_unread(getActiveFeedId()));
300 } else if (article_is_unread
&& view_mode
== "all_articles") {
302 cache_invalidate(cache_prefix
+ getActiveFeedId());
304 cache_inject(cache_prefix
+ getActiveFeedId(),
305 document
.getElementById("headlines-frame").innerHTML
,
306 get_feed_unread(getActiveFeedId())-1);
308 } else if (article_is_unread
) {
309 cache_invalidate(cache_prefix
+ getActiveFeedId());
315 exception_error("showArticleInHeadlines", e
);
319 function article_callback2(transport
, id
, feed_id
) {
321 debug("article_callback2 " + id
);
323 if (transport
.responseXML
) {
325 active_real_feed_id
= feed_id
;
328 //showArticleInHeadlines(id);
330 var reply
= transport
.responseXML
.firstChild
.firstChild
;
332 var articles
= transport
.responseXML
.getElementsByTagName("article");
334 for (var i
= 0; i
< articles
.length
; i
++) {
335 var a_id
= articles
[i
].getAttribute("id");
337 debug("found id: " + a_id
);
339 if (a_id
== active_post_id
) {
340 debug("active article, rendering...");
341 render_article(articles
[i
].firstChild
.nodeValue
);
344 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
348 debug("article_callback: returned no XML object");
349 var f
= document
.getElementById("content-frame");
350 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
353 var date
= new Date();
354 last_article_view
= date
.getTime() / 1000;
356 if (typeof correctPNG
!= 'undefined') {
360 if (_reload_feedlist_after_view
) {
361 setTimeout('updateFeedList(false, false)', 50);
362 _reload_feedlist_after_view
= false;
364 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
367 debug("parsing piggybacked counters: " + counters
);
368 parse_counters(counters
, false);
370 debug("counters container not found in reply");
376 exception_error("article_callback2", e
);
380 function view(id
, feed_id
, skip_history
) {
383 debug("loading article: " + id
+ "/" + feed_id
);
385 var cached_article
= cache_find(id
);
387 debug("cache check result: " + (cached_article
!= false));
391 //setActiveFeedId(feed_id);
393 var query
= "backend.php?op=view&id=" + param_escape(id
) +
394 "&feed=" + param_escape(feed_id
);
396 var date
= new Date();
398 var neighbor_ids
= getRelativePostIds(active_post_id
);
400 /* only request uncached articles */
402 var cids_to_request
= Array();
404 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
405 if (!cache_check(neighbor_ids
[i
])) {
406 cids_to_request
.push(neighbor_ids
[i
]);
410 debug("additional ids: " + cids_to_request
.toString());
412 /* additional info for piggyback counters */
414 if (tagsAreDisplayed()) {
415 query
= query
+ "&omode=lt";
417 query
= query
+ "&omode=flc";
420 var date
= new Date();
421 var timestamp
= Math
.round(date
.getTime() / 1000);
422 query
= query
+ "&ts=" + timestamp
;
424 query
= query
+ "&cids=" + cids_to_request
.toString();
426 var crow
= document
.getElementById("RROW-" + id
);
427 var article_is_unread
= crow
.className
.match("Unread");
429 showArticleInHeadlines(id
);
431 if (!cached_article
) {
433 notify_progress("Loading, please wait...");
435 } else if (cached_article
&& article_is_unread
) {
437 query
= query
+ "&mode=prefetch";
439 render_article(cached_article
);
441 } else if (cached_article
) {
443 query
= query
+ "&mode=prefetch_old";
444 render_article(cached_article
);
449 new Ajax
.Request(query
, {
450 onComplete: function(transport
) {
451 article_callback2(transport
, id
, feed_id
);
455 exception_error("view", e
);
460 return toggleMark(id
);
464 return togglePub(id
);
467 function tMark_afh_off(effect
) {
469 var elem
= effect
.effects
[0].element
;
471 debug("tMark_afh_off : " + elem
.id
);
474 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
475 elem
.alt
= __("Star article");
480 exception_error("tMark_afh_off", e
);
484 function tPub_afh_off(effect
) {
486 var elem
= effect
.effects
[0].element
;
488 debug("tPub_afh_off : " + elem
.id
);
491 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
492 elem
.alt
= __("Publish article");
497 exception_error("tPub_afh_off", e
);
501 function toggleMark(id
, client_only
, no_effects
) {
505 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
507 query
= query
+ "&afid=" + getActiveFeedId();
509 if (tagsAreDisplayed()) {
510 query
= query
+ "&omode=tl";
512 query
= query
+ "&omode=flc";
515 var mark_img
= document
.getElementById("FMPIC-" + id
);
516 var vfeedu
= document
.getElementById("FEEDU--1");
517 var crow
= document
.getElementById("RROW-" + id
);
519 if (mark_img
.src
.match("mark_unset")) {
520 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
521 mark_img
.alt
= __("Unstar article");
522 query
= query
+ "&mark=1";
525 //mark_img.src = "images/mark_unset.png";
526 mark_img
.alt
= __("Please wait...");
527 query
= query
+ "&mark=0";
529 if (document
.getElementById("headlinesList") && !no_effects
) {
530 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
532 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
533 mark_img
.alt
= __("Star article");
540 new Ajax
.Request(query
, {
541 onComplete: function(transport
) {
542 all_counters_callback2(transport
);
548 exception_error("toggleMark", e
);
552 function togglePub(id
, client_only
, no_effects
) {
556 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
558 query
= query
+ "&afid=" + getActiveFeedId();
560 if (tagsAreDisplayed()) {
561 query
= query
+ "&omode=tl";
563 query
= query
+ "&omode=flc";
566 var mark_img
= document
.getElementById("FPPIC-" + id
);
567 var vfeedu
= document
.getElementById("FEEDU--2");
568 var crow
= document
.getElementById("RROW-" + id
);
570 if (mark_img
.src
.match("pub_unset")) {
571 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
572 mark_img
.alt
= __("Unpublish article");
573 query
= query
+ "&pub=1";
577 //mark_img.src = "images/pub_unset.png";
578 mark_img
.alt
= __("Please wait...");
579 query
= query
+ "&pub=0";
581 if (document
.getElementById("headlinesList") && !no_effects
) {
582 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
584 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
585 mark_img
.alt
= __("Publish article");
590 new Ajax
.Request(query
, {
591 onComplete: function(transport
) {
592 all_counters_callback2(transport
);
598 exception_error("togglePub", e
);
602 function correctHeadlinesOffset(id
) {
606 var hlist
= document
.getElementById("headlinesList");
607 var container
= document
.getElementById("headlinesInnerContainer");
608 var row
= document
.getElementById("RROW-" + id
);
610 var viewport
= container
.offsetHeight
;
612 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
613 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
615 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
616 debug("Vport: " + viewport
);
618 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
619 container
.scrollTop
= row
.offsetTop
;
620 } else if (rel_offset_bottom
> viewport
) {
622 /* doesn't properly work with Opera in some cases because
623 Opera fucks up element scrolling */
625 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
629 exception_error("correctHeadlinesOffset", e
);
634 function moveToPost(mode
) {
641 rows
= cdmGetVisibleArticles();
643 rows
= getVisibleHeadlineIds();
649 if (!document
.getElementById('RROW-' + active_post_id
)) {
650 active_post_id
= false;
653 if (active_post_id
== false) {
654 next_id
= getFirstVisibleHeadlineId();
655 prev_id
= getLastVisibleHeadlineId();
657 for (var i
= 0; i
< rows
.length
; i
++) {
658 if (rows
[i
] == active_post_id
) {
665 if (mode
== "next") {
669 if (!cdmArticleIsActuallyVisible(next_id
)) {
670 cdmScrollToArticleId(next_id
);
672 cdmSelectArticles("none");
673 toggleUnread(next_id
, 0, true);
674 toggleSelected(next_id
);
677 correctHeadlinesOffset(next_id
);
678 view(next_id
, getActiveFeedId());
683 if (mode
== "prev") {
686 cdmScrollToArticleId(prev_id
);
687 cdmSelectArticles("none");
688 toggleUnread(prev_id
, 0, true);
689 toggleSelected(prev_id
);
691 correctHeadlinesOffset(prev_id
);
692 view(prev_id
, getActiveFeedId());
698 exception_error("moveToPost", e
);
702 function toggleSelected(id
) {
705 var cb
= document
.getElementById("RCHK-" + id
);
707 var row
= document
.getElementById("RROW-" + id
);
709 var nc
= row
.className
;
711 if (!nc
.match("Selected")) {
712 nc
= nc
+ "Selected";
717 // In CDM basically last selected article == active article
718 if (isCdmMode()) active_post_id
= id
;
720 nc
= nc
.replace("Selected", "");
730 exception_error("toggleSelected", e
);
734 function toggleUnread_afh(effect
) {
737 var elem
= effect
.element
;
738 elem
.style
.backgroundColor
= "";
741 exception_error("toggleUnread_afh", e
);
745 function toggleUnread(id
, cmode
, effect
) {
748 var row
= document
.getElementById("RROW-" + id
);
750 var nc
= row
.className
;
751 var is_selected
= row
.className
.match("Selected");
752 nc
= nc
.replace("Unread", "");
753 nc
= nc
.replace("Selected", "");
755 // since we are removing selection from the object, uncheck
756 // corresponding checkbox
758 var cb
= document
.getElementById("RCHK-" + id
);
763 // NOTE: I'm not sure that resetting selection here is a feature -fox
765 if (cmode
== undefined || cmode
== 2) {
766 if (row
.className
.match("Unread")) {
770 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
771 afterFinish
: toggleUnread_afh
,
772 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
776 row
.className
= nc
+ "Unread";
778 } else if (cmode
== 0) {
782 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
783 afterFinish
: toggleUnread_afh
,
784 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
786 } else if (cmode
== 1) {
787 row
.className
= nc
+ "Unread";
790 // Disable unmarking as selected for the time being (16.05.08) -fox
791 if (is_selected
) row
.className
= row
.className
+ "Selected";
793 if (cmode
== undefined) cmode
= 2;
795 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
796 param_escape(id
) + "&cmode=" + param_escape(cmode
);
798 // notify_progress("Loading, please wait...");
800 new Ajax
.Request(query
, {
801 onComplete: function(transport
) {
802 all_counters_callback2(transport
);
809 exception_error("toggleUnread", e
);
813 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
818 rows
= cdmGetSelectedArticles();
820 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
823 if (rows
.length
== 0 && !no_error
) {
824 alert(__("No articles are selected."));
828 for (i
= 0; i
< rows
.length
; i
++) {
829 var row
= document
.getElementById("RROW-" + rows
[i
]);
831 var nc
= row
.className
;
832 nc
= nc
.replace("Unread", "");
833 nc
= nc
.replace("Selected", "");
835 if (set_state
== undefined) {
836 if (row
.className
.match("Unread")) {
837 row
.className
= nc
+ "Selected";
839 row
.className
= nc
+ "UnreadSelected";
843 if (set_state
== false) {
844 row
.className
= nc
+ "Selected";
847 if (set_state
== true) {
848 row
.className
= nc
+ "UnreadSelected";
853 if (rows
.length
> 0) {
857 if (set_state
== undefined) {
859 } else if (set_state
== true) {
861 } else if (set_state
== false) {
865 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
866 param_escape(rows
.toString()) + "&cmode=" + cmode
;
868 notify_progress("Loading, please wait...");
870 new Ajax
.Request(query
, {
871 onComplete: function(transport
) {
872 catchup_callback2(transport
, callback_func
);
878 exception_error("selectionToggleUnread", e
);
882 function selectionToggleMarked(cdm_mode
) {
888 rows
= cdmGetSelectedArticles();
890 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
893 if (rows
.length
== 0) {
894 alert(__("No articles are selected."));
898 for (i
= 0; i
< rows
.length
; i
++) {
899 toggleMark(rows
[i
], true, true);
902 if (rows
.length
> 0) {
904 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
905 param_escape(rows
.toString()) + "&cmode=2";
907 query
= query
+ "&afid=" + getActiveFeedId();
909 /* if (tagsAreDisplayed()) {
910 query = query + "&omode=tl";
912 query = query + "&omode=flc";
915 query
= query
+ "&omode=lc";
917 new Ajax
.Request(query
, {
918 onComplete: function(transport
) {
919 all_counters_callback2(transport
);
925 exception_error("selectionToggleMarked", e
);
929 function selectionTogglePublished(cdm_mode
) {
935 rows
= cdmGetSelectedArticles();
937 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
940 if (rows
.length
== 0) {
941 alert(__("No articles are selected."));
945 for (i
= 0; i
< rows
.length
; i
++) {
946 togglePub(rows
[i
], true, true);
949 if (rows
.length
> 0) {
951 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
952 param_escape(rows
.toString()) + "&cmode=2";
954 query
= query
+ "&afid=" + getActiveFeedId();
956 /* if (tagsAreDisplayed()) {
957 query = query + "&omode=tl";
959 query = query + "&omode=flc";
962 query
= query
+ "&omode=lc";
964 new Ajax
.Request(query
, {
965 onComplete: function(transport
) {
966 all_counters_callback2(transport
);
972 exception_error("selectionToggleMarked", e
);
976 function cdmGetSelectedArticles() {
977 var sel_articles
= new Array();
978 var container
= document
.getElementById("headlinesInnerContainer");
980 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
981 var child
= container
.childNodes
[i
];
983 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
984 var c_id
= child
.id
.replace("RROW-", "");
985 sel_articles
.push(c_id
);
992 function cdmGetVisibleArticles() {
993 var sel_articles
= new Array();
994 var container
= document
.getElementById("headlinesInnerContainer");
996 if (!container
) return sel_articles
;
998 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
999 var child
= container
.childNodes
[i
];
1001 if (child
.id
.match("RROW-")) {
1002 var c_id
= child
.id
.replace("RROW-", "");
1003 sel_articles
.push(c_id
);
1007 return sel_articles
;
1010 function cdmGetUnreadArticles() {
1011 var sel_articles
= new Array();
1012 var container
= document
.getElementById("headlinesInnerContainer");
1014 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1015 var child
= container
.childNodes
[i
];
1017 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1018 var c_id
= child
.id
.replace("RROW-", "");
1019 sel_articles
.push(c_id
);
1023 return sel_articles
;
1027 // mode = all,none,unread
1028 function cdmSelectArticles(mode
) {
1029 var container
= document
.getElementById("headlinesInnerContainer");
1031 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1032 var child
= container
.childNodes
[i
];
1034 if (child
.id
.match("RROW-")) {
1035 var aid
= child
.id
.replace("RROW-", "");
1037 var cb
= document
.getElementById("RCHK-" + aid
);
1039 if (mode
== "all") {
1040 if (!child
.className
.match("Selected")) {
1041 child
.className
= child
.className
+ "Selected";
1044 } else if (mode
== "unread") {
1045 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1046 child
.className
= child
.className
+ "Selected";
1050 child
.className
= child
.className
.replace("Selected", "");
1057 function catchupPage() {
1059 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1061 var str
= __("Mark all visible articles in %s as read?");
1063 str
= str
.replace("%s", fn
);
1065 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1069 if (document
.getElementById("headlinesList")) {
1070 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1071 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1072 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1074 cdmSelectArticles('all');
1075 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1076 cdmSelectArticles('none');
1080 function catchupSelection() {
1086 if (document
.getElementById("headlinesList")) {
1087 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1089 rows
= cdmGetSelectedArticles();
1092 if (rows
.length
== 0) {
1093 alert(__("No articles are selected."));
1098 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1100 var str
= __("Mark %d selected articles in %s as read?");
1102 str
= str
.replace("%d", rows
.length
);
1103 str
= str
.replace("%s", fn
);
1105 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1109 if (document
.getElementById("headlinesList")) {
1110 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1111 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1113 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1114 // cdmSelectArticles('none');
1118 exception_error("catchupSelection", e
);
1123 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1125 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1126 printLockingError();
1129 var title
= prompt(__("Please enter label title:"), "");
1133 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1134 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1135 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1136 "&title=" + param_escape(title
);
1138 debug("LFS: " + query
);
1140 new Ajax
.Request(query
, {
1141 onComplete: function(transport
) {
1142 dlg_frefresh_callback(transport
);
1147 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1148 _tag_active_post_id
= id
;
1149 _tag_active_feed_id
= feed_id
;
1150 _tag_active_cdm
= cdm_enabled
;
1152 cache_invalidate(id
);
1155 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1157 displayDlg('editArticleTags', id
);
1161 function tag_saved_callback(transport
) {
1163 debug("in tag_saved_callback");
1168 if (tagsAreDisplayed()) {
1169 _reload_feedlist_after_view
= true;
1172 if (!_tag_active_cdm
) {
1173 if (active_post_id
== _tag_active_post_id
) {
1174 debug("reloading current article");
1175 view(_tag_active_post_id
, _tag_active_feed_id
);
1178 debug("reloading current feed");
1183 exception_error("catchup_callback", e
);
1187 function editTagsSave() {
1189 notify_progress("Saving article tags...");
1191 var form
= document
.forms
["tag_edit_form"];
1193 var query
= Form
.serialize("tag_edit_form");
1195 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1199 new Ajax
.Request(query
, {
1200 onComplete: function(transport
) {
1201 tag_saved_callback(transport
);
1206 function editTagsInsert() {
1209 var form
= document
.forms
["tag_edit_form"];
1211 var found_tags
= form
.found_tags
;
1212 var tags_str
= form
.tags_str
;
1214 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1216 if (tags_str
.value
.length
> 0 &&
1217 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1219 tags_str
.value
= tags_str
.value
+ ", ";
1222 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1224 found_tags
.selectedIndex
= 0;
1227 exception_error("editTagsInsert", e
);
1231 function cdmScrollViewport(where
) {
1232 debug("cdmScrollViewport: " + where
);
1234 var ctr
= document
.getElementById("headlinesInnerContainer");
1238 if (where
== "bottom") {
1239 ctr
.scrollTop
= ctr
.scrollHeight
;
1241 ctr
.scrollTop
= where
;
1245 function cdmArticleIsBelowViewport(id
) {
1247 var ctr
= document
.getElementById("headlinesInnerContainer");
1248 var e
= document
.getElementById("RROW-" + id
);
1250 if (!e
|| !ctr
) return;
1252 // article starts below viewport
1254 if (ctr
.scrollTop
< e
.offsetTop
) {
1261 exception_error("cdmArticleIsVisible", e
);
1265 function cdmArticleIsAboveViewport(id
) {
1267 var ctr
= document
.getElementById("headlinesInnerContainer");
1268 var e
= document
.getElementById("RROW-" + id
);
1270 if (!e
|| !ctr
) return;
1272 // article starts above viewport
1274 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1281 exception_error("cdmArticleIsVisible", e
);
1285 function cdmScrollToArticleId(id
) {
1287 var ctr
= document
.getElementById("headlinesInnerContainer");
1288 var e
= document
.getElementById("RROW-" + id
);
1290 if (!e
|| !ctr
) return;
1292 ctr
.scrollTop
= e
.offsetTop
;
1295 exception_error("cdmScrollToArticleId", e
);
1299 function cdmArticleIsActuallyVisible(id
) {
1301 var ctr
= document
.getElementById("headlinesInnerContainer");
1302 var e
= document
.getElementById("RROW-" + id
);
1304 if (!e
|| !ctr
) return;
1306 // article fits in viewport OR article is longer than viewport and
1307 // its bottom is visible
1309 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1310 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1314 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1315 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1316 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1325 exception_error("cdmArticleIsVisible", e
);
1329 function cdmWatchdog() {
1333 var ctr
= document
.getElementById("headlinesInnerContainer");
1337 var ids
= new Array();
1339 var e
= ctr
.firstChild
;
1342 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1343 e
.id
.match("RROW-")) {
1345 // article fits in viewport OR article is longer than viewport and
1346 // its bottom is visible
1348 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1349 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1351 // debug(e.id + " is visible " + e.offsetTop + "." +
1352 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1353 // (ctr.scrollTop + ctr.offsetHeight));
1355 ids
.push(e
.id
.replace("RROW-", ""));
1357 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1358 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1359 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1361 ids
.push(e
.id
.replace("RROW-", ""));
1365 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1367 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1368 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1370 ids.push(e.id.replace("RROW-", ""));
1379 debug("cdmWatchdog, ids= " + ids
.toString());
1381 if (ids
.length
> 0) {
1383 for (var i
= 0; i
< ids
.length
; i
++) {
1384 var e
= document
.getElementById("RROW-" + ids
[i
]);
1386 e
.className
= e
.className
.replace("Unread", "");
1390 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1391 param_escape(ids
.toString()) + "&cmode=0";
1393 new Ajax
.Request(query
, {
1394 onComplete: function(transport
) {
1395 all_counters_callback2(transport
);
1400 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1403 exception_error("cdmWatchdog", e
);
1409 function cache_inject(id
, article
, param
) {
1410 if (!cache_check_param(id
, param
)) {
1411 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1413 var cache_obj
= new Array();
1415 cache_obj
["id"] = id
;
1416 cache_obj
["data"] = article
;
1417 cache_obj
["param"] = param
;
1419 article_cache
.push(cache_obj
);
1422 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1426 function cache_find(id
) {
1427 for (var i
= 0; i
< article_cache
.length
; i
++) {
1428 if (article_cache
[i
]["id"] == id
) {
1429 return article_cache
[i
]["data"];
1435 function cache_find_param(id
, param
) {
1436 for (var i
= 0; i
< article_cache
.length
; i
++) {
1437 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1438 return article_cache
[i
]["data"];
1444 function cache_check(id
) {
1445 for (var i
= 0; i
< article_cache
.length
; i
++) {
1446 if (article_cache
[i
]["id"] == id
) {
1453 function cache_check_param(id
, param
) {
1454 for (var i
= 0; i
< article_cache
.length
; i
++) {
1456 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1457 // article_cache[i]["param"] + " vs " + id + ":" + param);
1459 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1466 function cache_expire() {
1467 while (article_cache
.length
> 25) {
1468 article_cache
.shift();
1472 function cache_empty() {
1473 article_cache
= new Array();
1476 function cache_invalidate(id
) {
1481 while (i
< article_cache
.length
) {
1482 if (article_cache
[i
]["id"] == id
) {
1483 debug("cache_invalidate: removed id " + id
);
1484 article_cache
.splice(i
, 1);
1489 debug("cache_invalidate: id not found: " + id
);
1492 exception_error("cache_invalidate", e
);
1496 function getActiveArticleId() {
1497 return active_post_id
;
1500 function cdmClicked(elem
) {
1502 if (elem
.id
&& elem
.id
.match("RROW-")) {
1503 var id
= elem
.id
.replace("RROW-", "");
1504 active_post_id
= id
;
1506 cdmSelectArticles("none");
1507 toggleUnread(id
, 0, true);
1512 exception_error("cdmClicked", e
);
1516 function preload_article_callback(transport
) {
1518 if (transport
.responseXML
) {
1519 var articles
= transport
.responseXML
.getElementsByTagName("article");
1521 for (var i
= 0; i
< articles
.length
; i
++) {
1522 var id
= articles
[i
].getAttribute("id");
1523 if (!cache_check(id
)) {
1524 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1525 debug("preloaded article: " + id
);
1530 exception_error("preload_article_callback", e
);
1534 function preloadArticleUnderPointer(id
) {
1536 if (post_under_pointer
== id
&& !cache_check(id
)) {
1538 debug("trying to preload article " + id
);
1540 var neighbor_ids
= getRelativePostIds(id
, 1);
1542 /* only request uncached articles */
1544 var cids_to_request
= Array();
1546 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1547 if (!cache_check(neighbor_ids
[i
])) {
1548 cids_to_request
.push(neighbor_ids
[i
]);
1551 debug("additional ids: " + cids_to_request
.toString());
1553 cids_to_request
.push(id
);
1555 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1556 cids_to_request
.toString();
1557 new Ajax
.Request(query
, {
1558 onComplete: function(transport
) {
1559 preload_article_callback(transport
);
1563 exception_error("preloadArticleUnderPointer", e
);
1567 function postMouseIn(id
) {
1569 if (post_under_pointer
!= id
) {
1570 post_under_pointer
= id
;
1572 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1577 exception_error("postMouseIn", e
);
1581 function postMouseOut(id
) {
1583 post_under_pointer
= false;
1585 exception_error("postMouseOut", e
);
1589 function headlines_scroll_handler() {
1592 var e
= document
.getElementById("headlinesInnerContainer");
1594 // don't do infinite scrolling when Limit == All
1596 var toolbar_form
= document
.forms
["main_toolbar_form"];
1598 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1599 if (limit
.value
!= 0) {
1601 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1602 _infscroll_disable
);
1604 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1605 if (!_infscroll_disable
) {
1606 debug("more cowbell!");
1613 exception_error("headlines_scroll_handler", e
);
1617 function catchupRelativeToArticle(below
) {
1621 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1622 printLockingError();
1625 if (!getActiveArticleId()) {
1626 alert(__("No article is selected."));
1632 if (document
.getElementById("headlinesList")) {
1633 visible_ids
= getVisibleHeadlineIds();
1635 visible_ids
= cdmGetVisibleArticles();
1638 var ids_to_mark
= new Array();
1641 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1642 if (visible_ids
[i
] != getActiveArticleId()) {
1643 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1645 if (e
&& e
.className
.match("Unread")) {
1646 ids_to_mark
.push(visible_ids
[i
]);
1653 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1654 if (visible_ids
[i
] != getActiveArticleId()) {
1655 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1657 if (e
&& e
.className
.match("Unread")) {
1658 ids_to_mark
.push(visible_ids
[i
]);
1666 if (ids_to_mark
.length
== 0) {
1667 alert(__("No articles found to mark"));
1669 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1673 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1674 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1675 e
.className
= e
.className
.replace("Unread", "");
1678 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1679 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1681 new Ajax
.Request(query
, {
1682 onComplete: function(transport
) {
1683 catchup_callback2(transport
);
1690 exception_error("catchupRelativeToArticle", e
);
1694 function cdmExpandArticle(a_id
) {
1696 var id
= 'CICD-' + a_id
;
1698 Effect
.Appear(id
, {duration
: 0.5,
1699 beforeStart: function(effect
) {
1700 var h_id
= 'CICH-' + a_id
;
1701 var h_elem
= document
.getElementById(h_id
);
1702 if (h_elem
) { h_elem
.style
.display
= "none"; }
1704 toggleUnread(a_id
, 0);
1709 exception_error("appearBlockElementF", e
);
1714 function fixHeadlinesOrder(ids
) {
1716 for (var i
= 0; i
< ids
.length
; i
++) {
1717 var e
= document
.getElementById("RROW-" + ids
[i
]);
1721 e
.className
= e
.className
.replace("even", "odd");
1723 e
.className
= e
.className
.replace("odd", "even");
1728 exception_error("fixHeadlinesOrder", e
);
1732 function subtoolbarSearch() {
1735 var q
= document
.getElementById("subtoolbar_search_box");
1739 q
= q
.value
.toUpperCase();
1742 var vis_ids
= new Array();
1744 if (document
.getElementById("headlinesList")) {
1745 ids
= getVisibleHeadlineIds();
1747 ids
= cdmGetVisibleArticles();
1750 for (var i
= 0; i
< ids
.length
; i
++) {
1751 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1754 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1755 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1757 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1758 vis_ids
.push(ids
[i
]);
1763 fixHeadlinesOrder(vis_ids
);
1766 exception_error("subtoolbarSearch", e
);
1770 function getArticleUnderPointer() {
1771 return post_under_pointer
;