1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _tag_active_post_id
= false;
6 var _tag_active_feed_id
= false;
7 var _tag_active_cdm
= false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll
= false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view
= false;
15 var _cdm_wd_timeout
= false;
16 var _cdm_wd_vishist
= new Array();
18 var article_cache
= new Array();
20 var vgroup_last_feed
= false;
21 var post_under_pointer
= false;
23 var last_requested_article
= false;
25 function catchup_callback() {
26 if (xmlhttp_rpc
.readyState
== 4) {
28 debug("catchup_callback");
30 all_counters_callback2(xmlhttp_rpc
);
31 if (_catchup_callback_func
) {
32 setTimeout(_catchup_callback_func
, 10);
35 exception_error("catchup_callback", e
);
40 function catchup_callback2(transport
, callback
) {
42 debug("catchup_callback2 " + transport
+ ", " + callback
);
44 all_counters_callback2(transport
);
46 setTimeout(callback
, 10);
49 exception_error("catchup_callback2", e
);
53 function clean_feed_selections() {
55 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
57 for (var i
= 0; i
< feeds
.length
; i
++) {
58 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
59 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
62 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
66 exception_error("clean_feed_selections", e
);
70 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
73 loading_set_progress(100);
75 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
77 clean_feed_selections();
79 setActiveFeedId(active_feed_id
);
81 if (is_cat
!= undefined) {
82 active_feed_is_cat
= is_cat
;
86 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
87 if (feedr
&& !feedr
.className
.match("Selected")) {
88 feedr
.className
= feedr
.className
+ "Selected";
91 var feedr
= document
.getElementById("FCAT-" + active_feed_id
);
92 if (feedr
&& !feedr
.className
.match("Selected")) {
93 feedr
.className
= feedr
.className
+ "Selected";
97 var f
= document
.getElementById("headlines-frame");
99 if (feed_cur_page
== 0) {
100 debug("resetting headlines scrollTop");
105 if (transport
.responseXML
) {
106 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
107 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
108 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
109 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
111 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
113 var headlines_count
= headlines_count_obj
.getAttribute("value");
114 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
115 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
117 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
119 if (headlines_count
== 0) {
120 _infscroll_disable
= 1;
122 _infscroll_disable
= 0;
125 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
126 var articles
= transport
.responseXML
.getElementsByTagName("article");
127 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
129 if (feed_cur_page
== 0) {
131 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
133 var cache_prefix
= "";
141 cache_invalidate(cache_prefix
+ active_feed_id
);
143 if (!disable_cache
) {
144 cache_inject(cache_prefix
+ active_feed_id
,
145 headlines
.firstChild
.nodeValue
, headlines_unread
);
149 debug("headlines_callback: returned no data");
150 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
155 if (headlines_count
> 0) {
156 debug("adding some more headlines...");
158 var c
= document
.getElementById("headlinesList");
161 c
= document
.getElementById("headlinesInnerContainer");
164 var ids
= getSelectedArticleIds2();
166 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
168 debug("restore selected ids: " + ids
);
170 for (var i
= 0; i
< ids
.length
; i
++) {
171 markHeadline(ids
[i
]);
177 debug("no new headlines received");
180 debug("headlines_callback: returned no data");
181 notify_error("Error while trying to load more headlines");
187 for (var i
= 0; i
< articles
.length
; i
++) {
188 var a_id
= articles
[i
].getAttribute("id");
189 debug("found id: " + a_id
);
190 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
193 debug("no cached articles received");
197 debug("parsing piggybacked counters: " + counters
);
198 parse_counters(counters
, false);
200 debug("counters container not found in reply, requesting...");
205 debug("parsing runtime info: " + runtime_info
[0]);
206 parse_runtime_info(runtime_info
[0]);
208 debug("counters container not found in reply");
212 debug("headlines_callback: returned no XML object");
213 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
216 if (typeof correctPNG
!= 'undefined') {
220 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
222 if (!document
.getElementById("headlinesList") &&
223 getInitParam("cdm_auto_catchup") == 1) {
224 debug("starting CDM watchdog");
225 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
226 _cdm_wd_vishist
= new Array();
228 debug("not in CDM mode or watchdog disabled");
231 if (_tag_cdm_scroll
) {
233 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
234 _tag_cdm_scroll
= false;
235 debug("resetting headlinesInner scrollTop");
240 _feed_cur_page
= feed_cur_page
;
241 _infscroll_request_sent
= 0;
248 exception_error("headlines_callback2", e
);
252 function render_article(article
) {
254 var f
= document
.getElementById("content-frame");
259 f
.innerHTML
= article
;
262 exception_error("render_article", e
);
266 function showArticleInHeadlines(id
) {
270 cleanSelected("headlinesList");
272 var crow
= document
.getElementById("RROW-" + id
);
276 var article_is_unread
= crow
.className
.match("Unread");
278 crow
.className
= crow
.className
.replace("Unread", "");
280 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
282 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
284 var cache_prefix
= "";
286 if (activeFeedIsCat()) {
292 var view_mode
= false;
295 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
296 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
298 exception_error("showArticleInHeadlines/viewmode", e
, true);
301 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
302 upd_img_pic
.src
= "images/blank_icon.gif";
304 cache_invalidate(cache_prefix
+ getActiveFeedId());
306 cache_inject(cache_prefix
+ getActiveFeedId(),
307 document
.getElementById("headlines-frame").innerHTML
,
308 get_feed_unread(getActiveFeedId()));
310 } else if (article_is_unread
&& view_mode
== "all_articles") {
312 cache_invalidate(cache_prefix
+ getActiveFeedId());
314 cache_inject(cache_prefix
+ getActiveFeedId(),
315 document
.getElementById("headlines-frame").innerHTML
,
316 get_feed_unread(getActiveFeedId())-1);
318 } else if (article_is_unread
) {
319 cache_invalidate(cache_prefix
+ getActiveFeedId());
325 exception_error("showArticleInHeadlines", e
);
329 function article_callback2(transport
, id
, feed_id
) {
331 debug("article_callback2 " + id
);
333 if (transport
.responseXML
) {
335 debug("looking for articles to cache...");
337 var articles
= transport
.responseXML
.getElementsByTagName("article");
339 for (var i
= 0; i
< articles
.length
; i
++) {
340 var a_id
= articles
[i
].getAttribute("id");
342 debug("found id: " + a_id
);
344 if (a_id
== active_post_id
) {
345 debug("active article, rendering...");
346 render_article(articles
[i
].firstChild
.nodeValue
);
349 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
352 if (id
!= last_requested_article
) {
353 debug("requested article id is out of sequence, aborting");
357 active_real_feed_id
= feed_id
;
360 showArticleInHeadlines(id
);
362 var reply
= transport
.responseXML
.firstChild
.firstChild
;
365 debug("article_callback: returned no XML object");
366 var f
= document
.getElementById("content-frame");
367 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
370 var date
= new Date();
371 last_article_view
= date
.getTime() / 1000;
373 if (typeof correctPNG
!= 'undefined') {
377 if (_reload_feedlist_after_view
) {
378 setTimeout('updateFeedList(false, false)', 50);
379 _reload_feedlist_after_view
= false;
381 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
384 debug("parsing piggybacked counters: " + counters
);
385 parse_counters(counters
, false);
387 debug("counters container not found in reply, requesting...");
394 exception_error("article_callback2", e
);
398 function view(id
, feed_id
, skip_history
) {
401 debug("loading article: " + id
+ "/" + feed_id
);
403 var cached_article
= cache_find(id
);
405 debug("cache check result: " + (cached_article
!= false));
409 //setActiveFeedId(feed_id);
411 var query
= "backend.php?op=view&id=" + param_escape(id
) +
412 "&feed=" + param_escape(feed_id
);
414 var date
= new Date();
416 var neighbor_ids
= getRelativePostIds(active_post_id
);
418 /* only request uncached articles */
420 var cids_to_request
= Array();
422 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
423 if (!cache_check(neighbor_ids
[i
])) {
424 cids_to_request
.push(neighbor_ids
[i
]);
428 debug("additional ids: " + cids_to_request
.toString());
430 /* additional info for piggyback counters */
432 if (tagsAreDisplayed()) {
433 query
= query
+ "&omode=lt";
435 query
= query
+ "&omode=flc";
438 var date
= new Date();
439 var timestamp
= Math
.round(date
.getTime() / 1000);
440 query
= query
+ "&ts=" + timestamp
;
442 query
= query
+ "&cids=" + cids_to_request
.toString();
444 var crow
= document
.getElementById("RROW-" + id
);
445 var article_is_unread
= crow
.className
.match("Unread");
447 if (!async_counters_work
) {
448 query
= query
+ "&csync=true";
451 showArticleInHeadlines(id
);
453 if (!cached_article
) {
455 notify_progress("Loading, please wait...", true);
457 } else if (cached_article
&& article_is_unread
) {
459 query
= query
+ "&mode=prefetch";
461 render_article(cached_article
);
463 } else if (cached_article
) {
465 query
= query
+ "&mode=prefetch_old";
466 render_article(cached_article
);
472 last_requested_article
= id
;
474 new Ajax
.Request(query
, {
475 onComplete: function(transport
) {
476 article_callback2(transport
, id
, feed_id
);
482 exception_error("view", e
);
487 return toggleMark(id
);
491 return togglePub(id
);
494 function tMark_afh_off(effect
) {
496 var elem
= effect
.effects
[0].element
;
498 debug("tMark_afh_off : " + elem
.id
);
501 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
502 elem
.alt
= __("Star article");
507 exception_error("tMark_afh_off", e
);
511 function tPub_afh_off(effect
) {
513 var elem
= effect
.effects
[0].element
;
515 debug("tPub_afh_off : " + elem
.id
);
518 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
519 elem
.alt
= __("Publish article");
524 exception_error("tPub_afh_off", e
);
528 function toggleMark(id
, client_only
, no_effects
) {
532 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
534 query
= query
+ "&afid=" + getActiveFeedId();
536 if (tagsAreDisplayed()) {
537 query
= query
+ "&omode=tl";
539 query
= query
+ "&omode=flc";
542 var mark_img
= document
.getElementById("FMPIC-" + id
);
543 var vfeedu
= document
.getElementById("FEEDU--1");
544 var crow
= document
.getElementById("RROW-" + id
);
546 if (mark_img
.src
.match("mark_unset")) {
547 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
548 mark_img
.alt
= __("Unstar article");
549 query
= query
+ "&mark=1";
552 //mark_img.src = "images/mark_unset.png";
553 mark_img
.alt
= __("Please wait...");
554 query
= query
+ "&mark=0";
556 if (document
.getElementById("headlinesList") && !no_effects
) {
557 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
559 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
560 mark_img
.alt
= __("Star article");
567 new Ajax
.Request(query
, {
568 onComplete: function(transport
) {
569 all_counters_callback2(transport
);
575 exception_error("toggleMark", e
);
579 function togglePub(id
, client_only
, no_effects
) {
583 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
585 query
= query
+ "&afid=" + getActiveFeedId();
587 if (tagsAreDisplayed()) {
588 query
= query
+ "&omode=tl";
590 query
= query
+ "&omode=flc";
593 var mark_img
= document
.getElementById("FPPIC-" + id
);
594 var vfeedu
= document
.getElementById("FEEDU--2");
595 var crow
= document
.getElementById("RROW-" + id
);
597 if (mark_img
.src
.match("pub_unset")) {
598 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
599 mark_img
.alt
= __("Unpublish article");
600 query
= query
+ "&pub=1";
604 //mark_img.src = "images/pub_unset.png";
605 mark_img
.alt
= __("Please wait...");
606 query
= query
+ "&pub=0";
608 if (document
.getElementById("headlinesList") && !no_effects
) {
609 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
611 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
612 mark_img
.alt
= __("Publish article");
617 new Ajax
.Request(query
, {
618 onComplete: function(transport
) {
619 all_counters_callback2(transport
);
625 exception_error("togglePub", e
);
629 function correctHeadlinesOffset(id
) {
633 var hlist
= document
.getElementById("headlinesList");
634 var container
= document
.getElementById("headlinesInnerContainer");
635 var row
= document
.getElementById("RROW-" + id
);
637 var viewport
= container
.offsetHeight
;
639 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
640 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
642 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
643 debug("Vport: " + viewport
);
645 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
646 container
.scrollTop
= row
.offsetTop
;
647 } else if (rel_offset_bottom
> viewport
) {
649 /* doesn't properly work with Opera in some cases because
650 Opera fucks up element scrolling */
652 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
656 exception_error("correctHeadlinesOffset", e
);
661 function moveToPost(mode
) {
668 rows
= cdmGetVisibleArticles();
670 rows
= getVisibleHeadlineIds();
676 if (!document
.getElementById('RROW-' + active_post_id
)) {
677 active_post_id
= false;
680 if (active_post_id
== false) {
681 next_id
= getFirstVisibleHeadlineId();
682 prev_id
= getLastVisibleHeadlineId();
684 for (var i
= 0; i
< rows
.length
; i
++) {
685 if (rows
[i
] == active_post_id
) {
692 if (mode
== "next") {
696 if (!cdmArticleIsActuallyVisible(next_id
)) {
697 cdmScrollToArticleId(next_id
);
699 cdmSelectArticles("none");
700 toggleUnread(next_id
, 0, true);
701 toggleSelected(next_id
);
704 correctHeadlinesOffset(next_id
);
705 view(next_id
, getActiveFeedId());
710 if (mode
== "prev") {
713 cdmScrollToArticleId(prev_id
);
714 cdmSelectArticles("none");
715 toggleUnread(prev_id
, 0, true);
716 toggleSelected(prev_id
);
718 correctHeadlinesOffset(prev_id
);
719 view(prev_id
, getActiveFeedId());
725 exception_error("moveToPost", e
);
729 function toggleSelected(id
) {
732 var cb
= document
.getElementById("RCHK-" + id
);
734 var row
= document
.getElementById("RROW-" + id
);
736 var nc
= row
.className
;
738 if (!nc
.match("Selected")) {
739 nc
= nc
+ "Selected";
744 // In CDM basically last selected article == active article
745 if (isCdmMode()) active_post_id
= id
;
747 nc
= nc
.replace("Selected", "");
757 exception_error("toggleSelected", e
);
761 function toggleUnread_afh(effect
) {
764 var elem
= effect
.element
;
765 elem
.style
.backgroundColor
= "";
768 exception_error("toggleUnread_afh", e
);
772 function toggleUnread(id
, cmode
, effect
) {
775 var row
= document
.getElementById("RROW-" + id
);
777 var nc
= row
.className
;
778 var is_selected
= row
.className
.match("Selected");
779 nc
= nc
.replace("Unread", "");
780 nc
= nc
.replace("Selected", "");
782 // since we are removing selection from the object, uncheck
783 // corresponding checkbox
785 var cb
= document
.getElementById("RCHK-" + id
);
790 // NOTE: I'm not sure that resetting selection here is a feature -fox
792 if (cmode
== undefined || cmode
== 2) {
793 if (row
.className
.match("Unread")) {
797 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
798 afterFinish
: toggleUnread_afh
,
799 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
803 row
.className
= nc
+ "Unread";
805 } else if (cmode
== 0) {
809 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
810 afterFinish
: toggleUnread_afh
,
811 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
813 } else if (cmode
== 1) {
814 row
.className
= nc
+ "Unread";
817 // Disable unmarking as selected for the time being (16.05.08) -fox
818 if (is_selected
) row
.className
= row
.className
+ "Selected";
820 if (cmode
== undefined) cmode
= 2;
822 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
823 param_escape(id
) + "&cmode=" + param_escape(cmode
);
825 // notify_progress("Loading, please wait...");
827 new Ajax
.Request(query
, {
828 onComplete: function(transport
) {
829 all_counters_callback2(transport
);
836 exception_error("toggleUnread", e
);
840 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
845 rows
= cdmGetSelectedArticles();
847 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
850 if (rows
.length
== 0 && !no_error
) {
851 alert(__("No articles are selected."));
855 for (i
= 0; i
< rows
.length
; i
++) {
856 var row
= document
.getElementById("RROW-" + rows
[i
]);
858 var nc
= row
.className
;
859 nc
= nc
.replace("Unread", "");
860 nc
= nc
.replace("Selected", "");
862 if (set_state
== undefined) {
863 if (row
.className
.match("Unread")) {
864 row
.className
= nc
+ "Selected";
866 row
.className
= nc
+ "UnreadSelected";
870 if (set_state
== false) {
871 row
.className
= nc
+ "Selected";
874 if (set_state
== true) {
875 row
.className
= nc
+ "UnreadSelected";
880 if (rows
.length
> 0) {
884 if (set_state
== undefined) {
886 } else if (set_state
== true) {
888 } else if (set_state
== false) {
892 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
893 param_escape(rows
.toString()) + "&cmode=" + cmode
;
895 notify_progress("Loading, please wait...");
897 new Ajax
.Request(query
, {
898 onComplete: function(transport
) {
899 catchup_callback2(transport
, callback_func
);
905 exception_error("selectionToggleUnread", e
);
909 function selectionToggleMarked(cdm_mode
) {
915 rows
= cdmGetSelectedArticles();
917 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
920 if (rows
.length
== 0) {
921 alert(__("No articles are selected."));
925 for (i
= 0; i
< rows
.length
; i
++) {
926 toggleMark(rows
[i
], true, true);
929 if (rows
.length
> 0) {
931 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
932 param_escape(rows
.toString()) + "&cmode=2";
934 query
= query
+ "&afid=" + getActiveFeedId();
936 /* if (tagsAreDisplayed()) {
937 query = query + "&omode=tl";
939 query = query + "&omode=flc";
942 query
= query
+ "&omode=lc";
944 new Ajax
.Request(query
, {
945 onComplete: function(transport
) {
946 all_counters_callback2(transport
);
952 exception_error("selectionToggleMarked", e
);
956 function selectionTogglePublished(cdm_mode
) {
962 rows
= cdmGetSelectedArticles();
964 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
967 if (rows
.length
== 0) {
968 alert(__("No articles are selected."));
972 for (i
= 0; i
< rows
.length
; i
++) {
973 togglePub(rows
[i
], true, true);
976 if (rows
.length
> 0) {
978 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
979 param_escape(rows
.toString()) + "&cmode=2";
981 query
= query
+ "&afid=" + getActiveFeedId();
983 /* if (tagsAreDisplayed()) {
984 query = query + "&omode=tl";
986 query = query + "&omode=flc";
989 query
= query
+ "&omode=lc";
991 new Ajax
.Request(query
, {
992 onComplete: function(transport
) {
993 all_counters_callback2(transport
);
999 exception_error("selectionToggleMarked", e
);
1003 function cdmGetSelectedArticles() {
1004 var sel_articles
= new Array();
1005 var container
= document
.getElementById("headlinesInnerContainer");
1007 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1008 var child
= container
.childNodes
[i
];
1010 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1011 var c_id
= child
.id
.replace("RROW-", "");
1012 sel_articles
.push(c_id
);
1016 return sel_articles
;
1019 function cdmGetVisibleArticles() {
1020 var sel_articles
= new Array();
1021 var container
= document
.getElementById("headlinesInnerContainer");
1023 if (!container
) return sel_articles
;
1025 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1026 var child
= container
.childNodes
[i
];
1028 if (child
.id
&& child
.id
.match("RROW-")) {
1029 var c_id
= child
.id
.replace("RROW-", "");
1030 sel_articles
.push(c_id
);
1034 return sel_articles
;
1037 function cdmGetUnreadArticles() {
1038 var sel_articles
= new Array();
1039 var container
= document
.getElementById("headlinesInnerContainer");
1041 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1042 var child
= container
.childNodes
[i
];
1044 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1045 var c_id
= child
.id
.replace("RROW-", "");
1046 sel_articles
.push(c_id
);
1050 return sel_articles
;
1054 // mode = all,none,unread
1055 function cdmSelectArticles(mode
) {
1056 var container
= document
.getElementById("headlinesInnerContainer");
1058 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1059 var child
= container
.childNodes
[i
];
1061 if (child
.id
&& child
.id
.match("RROW-")) {
1062 var aid
= child
.id
.replace("RROW-", "");
1064 var cb
= document
.getElementById("RCHK-" + aid
);
1066 if (mode
== "all") {
1067 if (!child
.className
.match("Selected")) {
1068 child
.className
= child
.className
+ "Selected";
1071 } else if (mode
== "unread") {
1072 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1073 child
.className
= child
.className
+ "Selected";
1077 child
.className
= child
.className
.replace("Selected", "");
1084 function catchupPage() {
1086 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1088 var str
= __("Mark all visible articles in %s as read?");
1090 str
= str
.replace("%s", fn
);
1092 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1096 if (document
.getElementById("headlinesList")) {
1097 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1098 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1099 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1101 cdmSelectArticles('all');
1102 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1103 cdmSelectArticles('none');
1107 function catchupSelection() {
1113 if (document
.getElementById("headlinesList")) {
1114 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1116 rows
= cdmGetSelectedArticles();
1119 if (rows
.length
== 0) {
1120 alert(__("No articles are selected."));
1125 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1127 var str
= __("Mark %d selected articles in %s as read?");
1129 str
= str
.replace("%d", rows
.length
);
1130 str
= str
.replace("%s", fn
);
1132 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1136 if (document
.getElementById("headlinesList")) {
1137 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1138 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1140 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1141 // cdmSelectArticles('none');
1145 exception_error("catchupSelection", e
);
1150 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1152 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1153 printLockingError();
1156 var title
= prompt(__("Please enter label title:"), "");
1160 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1161 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1162 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1163 "&title=" + param_escape(title
);
1165 debug("LFS: " + query
);
1167 new Ajax
.Request(query
, {
1168 onComplete: function(transport
) {
1169 dlg_frefresh_callback(transport
);
1174 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1175 _tag_active_post_id
= id
;
1176 _tag_active_feed_id
= feed_id
;
1177 _tag_active_cdm
= cdm_enabled
;
1179 cache_invalidate(id
);
1182 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1184 displayDlg('editArticleTags', id
);
1188 function tag_saved_callback(transport
) {
1190 debug("in tag_saved_callback");
1195 if (tagsAreDisplayed()) {
1196 _reload_feedlist_after_view
= true;
1199 if (!_tag_active_cdm
) {
1200 if (active_post_id
== _tag_active_post_id
) {
1201 debug("reloading current article");
1202 view(_tag_active_post_id
, _tag_active_feed_id
);
1205 debug("reloading current feed");
1210 exception_error("catchup_callback", e
);
1214 function editTagsSave() {
1216 notify_progress("Saving article tags...");
1218 var form
= document
.forms
["tag_edit_form"];
1220 var query
= Form
.serialize("tag_edit_form");
1222 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1226 new Ajax
.Request(query
, {
1227 onComplete: function(transport
) {
1228 tag_saved_callback(transport
);
1233 function editTagsInsert() {
1236 var form
= document
.forms
["tag_edit_form"];
1238 var found_tags
= form
.found_tags
;
1239 var tags_str
= form
.tags_str
;
1241 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1243 if (tags_str
.value
.length
> 0 &&
1244 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1246 tags_str
.value
= tags_str
.value
+ ", ";
1249 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1251 found_tags
.selectedIndex
= 0;
1254 exception_error("editTagsInsert", e
);
1258 function cdmScrollViewport(where
) {
1259 debug("cdmScrollViewport: " + where
);
1261 var ctr
= document
.getElementById("headlinesInnerContainer");
1265 if (where
== "bottom") {
1266 ctr
.scrollTop
= ctr
.scrollHeight
;
1268 ctr
.scrollTop
= where
;
1272 function cdmArticleIsBelowViewport(id
) {
1274 var ctr
= document
.getElementById("headlinesInnerContainer");
1275 var e
= document
.getElementById("RROW-" + id
);
1277 if (!e
|| !ctr
) return;
1279 // article starts below viewport
1281 if (ctr
.scrollTop
< e
.offsetTop
) {
1288 exception_error("cdmArticleIsVisible", e
);
1292 function cdmArticleIsAboveViewport(id
) {
1294 var ctr
= document
.getElementById("headlinesInnerContainer");
1295 var e
= document
.getElementById("RROW-" + id
);
1297 if (!e
|| !ctr
) return;
1299 // article starts above viewport
1301 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1308 exception_error("cdmArticleIsVisible", e
);
1312 function cdmScrollToArticleId(id
) {
1314 var ctr
= document
.getElementById("headlinesInnerContainer");
1315 var e
= document
.getElementById("RROW-" + id
);
1317 if (!e
|| !ctr
) return;
1319 ctr
.scrollTop
= e
.offsetTop
;
1322 exception_error("cdmScrollToArticleId", e
);
1326 function cdmArticleIsActuallyVisible(id
) {
1328 var ctr
= document
.getElementById("headlinesInnerContainer");
1329 var e
= document
.getElementById("RROW-" + id
);
1331 if (!e
|| !ctr
) return;
1333 // article fits in viewport OR article is longer than viewport and
1334 // its bottom is visible
1336 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1337 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1341 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1342 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1343 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1352 exception_error("cdmArticleIsVisible", e
);
1356 function cdmWatchdog() {
1360 var ctr
= document
.getElementById("headlinesInnerContainer");
1364 var ids
= new Array();
1366 var e
= ctr
.firstChild
;
1369 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1370 e
.id
.match("RROW-")) {
1372 // article fits in viewport OR article is longer than viewport and
1373 // its bottom is visible
1375 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1376 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1378 // debug(e.id + " is visible " + e.offsetTop + "." +
1379 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1380 // (ctr.scrollTop + ctr.offsetHeight));
1382 ids
.push(e
.id
.replace("RROW-", ""));
1384 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1385 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1386 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1388 ids
.push(e
.id
.replace("RROW-", ""));
1392 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1394 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1395 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1397 ids.push(e.id.replace("RROW-", ""));
1406 debug("cdmWatchdog, ids= " + ids
.toString());
1408 if (ids
.length
> 0) {
1410 for (var i
= 0; i
< ids
.length
; i
++) {
1411 var e
= document
.getElementById("RROW-" + ids
[i
]);
1413 e
.className
= e
.className
.replace("Unread", "");
1417 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1418 param_escape(ids
.toString()) + "&cmode=0";
1420 new Ajax
.Request(query
, {
1421 onComplete: function(transport
) {
1422 all_counters_callback2(transport
);
1427 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1430 exception_error("cdmWatchdog", e
);
1436 function cache_inject(id
, article
, param
) {
1437 if (!cache_check_param(id
, param
)) {
1438 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1440 var cache_obj
= new Array();
1442 cache_obj
["id"] = id
;
1443 cache_obj
["data"] = article
;
1444 cache_obj
["param"] = param
;
1446 article_cache
.push(cache_obj
);
1449 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1453 function cache_find(id
) {
1454 for (var i
= 0; i
< article_cache
.length
; i
++) {
1455 if (article_cache
[i
]["id"] == id
) {
1456 return article_cache
[i
]["data"];
1462 function cache_find_param(id
, param
) {
1463 for (var i
= 0; i
< article_cache
.length
; i
++) {
1464 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1465 return article_cache
[i
]["data"];
1471 function cache_check(id
) {
1472 for (var i
= 0; i
< article_cache
.length
; i
++) {
1473 if (article_cache
[i
]["id"] == id
) {
1480 function cache_check_param(id
, param
) {
1481 for (var i
= 0; i
< article_cache
.length
; i
++) {
1483 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1484 // article_cache[i]["param"] + " vs " + id + ":" + param);
1486 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1493 function cache_expire() {
1494 while (article_cache
.length
> 25) {
1495 article_cache
.shift();
1499 function cache_empty() {
1500 article_cache
= new Array();
1503 function cache_invalidate(id
) {
1508 while (i
< article_cache
.length
) {
1509 if (article_cache
[i
]["id"] == id
) {
1510 debug("cache_invalidate: removed id " + id
);
1511 article_cache
.splice(i
, 1);
1516 debug("cache_invalidate: id not found: " + id
);
1519 exception_error("cache_invalidate", e
);
1523 function getActiveArticleId() {
1524 return active_post_id
;
1527 function cdmClicked(id
) {
1529 var elem
= document
.getElementById("RROW-" + id
);
1532 var id
= elem
.id
.replace("RROW-", "");
1533 active_post_id
= id
;
1535 cdmSelectArticles("none");
1536 toggleUnread(id
, 0, true);
1541 exception_error("cdmClicked", e
);
1545 function preload_article_callback(transport
) {
1547 if (transport
.responseXML
) {
1548 var articles
= transport
.responseXML
.getElementsByTagName("article");
1550 for (var i
= 0; i
< articles
.length
; i
++) {
1551 var id
= articles
[i
].getAttribute("id");
1552 if (!cache_check(id
)) {
1553 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1554 debug("preloaded article: " + id
);
1559 exception_error("preload_article_callback", e
);
1563 function preloadArticleUnderPointer(id
) {
1565 if (post_under_pointer
== id
&& !cache_check(id
)) {
1567 debug("trying to preload article " + id
);
1569 var neighbor_ids
= getRelativePostIds(id
, 1);
1571 /* only request uncached articles */
1573 var cids_to_request
= Array();
1575 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1576 if (!cache_check(neighbor_ids
[i
])) {
1577 cids_to_request
.push(neighbor_ids
[i
]);
1580 debug("additional ids: " + cids_to_request
.toString());
1582 cids_to_request
.push(id
);
1584 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1585 cids_to_request
.toString();
1586 new Ajax
.Request(query
, {
1587 onComplete: function(transport
) {
1588 preload_article_callback(transport
);
1592 exception_error("preloadArticleUnderPointer", e
);
1596 function postMouseIn(id
) {
1598 if (post_under_pointer
!= id
) {
1599 post_under_pointer
= id
;
1601 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1606 exception_error("postMouseIn", e
);
1610 function postMouseOut(id
) {
1612 post_under_pointer
= false;
1614 exception_error("postMouseOut", e
);
1618 function headlines_scroll_handler() {
1621 var e
= document
.getElementById("headlinesInnerContainer");
1623 // don't do infinite scrolling when Limit == All
1625 var toolbar_form
= document
.forms
["main_toolbar_form"];
1627 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1628 if (limit
.value
!= 0) {
1630 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1631 _infscroll_disable
);
1633 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1634 if (!_infscroll_disable
) {
1635 debug("more cowbell!");
1642 exception_error("headlines_scroll_handler", e
);
1646 function catchupRelativeToArticle(below
) {
1650 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1651 printLockingError();
1654 if (!getActiveArticleId()) {
1655 alert(__("No article is selected."));
1661 if (document
.getElementById("headlinesList")) {
1662 visible_ids
= getVisibleHeadlineIds();
1664 visible_ids
= cdmGetVisibleArticles();
1667 var ids_to_mark
= new Array();
1670 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1671 if (visible_ids
[i
] != getActiveArticleId()) {
1672 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1674 if (e
&& e
.className
.match("Unread")) {
1675 ids_to_mark
.push(visible_ids
[i
]);
1682 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1683 if (visible_ids
[i
] != getActiveArticleId()) {
1684 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1686 if (e
&& e
.className
.match("Unread")) {
1687 ids_to_mark
.push(visible_ids
[i
]);
1695 if (ids_to_mark
.length
== 0) {
1696 alert(__("No articles found to mark"));
1698 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1702 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1703 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1704 e
.className
= e
.className
.replace("Unread", "");
1707 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1708 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1710 new Ajax
.Request(query
, {
1711 onComplete: function(transport
) {
1712 catchup_callback2(transport
);
1719 exception_error("catchupRelativeToArticle", e
);
1723 function cdmExpandArticle(a_id
) {
1725 var id
= 'CICD-' + a_id
;
1728 Element
.hide("CEXC-" + a_id
);
1731 Effect
.Appear(id
, {duration
: 0.5,
1732 beforeStart: function(effect
) {
1733 var h_id
= 'CICH-' + a_id
;
1734 var h_elem
= document
.getElementById(h_id
);
1735 if (h_elem
) { h_elem
.style
.display
= "none"; }
1737 toggleUnread(a_id
, 0);
1742 exception_error("appearBlockElementF", e
);
1747 function fixHeadlinesOrder(ids
) {
1749 for (var i
= 0; i
< ids
.length
; i
++) {
1750 var e
= document
.getElementById("RROW-" + ids
[i
]);
1754 e
.className
= e
.className
.replace("even", "odd");
1756 e
.className
= e
.className
.replace("odd", "even");
1761 exception_error("fixHeadlinesOrder", e
);
1765 function subtoolbarSearch() {
1768 var q
= document
.getElementById("subtoolbar_search_box");
1772 q
= q
.value
.toUpperCase();
1775 var vis_ids
= new Array();
1777 if (document
.getElementById("headlinesList")) {
1778 ids
= getVisibleHeadlineIds();
1780 ids
= cdmGetVisibleArticles();
1783 for (var i
= 0; i
< ids
.length
; i
++) {
1784 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1787 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1788 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1790 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1791 vis_ids
.push(ids
[i
]);
1796 fixHeadlinesOrder(vis_ids
);
1799 exception_error("subtoolbarSearch", e
);
1803 function hideReadHeadlines() {
1807 var vis_ids
= new Array();
1809 if (document
.getElementById("headlinesList")) {
1810 ids
= getVisibleHeadlineIds();
1812 ids
= cdmGetVisibleArticles();
1815 var read_headlines_visible
= true;
1817 for (var i
= 0; i
< ids
.length
; i
++) {
1818 var row
= document
.getElementById("RROW-" + ids
[i
]);
1820 if (row
&& row
.className
) {
1821 if (read_headlines_visible
) {
1822 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1824 vis_ids
.push(ids
[i
]);
1826 //Effect.Fade(row, {duration : 0.3});
1831 vis_ids
.push(ids
[i
]);
1836 fixHeadlinesOrder(vis_ids
);
1838 read_headlines_visible
= !read_headlines_visible
;
1841 exception_error("hideReadHeadlines", e
);
1845 function getArticleUnderPointer() {
1846 return post_under_pointer
;