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
);
254 upd_img_pic
.src
= "images/blank_icon.gif";
257 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
261 exception_error("showArticleInHeadlines", e
);
265 function article_callback2(transport
, id
, feed_id
) {
267 debug("article_callback2 " + id
);
269 if (transport
.responseXML
) {
271 active_real_feed_id
= feed_id
;
274 showArticleInHeadlines(id
);
276 var reply
= transport
.responseXML
.firstChild
.firstChild
;
278 var articles
= transport
.responseXML
.getElementsByTagName("article");
280 for (var i
= 0; i
< articles
.length
; i
++) {
281 var a_id
= articles
[i
].getAttribute("id");
283 debug("found id: " + a_id
);
285 if (a_id
== active_post_id
) {
286 debug("active article, rendering...");
287 render_article(articles
[i
].firstChild
.nodeValue
);
290 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
294 debug("article_callback: returned no XML object");
295 var f
= document
.getElementById("content-frame");
296 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
299 var date
= new Date();
300 last_article_view
= date
.getTime() / 1000;
302 if (typeof correctPNG
!= 'undefined') {
306 if (_reload_feedlist_after_view
) {
307 setTimeout('updateFeedList(false, false)', 50);
308 _reload_feedlist_after_view
= false;
310 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
313 debug("parsing piggybacked counters: " + counters
);
314 parse_counters(counters
, false);
316 debug("counters container not found in reply");
322 exception_error("article_callback2", e
);
326 function view(id
, feed_id
, skip_history
) {
329 debug("loading article: " + id
+ "/" + feed_id
);
331 var cached_article
= cache_find(id
);
333 debug("cache check result: " + (cached_article
!= false));
337 //setActiveFeedId(feed_id);
339 var query
= "backend.php?op=view&id=" + param_escape(id
) +
340 "&feed=" + param_escape(feed_id
);
342 var date
= new Date();
344 var neighbor_ids
= getRelativePostIds(active_post_id
);
346 /* only request uncached articles */
348 var cids_to_request
= Array();
350 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
351 if (!cache_check(neighbor_ids
[i
])) {
352 cids_to_request
.push(neighbor_ids
[i
]);
356 debug("additional ids: " + cids_to_request
.toString());
358 /* additional info for piggyback counters */
360 if (tagsAreDisplayed()) {
361 query
= query
+ "&omode=lt";
363 query
= query
+ "&omode=flc";
366 var date
= new Date();
367 var timestamp
= Math
.round(date
.getTime() / 1000);
368 query
= query
+ "&ts=" + timestamp
;
370 query
= query
+ "&cids=" + cids_to_request
.toString();
372 var crow
= document
.getElementById("RROW-" + id
);
373 var article_is_unread
= crow
.className
.match("Unread");
375 showArticleInHeadlines(id
);
377 if (!cached_article
) {
379 notify_progress("Loading, please wait...");
381 } else if (cached_article
&& article_is_unread
) {
383 query
= query
+ "&mode=prefetch";
385 render_article(cached_article
);
387 } else if (cached_article
) {
389 query
= query
+ "&mode=prefetch_old";
390 render_article(cached_article
);
395 new Ajax
.Request(query
, {
396 onComplete: function(transport
) {
397 article_callback2(transport
, id
, feed_id
);
401 exception_error("view", e
);
406 return toggleMark(id
);
410 return togglePub(id
);
413 function tMark_afh_off(effect
) {
415 var elem
= effect
.effects
[0].element
;
417 debug("tMark_afh_off : " + elem
.id
);
420 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
421 elem
.alt
= __("Star article");
426 exception_error("tMark_afh_off", e
);
430 function tPub_afh_off(effect
) {
432 var elem
= effect
.effects
[0].element
;
434 debug("tPub_afh_off : " + elem
.id
);
437 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
438 elem
.alt
= __("Publish article");
443 exception_error("tPub_afh_off", e
);
447 function toggleMark(id
, client_only
, no_effects
) {
451 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
453 query
= query
+ "&afid=" + getActiveFeedId();
455 if (tagsAreDisplayed()) {
456 query
= query
+ "&omode=tl";
458 query
= query
+ "&omode=flc";
461 var mark_img
= document
.getElementById("FMPIC-" + id
);
462 var vfeedu
= document
.getElementById("FEEDU--1");
463 var crow
= document
.getElementById("RROW-" + id
);
465 if (mark_img
.src
.match("mark_unset")) {
466 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
467 mark_img
.alt
= __("Unstar article");
468 query
= query
+ "&mark=1";
470 /* if (vfeedu && crow.className.match("Unread")) {
471 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
475 //mark_img.src = "images/mark_unset.png";
476 mark_img
.alt
= __("Please wait...");
477 query
= query
+ "&mark=0";
479 /* if (vfeedu && crow.className.match("Unread")) {
480 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
483 if (document
.getElementById("headlinesList") && !no_effects
) {
484 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
486 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
487 mark_img
.alt
= __("Star article");
491 /* var vfeedctr = document.getElementById("FEEDCTR--1");
492 var vfeedr = document.getElementById("FEEDR--1");
494 if (vfeedu && vfeedctr) {
495 if ((+vfeedu.innerHTML) > 0) {
496 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
497 vfeedr.className = vfeedr.className + "Unread";
498 vfeedctr.className = "odd";
501 vfeedctr.className = "invisible";
502 vfeedr.className = vfeedr.className.replace("Unread", "");
506 debug("toggle starred for aid " + id);
508 //new Ajax.Request(query); */
513 new Ajax
.Request(query
, {
514 onComplete: function(transport
) {
515 all_counters_callback2(transport
);
521 exception_error("toggleMark", e
);
525 function togglePub(id
, client_only
, no_effects
) {
529 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
531 query
= query
+ "&afid=" + getActiveFeedId();
533 if (tagsAreDisplayed()) {
534 query
= query
+ "&omode=tl";
536 query
= query
+ "&omode=flc";
539 var mark_img
= document
.getElementById("FPPIC-" + id
);
540 var vfeedu
= document
.getElementById("FEEDU--2");
541 var crow
= document
.getElementById("RROW-" + id
);
543 if (mark_img
.src
.match("pub_unset")) {
544 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
545 mark_img
.alt
= __("Unpublish article");
546 query
= query
+ "&pub=1";
548 /* if (vfeedu && crow.className.match("Unread")) {
549 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
553 //mark_img.src = "images/pub_unset.png";
554 mark_img
.alt
= __("Please wait...");
555 query
= query
+ "&pub=0";
557 /* if (vfeedu && crow.className.match("Unread")) {
558 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
561 if (document
.getElementById("headlinesList") && !no_effects
) {
562 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
564 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
565 mark_img
.alt
= __("Publish article");
569 /* var vfeedctr = document.getElementById("FEEDCTR--2");
570 var vfeedr = document.getElementById("FEEDR--2");
572 if (vfeedu && vfeedctr) {
573 if ((+vfeedu.innerHTML) > 0) {
574 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
575 vfeedr.className = vfeedr.className + "Unread";
576 vfeedctr.className = "odd";
579 vfeedctr.className = "invisible";
580 vfeedr.className = vfeedr.className.replace("Unread", "");
584 debug("toggle published for aid " + id);
586 new Ajax.Request(query); */
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
) {
635 // check for combined mode
636 if (!document
.getElementById("headlinesList"))
639 var rows
= getVisibleHeadlineIds();
644 if (!document
.getElementById('RROW-' + active_post_id
)) {
645 active_post_id
= false;
648 if (active_post_id
== false) {
649 next_id
= getFirstVisibleHeadlineId();
650 prev_id
= getLastVisibleHeadlineId();
652 for (var i
= 0; i
< rows
.length
; i
++) {
653 if (rows
[i
] == active_post_id
) {
660 if (mode
== "next") {
662 correctHeadlinesOffset(next_id
);
663 view(next_id
, getActiveFeedId());
667 if (mode
== "prev") {
669 correctHeadlinesOffset(prev_id
);
670 view(prev_id
, getActiveFeedId());
675 function toggleUnread(id
, cmode
) {
678 var row
= document
.getElementById("RROW-" + id
);
680 var nc
= row
.className
;
681 nc
= nc
.replace("Unread", "");
682 nc
= nc
.replace("Selected", "");
684 if (cmode
== undefined || cmode
== 2) {
685 if (row
.className
.match("Unread")) {
688 row
.className
= nc
+ "Unread";
690 } else if (cmode
== 0) {
692 } else if (cmode
== 1) {
693 row
.className
= nc
+ "Unread";
696 if (cmode
== undefined) cmode
= 2;
698 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
699 param_escape(id
) + "&cmode=" + param_escape(cmode
);
701 // notify_progress("Loading, please wait...");
703 new Ajax
.Request(query
, {
704 onComplete: function(transport
) {
705 all_counters_callback2(transport
);
712 exception_error("toggleUnread", e
);
716 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
721 rows
= cdmGetSelectedArticles();
723 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
726 if (rows
.length
== 0 && !no_error
) {
727 alert(__("No articles are selected."));
731 for (i
= 0; i
< rows
.length
; i
++) {
732 var row
= document
.getElementById("RROW-" + rows
[i
]);
734 var nc
= row
.className
;
735 nc
= nc
.replace("Unread", "");
736 nc
= nc
.replace("Selected", "");
738 if (set_state
== undefined) {
739 if (row
.className
.match("Unread")) {
740 row
.className
= nc
+ "Selected";
742 row
.className
= nc
+ "UnreadSelected";
746 if (set_state
== false) {
747 row
.className
= nc
+ "Selected";
750 if (set_state
== true) {
751 row
.className
= nc
+ "UnreadSelected";
756 if (rows
.length
> 0) {
760 if (set_state
== undefined) {
762 } else if (set_state
== true) {
764 } else if (set_state
== false) {
768 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
769 param_escape(rows
.toString()) + "&cmode=" + cmode
;
771 notify_progress("Loading, please wait...");
773 new Ajax
.Request(query
, {
774 onComplete: function(transport
) {
775 catchup_callback2(transport
, callback_func
);
781 exception_error("selectionToggleUnread", e
);
785 function selectionToggleMarked(cdm_mode
) {
791 rows
= cdmGetSelectedArticles();
793 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
796 if (rows
.length
== 0) {
797 alert(__("No articles are selected."));
801 for (i
= 0; i
< rows
.length
; i
++) {
802 toggleMark(rows
[i
], true, true);
805 if (rows
.length
> 0) {
807 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
808 param_escape(rows
.toString()) + "&cmode=2";
810 query
= query
+ "&afid=" + getActiveFeedId();
812 /* if (tagsAreDisplayed()) {
813 query = query + "&omode=tl";
815 query = query + "&omode=flc";
818 query
= query
+ "&omode=lc";
820 new Ajax
.Request(query
, {
821 onComplete: function(transport
) {
822 all_counters_callback2(transport
);
828 exception_error("selectionToggleMarked", e
);
832 function selectionTogglePublished(cdm_mode
) {
838 rows
= cdmGetSelectedArticles();
840 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
843 if (rows
.length
== 0) {
844 alert(__("No articles are selected."));
848 for (i
= 0; i
< rows
.length
; i
++) {
849 togglePub(rows
[i
], true, true);
852 if (rows
.length
> 0) {
854 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
855 param_escape(rows
.toString()) + "&cmode=2";
857 query
= query
+ "&afid=" + getActiveFeedId();
859 /* if (tagsAreDisplayed()) {
860 query = query + "&omode=tl";
862 query = query + "&omode=flc";
865 query
= query
+ "&omode=lc";
867 new Ajax
.Request(query
, {
868 onComplete: function(transport
) {
869 all_counters_callback2(transport
);
875 exception_error("selectionToggleMarked", e
);
879 function cdmGetSelectedArticles() {
880 var sel_articles
= new Array();
881 var container
= document
.getElementById("headlinesInnerContainer");
883 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
884 var child
= container
.childNodes
[i
];
886 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
887 var c_id
= child
.id
.replace("RROW-", "");
888 sel_articles
.push(c_id
);
895 function cdmGetVisibleArticles() {
896 var sel_articles
= new Array();
897 var container
= document
.getElementById("headlinesInnerContainer");
899 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
900 var child
= container
.childNodes
[i
];
902 if (child
.id
.match("RROW-")) {
903 var c_id
= child
.id
.replace("RROW-", "");
904 sel_articles
.push(c_id
);
911 function cdmGetUnreadArticles() {
912 var sel_articles
= new Array();
913 var container
= document
.getElementById("headlinesInnerContainer");
915 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
916 var child
= container
.childNodes
[i
];
918 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
919 var c_id
= child
.id
.replace("RROW-", "");
920 sel_articles
.push(c_id
);
928 // mode = all,none,unread
929 function cdmSelectArticles(mode
) {
930 var container
= document
.getElementById("headlinesInnerContainer");
932 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
933 var child
= container
.childNodes
[i
];
935 if (child
.id
.match("RROW-")) {
936 var aid
= child
.id
.replace("RROW-", "");
938 var cb
= document
.getElementById("RCHK-" + aid
);
941 if (!child
.className
.match("Selected")) {
942 child
.className
= child
.className
+ "Selected";
945 } else if (mode
== "unread") {
946 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
947 child
.className
= child
.className
+ "Selected";
951 child
.className
= child
.className
.replace("Selected", "");
958 function catchupPage() {
960 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
962 var str
= __("Mark all visible articles in %s as read?");
964 str
= str
.replace("%s", fn
);
966 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
970 if (document
.getElementById("headlinesList")) {
971 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
972 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
973 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
975 cdmSelectArticles('all');
976 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
977 cdmSelectArticles('none');
981 function catchupSelection() {
987 if (document
.getElementById("headlinesList")) {
988 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
990 rows
= cdmGetSelectedArticles();
993 if (rows
.length
== 0) {
994 alert(__("No articles are selected."));
999 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1001 var str
= __("Mark %d selected articles in %s as read?");
1003 str
= str
.replace("%d", rows
.length
);
1004 str
= str
.replace("%s", fn
);
1006 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1010 if (document
.getElementById("headlinesList")) {
1011 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1012 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1014 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1015 // cdmSelectArticles('none');
1019 exception_error("catchupSelection", e
);
1024 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1026 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1027 printLockingError();
1030 var title
= prompt(__("Please enter label title:"), "");
1034 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1035 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1036 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1037 "&title=" + param_escape(title
);
1039 debug("LFS: " + query
);
1041 new Ajax
.Request(query
, {
1042 onComplete: function(transport
) {
1043 dlg_frefresh_callback(transport
);
1048 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1049 _tag_active_post_id
= id
;
1050 _tag_active_feed_id
= feed_id
;
1051 _tag_active_cdm
= cdm_enabled
;
1053 cache_invalidate(id
);
1056 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1058 displayDlg('editArticleTags', id
);
1062 function tag_saved_callback(transport
) {
1064 debug("in tag_saved_callback");
1069 if (tagsAreDisplayed()) {
1070 _reload_feedlist_after_view
= true;
1073 if (!_tag_active_cdm
) {
1074 if (active_post_id
== _tag_active_post_id
) {
1075 debug("reloading current article");
1076 view(_tag_active_post_id
, _tag_active_feed_id
);
1079 debug("reloading current feed");
1084 exception_error("catchup_callback", e
);
1088 function editTagsSave() {
1090 notify_progress("Saving article tags...");
1092 var form
= document
.forms
["tag_edit_form"];
1094 var query
= Form
.serialize("tag_edit_form");
1096 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1100 new Ajax
.Request(query
, {
1101 onComplete: function(transport
) {
1102 tag_saved_callback(transport
);
1107 function editTagsInsert() {
1110 var form
= document
.forms
["tag_edit_form"];
1112 var found_tags
= form
.found_tags
;
1113 var tags_str
= form
.tags_str
;
1115 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1117 if (tags_str
.value
.length
> 0 &&
1118 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1120 tags_str
.value
= tags_str
.value
+ ", ";
1123 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1125 found_tags
.selectedIndex
= 0;
1128 exception_error(e
, "editTagsInsert");
1132 function cdmWatchdog() {
1136 var ctr
= document
.getElementById("headlinesInnerContainer");
1140 var ids
= new Array();
1142 var e
= ctr
.firstChild
;
1145 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1146 e
.id
.match("RROW-")) {
1148 // article fits in viewport OR article is longer than viewport and
1149 // its bottom is visible
1151 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1152 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1154 // debug(e.id + " is visible " + e.offsetTop + "." +
1155 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1156 // (ctr.scrollTop + ctr.offsetHeight));
1158 ids
.push(e
.id
.replace("RROW-", ""));
1160 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1161 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1162 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1164 ids
.push(e
.id
.replace("RROW-", ""));
1168 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1170 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1171 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1173 ids.push(e.id.replace("RROW-", ""));
1182 debug("cdmWatchdog, ids= " + ids
.toString());
1184 if (ids
.length
> 0) {
1186 for (var i
= 0; i
< ids
.length
; i
++) {
1187 var e
= document
.getElementById("RROW-" + ids
[i
]);
1189 e
.className
= e
.className
.replace("Unread", "");
1193 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1194 param_escape(ids
.toString()) + "&cmode=0";
1196 new Ajax
.Request(query
, {
1197 onComplete: function(transport
) {
1198 all_counters_callback2(transport
);
1203 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1206 exception_error(e
, "cdmWatchdog");
1212 function cache_inject(id
, article
, param
) {
1213 if (!cache_check_param(id
, param
)) {
1214 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1216 var cache_obj
= new Array();
1218 cache_obj
["id"] = id
;
1219 cache_obj
["data"] = article
;
1220 cache_obj
["param"] = param
;
1222 article_cache
.push(cache_obj
);
1225 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1229 function cache_find(id
) {
1230 for (var i
= 0; i
< article_cache
.length
; i
++) {
1231 if (article_cache
[i
]["id"] == id
) {
1232 return article_cache
[i
]["data"];
1238 function cache_find_param(id
, param
) {
1239 for (var i
= 0; i
< article_cache
.length
; i
++) {
1240 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1241 return article_cache
[i
]["data"];
1247 function cache_check(id
) {
1248 for (var i
= 0; i
< article_cache
.length
; i
++) {
1249 if (article_cache
[i
]["id"] == id
) {
1256 function cache_check_param(id
, param
) {
1257 for (var i
= 0; i
< article_cache
.length
; i
++) {
1259 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1260 // article_cache[i]["param"] + " vs " + id + ":" + param);
1262 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1269 function cache_expire() {
1270 while (article_cache
.length
> 20) {
1271 article_cache
.shift();
1275 function cache_invalidate(id
) {
1280 while (i
< article_cache
.length
) {
1281 if (article_cache
[i
]["id"] == id
) {
1282 debug("cache_invalidate: removed id " + id
);
1283 article_cache
.splice(i
, 1);
1288 debug("cache_invalidate: id not found: " + id
);
1291 exception_error("cache_invalidate", e
);
1295 function getActiveArticleId() {
1296 return active_post_id
;
1299 function cdmMouseIn(elem
) {
1301 if (elem
.id
&& elem
.id
.match("RROW-")) {
1302 var id
= elem
.id
.replace("RROW-", "");
1303 active_post_id
= id
;
1306 exception_error("cdmMouseIn", e
);
1311 function cdmMouseOut(elem
) {
1312 active_post_id
= false;
1315 function headlines_scroll_handler() {
1318 var e
= document
.getElementById("headlinesInnerContainer");
1320 // don't do infinite scrolling when Limit == All
1322 var toolbar_form
= document
.forms
["main_toolbar_form"];
1324 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1325 if (limit
.value
!= 0) {
1326 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1327 if (!_infscroll_disable
) {
1328 debug("more cowbell!");
1335 exception_error("headlines_scroll_handler", e
);
1339 function catchupRelativeToArticle(below
) {
1343 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1344 printLockingError();
1347 if (!getActiveArticleId()) {
1348 alert(__("No article is selected."));
1354 if (document
.getElementById("headlinesList")) {
1355 visible_ids
= getVisibleHeadlineIds();
1357 visible_ids
= cdmGetVisibleArticles();
1360 var ids_to_mark
= new Array();
1363 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1364 if (visible_ids
[i
] != getActiveArticleId()) {
1365 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1367 if (e
&& e
.className
.match("Unread")) {
1368 ids_to_mark
.push(visible_ids
[i
]);
1375 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1376 if (visible_ids
[i
] != getActiveArticleId()) {
1377 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1379 if (e
&& e
.className
.match("Unread")) {
1380 ids_to_mark
.push(visible_ids
[i
]);
1388 if (ids_to_mark
.length
== 0) {
1389 alert(__("No articles found to mark"));
1391 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1395 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1396 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1397 e
.className
= e
.className
.replace("Unread", "");
1400 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1401 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1403 new Ajax
.Request(query
, {
1404 onComplete: function(transport
) {
1405 catchup_callback2(transport
);
1412 exception_error("catchupRelativeToArticle", e
);
1416 function cdmExpandArticle(a_id
) {
1418 var id
= 'CICD-' + a_id
;
1420 Effect
.Appear(id
, {duration
: 0.5,
1421 beforeStart: function(effect
) {
1422 var h_id
= 'CICH-' + a_id
;
1423 var h_elem
= document
.getElementById(h_id
);
1424 if (h_elem
) { h_elem
.style
.display
= "none"; }
1426 toggleUnread(a_id
, 0);
1431 exception_error("appearBlockElementF", e
);