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_invalidate(cache_prefix
+ active_feed_id
);
118 cache_inject(cache_prefix
+ active_feed_id
,
119 headlines
.firstChild
.nodeValue
, headlines_unread
);
122 debug("headlines_callback: returned no data");
123 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
128 if (headlines_count
> 0) {
129 debug("adding some more headlines...");
131 var c
= document
.getElementById("headlinesList");
134 c
= document
.getElementById("headlinesInnerContainer");
137 var ids
= getSelectedArticleIds2();
139 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
141 debug("restore selected ids: " + ids
);
143 for (var i
= 0; i
< ids
.length
; i
++) {
144 markHeadline(ids
[i
]);
148 debug("no new headlines received");
151 debug("headlines_callback: returned no data");
152 notify_error("Error while trying to load more headlines");
158 for (var i
= 0; i
< articles
.length
; i
++) {
159 var a_id
= articles
[i
].getAttribute("id");
160 debug("found id: " + a_id
);
161 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
164 debug("no cached articles received");
168 debug("parsing piggybacked counters: " + counters
);
169 parse_counters(counters
, false);
171 debug("counters container not found in reply");
175 debug("parsing runtime info: " + runtime_info
[0]);
176 parse_runtime_info(runtime_info
[0]);
178 debug("counters container not found in reply");
182 debug("headlines_callback: returned no XML object");
183 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
186 if (typeof correctPNG
!= 'undefined') {
190 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
192 if (!document
.getElementById("headlinesList") &&
193 getInitParam("cdm_auto_catchup") == 1) {
194 debug("starting CDM watchdog");
195 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
196 _cdm_wd_vishist
= new Array();
198 debug("not in CDM mode or watchdog disabled");
201 if (_tag_cdm_scroll
) {
203 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
204 _tag_cdm_scroll
= false;
205 debug("resetting headlinesInner scrollTop");
210 _feed_cur_page
= feed_cur_page
;
211 _infscroll_request_sent
= 0;
215 exception_error("headlines_callback2", e
);
219 function render_article(article
) {
221 var f
= document
.getElementById("content-frame");
226 f
.innerHTML
= article
;
229 exception_error("render_article", e
);
233 function showArticleInHeadlines(id
) {
237 cleanSelected("headlinesList");
239 var crow
= document
.getElementById("RROW-" + id
);
243 var article_is_unread
= crow
.className
.match("Unread");
245 crow
.className
= crow
.className
.replace("Unread", "");
247 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
250 upd_img_pic
.src
= "images/blank_icon.gif";
253 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
257 exception_error("showArticleInHeadlines", e
);
261 function article_callback2(transport
, id
, feed_id
) {
263 debug("article_callback2 " + id
);
265 if (transport
.responseXML
) {
267 active_real_feed_id
= feed_id
;
270 showArticleInHeadlines(id
);
272 var reply
= transport
.responseXML
.firstChild
.firstChild
;
274 var articles
= transport
.responseXML
.getElementsByTagName("article");
276 for (var i
= 0; i
< articles
.length
; i
++) {
277 var a_id
= articles
[i
].getAttribute("id");
279 debug("found id: " + a_id
);
281 if (a_id
== active_post_id
) {
282 debug("active article, rendering...");
283 render_article(articles
[i
].firstChild
.nodeValue
);
286 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
290 debug("article_callback: returned no XML object");
291 var f
= document
.getElementById("content-frame");
292 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
295 var date
= new Date();
296 last_article_view
= date
.getTime() / 1000;
298 if (typeof correctPNG
!= 'undefined') {
302 if (_reload_feedlist_after_view
) {
303 setTimeout('updateFeedList(false, false)', 50);
304 _reload_feedlist_after_view
= false;
306 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
309 debug("parsing piggybacked counters: " + counters
);
310 parse_counters(counters
, false);
312 debug("counters container not found in reply");
318 exception_error("article_callback2", e
);
322 function view(id
, feed_id
, skip_history
) {
325 debug("loading article: " + id
+ "/" + feed_id
);
327 var cached_article
= cache_find(id
);
329 debug("cache check result: " + (cached_article
!= false));
333 //setActiveFeedId(feed_id);
335 var query
= "backend.php?op=view&id=" + param_escape(id
) +
336 "&feed=" + param_escape(feed_id
);
338 var date
= new Date();
340 var neighbor_ids
= getRelativePostIds(active_post_id
);
342 /* only request uncached articles */
344 var cids_to_request
= Array();
346 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
347 if (!cache_check(neighbor_ids
[i
])) {
348 cids_to_request
.push(neighbor_ids
[i
]);
352 debug("additional ids: " + cids_to_request
.toString());
354 /* additional info for piggyback counters */
356 if (tagsAreDisplayed()) {
357 query
= query
+ "&omode=lt";
359 query
= query
+ "&omode=flc";
362 var date
= new Date();
363 var timestamp
= Math
.round(date
.getTime() / 1000);
364 query
= query
+ "&ts=" + timestamp
;
366 query
= query
+ "&cids=" + cids_to_request
.toString();
368 var crow
= document
.getElementById("RROW-" + id
);
369 var article_is_unread
= crow
.className
.match("Unread");
371 showArticleInHeadlines(id
);
373 if (!cached_article
) {
375 notify_progress("Loading, please wait...");
377 } else if (cached_article
&& article_is_unread
) {
379 query
= query
+ "&mode=prefetch";
381 render_article(cached_article
);
383 } else if (cached_article
) {
385 query
= query
+ "&mode=prefetch_old";
386 render_article(cached_article
);
391 new Ajax
.Request(query
, {
392 onComplete: function(transport
) {
393 article_callback2(transport
, id
, feed_id
);
397 exception_error("view", e
);
402 return toggleMark(id
);
406 return togglePub(id
);
409 function tMark_afh_off(effect
) {
411 var elem
= effect
.effects
[0].element
;
413 debug("tMark_afh_off : " + elem
.id
);
416 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
417 elem
.alt
= __("Star article");
422 exception_error("tMark_afh_off", e
);
426 function tPub_afh_off(effect
) {
428 var elem
= effect
.effects
[0].element
;
430 debug("tPub_afh_off : " + elem
.id
);
433 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
434 elem
.alt
= __("Publish article");
439 exception_error("tPub_afh_off", e
);
443 function toggleMark(id
, client_only
, no_effects
) {
447 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
449 query
= query
+ "&afid=" + getActiveFeedId();
451 if (tagsAreDisplayed()) {
452 query
= query
+ "&omode=tl";
454 query
= query
+ "&omode=flc";
457 var mark_img
= document
.getElementById("FMPIC-" + id
);
458 var vfeedu
= document
.getElementById("FEEDU--1");
459 var crow
= document
.getElementById("RROW-" + id
);
461 if (mark_img
.src
.match("mark_unset")) {
462 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
463 mark_img
.alt
= __("Unstar article");
464 query
= query
+ "&mark=1";
466 /* if (vfeedu && crow.className.match("Unread")) {
467 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
471 //mark_img.src = "images/mark_unset.png";
472 mark_img
.alt
= __("Please wait...");
473 query
= query
+ "&mark=0";
475 /* if (vfeedu && crow.className.match("Unread")) {
476 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
479 if (document
.getElementById("headlinesList") && !no_effects
) {
480 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
482 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
483 mark_img
.alt
= __("Star article");
487 /* var vfeedctr = document.getElementById("FEEDCTR--1");
488 var vfeedr = document.getElementById("FEEDR--1");
490 if (vfeedu && vfeedctr) {
491 if ((+vfeedu.innerHTML) > 0) {
492 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
493 vfeedr.className = vfeedr.className + "Unread";
494 vfeedctr.className = "odd";
497 vfeedctr.className = "invisible";
498 vfeedr.className = vfeedr.className.replace("Unread", "");
502 debug("toggle starred for aid " + id);
504 //new Ajax.Request(query); */
509 new Ajax
.Request(query
, {
510 onComplete: function(transport
) {
511 all_counters_callback2(transport
);
517 exception_error("toggleMark", e
);
521 function togglePub(id
, client_only
, no_effects
) {
525 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
527 query
= query
+ "&afid=" + getActiveFeedId();
529 if (tagsAreDisplayed()) {
530 query
= query
+ "&omode=tl";
532 query
= query
+ "&omode=flc";
535 var mark_img
= document
.getElementById("FPPIC-" + id
);
536 var vfeedu
= document
.getElementById("FEEDU--2");
537 var crow
= document
.getElementById("RROW-" + id
);
539 if (mark_img
.src
.match("pub_unset")) {
540 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
541 mark_img
.alt
= __("Unpublish article");
542 query
= query
+ "&pub=1";
544 /* if (vfeedu && crow.className.match("Unread")) {
545 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
549 //mark_img.src = "images/pub_unset.png";
550 mark_img
.alt
= __("Please wait...");
551 query
= query
+ "&pub=0";
553 /* if (vfeedu && crow.className.match("Unread")) {
554 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
557 if (document
.getElementById("headlinesList") && !no_effects
) {
558 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
560 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
561 mark_img
.alt
= __("Publish article");
565 /* var vfeedctr = document.getElementById("FEEDCTR--2");
566 var vfeedr = document.getElementById("FEEDR--2");
568 if (vfeedu && vfeedctr) {
569 if ((+vfeedu.innerHTML) > 0) {
570 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
571 vfeedr.className = vfeedr.className + "Unread";
572 vfeedctr.className = "odd";
575 vfeedctr.className = "invisible";
576 vfeedr.className = vfeedr.className.replace("Unread", "");
580 debug("toggle published for aid " + id);
582 new Ajax.Request(query); */
585 new Ajax
.Request(query
, {
586 onComplete: function(transport
) {
587 all_counters_callback2(transport
);
593 exception_error("togglePub", e
);
597 function correctHeadlinesOffset(id
) {
601 var hlist
= document
.getElementById("headlinesList");
602 var container
= document
.getElementById("headlinesInnerContainer");
603 var row
= document
.getElementById("RROW-" + id
);
605 var viewport
= container
.offsetHeight
;
607 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
608 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
610 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
611 debug("Vport: " + viewport
);
613 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
614 container
.scrollTop
= row
.offsetTop
;
615 } else if (rel_offset_bottom
> viewport
) {
617 /* doesn't properly work with Opera in some cases because
618 Opera fucks up element scrolling */
620 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
624 exception_error("correctHeadlinesOffset", e
);
629 function moveToPost(mode
) {
631 // check for combined mode
632 if (!document
.getElementById("headlinesList"))
635 var rows
= getVisibleHeadlineIds();
640 if (!document
.getElementById('RROW-' + active_post_id
)) {
641 active_post_id
= false;
644 if (active_post_id
== false) {
645 next_id
= getFirstVisibleHeadlineId();
646 prev_id
= getLastVisibleHeadlineId();
648 for (var i
= 0; i
< rows
.length
; i
++) {
649 if (rows
[i
] == active_post_id
) {
656 if (mode
== "next") {
658 correctHeadlinesOffset(next_id
);
659 view(next_id
, getActiveFeedId());
663 if (mode
== "prev") {
665 correctHeadlinesOffset(prev_id
);
666 view(prev_id
, getActiveFeedId());
671 function toggleUnread(id
, cmode
) {
674 var row
= document
.getElementById("RROW-" + id
);
676 var nc
= row
.className
;
677 nc
= nc
.replace("Unread", "");
678 nc
= nc
.replace("Selected", "");
680 if (cmode
== undefined || cmode
== 2) {
681 if (row
.className
.match("Unread")) {
684 row
.className
= nc
+ "Unread";
686 } else if (cmode
== 0) {
688 } else if (cmode
== 1) {
689 row
.className
= nc
+ "Unread";
692 if (cmode
== undefined) cmode
= 2;
694 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
695 param_escape(id
) + "&cmode=" + param_escape(cmode
);
697 // notify_progress("Loading, please wait...");
699 new Ajax
.Request(query
, {
700 onComplete: function(transport
) {
701 all_counters_callback2(transport
);
708 exception_error("toggleUnread", e
);
712 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
717 rows
= cdmGetSelectedArticles();
719 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
722 if (rows
.length
== 0 && !no_error
) {
723 alert(__("No articles are selected."));
727 for (i
= 0; i
< rows
.length
; i
++) {
728 var row
= document
.getElementById("RROW-" + rows
[i
]);
730 var nc
= row
.className
;
731 nc
= nc
.replace("Unread", "");
732 nc
= nc
.replace("Selected", "");
734 if (set_state
== undefined) {
735 if (row
.className
.match("Unread")) {
736 row
.className
= nc
+ "Selected";
738 row
.className
= nc
+ "UnreadSelected";
742 if (set_state
== false) {
743 row
.className
= nc
+ "Selected";
746 if (set_state
== true) {
747 row
.className
= nc
+ "UnreadSelected";
752 if (rows
.length
> 0) {
756 if (set_state
== undefined) {
758 } else if (set_state
== true) {
760 } else if (set_state
== false) {
764 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
765 param_escape(rows
.toString()) + "&cmode=" + cmode
;
767 notify_progress("Loading, please wait...");
769 new Ajax
.Request(query
, {
770 onComplete: function(transport
) {
771 catchup_callback2(transport
, callback_func
);
777 exception_error("selectionToggleUnread", e
);
781 function selectionToggleMarked(cdm_mode
) {
787 rows
= cdmGetSelectedArticles();
789 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
792 if (rows
.length
== 0) {
793 alert(__("No articles are selected."));
797 for (i
= 0; i
< rows
.length
; i
++) {
798 toggleMark(rows
[i
], true, true);
801 if (rows
.length
> 0) {
803 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
804 param_escape(rows
.toString()) + "&cmode=2";
806 query
= query
+ "&afid=" + getActiveFeedId();
808 /* if (tagsAreDisplayed()) {
809 query = query + "&omode=tl";
811 query = query + "&omode=flc";
814 query
= query
+ "&omode=lc";
816 new Ajax
.Request(query
, {
817 onComplete: function(transport
) {
818 all_counters_callback2(transport
);
824 exception_error("selectionToggleMarked", e
);
828 function selectionTogglePublished(cdm_mode
) {
834 rows
= cdmGetSelectedArticles();
836 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
839 if (rows
.length
== 0) {
840 alert(__("No articles are selected."));
844 for (i
= 0; i
< rows
.length
; i
++) {
845 togglePub(rows
[i
], true, true);
848 if (rows
.length
> 0) {
850 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
851 param_escape(rows
.toString()) + "&cmode=2";
853 query
= query
+ "&afid=" + getActiveFeedId();
855 /* if (tagsAreDisplayed()) {
856 query = query + "&omode=tl";
858 query = query + "&omode=flc";
861 query
= query
+ "&omode=lc";
863 new Ajax
.Request(query
, {
864 onComplete: function(transport
) {
865 all_counters_callback2(transport
);
871 exception_error("selectionToggleMarked", e
);
875 function cdmGetSelectedArticles() {
876 var sel_articles
= new Array();
877 var container
= document
.getElementById("headlinesInnerContainer");
879 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
880 var child
= container
.childNodes
[i
];
882 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
883 var c_id
= child
.id
.replace("RROW-", "");
884 sel_articles
.push(c_id
);
891 function cdmGetVisibleArticles() {
892 var sel_articles
= new Array();
893 var container
= document
.getElementById("headlinesInnerContainer");
895 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
896 var child
= container
.childNodes
[i
];
898 if (child
.id
.match("RROW-")) {
899 var c_id
= child
.id
.replace("RROW-", "");
900 sel_articles
.push(c_id
);
907 function cdmGetUnreadArticles() {
908 var sel_articles
= new Array();
909 var container
= document
.getElementById("headlinesInnerContainer");
911 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
912 var child
= container
.childNodes
[i
];
914 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
915 var c_id
= child
.id
.replace("RROW-", "");
916 sel_articles
.push(c_id
);
924 // mode = all,none,unread
925 function cdmSelectArticles(mode
) {
926 var container
= document
.getElementById("headlinesInnerContainer");
928 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
929 var child
= container
.childNodes
[i
];
931 if (child
.id
.match("RROW-")) {
932 var aid
= child
.id
.replace("RROW-", "");
934 var cb
= document
.getElementById("RCHK-" + aid
);
937 if (!child
.className
.match("Selected")) {
938 child
.className
= child
.className
+ "Selected";
941 } else if (mode
== "unread") {
942 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
943 child
.className
= child
.className
+ "Selected";
947 child
.className
= child
.className
.replace("Selected", "");
954 function catchupPage() {
956 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
958 var str
= __("Mark all visible articles in %s as read?");
960 str
= str
.replace("%s", fn
);
962 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
966 if (document
.getElementById("headlinesList")) {
967 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
968 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
969 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
971 cdmSelectArticles('all');
972 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
973 cdmSelectArticles('none');
977 function catchupSelection() {
983 if (document
.getElementById("headlinesList")) {
984 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
986 rows
= cdmGetSelectedArticles();
989 if (rows
.length
== 0) {
990 alert(__("No articles are selected."));
995 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
997 var str
= __("Mark %d selected articles in %s as read?");
999 str
= str
.replace("%d", rows
.length
);
1000 str
= str
.replace("%s", fn
);
1002 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1006 if (document
.getElementById("headlinesList")) {
1007 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1008 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1010 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1011 // cdmSelectArticles('none');
1015 exception_error("catchupSelection", e
);
1020 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1022 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1023 printLockingError();
1026 var title
= prompt(__("Please enter label title:"), "");
1030 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1031 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1032 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1033 "&title=" + param_escape(title
);
1035 debug("LFS: " + query
);
1037 new Ajax
.Request(query
, {
1038 onComplete: function(transport
) {
1039 dlg_frefresh_callback(transport
);
1044 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1045 _tag_active_post_id
= id
;
1046 _tag_active_feed_id
= feed_id
;
1047 _tag_active_cdm
= cdm_enabled
;
1049 cache_invalidate(id
);
1052 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1054 displayDlg('editArticleTags', id
);
1058 function tag_saved_callback(transport
) {
1060 debug("in tag_saved_callback");
1065 if (tagsAreDisplayed()) {
1066 _reload_feedlist_after_view
= true;
1069 if (!_tag_active_cdm
) {
1070 if (active_post_id
== _tag_active_post_id
) {
1071 debug("reloading current article");
1072 view(_tag_active_post_id
, _tag_active_feed_id
);
1075 debug("reloading current feed");
1080 exception_error("catchup_callback", e
);
1084 function editTagsSave() {
1086 notify_progress("Saving article tags...");
1088 var form
= document
.forms
["tag_edit_form"];
1090 var query
= Form
.serialize("tag_edit_form");
1092 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1096 new Ajax
.Request(query
, {
1097 onComplete: function(transport
) {
1098 tag_saved_callback(transport
);
1103 function editTagsInsert() {
1106 var form
= document
.forms
["tag_edit_form"];
1108 var found_tags
= form
.found_tags
;
1109 var tags_str
= form
.tags_str
;
1111 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1113 if (tags_str
.value
.length
> 0 &&
1114 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1116 tags_str
.value
= tags_str
.value
+ ", ";
1119 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1121 found_tags
.selectedIndex
= 0;
1124 exception_error(e
, "editTagsInsert");
1128 function cdmWatchdog() {
1132 var ctr
= document
.getElementById("headlinesInnerContainer");
1136 var ids
= new Array();
1138 var e
= ctr
.firstChild
;
1141 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1142 e
.id
.match("RROW-")) {
1144 // article fits in viewport OR article is longer than viewport and
1145 // its bottom is visible
1147 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1148 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1150 // debug(e.id + " is visible " + e.offsetTop + "." +
1151 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1152 // (ctr.scrollTop + ctr.offsetHeight));
1154 ids
.push(e
.id
.replace("RROW-", ""));
1156 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1157 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1158 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1160 ids
.push(e
.id
.replace("RROW-", ""));
1164 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1166 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1167 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1169 ids.push(e.id.replace("RROW-", ""));
1178 debug("cdmWatchdog, ids= " + ids
.toString());
1180 if (ids
.length
> 0) {
1182 for (var i
= 0; i
< ids
.length
; i
++) {
1183 var e
= document
.getElementById("RROW-" + ids
[i
]);
1185 e
.className
= e
.className
.replace("Unread", "");
1189 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1190 param_escape(ids
.toString()) + "&cmode=0";
1192 new Ajax
.Request(query
, {
1193 onComplete: function(transport
) {
1194 all_counters_callback2(transport
);
1199 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1202 exception_error(e
, "cdmWatchdog");
1208 function cache_inject(id
, article
, param
) {
1209 if (!cache_check_param(id
, param
)) {
1210 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1212 var cache_obj
= new Array();
1214 cache_obj
["id"] = id
;
1215 cache_obj
["data"] = article
;
1216 cache_obj
["param"] = param
;
1218 article_cache
.push(cache_obj
);
1221 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1225 function cache_find(id
) {
1226 for (var i
= 0; i
< article_cache
.length
; i
++) {
1227 if (article_cache
[i
]["id"] == id
) {
1228 return article_cache
[i
]["data"];
1234 function cache_find_param(id
, param
) {
1235 for (var i
= 0; i
< article_cache
.length
; i
++) {
1236 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1237 return article_cache
[i
]["data"];
1243 function cache_check(id
) {
1244 for (var i
= 0; i
< article_cache
.length
; i
++) {
1245 if (article_cache
[i
]["id"] == id
) {
1252 function cache_check_param(id
, param
) {
1253 for (var i
= 0; i
< article_cache
.length
; i
++) {
1255 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1256 // article_cache[i]["param"] + " vs " + id + ":" + param);
1258 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1265 function cache_expire() {
1266 while (article_cache
.length
> 20) {
1267 article_cache
.shift();
1271 function cache_invalidate(id
) {
1276 while (i
< article_cache
.length
) {
1277 if (article_cache
[i
]["id"] == id
) {
1278 debug("cache_invalidate: removed id " + id
);
1279 article_cache
.splice(i
, 1);
1284 debug("cache_invalidate: id not found: " + id
);
1287 exception_error("cache_invalidate", e
);
1291 function getActiveArticleId() {
1292 return active_post_id
;
1295 function cdmMouseIn(elem
) {
1297 if (elem
.id
&& elem
.id
.match("RROW-")) {
1298 var id
= elem
.id
.replace("RROW-", "");
1299 active_post_id
= id
;
1302 exception_error("cdmMouseIn", e
);
1307 function cdmMouseOut(elem
) {
1308 active_post_id
= false;
1311 function headlines_scroll_handler() {
1314 var e
= document
.getElementById("headlinesInnerContainer");
1316 // don't do infinite scrolling when Limit == All
1318 var toolbar_form
= document
.forms
["main_toolbar_form"];
1320 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1321 if (limit
.value
!= 0) {
1322 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1323 if (!_infscroll_disable
) {
1324 debug("more cowbell!");
1331 exception_error("headlines_scroll_handler", e
);
1335 function catchupRelativeToArticle(below
) {
1339 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1340 printLockingError();
1343 if (!getActiveArticleId()) {
1344 alert(__("No article is selected."));
1350 if (document
.getElementById("headlinesList")) {
1351 visible_ids
= getVisibleHeadlineIds();
1353 visible_ids
= cdmGetVisibleArticles();
1356 var ids_to_mark
= new Array();
1359 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1360 if (visible_ids
[i
] != getActiveArticleId()) {
1361 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1363 if (e
&& e
.className
.match("Unread")) {
1364 ids_to_mark
.push(visible_ids
[i
]);
1371 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1372 if (visible_ids
[i
] != getActiveArticleId()) {
1373 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1375 if (e
&& e
.className
.match("Unread")) {
1376 ids_to_mark
.push(visible_ids
[i
]);
1384 if (ids_to_mark
.length
== 0) {
1385 alert(__("No articles found to mark"));
1387 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1391 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1392 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1393 e
.className
= e
.className
.replace("Unread", "");
1396 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1397 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1399 new Ajax
.Request(query
, {
1400 onComplete: function(transport
) {
1401 catchup_callback2(transport
);
1408 exception_error("catchupRelativeToArticle", e
);
1412 function cdmExpandArticle(a_id
) {
1414 var id
= 'CICD-' + a_id
;
1416 Effect
.Appear(id
, {duration
: 0.5,
1417 beforeStart: function(effect
) {
1418 var h_id
= 'CICH-' + a_id
;
1419 var h_elem
= document
.getElementById(h_id
);
1420 if (h_elem
) { h_elem
.style
.display
= "none"; }
1422 toggleUnread(a_id
, 0);
1427 exception_error("appearBlockElementF", e
);