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");
194 debug("parsing runtime info: " + runtime_info
[0]);
195 parse_runtime_info(runtime_info
[0]);
197 debug("counters container not found in reply");
201 debug("headlines_callback: returned no XML object");
202 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
205 if (typeof correctPNG
!= 'undefined') {
209 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
211 if (!document
.getElementById("headlinesList") &&
212 getInitParam("cdm_auto_catchup") == 1) {
213 debug("starting CDM watchdog");
214 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
215 _cdm_wd_vishist
= new Array();
217 debug("not in CDM mode or watchdog disabled");
220 if (_tag_cdm_scroll
) {
222 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
223 _tag_cdm_scroll
= false;
224 debug("resetting headlinesInner scrollTop");
229 _feed_cur_page
= feed_cur_page
;
230 _infscroll_request_sent
= 0;
237 exception_error("headlines_callback2", e
);
241 function render_article(article
) {
243 var f
= document
.getElementById("content-frame");
248 f
.innerHTML
= article
;
251 exception_error("render_article", e
);
255 function showArticleInHeadlines(id
) {
259 cleanSelected("headlinesList");
261 var crow
= document
.getElementById("RROW-" + id
);
265 var article_is_unread
= crow
.className
.match("Unread");
267 crow
.className
= crow
.className
.replace("Unread", "");
269 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
271 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
273 var cache_prefix
= "";
275 if (activeFeedIsCat()) {
281 var view_mode
= false;
284 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
285 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
287 exception_error("showArticleInHeadlines/viewmode", e
, true);
290 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
291 upd_img_pic
.src
= "images/blank_icon.gif";
293 cache_invalidate(cache_prefix
+ getActiveFeedId());
295 cache_inject(cache_prefix
+ getActiveFeedId(),
296 document
.getElementById("headlines-frame").innerHTML
,
297 get_feed_unread(getActiveFeedId()));
299 } else if (article_is_unread
&& view_mode
== "all_articles") {
301 cache_invalidate(cache_prefix
+ getActiveFeedId());
303 cache_inject(cache_prefix
+ getActiveFeedId(),
304 document
.getElementById("headlines-frame").innerHTML
,
305 get_feed_unread(getActiveFeedId())-1);
307 } else if (article_is_unread
) {
308 cache_invalidate(cache_prefix
+ getActiveFeedId());
314 exception_error("showArticleInHeadlines", e
);
318 function article_callback2(transport
, id
, feed_id
) {
320 debug("article_callback2 " + id
);
322 if (transport
.responseXML
) {
324 active_real_feed_id
= feed_id
;
327 //showArticleInHeadlines(id);
329 var reply
= transport
.responseXML
.firstChild
.firstChild
;
331 var articles
= transport
.responseXML
.getElementsByTagName("article");
333 for (var i
= 0; i
< articles
.length
; i
++) {
334 var a_id
= articles
[i
].getAttribute("id");
336 debug("found id: " + a_id
);
338 if (a_id
== active_post_id
) {
339 debug("active article, rendering...");
340 render_article(articles
[i
].firstChild
.nodeValue
);
343 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
347 debug("article_callback: returned no XML object");
348 var f
= document
.getElementById("content-frame");
349 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
352 var date
= new Date();
353 last_article_view
= date
.getTime() / 1000;
355 if (typeof correctPNG
!= 'undefined') {
359 if (_reload_feedlist_after_view
) {
360 setTimeout('updateFeedList(false, false)', 50);
361 _reload_feedlist_after_view
= false;
363 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
366 debug("parsing piggybacked counters: " + counters
);
367 parse_counters(counters
, false);
369 debug("counters container not found in reply");
375 exception_error("article_callback2", e
);
379 function view(id
, feed_id
, skip_history
) {
382 debug("loading article: " + id
+ "/" + feed_id
);
384 var cached_article
= cache_find(id
);
386 debug("cache check result: " + (cached_article
!= false));
390 //setActiveFeedId(feed_id);
392 var query
= "backend.php?op=view&id=" + param_escape(id
) +
393 "&feed=" + param_escape(feed_id
);
395 var date
= new Date();
397 var neighbor_ids
= getRelativePostIds(active_post_id
);
399 /* only request uncached articles */
401 var cids_to_request
= Array();
403 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
404 if (!cache_check(neighbor_ids
[i
])) {
405 cids_to_request
.push(neighbor_ids
[i
]);
409 debug("additional ids: " + cids_to_request
.toString());
411 /* additional info for piggyback counters */
413 if (tagsAreDisplayed()) {
414 query
= query
+ "&omode=lt";
416 query
= query
+ "&omode=flc";
419 var date
= new Date();
420 var timestamp
= Math
.round(date
.getTime() / 1000);
421 query
= query
+ "&ts=" + timestamp
;
423 query
= query
+ "&cids=" + cids_to_request
.toString();
425 var crow
= document
.getElementById("RROW-" + id
);
426 var article_is_unread
= crow
.className
.match("Unread");
428 showArticleInHeadlines(id
);
430 if (!cached_article
) {
432 notify_progress("Loading, please wait...");
434 } else if (cached_article
&& article_is_unread
) {
436 query
= query
+ "&mode=prefetch";
438 render_article(cached_article
);
440 } else if (cached_article
) {
442 query
= query
+ "&mode=prefetch_old";
443 render_article(cached_article
);
448 new Ajax
.Request(query
, {
449 onComplete: function(transport
) {
450 article_callback2(transport
, id
, feed_id
);
454 exception_error("view", e
);
459 return toggleMark(id
);
463 return togglePub(id
);
466 function tMark_afh_off(effect
) {
468 var elem
= effect
.effects
[0].element
;
470 debug("tMark_afh_off : " + elem
.id
);
473 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
474 elem
.alt
= __("Star article");
479 exception_error("tMark_afh_off", e
);
483 function tPub_afh_off(effect
) {
485 var elem
= effect
.effects
[0].element
;
487 debug("tPub_afh_off : " + elem
.id
);
490 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
491 elem
.alt
= __("Publish article");
496 exception_error("tPub_afh_off", e
);
500 function toggleMark(id
, client_only
, no_effects
) {
504 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
506 query
= query
+ "&afid=" + getActiveFeedId();
508 if (tagsAreDisplayed()) {
509 query
= query
+ "&omode=tl";
511 query
= query
+ "&omode=flc";
514 var mark_img
= document
.getElementById("FMPIC-" + id
);
515 var vfeedu
= document
.getElementById("FEEDU--1");
516 var crow
= document
.getElementById("RROW-" + id
);
518 if (mark_img
.src
.match("mark_unset")) {
519 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
520 mark_img
.alt
= __("Unstar article");
521 query
= query
+ "&mark=1";
524 //mark_img.src = "images/mark_unset.png";
525 mark_img
.alt
= __("Please wait...");
526 query
= query
+ "&mark=0";
528 if (document
.getElementById("headlinesList") && !no_effects
) {
529 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
531 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
532 mark_img
.alt
= __("Star article");
539 new Ajax
.Request(query
, {
540 onComplete: function(transport
) {
541 all_counters_callback2(transport
);
547 exception_error("toggleMark", e
);
551 function togglePub(id
, client_only
, no_effects
) {
555 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
557 query
= query
+ "&afid=" + getActiveFeedId();
559 if (tagsAreDisplayed()) {
560 query
= query
+ "&omode=tl";
562 query
= query
+ "&omode=flc";
565 var mark_img
= document
.getElementById("FPPIC-" + id
);
566 var vfeedu
= document
.getElementById("FEEDU--2");
567 var crow
= document
.getElementById("RROW-" + id
);
569 if (mark_img
.src
.match("pub_unset")) {
570 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
571 mark_img
.alt
= __("Unpublish article");
572 query
= query
+ "&pub=1";
576 //mark_img.src = "images/pub_unset.png";
577 mark_img
.alt
= __("Please wait...");
578 query
= query
+ "&pub=0";
580 if (document
.getElementById("headlinesList") && !no_effects
) {
581 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
583 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
584 mark_img
.alt
= __("Publish article");
589 new Ajax
.Request(query
, {
590 onComplete: function(transport
) {
591 all_counters_callback2(transport
);
597 exception_error("togglePub", e
);
601 function correctHeadlinesOffset(id
) {
605 var hlist
= document
.getElementById("headlinesList");
606 var container
= document
.getElementById("headlinesInnerContainer");
607 var row
= document
.getElementById("RROW-" + id
);
609 var viewport
= container
.offsetHeight
;
611 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
612 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
614 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
615 debug("Vport: " + viewport
);
617 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
618 container
.scrollTop
= row
.offsetTop
;
619 } else if (rel_offset_bottom
> viewport
) {
621 /* doesn't properly work with Opera in some cases because
622 Opera fucks up element scrolling */
624 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
628 exception_error("correctHeadlinesOffset", e
);
633 function moveToPost(mode
) {
640 rows
= cdmGetVisibleArticles();
642 rows
= getVisibleHeadlineIds();
648 if (!document
.getElementById('RROW-' + active_post_id
)) {
649 active_post_id
= false;
652 if (active_post_id
== false) {
653 next_id
= getFirstVisibleHeadlineId();
654 prev_id
= getLastVisibleHeadlineId();
656 for (var i
= 0; i
< rows
.length
; i
++) {
657 if (rows
[i
] == active_post_id
) {
664 if (mode
== "next") {
668 if (!cdmArticleIsActuallyVisible(next_id
)) {
669 cdmScrollToArticleId(next_id
);
671 cdmSelectArticles("none");
672 toggleUnread(next_id
, 0, true);
673 toggleSelected(next_id
);
676 correctHeadlinesOffset(next_id
);
677 view(next_id
, getActiveFeedId());
682 if (mode
== "prev") {
685 cdmScrollToArticleId(prev_id
);
686 cdmSelectArticles("none");
687 toggleUnread(prev_id
, 0, true);
688 toggleSelected(prev_id
);
690 correctHeadlinesOffset(prev_id
);
691 view(prev_id
, getActiveFeedId());
697 exception_error("moveToPost", e
);
701 function toggleSelected(id
) {
704 var cb
= document
.getElementById("RCHK-" + id
);
706 var row
= document
.getElementById("RROW-" + id
);
708 var nc
= row
.className
;
710 if (!nc
.match("Selected")) {
711 nc
= nc
+ "Selected";
716 // In CDM basically last selected article == active article
717 if (isCdmMode()) active_post_id
= id
;
719 nc
= nc
.replace("Selected", "");
729 exception_error("toggleSelected", e
);
733 function toggleUnread_afh(effect
) {
736 var elem
= effect
.element
;
737 elem
.style
.backgroundColor
= "";
740 exception_error("toggleUnread_afh", e
);
744 function toggleUnread(id
, cmode
, effect
) {
747 var row
= document
.getElementById("RROW-" + id
);
749 var nc
= row
.className
;
750 var is_selected
= row
.className
.match("Selected");
751 nc
= nc
.replace("Unread", "");
752 nc
= nc
.replace("Selected", "");
754 // since we are removing selection from the object, uncheck
755 // corresponding checkbox
757 var cb
= document
.getElementById("RCHK-" + id
);
762 // NOTE: I'm not sure that resetting selection here is a feature -fox
764 if (cmode
== undefined || cmode
== 2) {
765 if (row
.className
.match("Unread")) {
769 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
770 afterFinish
: toggleUnread_afh
,
771 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
775 row
.className
= nc
+ "Unread";
777 } else if (cmode
== 0) {
781 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
782 afterFinish
: toggleUnread_afh
,
783 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
785 } else if (cmode
== 1) {
786 row
.className
= nc
+ "Unread";
789 // Disable unmarking as selected for the time being (16.05.08) -fox
790 if (is_selected
) row
.className
= row
.className
+ "Selected";
792 if (cmode
== undefined) cmode
= 2;
794 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
795 param_escape(id
) + "&cmode=" + param_escape(cmode
);
797 // notify_progress("Loading, please wait...");
799 new Ajax
.Request(query
, {
800 onComplete: function(transport
) {
801 all_counters_callback2(transport
);
808 exception_error("toggleUnread", e
);
812 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
817 rows
= cdmGetSelectedArticles();
819 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
822 if (rows
.length
== 0 && !no_error
) {
823 alert(__("No articles are selected."));
827 for (i
= 0; i
< rows
.length
; i
++) {
828 var row
= document
.getElementById("RROW-" + rows
[i
]);
830 var nc
= row
.className
;
831 nc
= nc
.replace("Unread", "");
832 nc
= nc
.replace("Selected", "");
834 if (set_state
== undefined) {
835 if (row
.className
.match("Unread")) {
836 row
.className
= nc
+ "Selected";
838 row
.className
= nc
+ "UnreadSelected";
842 if (set_state
== false) {
843 row
.className
= nc
+ "Selected";
846 if (set_state
== true) {
847 row
.className
= nc
+ "UnreadSelected";
852 if (rows
.length
> 0) {
856 if (set_state
== undefined) {
858 } else if (set_state
== true) {
860 } else if (set_state
== false) {
864 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
865 param_escape(rows
.toString()) + "&cmode=" + cmode
;
867 notify_progress("Loading, please wait...");
869 new Ajax
.Request(query
, {
870 onComplete: function(transport
) {
871 catchup_callback2(transport
, callback_func
);
877 exception_error("selectionToggleUnread", e
);
881 function selectionToggleMarked(cdm_mode
) {
887 rows
= cdmGetSelectedArticles();
889 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
892 if (rows
.length
== 0) {
893 alert(__("No articles are selected."));
897 for (i
= 0; i
< rows
.length
; i
++) {
898 toggleMark(rows
[i
], true, true);
901 if (rows
.length
> 0) {
903 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
904 param_escape(rows
.toString()) + "&cmode=2";
906 query
= query
+ "&afid=" + getActiveFeedId();
908 /* if (tagsAreDisplayed()) {
909 query = query + "&omode=tl";
911 query = query + "&omode=flc";
914 query
= query
+ "&omode=lc";
916 new Ajax
.Request(query
, {
917 onComplete: function(transport
) {
918 all_counters_callback2(transport
);
924 exception_error("selectionToggleMarked", e
);
928 function selectionTogglePublished(cdm_mode
) {
934 rows
= cdmGetSelectedArticles();
936 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
939 if (rows
.length
== 0) {
940 alert(__("No articles are selected."));
944 for (i
= 0; i
< rows
.length
; i
++) {
945 togglePub(rows
[i
], true, true);
948 if (rows
.length
> 0) {
950 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
951 param_escape(rows
.toString()) + "&cmode=2";
953 query
= query
+ "&afid=" + getActiveFeedId();
955 /* if (tagsAreDisplayed()) {
956 query = query + "&omode=tl";
958 query = query + "&omode=flc";
961 query
= query
+ "&omode=lc";
963 new Ajax
.Request(query
, {
964 onComplete: function(transport
) {
965 all_counters_callback2(transport
);
971 exception_error("selectionToggleMarked", e
);
975 function cdmGetSelectedArticles() {
976 var sel_articles
= new Array();
977 var container
= document
.getElementById("headlinesInnerContainer");
979 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
980 var child
= container
.childNodes
[i
];
982 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
983 var c_id
= child
.id
.replace("RROW-", "");
984 sel_articles
.push(c_id
);
991 function cdmGetVisibleArticles() {
992 var sel_articles
= new Array();
993 var container
= document
.getElementById("headlinesInnerContainer");
995 if (!container
) return sel_articles
;
997 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
998 var child
= container
.childNodes
[i
];
1000 if (child
.id
.match("RROW-")) {
1001 var c_id
= child
.id
.replace("RROW-", "");
1002 sel_articles
.push(c_id
);
1006 return sel_articles
;
1009 function cdmGetUnreadArticles() {
1010 var sel_articles
= new Array();
1011 var container
= document
.getElementById("headlinesInnerContainer");
1013 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1014 var child
= container
.childNodes
[i
];
1016 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1017 var c_id
= child
.id
.replace("RROW-", "");
1018 sel_articles
.push(c_id
);
1022 return sel_articles
;
1026 // mode = all,none,unread
1027 function cdmSelectArticles(mode
) {
1028 var container
= document
.getElementById("headlinesInnerContainer");
1030 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1031 var child
= container
.childNodes
[i
];
1033 if (child
.id
.match("RROW-")) {
1034 var aid
= child
.id
.replace("RROW-", "");
1036 var cb
= document
.getElementById("RCHK-" + aid
);
1038 if (mode
== "all") {
1039 if (!child
.className
.match("Selected")) {
1040 child
.className
= child
.className
+ "Selected";
1043 } else if (mode
== "unread") {
1044 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1045 child
.className
= child
.className
+ "Selected";
1049 child
.className
= child
.className
.replace("Selected", "");
1056 function catchupPage() {
1058 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1060 var str
= __("Mark all visible articles in %s as read?");
1062 str
= str
.replace("%s", fn
);
1064 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1068 if (document
.getElementById("headlinesList")) {
1069 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1070 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1071 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1073 cdmSelectArticles('all');
1074 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1075 cdmSelectArticles('none');
1079 function catchupSelection() {
1085 if (document
.getElementById("headlinesList")) {
1086 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1088 rows
= cdmGetSelectedArticles();
1091 if (rows
.length
== 0) {
1092 alert(__("No articles are selected."));
1097 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1099 var str
= __("Mark %d selected articles in %s as read?");
1101 str
= str
.replace("%d", rows
.length
);
1102 str
= str
.replace("%s", fn
);
1104 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1108 if (document
.getElementById("headlinesList")) {
1109 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1110 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1112 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1113 // cdmSelectArticles('none');
1117 exception_error("catchupSelection", e
);
1122 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1124 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1125 printLockingError();
1128 var title
= prompt(__("Please enter label title:"), "");
1132 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1133 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1134 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1135 "&title=" + param_escape(title
);
1137 debug("LFS: " + query
);
1139 new Ajax
.Request(query
, {
1140 onComplete: function(transport
) {
1141 dlg_frefresh_callback(transport
);
1146 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1147 _tag_active_post_id
= id
;
1148 _tag_active_feed_id
= feed_id
;
1149 _tag_active_cdm
= cdm_enabled
;
1151 cache_invalidate(id
);
1154 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1156 displayDlg('editArticleTags', id
);
1160 function tag_saved_callback(transport
) {
1162 debug("in tag_saved_callback");
1167 if (tagsAreDisplayed()) {
1168 _reload_feedlist_after_view
= true;
1171 if (!_tag_active_cdm
) {
1172 if (active_post_id
== _tag_active_post_id
) {
1173 debug("reloading current article");
1174 view(_tag_active_post_id
, _tag_active_feed_id
);
1177 debug("reloading current feed");
1182 exception_error("catchup_callback", e
);
1186 function editTagsSave() {
1188 notify_progress("Saving article tags...");
1190 var form
= document
.forms
["tag_edit_form"];
1192 var query
= Form
.serialize("tag_edit_form");
1194 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1198 new Ajax
.Request(query
, {
1199 onComplete: function(transport
) {
1200 tag_saved_callback(transport
);
1205 function editTagsInsert() {
1208 var form
= document
.forms
["tag_edit_form"];
1210 var found_tags
= form
.found_tags
;
1211 var tags_str
= form
.tags_str
;
1213 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1215 if (tags_str
.value
.length
> 0 &&
1216 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1218 tags_str
.value
= tags_str
.value
+ ", ";
1221 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1223 found_tags
.selectedIndex
= 0;
1226 exception_error("editTagsInsert", e
);
1230 function cdmScrollViewport(where
) {
1231 debug("cdmScrollViewport: " + where
);
1233 var ctr
= document
.getElementById("headlinesInnerContainer");
1237 if (where
== "bottom") {
1238 ctr
.scrollTop
= ctr
.scrollHeight
;
1240 ctr
.scrollTop
= where
;
1244 function cdmArticleIsBelowViewport(id
) {
1246 var ctr
= document
.getElementById("headlinesInnerContainer");
1247 var e
= document
.getElementById("RROW-" + id
);
1249 if (!e
|| !ctr
) return;
1251 // article starts below viewport
1253 if (ctr
.scrollTop
< e
.offsetTop
) {
1260 exception_error("cdmArticleIsVisible", e
);
1264 function cdmArticleIsAboveViewport(id
) {
1266 var ctr
= document
.getElementById("headlinesInnerContainer");
1267 var e
= document
.getElementById("RROW-" + id
);
1269 if (!e
|| !ctr
) return;
1271 // article starts above viewport
1273 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1280 exception_error("cdmArticleIsVisible", e
);
1284 function cdmScrollToArticleId(id
) {
1286 var ctr
= document
.getElementById("headlinesInnerContainer");
1287 var e
= document
.getElementById("RROW-" + id
);
1289 if (!e
|| !ctr
) return;
1291 ctr
.scrollTop
= e
.offsetTop
;
1294 exception_error("cdmScrollToArticleId", e
);
1298 function cdmArticleIsActuallyVisible(id
) {
1300 var ctr
= document
.getElementById("headlinesInnerContainer");
1301 var e
= document
.getElementById("RROW-" + id
);
1303 if (!e
|| !ctr
) return;
1305 // article fits in viewport OR article is longer than viewport and
1306 // its bottom is visible
1308 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1309 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1313 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1314 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1315 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1324 exception_error("cdmArticleIsVisible", e
);
1328 function cdmWatchdog() {
1332 var ctr
= document
.getElementById("headlinesInnerContainer");
1336 var ids
= new Array();
1338 var e
= ctr
.firstChild
;
1341 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1342 e
.id
.match("RROW-")) {
1344 // article fits in viewport OR article is longer than viewport and
1345 // its bottom is visible
1347 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1348 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1350 // debug(e.id + " is visible " + e.offsetTop + "." +
1351 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1352 // (ctr.scrollTop + ctr.offsetHeight));
1354 ids
.push(e
.id
.replace("RROW-", ""));
1356 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1357 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1358 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1360 ids
.push(e
.id
.replace("RROW-", ""));
1364 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1366 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1367 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1369 ids.push(e.id.replace("RROW-", ""));
1378 debug("cdmWatchdog, ids= " + ids
.toString());
1380 if (ids
.length
> 0) {
1382 for (var i
= 0; i
< ids
.length
; i
++) {
1383 var e
= document
.getElementById("RROW-" + ids
[i
]);
1385 e
.className
= e
.className
.replace("Unread", "");
1389 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1390 param_escape(ids
.toString()) + "&cmode=0";
1392 new Ajax
.Request(query
, {
1393 onComplete: function(transport
) {
1394 all_counters_callback2(transport
);
1399 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1402 exception_error("cdmWatchdog", e
);
1408 function cache_inject(id
, article
, param
) {
1409 if (!cache_check_param(id
, param
)) {
1410 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1412 var cache_obj
= new Array();
1414 cache_obj
["id"] = id
;
1415 cache_obj
["data"] = article
;
1416 cache_obj
["param"] = param
;
1418 article_cache
.push(cache_obj
);
1421 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1425 function cache_find(id
) {
1426 for (var i
= 0; i
< article_cache
.length
; i
++) {
1427 if (article_cache
[i
]["id"] == id
) {
1428 return article_cache
[i
]["data"];
1434 function cache_find_param(id
, param
) {
1435 for (var i
= 0; i
< article_cache
.length
; i
++) {
1436 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1437 return article_cache
[i
]["data"];
1443 function cache_check(id
) {
1444 for (var i
= 0; i
< article_cache
.length
; i
++) {
1445 if (article_cache
[i
]["id"] == id
) {
1452 function cache_check_param(id
, param
) {
1453 for (var i
= 0; i
< article_cache
.length
; i
++) {
1455 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1456 // article_cache[i]["param"] + " vs " + id + ":" + param);
1458 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1465 function cache_expire() {
1466 while (article_cache
.length
> 25) {
1467 article_cache
.shift();
1471 function cache_empty() {
1472 article_cache
= new Array();
1475 function cache_invalidate(id
) {
1480 while (i
< article_cache
.length
) {
1481 if (article_cache
[i
]["id"] == id
) {
1482 debug("cache_invalidate: removed id " + id
);
1483 article_cache
.splice(i
, 1);
1488 debug("cache_invalidate: id not found: " + id
);
1491 exception_error("cache_invalidate", e
);
1495 function getActiveArticleId() {
1496 return active_post_id
;
1499 function cdmClicked(elem
) {
1501 if (elem
.id
&& elem
.id
.match("RROW-")) {
1502 var id
= elem
.id
.replace("RROW-", "");
1503 active_post_id
= id
;
1505 cdmSelectArticles("none");
1506 toggleUnread(id
, 0, true);
1511 exception_error("cdmClicked", e
);
1515 function preload_article_callback(transport
) {
1517 if (transport
.responseXML
) {
1518 var articles
= transport
.responseXML
.getElementsByTagName("article");
1520 for (var i
= 0; i
< articles
.length
; i
++) {
1521 var id
= articles
[i
].getAttribute("id");
1522 if (!cache_check(id
)) {
1523 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1524 debug("preloaded article: " + id
);
1529 exception_error("preload_article_callback", e
);
1533 function preloadArticleUnderPointer(id
) {
1535 if (post_under_pointer
== id
&& !cache_check(id
)) {
1537 debug("trying to preload article " + id
);
1539 var neighbor_ids
= getRelativePostIds(id
, 1);
1541 /* only request uncached articles */
1543 var cids_to_request
= Array();
1545 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1546 if (!cache_check(neighbor_ids
[i
])) {
1547 cids_to_request
.push(neighbor_ids
[i
]);
1550 debug("additional ids: " + cids_to_request
.toString());
1552 cids_to_request
.push(id
);
1554 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1555 cids_to_request
.toString();
1556 new Ajax
.Request(query
, {
1557 onComplete: function(transport
) {
1558 preload_article_callback(transport
);
1562 exception_error("preloadArticleUnderPointer", e
);
1566 function postMouseIn(id
) {
1568 if (post_under_pointer
!= id
) {
1569 post_under_pointer
= id
;
1571 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1576 exception_error("postMouseIn", e
);
1580 function postMouseOut(id
) {
1582 post_under_pointer
= false;
1584 exception_error("postMouseOut", e
);
1588 function headlines_scroll_handler() {
1591 var e
= document
.getElementById("headlinesInnerContainer");
1593 // don't do infinite scrolling when Limit == All
1595 var toolbar_form
= document
.forms
["main_toolbar_form"];
1597 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1598 if (limit
.value
!= 0) {
1600 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1601 _infscroll_disable
);
1603 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1604 if (!_infscroll_disable
) {
1605 debug("more cowbell!");
1612 exception_error("headlines_scroll_handler", e
);
1616 function catchupRelativeToArticle(below
) {
1620 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1621 printLockingError();
1624 if (!getActiveArticleId()) {
1625 alert(__("No article is selected."));
1631 if (document
.getElementById("headlinesList")) {
1632 visible_ids
= getVisibleHeadlineIds();
1634 visible_ids
= cdmGetVisibleArticles();
1637 var ids_to_mark
= new Array();
1640 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1641 if (visible_ids
[i
] != getActiveArticleId()) {
1642 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1644 if (e
&& e
.className
.match("Unread")) {
1645 ids_to_mark
.push(visible_ids
[i
]);
1652 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1653 if (visible_ids
[i
] != getActiveArticleId()) {
1654 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1656 if (e
&& e
.className
.match("Unread")) {
1657 ids_to_mark
.push(visible_ids
[i
]);
1665 if (ids_to_mark
.length
== 0) {
1666 alert(__("No articles found to mark"));
1668 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1672 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1673 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1674 e
.className
= e
.className
.replace("Unread", "");
1677 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1678 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1680 new Ajax
.Request(query
, {
1681 onComplete: function(transport
) {
1682 catchup_callback2(transport
);
1689 exception_error("catchupRelativeToArticle", e
);
1693 function cdmExpandArticle(a_id
) {
1695 var id
= 'CICD-' + a_id
;
1697 Effect
.Appear(id
, {duration
: 0.5,
1698 beforeStart: function(effect
) {
1699 var h_id
= 'CICH-' + a_id
;
1700 var h_elem
= document
.getElementById(h_id
);
1701 if (h_elem
) { h_elem
.style
.display
= "none"; }
1703 toggleUnread(a_id
, 0);
1708 exception_error("appearBlockElementF", e
);
1713 function fixHeadlinesOrder(ids
) {
1715 for (var i
= 0; i
< ids
.length
; i
++) {
1716 var e
= document
.getElementById("RROW-" + ids
[i
]);
1720 e
.className
= e
.className
.replace("even", "odd");
1722 e
.className
= e
.className
.replace("odd", "even");
1727 exception_error("fixHeadlinesOrder", e
);
1731 function subtoolbarSearch() {
1734 var q
= document
.getElementById("subtoolbar_search_box");
1738 q
= q
.value
.toUpperCase();
1741 var vis_ids
= new Array();
1743 if (document
.getElementById("headlinesList")) {
1744 ids
= getVisibleHeadlineIds();
1746 ids
= cdmGetVisibleArticles();
1749 for (var i
= 0; i
< ids
.length
; i
++) {
1750 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1753 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1754 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1756 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1757 vis_ids
.push(ids
[i
]);
1762 fixHeadlinesOrder(vis_ids
);
1765 exception_error("subtoolbarSearch", e
);
1769 function getArticleUnderPointer() {
1770 return post_under_pointer
;