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];
95 var headlines_count
= headlines_count_obj
.getAttribute("value");
96 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
98 if (headlines_count
== 0) _infscroll_disable
= 1;
100 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
101 var articles
= transport
.responseXML
.getElementsByTagName("article");
102 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
104 if (feed_cur_page
== 0) {
106 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
108 var cache_prefix
= "";
116 cache_inject(cache_prefix
+ active_feed_id
,
117 headlines
.firstChild
.nodeValue
, headlines_unread
);
120 debug("headlines_callback: returned no data");
121 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
126 if (headlines_count
> 0) {
127 debug("adding some more headlines...");
129 var c
= document
.getElementById("headlinesList");
132 c
= document
.getElementById("headlinesInnerContainer");
135 var ids
= getSelectedArticleIds2();
137 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
139 debug("restore selected ids: " + ids
);
141 for (var i
= 0; i
< ids
.length
; i
++) {
142 markHeadline(ids
[i
]);
146 debug("no new headlines received");
149 debug("headlines_callback: returned no data");
150 notify_error("Error while trying to load more headlines");
156 for (var i
= 0; i
< articles
.length
; i
++) {
157 var a_id
= articles
[i
].getAttribute("id");
158 debug("found id: " + a_id
);
159 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
162 debug("no cached articles received");
166 debug("parsing piggybacked counters: " + counters
);
167 parse_counters(counters
, false);
169 debug("counters container not found in reply");
173 debug("parsing runtime info: " + runtime_info
[0]);
174 parse_runtime_info(runtime_info
[0]);
176 debug("counters container not found in reply");
180 debug("headlines_callback: returned no XML object");
181 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
184 if (typeof correctPNG
!= 'undefined') {
188 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
190 if (!document
.getElementById("headlinesList") &&
191 getInitParam("cdm_auto_catchup") == 1) {
192 debug("starting CDM watchdog");
193 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
194 _cdm_wd_vishist
= new Array();
196 debug("not in CDM mode or watchdog disabled");
199 if (_tag_cdm_scroll
) {
201 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
202 _tag_cdm_scroll
= false;
203 debug("resetting headlinesInner scrollTop");
208 _feed_cur_page
= feed_cur_page
;
209 _infscroll_request_sent
= 0;
213 exception_error("headlines_callback2", e
);
217 function render_article(article
) {
219 var f
= document
.getElementById("content-frame");
224 f
.innerHTML
= article
;
227 exception_error("render_article", e
);
231 function showArticleInHeadlines(id
) {
235 cleanSelected("headlinesList");
237 var crow
= document
.getElementById("RROW-" + id
);
241 var article_is_unread
= crow
.className
.match("Unread");
243 crow
.className
= crow
.className
.replace("Unread", "");
245 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
248 upd_img_pic
.src
= "images/blank_icon.gif";
251 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
255 exception_error("showArticleInHeadlines", e
);
259 function article_callback2(transport
, id
, feed_id
) {
261 debug("article_callback2 " + id
);
263 if (transport
.responseXML
) {
265 active_real_feed_id
= feed_id
;
268 showArticleInHeadlines(id
);
270 var reply
= transport
.responseXML
.firstChild
.firstChild
;
272 var articles
= transport
.responseXML
.getElementsByTagName("article");
274 for (var i
= 0; i
< articles
.length
; i
++) {
275 var a_id
= articles
[i
].getAttribute("id");
277 debug("found id: " + a_id
);
279 if (a_id
== active_post_id
) {
280 debug("active article, rendering...");
281 render_article(articles
[i
].firstChild
.nodeValue
);
284 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
288 debug("article_callback: returned no XML object");
289 var f
= document
.getElementById("content-frame");
290 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
293 var date
= new Date();
294 last_article_view
= date
.getTime() / 1000;
296 if (typeof correctPNG
!= 'undefined') {
300 if (_reload_feedlist_after_view
) {
301 setTimeout('updateFeedList(false, false)', 50);
302 _reload_feedlist_after_view
= false;
304 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
307 debug("parsing piggybacked counters: " + counters
);
308 parse_counters(counters
, false);
310 debug("counters container not found in reply");
316 exception_error("article_callback2", e
);
320 function view(id
, feed_id
, skip_history
) {
323 debug("loading article: " + id
+ "/" + feed_id
);
325 var cached_article
= cache_find(id
);
327 debug("cache check result: " + (cached_article
!= false));
331 //setActiveFeedId(feed_id);
333 var query
= "backend.php?op=view&id=" + param_escape(id
) +
334 "&feed=" + param_escape(feed_id
);
336 var date
= new Date();
338 var neighbor_ids
= getRelativePostIds(active_post_id
);
340 /* only request uncached articles */
342 var cids_to_request
= Array();
344 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
345 if (!cache_check(neighbor_ids
[i
])) {
346 cids_to_request
.push(neighbor_ids
[i
]);
350 debug("additional ids: " + cids_to_request
.toString());
352 /* additional info for piggyback counters */
354 if (tagsAreDisplayed()) {
355 query
= query
+ "&omode=lt";
357 query
= query
+ "&omode=flc";
360 var date
= new Date();
361 var timestamp
= Math
.round(date
.getTime() / 1000);
362 query
= query
+ "&ts=" + timestamp
;
364 query
= query
+ "&cids=" + cids_to_request
.toString();
366 var crow
= document
.getElementById("RROW-" + id
);
367 var article_is_unread
= crow
.className
.match("Unread");
369 showArticleInHeadlines(id
);
371 if (!cached_article
) {
373 notify_progress("Loading, please wait...");
375 } else if (cached_article
&& article_is_unread
) {
377 query
= query
+ "&mode=prefetch";
379 render_article(cached_article
);
381 } else if (cached_article
) {
383 query
= query
+ "&mode=prefetch_old";
384 render_article(cached_article
);
389 new Ajax
.Request(query
, {
390 onComplete: function(transport
) {
391 article_callback2(transport
, id
, feed_id
);
395 exception_error("view", e
);
400 return toggleMark(id
);
404 return togglePub(id
);
407 function tMark_afh_off(effect
) {
409 var elem
= effect
.effects
[0].element
;
411 debug("tMark_afh_off : " + elem
.id
);
414 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
415 elem
.alt
= __("Star article");
420 exception_error("tMark_afh_off", e
);
424 function tPub_afh_off(effect
) {
426 var elem
= effect
.effects
[0].element
;
428 debug("tPub_afh_off : " + elem
.id
);
431 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
432 elem
.alt
= __("Publish article");
437 exception_error("tPub_afh_off", e
);
441 function toggleMark(id
, client_only
, no_effects
) {
445 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
447 query
= query
+ "&afid=" + getActiveFeedId();
449 if (tagsAreDisplayed()) {
450 query
= query
+ "&omode=tl";
452 query
= query
+ "&omode=flc";
455 var mark_img
= document
.getElementById("FMPIC-" + id
);
456 var vfeedu
= document
.getElementById("FEEDU--1");
457 var crow
= document
.getElementById("RROW-" + id
);
459 if (mark_img
.src
.match("mark_unset")) {
460 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
461 mark_img
.alt
= __("Unstar article");
462 query
= query
+ "&mark=1";
464 /* if (vfeedu && crow.className.match("Unread")) {
465 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
469 //mark_img.src = "images/mark_unset.png";
470 mark_img
.alt
= __("Please wait...");
471 query
= query
+ "&mark=0";
473 /* if (vfeedu && crow.className.match("Unread")) {
474 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
477 if (document
.getElementById("headlinesList") && !no_effects
) {
478 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
480 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
481 mark_img
.alt
= __("Star article");
485 /* var vfeedctr = document.getElementById("FEEDCTR--1");
486 var vfeedr = document.getElementById("FEEDR--1");
488 if (vfeedu && vfeedctr) {
489 if ((+vfeedu.innerHTML) > 0) {
490 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
491 vfeedr.className = vfeedr.className + "Unread";
492 vfeedctr.className = "odd";
495 vfeedctr.className = "invisible";
496 vfeedr.className = vfeedr.className.replace("Unread", "");
500 debug("toggle starred for aid " + id);
502 //new Ajax.Request(query); */
507 new Ajax
.Request(query
, {
508 onComplete: function(transport
) {
509 all_counters_callback2(transport
);
515 exception_error("toggleMark", e
);
519 function togglePub(id
, client_only
, no_effects
) {
523 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
525 query
= query
+ "&afid=" + getActiveFeedId();
527 if (tagsAreDisplayed()) {
528 query
= query
+ "&omode=tl";
530 query
= query
+ "&omode=flc";
533 var mark_img
= document
.getElementById("FPPIC-" + id
);
534 var vfeedu
= document
.getElementById("FEEDU--2");
535 var crow
= document
.getElementById("RROW-" + id
);
537 if (mark_img
.src
.match("pub_unset")) {
538 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
539 mark_img
.alt
= __("Unpublish article");
540 query
= query
+ "&pub=1";
542 /* if (vfeedu && crow.className.match("Unread")) {
543 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
547 //mark_img.src = "images/pub_unset.png";
548 mark_img
.alt
= __("Please wait...");
549 query
= query
+ "&pub=0";
551 /* if (vfeedu && crow.className.match("Unread")) {
552 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
555 if (document
.getElementById("headlinesList") && !no_effects
) {
556 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
558 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
559 mark_img
.alt
= __("Publish article");
563 /* var vfeedctr = document.getElementById("FEEDCTR--2");
564 var vfeedr = document.getElementById("FEEDR--2");
566 if (vfeedu && vfeedctr) {
567 if ((+vfeedu.innerHTML) > 0) {
568 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
569 vfeedr.className = vfeedr.className + "Unread";
570 vfeedctr.className = "odd";
573 vfeedctr.className = "invisible";
574 vfeedr.className = vfeedr.className.replace("Unread", "");
578 debug("toggle published for aid " + id);
580 new Ajax.Request(query); */
583 new Ajax
.Request(query
, {
584 onComplete: function(transport
) {
585 all_counters_callback2(transport
);
591 exception_error("togglePub", e
);
595 function correctHeadlinesOffset(id
) {
599 var hlist
= document
.getElementById("headlinesList");
600 var container
= document
.getElementById("headlinesInnerContainer");
601 var row
= document
.getElementById("RROW-" + id
);
603 var viewport
= container
.offsetHeight
;
605 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
606 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
608 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
609 debug("Vport: " + viewport
);
611 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
612 container
.scrollTop
= row
.offsetTop
;
613 } else if (rel_offset_bottom
> viewport
) {
615 /* doesn't properly work with Opera in some cases because
616 Opera fucks up element scrolling */
618 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
622 exception_error("correctHeadlinesOffset", e
);
627 function moveToPost(mode
) {
629 // check for combined mode
630 if (!document
.getElementById("headlinesList"))
633 var rows
= getVisibleHeadlineIds();
638 if (!document
.getElementById('RROW-' + active_post_id
)) {
639 active_post_id
= false;
642 if (active_post_id
== false) {
643 next_id
= getFirstVisibleHeadlineId();
644 prev_id
= getLastVisibleHeadlineId();
646 for (var i
= 0; i
< rows
.length
; i
++) {
647 if (rows
[i
] == active_post_id
) {
654 if (mode
== "next") {
656 correctHeadlinesOffset(next_id
);
657 view(next_id
, getActiveFeedId());
661 if (mode
== "prev") {
663 correctHeadlinesOffset(prev_id
);
664 view(prev_id
, getActiveFeedId());
669 function toggleUnread(id
, cmode
) {
672 var row
= document
.getElementById("RROW-" + id
);
674 var nc
= row
.className
;
675 nc
= nc
.replace("Unread", "");
676 nc
= nc
.replace("Selected", "");
678 if (cmode
== undefined || cmode
== 2) {
679 if (row
.className
.match("Unread")) {
682 row
.className
= nc
+ "Unread";
684 } else if (cmode
== 0) {
686 } else if (cmode
== 1) {
687 row
.className
= nc
+ "Unread";
690 if (cmode
== undefined) cmode
= 2;
692 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
693 param_escape(id
) + "&cmode=" + param_escape(cmode
);
695 // notify_progress("Loading, please wait...");
697 new Ajax
.Request(query
, {
698 onComplete: function(transport
) {
699 all_counters_callback2(transport
);
706 exception_error("toggleUnread", e
);
710 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
715 rows
= cdmGetSelectedArticles();
717 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
720 if (rows
.length
== 0 && !no_error
) {
721 alert(__("No articles are selected."));
725 for (i
= 0; i
< rows
.length
; i
++) {
726 var row
= document
.getElementById("RROW-" + rows
[i
]);
728 var nc
= row
.className
;
729 nc
= nc
.replace("Unread", "");
730 nc
= nc
.replace("Selected", "");
732 if (set_state
== undefined) {
733 if (row
.className
.match("Unread")) {
734 row
.className
= nc
+ "Selected";
736 row
.className
= nc
+ "UnreadSelected";
740 if (set_state
== false) {
741 row
.className
= nc
+ "Selected";
744 if (set_state
== true) {
745 row
.className
= nc
+ "UnreadSelected";
750 if (rows
.length
> 0) {
754 if (set_state
== undefined) {
756 } else if (set_state
== true) {
758 } else if (set_state
== false) {
762 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
763 param_escape(rows
.toString()) + "&cmode=" + cmode
;
765 notify_progress("Loading, please wait...");
767 new Ajax
.Request(query
, {
768 onComplete: function(transport
) {
769 catchup_callback2(transport
, callback_func
);
775 exception_error("selectionToggleUnread", e
);
779 function selectionToggleMarked(cdm_mode
) {
785 rows
= cdmGetSelectedArticles();
787 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
790 if (rows
.length
== 0) {
791 alert(__("No articles are selected."));
795 for (i
= 0; i
< rows
.length
; i
++) {
796 toggleMark(rows
[i
], true, true);
799 if (rows
.length
> 0) {
801 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
802 param_escape(rows
.toString()) + "&cmode=2";
804 query
= query
+ "&afid=" + getActiveFeedId();
806 /* if (tagsAreDisplayed()) {
807 query = query + "&omode=tl";
809 query = query + "&omode=flc";
812 query
= query
+ "&omode=lc";
814 new Ajax
.Request(query
, {
815 onComplete: function(transport
) {
816 all_counters_callback2(transport
);
822 exception_error("selectionToggleMarked", e
);
826 function selectionTogglePublished(cdm_mode
) {
832 rows
= cdmGetSelectedArticles();
834 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
837 if (rows
.length
== 0) {
838 alert(__("No articles are selected."));
842 for (i
= 0; i
< rows
.length
; i
++) {
843 togglePub(rows
[i
], true, true);
846 if (rows
.length
> 0) {
848 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
849 param_escape(rows
.toString()) + "&cmode=2";
851 query
= query
+ "&afid=" + getActiveFeedId();
853 /* if (tagsAreDisplayed()) {
854 query = query + "&omode=tl";
856 query = query + "&omode=flc";
859 query
= query
+ "&omode=lc";
861 new Ajax
.Request(query
, {
862 onComplete: function(transport
) {
863 all_counters_callback2(transport
);
869 exception_error("selectionToggleMarked", e
);
873 function cdmGetSelectedArticles() {
874 var sel_articles
= new Array();
875 var container
= document
.getElementById("headlinesInnerContainer");
877 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
878 var child
= container
.childNodes
[i
];
880 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
881 var c_id
= child
.id
.replace("RROW-", "");
882 sel_articles
.push(c_id
);
889 function cdmGetVisibleArticles() {
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-")) {
897 var c_id
= child
.id
.replace("RROW-", "");
898 sel_articles
.push(c_id
);
905 function cdmGetUnreadArticles() {
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-") && child
.className
.match("Unread")) {
913 var c_id
= child
.id
.replace("RROW-", "");
914 sel_articles
.push(c_id
);
922 // mode = all,none,unread
923 function cdmSelectArticles(mode
) {
924 var container
= document
.getElementById("headlinesInnerContainer");
926 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
927 var child
= container
.childNodes
[i
];
929 if (child
.id
.match("RROW-")) {
930 var aid
= child
.id
.replace("RROW-", "");
932 var cb
= document
.getElementById("RCHK-" + aid
);
935 if (!child
.className
.match("Selected")) {
936 child
.className
= child
.className
+ "Selected";
939 } else if (mode
== "unread") {
940 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
941 child
.className
= child
.className
+ "Selected";
945 child
.className
= child
.className
.replace("Selected", "");
952 function catchupPage() {
954 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
956 var str
= __("Mark all visible articles in %s as read?");
958 str
= str
.replace("%s", fn
);
960 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
964 if (document
.getElementById("headlinesList")) {
965 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
966 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
967 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
969 cdmSelectArticles('all');
970 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
971 cdmSelectArticles('none');
975 function catchupSelection() {
981 if (document
.getElementById("headlinesList")) {
982 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
984 rows
= cdmGetSelectedArticles();
987 if (rows
.length
== 0) {
988 alert(__("No articles are selected."));
993 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
995 var str
= __("Mark %d selected articles in %s as read?");
997 str
= str
.replace("%d", rows
.length
);
998 str
= str
.replace("%s", fn
);
1000 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1004 if (document
.getElementById("headlinesList")) {
1005 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1006 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1008 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1009 // cdmSelectArticles('none');
1013 exception_error("catchupSelection", e
);
1018 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1020 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1021 printLockingError();
1024 var title
= prompt(__("Please enter label title:"), "");
1028 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1029 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1030 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1031 "&title=" + param_escape(title
);
1033 debug("LFS: " + query
);
1035 new Ajax
.Request(query
, {
1036 onComplete: function(transport
) {
1037 dlg_frefresh_callback(transport
);
1042 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1043 _tag_active_post_id
= id
;
1044 _tag_active_feed_id
= feed_id
;
1045 _tag_active_cdm
= cdm_enabled
;
1047 cache_invalidate(id
);
1050 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1052 displayDlg('editArticleTags', id
);
1056 function tag_saved_callback(transport
) {
1058 debug("in tag_saved_callback");
1063 if (tagsAreDisplayed()) {
1064 _reload_feedlist_after_view
= true;
1067 if (!_tag_active_cdm
) {
1068 if (active_post_id
== _tag_active_post_id
) {
1069 debug("reloading current article");
1070 view(_tag_active_post_id
, _tag_active_feed_id
);
1073 debug("reloading current feed");
1078 exception_error("catchup_callback", e
);
1082 function editTagsSave() {
1084 notify_progress("Saving article tags...");
1086 var form
= document
.forms
["tag_edit_form"];
1088 var query
= Form
.serialize("tag_edit_form");
1090 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1094 new Ajax
.Request(query
, {
1095 onComplete: function(transport
) {
1096 tag_saved_callback(transport
);
1101 function editTagsInsert() {
1104 var form
= document
.forms
["tag_edit_form"];
1106 var found_tags
= form
.found_tags
;
1107 var tags_str
= form
.tags_str
;
1109 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1111 if (tags_str
.value
.length
> 0 &&
1112 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1114 tags_str
.value
= tags_str
.value
+ ", ";
1117 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1119 found_tags
.selectedIndex
= 0;
1122 exception_error(e
, "editTagsInsert");
1126 function cdmWatchdog() {
1130 var ctr
= document
.getElementById("headlinesInnerContainer");
1134 var ids
= new Array();
1136 var e
= ctr
.firstChild
;
1139 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1140 e
.id
.match("RROW-")) {
1142 // article fits in viewport OR article is longer than viewport and
1143 // its bottom is visible
1145 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1146 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1148 // debug(e.id + " is visible " + e.offsetTop + "." +
1149 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1150 // (ctr.scrollTop + ctr.offsetHeight));
1152 ids
.push(e
.id
.replace("RROW-", ""));
1154 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1155 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1156 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1158 ids
.push(e
.id
.replace("RROW-", ""));
1162 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1164 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1165 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1167 ids.push(e.id.replace("RROW-", ""));
1176 debug("cdmWatchdog, ids= " + ids
.toString());
1178 if (ids
.length
> 0) {
1180 for (var i
= 0; i
< ids
.length
; i
++) {
1181 var e
= document
.getElementById("RROW-" + ids
[i
]);
1183 e
.className
= e
.className
.replace("Unread", "");
1187 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1188 param_escape(ids
.toString()) + "&cmode=0";
1190 new Ajax
.Request(query
, {
1191 onComplete: function(transport
) {
1192 all_counters_callback2(transport
);
1197 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1200 exception_error(e
, "cdmWatchdog");
1206 function cache_inject(id
, article
, param
) {
1207 if (!cache_check_param(id
, param
)) {
1208 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1210 var cache_obj
= new Array();
1212 cache_obj
["id"] = id
;
1213 cache_obj
["data"] = article
;
1214 cache_obj
["param"] = param
;
1216 article_cache
.push(cache_obj
);
1219 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1223 function cache_find(id
) {
1224 for (var i
= 0; i
< article_cache
.length
; i
++) {
1225 if (article_cache
[i
]["id"] == id
) {
1226 return article_cache
[i
]["data"];
1232 function cache_find_param(id
, param
) {
1233 for (var i
= 0; i
< article_cache
.length
; i
++) {
1234 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1235 return article_cache
[i
]["data"];
1241 function cache_check(id
) {
1242 for (var i
= 0; i
< article_cache
.length
; i
++) {
1243 if (article_cache
[i
]["id"] == id
) {
1250 function cache_check_param(id
, param
) {
1251 for (var i
= 0; i
< article_cache
.length
; i
++) {
1253 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1254 // article_cache[i]["param"] + " vs " + id + ":" + param);
1256 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1263 function cache_expire() {
1264 while (article_cache
.length
> 20) {
1265 article_cache
.shift();
1269 function cache_invalidate(id
) {
1274 while (i
< article_cache
.length
) {
1275 if (article_cache
[i
]["id"] == id
) {
1276 debug("cache_invalidate: removed id " + id
);
1277 article_cache
.splice(i
, 1);
1282 debug("cache_invalidate: id not found: " + id
);
1285 exception_error("cache_invalidate", e
);
1289 function getActiveArticleId() {
1290 return active_post_id
;
1293 function cdmMouseIn(elem
) {
1295 if (elem
.id
&& elem
.id
.match("RROW-")) {
1296 var id
= elem
.id
.replace("RROW-", "");
1297 active_post_id
= id
;
1300 exception_error("cdmMouseIn", e
);
1305 function cdmMouseOut(elem
) {
1306 active_post_id
= false;
1309 function headlines_scroll_handler() {
1312 var e
= document
.getElementById("headlinesInnerContainer");
1314 // don't do infinite scrolling when Limit == All
1316 var toolbar_form
= document
.forms
["main_toolbar_form"];
1318 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1319 if (limit
.value
!= 0) {
1320 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1321 if (!_infscroll_disable
) {
1322 debug("more cowbell!");
1329 exception_error("headlines_scroll_handler", e
);
1333 function catchupRelativeToArticle(below
) {
1337 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1338 printLockingError();
1341 if (!getActiveArticleId()) {
1342 alert(__("No article is selected."));
1348 if (document
.getElementById("headlinesList")) {
1349 visible_ids
= getVisibleHeadlineIds();
1351 visible_ids
= cdmGetVisibleArticles();
1354 var ids_to_mark
= new Array();
1357 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1358 if (visible_ids
[i
] != getActiveArticleId()) {
1359 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1361 if (e
&& e
.className
.match("Unread")) {
1362 ids_to_mark
.push(visible_ids
[i
]);
1369 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1370 if (visible_ids
[i
] != getActiveArticleId()) {
1371 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1373 if (e
&& e
.className
.match("Unread")) {
1374 ids_to_mark
.push(visible_ids
[i
]);
1382 if (ids_to_mark
.length
== 0) {
1383 alert(__("No articles found to mark"));
1385 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1389 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1390 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1391 e
.className
= e
.className
.replace("Unread", "");
1394 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1395 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1397 new Ajax
.Request(query
, {
1398 onComplete: function(transport
) {
1399 catchup_callback2(transport
);
1406 exception_error("catchupRelativeToArticle", e
);
1410 function cdmExpandArticle(a_id
) {
1412 var id
= 'CICD-' + a_id
;
1414 Effect
.Appear(id
, {duration
: 0.5,
1415 beforeStart: function(effect
) {
1416 var h_id
= 'CICH-' + a_id
;
1417 var h_elem
= document
.getElementById(h_id
);
1418 if (h_elem
) { h_elem
.style
.display
= "none"; }
1420 toggleUnread(a_id
, 0);
1425 exception_error("appearBlockElementF", e
);