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 function catchup_callback() {
21 if (xmlhttp_rpc
.readyState
== 4) {
23 debug("catchup_callback");
25 all_counters_callback2(xmlhttp_rpc
);
26 if (_catchup_callback_func
) {
27 setTimeout(_catchup_callback_func
, 10);
30 exception_error("catchup_callback", e
);
35 function catchup_callback2(transport
, callback
) {
37 debug("catchup_callback2 " + transport
+ ", " + callback
);
39 all_counters_callback2(transport
);
41 setTimeout(callback
, 10);
44 exception_error("catchup_callback2", e
);
48 function clean_feed_selections() {
50 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
52 for (var i
= 0; i
< feeds
.length
; i
++) {
53 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
54 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
58 exception_error("clean_feed_selections", e
);
62 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
65 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
67 clean_feed_selections();
69 setActiveFeedId(active_feed_id
);
71 if (is_cat
!= undefined) {
72 active_feed_is_cat
= is_cat
;
76 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
77 if (feedr
&& !feedr
.className
.match("Selected")) {
78 feedr
.className
= feedr
.className
+ "Selected";
82 var f
= document
.getElementById("headlines-frame");
84 if (feed_cur_page
== 0) {
85 debug("resetting headlines scrollTop");
90 if (transport
.responseXML
) {
91 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
92 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
93 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
94 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
96 var headlines_count
= headlines_count_obj
.getAttribute("value");
97 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
98 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
100 if (headlines_count
== 0) _infscroll_disable
= 1;
102 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
103 var articles
= transport
.responseXML
.getElementsByTagName("article");
104 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
106 if (feed_cur_page
== 0) {
108 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
110 var cache_prefix
= "";
118 cache_invalidate(cache_prefix
+ active_feed_id
);
120 if (!disable_cache
) {
121 cache_inject(cache_prefix
+ active_feed_id
,
122 headlines
.firstChild
.nodeValue
, headlines_unread
);
126 debug("headlines_callback: returned no data");
127 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
132 if (headlines_count
> 0) {
133 debug("adding some more headlines...");
135 var c
= document
.getElementById("headlinesList");
138 c
= document
.getElementById("headlinesInnerContainer");
141 var ids
= getSelectedArticleIds2();
143 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
145 debug("restore selected ids: " + ids
);
147 for (var i
= 0; i
< ids
.length
; i
++) {
148 markHeadline(ids
[i
]);
152 debug("no new headlines received");
155 debug("headlines_callback: returned no data");
156 notify_error("Error while trying to load more headlines");
162 for (var i
= 0; i
< articles
.length
; i
++) {
163 var a_id
= articles
[i
].getAttribute("id");
164 debug("found id: " + a_id
);
165 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
168 debug("no cached articles received");
172 debug("parsing piggybacked counters: " + counters
);
173 parse_counters(counters
, false);
175 debug("counters container not found in reply");
179 debug("parsing runtime info: " + runtime_info
[0]);
180 parse_runtime_info(runtime_info
[0]);
182 debug("counters container not found in reply");
186 debug("headlines_callback: returned no XML object");
187 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
190 if (typeof correctPNG
!= 'undefined') {
194 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
196 if (!document
.getElementById("headlinesList") &&
197 getInitParam("cdm_auto_catchup") == 1) {
198 debug("starting CDM watchdog");
199 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
200 _cdm_wd_vishist
= new Array();
202 debug("not in CDM mode or watchdog disabled");
205 if (_tag_cdm_scroll
) {
207 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
208 _tag_cdm_scroll
= false;
209 debug("resetting headlinesInner scrollTop");
214 _feed_cur_page
= feed_cur_page
;
215 _infscroll_request_sent
= 0;
219 exception_error("headlines_callback2", e
);
223 function render_article(article
) {
225 var f
= document
.getElementById("content-frame");
230 f
.innerHTML
= article
;
233 exception_error("render_article", e
);
237 function showArticleInHeadlines(id
) {
241 cleanSelected("headlinesList");
243 var crow
= document
.getElementById("RROW-" + id
);
247 var article_is_unread
= crow
.className
.match("Unread");
249 crow
.className
= crow
.className
.replace("Unread", "");
251 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
253 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
254 upd_img_pic
.src
= "images/blank_icon.gif";
256 var cache_prefix
= "";
258 if (activeFeedIsCat()) {
264 cache_invalidate(cache_prefix
+ getActiveFeedId());
267 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
271 exception_error("showArticleInHeadlines", e
);
275 function article_callback2(transport
, id
, feed_id
) {
277 debug("article_callback2 " + id
);
279 if (transport
.responseXML
) {
281 active_real_feed_id
= feed_id
;
284 showArticleInHeadlines(id
);
286 var reply
= transport
.responseXML
.firstChild
.firstChild
;
288 var articles
= transport
.responseXML
.getElementsByTagName("article");
290 for (var i
= 0; i
< articles
.length
; i
++) {
291 var a_id
= articles
[i
].getAttribute("id");
293 debug("found id: " + a_id
);
295 if (a_id
== active_post_id
) {
296 debug("active article, rendering...");
297 render_article(articles
[i
].firstChild
.nodeValue
);
300 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
304 debug("article_callback: returned no XML object");
305 var f
= document
.getElementById("content-frame");
306 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
309 var date
= new Date();
310 last_article_view
= date
.getTime() / 1000;
312 if (typeof correctPNG
!= 'undefined') {
316 if (_reload_feedlist_after_view
) {
317 setTimeout('updateFeedList(false, false)', 50);
318 _reload_feedlist_after_view
= false;
320 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
323 debug("parsing piggybacked counters: " + counters
);
324 parse_counters(counters
, false);
326 debug("counters container not found in reply");
332 exception_error("article_callback2", e
);
336 function view(id
, feed_id
, skip_history
) {
339 debug("loading article: " + id
+ "/" + feed_id
);
341 var cached_article
= cache_find(id
);
343 debug("cache check result: " + (cached_article
!= false));
347 //setActiveFeedId(feed_id);
349 var query
= "backend.php?op=view&id=" + param_escape(id
) +
350 "&feed=" + param_escape(feed_id
);
352 var date
= new Date();
354 var neighbor_ids
= getRelativePostIds(active_post_id
);
356 /* only request uncached articles */
358 var cids_to_request
= Array();
360 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
361 if (!cache_check(neighbor_ids
[i
])) {
362 cids_to_request
.push(neighbor_ids
[i
]);
366 debug("additional ids: " + cids_to_request
.toString());
368 /* additional info for piggyback counters */
370 if (tagsAreDisplayed()) {
371 query
= query
+ "&omode=lt";
373 query
= query
+ "&omode=flc";
376 var date
= new Date();
377 var timestamp
= Math
.round(date
.getTime() / 1000);
378 query
= query
+ "&ts=" + timestamp
;
380 query
= query
+ "&cids=" + cids_to_request
.toString();
382 var crow
= document
.getElementById("RROW-" + id
);
383 var article_is_unread
= crow
.className
.match("Unread");
385 showArticleInHeadlines(id
);
387 if (!cached_article
) {
389 notify_progress("Loading, please wait...");
391 } else if (cached_article
&& article_is_unread
) {
393 query
= query
+ "&mode=prefetch";
395 render_article(cached_article
);
397 } else if (cached_article
) {
399 query
= query
+ "&mode=prefetch_old";
400 render_article(cached_article
);
405 new Ajax
.Request(query
, {
406 onComplete: function(transport
) {
407 article_callback2(transport
, id
, feed_id
);
411 exception_error("view", e
);
416 return toggleMark(id
);
420 return togglePub(id
);
423 function tMark_afh_off(effect
) {
425 var elem
= effect
.effects
[0].element
;
427 debug("tMark_afh_off : " + elem
.id
);
430 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
431 elem
.alt
= __("Star article");
436 exception_error("tMark_afh_off", e
);
440 function tPub_afh_off(effect
) {
442 var elem
= effect
.effects
[0].element
;
444 debug("tPub_afh_off : " + elem
.id
);
447 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
448 elem
.alt
= __("Publish article");
453 exception_error("tPub_afh_off", e
);
457 function toggleMark(id
, client_only
, no_effects
) {
461 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
463 query
= query
+ "&afid=" + getActiveFeedId();
465 if (tagsAreDisplayed()) {
466 query
= query
+ "&omode=tl";
468 query
= query
+ "&omode=flc";
471 var mark_img
= document
.getElementById("FMPIC-" + id
);
472 var vfeedu
= document
.getElementById("FEEDU--1");
473 var crow
= document
.getElementById("RROW-" + id
);
475 if (mark_img
.src
.match("mark_unset")) {
476 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
477 mark_img
.alt
= __("Unstar article");
478 query
= query
+ "&mark=1";
480 /* if (vfeedu && crow.className.match("Unread")) {
481 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
485 //mark_img.src = "images/mark_unset.png";
486 mark_img
.alt
= __("Please wait...");
487 query
= query
+ "&mark=0";
489 /* if (vfeedu && crow.className.match("Unread")) {
490 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
493 if (document
.getElementById("headlinesList") && !no_effects
) {
494 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
496 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
497 mark_img
.alt
= __("Star article");
501 /* var vfeedctr = document.getElementById("FEEDCTR--1");
502 var vfeedr = document.getElementById("FEEDR--1");
504 if (vfeedu && vfeedctr) {
505 if ((+vfeedu.innerHTML) > 0) {
506 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
507 vfeedr.className = vfeedr.className + "Unread";
508 vfeedctr.className = "odd";
511 vfeedctr.className = "invisible";
512 vfeedr.className = vfeedr.className.replace("Unread", "");
516 debug("toggle starred for aid " + id);
518 //new Ajax.Request(query); */
523 new Ajax
.Request(query
, {
524 onComplete: function(transport
) {
525 all_counters_callback2(transport
);
531 exception_error("toggleMark", e
);
535 function togglePub(id
, client_only
, no_effects
) {
539 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
541 query
= query
+ "&afid=" + getActiveFeedId();
543 if (tagsAreDisplayed()) {
544 query
= query
+ "&omode=tl";
546 query
= query
+ "&omode=flc";
549 var mark_img
= document
.getElementById("FPPIC-" + id
);
550 var vfeedu
= document
.getElementById("FEEDU--2");
551 var crow
= document
.getElementById("RROW-" + id
);
553 if (mark_img
.src
.match("pub_unset")) {
554 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
555 mark_img
.alt
= __("Unpublish article");
556 query
= query
+ "&pub=1";
558 /* if (vfeedu && crow.className.match("Unread")) {
559 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
563 //mark_img.src = "images/pub_unset.png";
564 mark_img
.alt
= __("Please wait...");
565 query
= query
+ "&pub=0";
567 /* if (vfeedu && crow.className.match("Unread")) {
568 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
571 if (document
.getElementById("headlinesList") && !no_effects
) {
572 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
574 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
575 mark_img
.alt
= __("Publish article");
579 /* var vfeedctr = document.getElementById("FEEDCTR--2");
580 var vfeedr = document.getElementById("FEEDR--2");
582 if (vfeedu && vfeedctr) {
583 if ((+vfeedu.innerHTML) > 0) {
584 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
585 vfeedr.className = vfeedr.className + "Unread";
586 vfeedctr.className = "odd";
589 vfeedctr.className = "invisible";
590 vfeedr.className = vfeedr.className.replace("Unread", "");
594 debug("toggle published for aid " + id);
596 new Ajax.Request(query); */
599 new Ajax
.Request(query
, {
600 onComplete: function(transport
) {
601 all_counters_callback2(transport
);
607 exception_error("togglePub", e
);
611 function correctHeadlinesOffset(id
) {
615 var hlist
= document
.getElementById("headlinesList");
616 var container
= document
.getElementById("headlinesInnerContainer");
617 var row
= document
.getElementById("RROW-" + id
);
619 var viewport
= container
.offsetHeight
;
621 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
622 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
624 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
625 debug("Vport: " + viewport
);
627 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
628 container
.scrollTop
= row
.offsetTop
;
629 } else if (rel_offset_bottom
> viewport
) {
631 /* doesn't properly work with Opera in some cases because
632 Opera fucks up element scrolling */
634 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
638 exception_error("correctHeadlinesOffset", e
);
643 function moveToPost(mode
) {
645 // check for combined mode
646 if (!document
.getElementById("headlinesList"))
649 var rows
= getVisibleHeadlineIds();
654 if (!document
.getElementById('RROW-' + active_post_id
)) {
655 active_post_id
= false;
658 if (active_post_id
== false) {
659 next_id
= getFirstVisibleHeadlineId();
660 prev_id
= getLastVisibleHeadlineId();
662 for (var i
= 0; i
< rows
.length
; i
++) {
663 if (rows
[i
] == active_post_id
) {
670 if (mode
== "next") {
672 correctHeadlinesOffset(next_id
);
673 view(next_id
, getActiveFeedId());
677 if (mode
== "prev") {
679 correctHeadlinesOffset(prev_id
);
680 view(prev_id
, getActiveFeedId());
685 function toggleUnread(id
, cmode
) {
688 var row
= document
.getElementById("RROW-" + id
);
690 var nc
= row
.className
;
691 nc
= nc
.replace("Unread", "");
692 nc
= nc
.replace("Selected", "");
694 if (cmode
== undefined || cmode
== 2) {
695 if (row
.className
.match("Unread")) {
698 row
.className
= nc
+ "Unread";
700 } else if (cmode
== 0) {
702 } else if (cmode
== 1) {
703 row
.className
= nc
+ "Unread";
706 if (cmode
== undefined) cmode
= 2;
708 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
709 param_escape(id
) + "&cmode=" + param_escape(cmode
);
711 // notify_progress("Loading, please wait...");
713 new Ajax
.Request(query
, {
714 onComplete: function(transport
) {
715 all_counters_callback2(transport
);
722 exception_error("toggleUnread", e
);
726 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
731 rows
= cdmGetSelectedArticles();
733 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
736 if (rows
.length
== 0 && !no_error
) {
737 alert(__("No articles are selected."));
741 for (i
= 0; i
< rows
.length
; i
++) {
742 var row
= document
.getElementById("RROW-" + rows
[i
]);
744 var nc
= row
.className
;
745 nc
= nc
.replace("Unread", "");
746 nc
= nc
.replace("Selected", "");
748 if (set_state
== undefined) {
749 if (row
.className
.match("Unread")) {
750 row
.className
= nc
+ "Selected";
752 row
.className
= nc
+ "UnreadSelected";
756 if (set_state
== false) {
757 row
.className
= nc
+ "Selected";
760 if (set_state
== true) {
761 row
.className
= nc
+ "UnreadSelected";
766 if (rows
.length
> 0) {
770 if (set_state
== undefined) {
772 } else if (set_state
== true) {
774 } else if (set_state
== false) {
778 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
779 param_escape(rows
.toString()) + "&cmode=" + cmode
;
781 notify_progress("Loading, please wait...");
783 new Ajax
.Request(query
, {
784 onComplete: function(transport
) {
785 catchup_callback2(transport
, callback_func
);
791 exception_error("selectionToggleUnread", e
);
795 function selectionToggleMarked(cdm_mode
) {
801 rows
= cdmGetSelectedArticles();
803 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
806 if (rows
.length
== 0) {
807 alert(__("No articles are selected."));
811 for (i
= 0; i
< rows
.length
; i
++) {
812 toggleMark(rows
[i
], true, true);
815 if (rows
.length
> 0) {
817 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
818 param_escape(rows
.toString()) + "&cmode=2";
820 query
= query
+ "&afid=" + getActiveFeedId();
822 /* if (tagsAreDisplayed()) {
823 query = query + "&omode=tl";
825 query = query + "&omode=flc";
828 query
= query
+ "&omode=lc";
830 new Ajax
.Request(query
, {
831 onComplete: function(transport
) {
832 all_counters_callback2(transport
);
838 exception_error("selectionToggleMarked", e
);
842 function selectionTogglePublished(cdm_mode
) {
848 rows
= cdmGetSelectedArticles();
850 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
853 if (rows
.length
== 0) {
854 alert(__("No articles are selected."));
858 for (i
= 0; i
< rows
.length
; i
++) {
859 togglePub(rows
[i
], true, true);
862 if (rows
.length
> 0) {
864 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
865 param_escape(rows
.toString()) + "&cmode=2";
867 query
= query
+ "&afid=" + getActiveFeedId();
869 /* if (tagsAreDisplayed()) {
870 query = query + "&omode=tl";
872 query = query + "&omode=flc";
875 query
= query
+ "&omode=lc";
877 new Ajax
.Request(query
, {
878 onComplete: function(transport
) {
879 all_counters_callback2(transport
);
885 exception_error("selectionToggleMarked", e
);
889 function cdmGetSelectedArticles() {
890 var sel_articles
= new Array();
891 var container
= document
.getElementById("headlinesInnerContainer");
893 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
894 var child
= container
.childNodes
[i
];
896 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
897 var c_id
= child
.id
.replace("RROW-", "");
898 sel_articles
.push(c_id
);
905 function cdmGetVisibleArticles() {
906 var sel_articles
= new Array();
907 var container
= document
.getElementById("headlinesInnerContainer");
909 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
910 var child
= container
.childNodes
[i
];
912 if (child
.id
.match("RROW-")) {
913 var c_id
= child
.id
.replace("RROW-", "");
914 sel_articles
.push(c_id
);
921 function cdmGetUnreadArticles() {
922 var sel_articles
= new Array();
923 var container
= document
.getElementById("headlinesInnerContainer");
925 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
926 var child
= container
.childNodes
[i
];
928 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
929 var c_id
= child
.id
.replace("RROW-", "");
930 sel_articles
.push(c_id
);
938 // mode = all,none,unread
939 function cdmSelectArticles(mode
) {
940 var container
= document
.getElementById("headlinesInnerContainer");
942 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
943 var child
= container
.childNodes
[i
];
945 if (child
.id
.match("RROW-")) {
946 var aid
= child
.id
.replace("RROW-", "");
948 var cb
= document
.getElementById("RCHK-" + aid
);
951 if (!child
.className
.match("Selected")) {
952 child
.className
= child
.className
+ "Selected";
955 } else if (mode
== "unread") {
956 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
957 child
.className
= child
.className
+ "Selected";
961 child
.className
= child
.className
.replace("Selected", "");
968 function catchupPage() {
970 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
972 var str
= __("Mark all visible articles in %s as read?");
974 str
= str
.replace("%s", fn
);
976 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
980 if (document
.getElementById("headlinesList")) {
981 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
982 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
983 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
985 cdmSelectArticles('all');
986 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
987 cdmSelectArticles('none');
991 function catchupSelection() {
997 if (document
.getElementById("headlinesList")) {
998 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1000 rows
= cdmGetSelectedArticles();
1003 if (rows
.length
== 0) {
1004 alert(__("No articles are selected."));
1009 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1011 var str
= __("Mark %d selected articles in %s as read?");
1013 str
= str
.replace("%d", rows
.length
);
1014 str
= str
.replace("%s", fn
);
1016 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1020 if (document
.getElementById("headlinesList")) {
1021 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1022 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1024 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1025 // cdmSelectArticles('none');
1029 exception_error("catchupSelection", e
);
1034 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1036 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1037 printLockingError();
1040 var title
= prompt(__("Please enter label title:"), "");
1044 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1045 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1046 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1047 "&title=" + param_escape(title
);
1049 debug("LFS: " + query
);
1051 new Ajax
.Request(query
, {
1052 onComplete: function(transport
) {
1053 dlg_frefresh_callback(transport
);
1058 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1059 _tag_active_post_id
= id
;
1060 _tag_active_feed_id
= feed_id
;
1061 _tag_active_cdm
= cdm_enabled
;
1063 cache_invalidate(id
);
1066 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1068 displayDlg('editArticleTags', id
);
1072 function tag_saved_callback(transport
) {
1074 debug("in tag_saved_callback");
1079 if (tagsAreDisplayed()) {
1080 _reload_feedlist_after_view
= true;
1083 if (!_tag_active_cdm
) {
1084 if (active_post_id
== _tag_active_post_id
) {
1085 debug("reloading current article");
1086 view(_tag_active_post_id
, _tag_active_feed_id
);
1089 debug("reloading current feed");
1094 exception_error("catchup_callback", e
);
1098 function editTagsSave() {
1100 notify_progress("Saving article tags...");
1102 var form
= document
.forms
["tag_edit_form"];
1104 var query
= Form
.serialize("tag_edit_form");
1106 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1110 new Ajax
.Request(query
, {
1111 onComplete: function(transport
) {
1112 tag_saved_callback(transport
);
1117 function editTagsInsert() {
1120 var form
= document
.forms
["tag_edit_form"];
1122 var found_tags
= form
.found_tags
;
1123 var tags_str
= form
.tags_str
;
1125 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1127 if (tags_str
.value
.length
> 0 &&
1128 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1130 tags_str
.value
= tags_str
.value
+ ", ";
1133 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1135 found_tags
.selectedIndex
= 0;
1138 exception_error(e
, "editTagsInsert");
1142 function cdmWatchdog() {
1146 var ctr
= document
.getElementById("headlinesInnerContainer");
1150 var ids
= new Array();
1152 var e
= ctr
.firstChild
;
1155 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1156 e
.id
.match("RROW-")) {
1158 // article fits in viewport OR article is longer than viewport and
1159 // its bottom is visible
1161 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1162 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1164 // debug(e.id + " is visible " + e.offsetTop + "." +
1165 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1166 // (ctr.scrollTop + ctr.offsetHeight));
1168 ids
.push(e
.id
.replace("RROW-", ""));
1170 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1171 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1172 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1174 ids
.push(e
.id
.replace("RROW-", ""));
1178 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1180 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1181 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1183 ids.push(e.id.replace("RROW-", ""));
1192 debug("cdmWatchdog, ids= " + ids
.toString());
1194 if (ids
.length
> 0) {
1196 for (var i
= 0; i
< ids
.length
; i
++) {
1197 var e
= document
.getElementById("RROW-" + ids
[i
]);
1199 e
.className
= e
.className
.replace("Unread", "");
1203 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1204 param_escape(ids
.toString()) + "&cmode=0";
1206 new Ajax
.Request(query
, {
1207 onComplete: function(transport
) {
1208 all_counters_callback2(transport
);
1213 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1216 exception_error(e
, "cdmWatchdog");
1222 function cache_inject(id
, article
, param
) {
1223 if (!cache_check_param(id
, param
)) {
1224 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1226 var cache_obj
= new Array();
1228 cache_obj
["id"] = id
;
1229 cache_obj
["data"] = article
;
1230 cache_obj
["param"] = param
;
1232 article_cache
.push(cache_obj
);
1235 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1239 function cache_find(id
) {
1240 for (var i
= 0; i
< article_cache
.length
; i
++) {
1241 if (article_cache
[i
]["id"] == id
) {
1242 return article_cache
[i
]["data"];
1248 function cache_find_param(id
, param
) {
1249 for (var i
= 0; i
< article_cache
.length
; i
++) {
1250 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1251 return article_cache
[i
]["data"];
1257 function cache_check(id
) {
1258 for (var i
= 0; i
< article_cache
.length
; i
++) {
1259 if (article_cache
[i
]["id"] == id
) {
1266 function cache_check_param(id
, param
) {
1267 for (var i
= 0; i
< article_cache
.length
; i
++) {
1269 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1270 // article_cache[i]["param"] + " vs " + id + ":" + param);
1272 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1279 function cache_expire() {
1280 while (article_cache
.length
> 20) {
1281 article_cache
.shift();
1285 function cache_invalidate(id
) {
1290 while (i
< article_cache
.length
) {
1291 if (article_cache
[i
]["id"] == id
) {
1292 debug("cache_invalidate: removed id " + id
);
1293 article_cache
.splice(i
, 1);
1298 debug("cache_invalidate: id not found: " + id
);
1301 exception_error("cache_invalidate", e
);
1305 function getActiveArticleId() {
1306 return active_post_id
;
1309 function cdmMouseIn(elem
) {
1311 if (elem
.id
&& elem
.id
.match("RROW-")) {
1312 var id
= elem
.id
.replace("RROW-", "");
1313 active_post_id
= id
;
1316 exception_error("cdmMouseIn", e
);
1321 function cdmMouseOut(elem
) {
1322 active_post_id
= false;
1325 function headlines_scroll_handler() {
1328 var e
= document
.getElementById("headlinesInnerContainer");
1330 // don't do infinite scrolling when Limit == All
1332 var toolbar_form
= document
.forms
["main_toolbar_form"];
1334 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1335 if (limit
.value
!= 0) {
1336 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1337 if (!_infscroll_disable
) {
1338 debug("more cowbell!");
1345 exception_error("headlines_scroll_handler", e
);
1349 function catchupRelativeToArticle(below
) {
1353 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1354 printLockingError();
1357 if (!getActiveArticleId()) {
1358 alert(__("No article is selected."));
1364 if (document
.getElementById("headlinesList")) {
1365 visible_ids
= getVisibleHeadlineIds();
1367 visible_ids
= cdmGetVisibleArticles();
1370 var ids_to_mark
= new Array();
1373 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1374 if (visible_ids
[i
] != getActiveArticleId()) {
1375 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1377 if (e
&& e
.className
.match("Unread")) {
1378 ids_to_mark
.push(visible_ids
[i
]);
1385 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1386 if (visible_ids
[i
] != getActiveArticleId()) {
1387 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1389 if (e
&& e
.className
.match("Unread")) {
1390 ids_to_mark
.push(visible_ids
[i
]);
1398 if (ids_to_mark
.length
== 0) {
1399 alert(__("No articles found to mark"));
1401 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1405 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1406 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1407 e
.className
= e
.className
.replace("Unread", "");
1410 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1411 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1413 new Ajax
.Request(query
, {
1414 onComplete: function(transport
) {
1415 catchup_callback2(transport
);
1422 exception_error("catchupRelativeToArticle", e
);
1426 function cdmExpandArticle(a_id
) {
1428 var id
= 'CICD-' + a_id
;
1430 Effect
.Appear(id
, {duration
: 0.5,
1431 beforeStart: function(effect
) {
1432 var h_id
= 'CICH-' + a_id
;
1433 var h_elem
= document
.getElementById(h_id
);
1434 if (h_elem
) { h_elem
.style
.display
= "none"; }
1436 toggleUnread(a_id
, 0);
1441 exception_error("appearBlockElementF", e
);