1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view
= false;
8 var _cdm_wd_timeout
= false;
9 var _cdm_wd_vishist
= new Array();
11 var article_cache
= new Array();
13 var vgroup_last_feed
= false;
14 var post_under_pointer
= false;
16 var last_requested_article
= false;
18 function catchup_callback2(transport
, callback
) {
20 debug("catchup_callback2 " + transport
+ ", " + callback
);
22 all_counters_callback2(transport
);
24 setTimeout(callback
, 10);
27 exception_error("catchup_callback2", e
, transport
);
31 function clean_feed_selections() {
33 var feeds
= $("feedList").getElementsByTagName("LI");
35 for (var i
= 0; i
< feeds
.length
; i
++) {
36 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
37 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
39 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
40 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
44 exception_error("clean_feed_selections", e
);
48 function headlines_callback2(transport
, feed_cur_page
) {
51 loading_set_progress(100);
53 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
55 if (!transport_error_check(transport
)) return;
57 clean_feed_selections();
62 if (transport
.responseXML
) {
63 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
65 is_cat
= headlines
.getAttribute("is_cat");
66 feed_id
= headlines
.getAttribute("id");
67 setActiveFeedId(feed_id
, is_cat
);
72 var feedr
= $("FEEDR-" + feed_id
);
73 if (feedr
&& !feedr
.className
.match("Selected")) {
74 feedr
.className
= feedr
.className
+ "Selected";
77 var feedr
= $("FCAT-" + feed_id
);
78 if (feedr
&& !feedr
.className
.match("Selected")) {
79 feedr
.className
= feedr
.className
+ "Selected";
83 var f
= $("headlines-frame");
85 if (feed_cur_page
== 0) {
86 debug("resetting headlines scrollTop");
91 if (transport
.responseXML
) {
92 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
93 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
94 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
95 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
97 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
99 var headlines_count
= headlines_count_obj
.getAttribute("value");
100 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
101 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
103 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
105 if (headlines_count
== 0) {
106 _infscroll_disable
= 1;
108 _infscroll_disable
= 0;
111 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
112 var articles
= transport
.responseXML
.getElementsByTagName("article");
113 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
115 if (feed_cur_page
== 0) {
117 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
119 var cache_prefix
= "";
127 cache_invalidate(cache_prefix
+ feed_id
);
129 if (!disable_cache
) {
130 cache_inject(cache_prefix
+ feed_id
,
131 headlines
.firstChild
.nodeValue
, headlines_unread
);
135 debug("headlines_callback: returned no data");
136 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
141 if (headlines_count
> 0) {
142 debug("adding some more headlines...");
144 var c
= $("headlinesList");
147 c
= $("headlinesInnerContainer");
150 var ids
= getSelectedArticleIds2();
152 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
154 debug("restore selected ids: " + ids
);
156 for (var i
= 0; i
< ids
.length
; i
++) {
157 markHeadline(ids
[i
]);
161 debug("no new headlines received");
164 debug("headlines_callback: returned no data");
165 notify_error("Error while trying to load more headlines");
171 for (var i
= 0; i
< articles
.length
; i
++) {
172 var a_id
= articles
[i
].getAttribute("id");
173 debug("found id: " + a_id
);
174 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
177 debug("no cached articles received");
181 debug("parsing piggybacked counters: " + counters
);
182 parse_counters(counters
, false);
184 debug("counters container not found in reply, requesting...");
189 debug("parsing runtime info: " + runtime_info
[0]);
190 parse_runtime_info(runtime_info
[0]);
192 debug("counters container not found in reply");
196 debug("headlines_callback: returned no XML object");
197 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
200 if (typeof correctPNG
!= 'undefined') {
204 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
206 if (!$("headlinesList") &&
207 getActiveFeedId() != -3 &&
208 getInitParam("cdm_auto_catchup") == 1) {
209 debug("starting CDM watchdog");
210 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
211 _cdm_wd_vishist
= new Array();
213 debug("not in CDM mode or watchdog disabled");
216 _feed_cur_page
= feed_cur_page
;
217 _infscroll_request_sent
= 0;
224 exception_error("headlines_callback2", e
, transport
);
228 function render_article(article
) {
230 var f
= $("content-frame");
235 var fi
= $("content-insert");
241 fi
.innerHTML
= article
;
244 exception_error("render_article", e
);
248 function showArticleInHeadlines(id
) {
252 cleanSelected("headlinesList");
254 var crow
= $("RROW-" + id
);
258 var article_is_unread
= crow
.className
.match("Unread");
260 crow
.className
= crow
.className
.replace("Unread", "");
262 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
264 var upd_img_pic
= $("FUPDPIC-" + id
);
266 var cache_prefix
= "";
268 if (activeFeedIsCat()) {
274 var view_mode
= false;
277 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
278 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
283 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
284 upd_img_pic
.src
= "images/blank_icon.gif";
286 cache_invalidate(cache_prefix
+ getActiveFeedId());
288 cache_inject(cache_prefix
+ getActiveFeedId(),
289 $("headlines-frame").innerHTML
,
290 get_feed_unread(getActiveFeedId()));
292 } else if (article_is_unread
&& view_mode
== "all_articles") {
294 cache_invalidate(cache_prefix
+ getActiveFeedId());
296 cache_inject(cache_prefix
+ getActiveFeedId(),
297 $("headlines-frame").innerHTML
,
298 get_feed_unread(getActiveFeedId())-1);
300 } else if (article_is_unread
) {
301 cache_invalidate(cache_prefix
+ getActiveFeedId());
307 exception_error("showArticleInHeadlines", e
);
311 function article_callback2(transport
, id
, feed_id
) {
313 debug("article_callback2 " + id
);
315 if (transport
.responseXML
) {
317 if (!transport_error_check(transport
)) return;
319 debug("looking for articles to cache...");
321 var articles
= transport
.responseXML
.getElementsByTagName("article");
323 for (var i
= 0; i
< articles
.length
; i
++) {
324 var a_id
= articles
[i
].getAttribute("id");
326 debug("found id: " + a_id
);
328 if (a_id
== active_post_id
) {
329 debug("active article, rendering...");
330 render_article(articles
[i
].firstChild
.nodeValue
);
333 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
336 if (id
!= last_requested_article
) {
337 debug("requested article id is out of sequence, aborting");
341 active_real_feed_id
= feed_id
;
344 showArticleInHeadlines(id
);
347 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id
]);
350 var reply
= transport
.responseXML
.firstChild
.firstChild
;
353 debug("article_callback: returned no XML object");
354 //var f = $("content-frame");
355 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
358 var date
= new Date();
359 last_article_view
= date
.getTime() / 1000;
361 if (typeof correctPNG
!= 'undefined') {
365 if (_reload_feedlist_after_view
) {
366 setTimeout('updateFeedList(false, false)', 50);
367 _reload_feedlist_after_view
= false;
369 if (transport
.responseXML
) {
370 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
373 debug("parsing piggybacked counters: " + counters
);
374 parse_counters(counters
, false);
376 debug("counters container not found in reply, requesting...");
384 exception_error("article_callback2", e
, transport
);
388 function view(id
, feed_id
, skip_history
) {
391 debug("loading article: " + id
+ "/" + feed_id
);
393 if (offline_mode
) return view_offline(id
, feed_id
);
395 var cached_article
= cache_find(id
);
397 debug("cache check result: " + (cached_article
!= false));
401 //setActiveFeedId(feed_id);
403 var query
= "backend.php?op=view&id=" + param_escape(id
) +
404 "&feed=" + param_escape(feed_id
);
406 var date
= new Date();
408 var neighbor_ids
= getRelativePostIds(active_post_id
);
410 /* only request uncached articles */
412 var cids_to_request
= Array();
414 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
415 if (!cache_check(neighbor_ids
[i
])) {
416 cids_to_request
.push(neighbor_ids
[i
]);
420 debug("additional ids: " + cids_to_request
.toString());
422 /* additional info for piggyback counters */
424 if (tagsAreDisplayed()) {
425 query
= query
+ "&omode=lt";
427 query
= query
+ "&omode=flc";
430 var date
= new Date();
431 var timestamp
= Math
.round(date
.getTime() / 1000);
432 query
= query
+ "&ts=" + timestamp
;
434 query
= query
+ "&cids=" + cids_to_request
.toString();
436 var crow
= $("RROW-" + id
);
437 var article_is_unread
= crow
.className
.match("Unread");
439 if (!async_counters_work
) {
440 query
= query
+ "&csync=true";
443 showArticleInHeadlines(id
);
445 if (!cached_article
) {
447 notify_progress("Loading, please wait...", true);
449 } else if (cached_article
&& article_is_unread
) {
451 query
= query
+ "&mode=prefetch";
453 render_article(cached_article
);
455 } else if (cached_article
) {
457 query
= query
+ "&mode=prefetch_old";
458 render_article(cached_article
);
464 last_requested_article
= id
;
466 new Ajax
.Request(query
, {
467 onComplete: function(transport
) {
468 article_callback2(transport
, id
, feed_id
);
474 exception_error("view", e
);
479 return toggleMark(id
);
483 return togglePub(id
);
486 function tMark_afh_off(effect
) {
488 var elem
= effect
.effects
[0].element
;
490 debug("tMark_afh_off : " + elem
.id
);
493 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
494 elem
.alt
= __("Star article");
499 exception_error("tMark_afh_off", e
);
503 function tPub_afh_off(effect
) {
505 var elem
= effect
.effects
[0].element
;
507 debug("tPub_afh_off : " + elem
.id
);
510 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
511 elem
.alt
= __("Publish article");
516 exception_error("tPub_afh_off", e
);
520 function toggleMark(id
, client_only
, no_effects
) {
524 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
526 query
= query
+ "&afid=" + getActiveFeedId();
528 if (tagsAreDisplayed()) {
529 query
= query
+ "&omode=tl";
531 query
= query
+ "&omode=flc";
534 var mark_img
= $("FMPIC-" + id
);
536 if (!mark_img
) return;
538 var vfeedu
= $("FEEDU--1");
539 var crow
= $("RROW-" + id
);
541 if (mark_img
.src
.match("mark_unset")) {
542 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
543 mark_img
.alt
= __("Unstar article");
544 query
= query
+ "&mark=1";
547 db
.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id
]);
551 //mark_img.src = "images/mark_unset.png";
552 mark_img
.alt
= __("Please wait...");
553 query
= query
+ "&mark=0";
555 if ($("headlinesList") && !no_effects
) {
556 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
558 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
559 mark_img
.alt
= __("Star article");
563 db
.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id
]);
568 update_local_feedlist_counters();
573 new Ajax
.Request(query
, {
574 onComplete: function(transport
) {
575 all_counters_callback2(transport
);
581 exception_error("toggleMark", e
);
585 function togglePub(id
, client_only
, no_effects
) {
589 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
591 query
= query
+ "&afid=" + getActiveFeedId();
593 if (tagsAreDisplayed()) {
594 query
= query
+ "&omode=tl";
596 query
= query
+ "&omode=flc";
599 var mark_img
= $("FPPIC-" + id
);
601 if (!mark_img
) return;
603 var vfeedu
= $("FEEDU--2");
604 var crow
= $("RROW-" + id
);
606 if (mark_img
.src
.match("pub_unset")) {
607 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
608 mark_img
.alt
= __("Unpublish article");
609 query
= query
+ "&pub=1";
613 //mark_img.src = "images/pub_unset.png";
614 mark_img
.alt
= __("Please wait...");
615 query
= query
+ "&pub=0";
617 if ($("headlinesList") && !no_effects
) {
618 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
620 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
621 mark_img
.alt
= __("Publish article");
626 new Ajax
.Request(query
, {
627 onComplete: function(transport
) {
628 all_counters_callback2(transport
);
634 exception_error("togglePub", e
);
638 function correctHeadlinesOffset(id
) {
642 var hlist
= $("headlinesList");
643 var container
= $("headlinesInnerContainer");
644 var row
= $("RROW-" + id
);
646 var viewport
= container
.offsetHeight
;
648 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
649 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
651 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
652 debug("Vport: " + viewport
);
654 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
655 container
.scrollTop
= row
.offsetTop
;
656 } else if (rel_offset_bottom
> viewport
) {
658 /* doesn't properly work with Opera in some cases because
659 Opera fucks up element scrolling */
661 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
665 exception_error("correctHeadlinesOffset", e
);
670 function moveToPost(mode
) {
677 rows
= cdmGetVisibleArticles();
679 rows
= getVisibleHeadlineIds();
685 if (!$('RROW-' + active_post_id
)) {
686 active_post_id
= false;
689 if (active_post_id
== false) {
690 next_id
= getFirstVisibleHeadlineId();
691 prev_id
= getLastVisibleHeadlineId();
693 for (var i
= 0; i
< rows
.length
; i
++) {
694 if (rows
[i
] == active_post_id
) {
701 if (mode
== "next") {
705 if (!cdmArticleIsActuallyVisible(next_id
)) {
706 cdmScrollToArticleId(next_id
);
708 cdmSelectArticles("none");
709 toggleUnread(next_id
, 0, true);
710 toggleSelected(next_id
);
713 correctHeadlinesOffset(next_id
);
714 view(next_id
, getActiveFeedId());
719 if (mode
== "prev") {
722 cdmScrollToArticleId(prev_id
);
723 cdmSelectArticles("none");
724 toggleUnread(prev_id
, 0, true);
725 toggleSelected(prev_id
);
727 correctHeadlinesOffset(prev_id
);
728 view(prev_id
, getActiveFeedId());
734 exception_error("moveToPost", e
);
738 function toggleSelected(id
) {
741 var cb
= $("RCHK-" + id
);
743 var row
= $("RROW-" + id
);
745 var nc
= row
.className
;
747 if (!nc
.match("Selected")) {
748 nc
= nc
+ "Selected";
753 // In CDM basically last selected article == active article
754 if (isCdmMode()) active_post_id
= id
;
756 nc
= nc
.replace("Selected", "");
766 exception_error("toggleSelected", e
);
770 function toggleUnread_afh(effect
) {
773 var elem
= effect
.element
;
774 elem
.style
.backgroundColor
= "";
777 exception_error("toggleUnread_afh", e
);
781 function toggleUnread(id
, cmode
, effect
) {
784 var row
= $("RROW-" + id
);
786 var nc
= row
.className
;
787 var is_selected
= row
.className
.match("Selected");
788 nc
= nc
.replace("Unread", "");
789 nc
= nc
.replace("Selected", "");
791 // since we are removing selection from the object, uncheck
792 // corresponding checkbox
794 var cb
= $("RCHK-" + id
);
799 // NOTE: I'm not sure that resetting selection here is a feature -fox
801 if (cmode
== undefined || cmode
== 2) {
802 if (row
.className
.match("Unread")) {
806 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
807 afterFinish
: toggleUnread_afh
,
808 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
812 row
.className
= nc
+ "Unread";
816 db
.execute("UPDATE articles SET unread = not unread "+
817 "WHERE id = ?", [id
]);
820 } else if (cmode
== 0) {
824 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
825 afterFinish
: toggleUnread_afh
,
826 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
830 db
.execute("UPDATE articles SET unread = 0 "+
831 "WHERE id = ?", [id
]);
834 } else if (cmode
== 1) {
835 row
.className
= nc
+ "Unread";
838 db
.execute("UPDATE articles SET unread = 1 "+
839 "WHERE id = ?", [id
]);
844 update_local_feedlist_counters();
846 // Disable unmarking as selected for the time being (16.05.08) -fox
847 if (is_selected
) row
.className
= row
.className
+ "Selected";
849 if (cmode
== undefined) cmode
= 2;
851 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
852 param_escape(id
) + "&cmode=" + param_escape(cmode
);
854 // notify_progress("Loading, please wait...");
856 new Ajax
.Request(query
, {
857 onComplete: function(transport
) {
858 all_counters_callback2(transport
);
864 exception_error("toggleUnread", e
);
868 function selectionRemoveLabel(id
) {
871 var ids
= getSelectedArticleIds2();
873 if (ids
.length
== 0) {
874 alert(__("No articles are selected."));
878 // var ok = confirm(__("Remove selected articles from label?"));
882 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
883 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
885 // notify_progress("Loading, please wait...");
887 cache_invalidate("F:" + (-11 - id
));
889 new Ajax
.Request(query
, {
890 onComplete: function(transport
) {
891 show_labels_in_headlines(transport
);
892 all_counters_callback2(transport
);
898 exception_error("selectionAssignLabel", e
);
903 function selectionAssignLabel(id
) {
906 var ids
= getSelectedArticleIds2();
908 if (ids
.length
== 0) {
909 alert(__("No articles are selected."));
913 // var ok = confirm(__("Assign selected articles to label?"));
917 cache_invalidate("F:" + (-11 - id
));
919 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
920 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
922 // notify_progress("Loading, please wait...");
924 new Ajax
.Request(query
, {
925 onComplete: function(transport
) {
926 show_labels_in_headlines(transport
);
927 all_counters_callback2(transport
);
933 exception_error("selectionAssignLabel", e
);
938 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
943 rows
= cdmGetSelectedArticles();
945 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
948 if (rows
.length
== 0 && !no_error
) {
949 alert(__("No articles are selected."));
953 for (i
= 0; i
< rows
.length
; i
++) {
954 var row
= $("RROW-" + rows
[i
]);
956 var nc
= row
.className
;
957 nc
= nc
.replace("Unread", "");
958 nc
= nc
.replace("Selected", "");
960 if (set_state
== undefined) {
961 if (row
.className
.match("Unread")) {
962 row
.className
= nc
+ "Selected";
964 row
.className
= nc
+ "UnreadSelected";
968 if (set_state
== false) {
969 row
.className
= nc
+ "Selected";
972 if (set_state
== true) {
973 row
.className
= nc
+ "UnreadSelected";
978 if (rows
.length
> 0) {
982 if (set_state
== undefined) {
984 } else if (set_state
== true) {
986 } else if (set_state
== false) {
990 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
991 param_escape(rows
.toString()) + "&cmode=" + cmode
;
993 notify_progress("Loading, please wait...");
995 new Ajax
.Request(query
, {
996 onComplete: function(transport
) {
997 catchup_callback2(transport
, callback_func
);
1003 exception_error("selectionToggleUnread", e
);
1007 function selectionToggleMarked(cdm_mode
) {
1013 rows
= cdmGetSelectedArticles();
1015 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1018 if (rows
.length
== 0) {
1019 alert(__("No articles are selected."));
1023 for (i
= 0; i
< rows
.length
; i
++) {
1024 toggleMark(rows
[i
], true, true);
1027 if (rows
.length
> 0) {
1029 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
1030 param_escape(rows
.toString()) + "&cmode=2";
1032 query
= query
+ "&afid=" + getActiveFeedId();
1034 /* if (tagsAreDisplayed()) {
1035 query = query + "&omode=tl";
1037 query = query + "&omode=flc";
1040 query
= query
+ "&omode=lc";
1042 new Ajax
.Request(query
, {
1043 onComplete: function(transport
) {
1044 all_counters_callback2(transport
);
1050 exception_error("selectionToggleMarked", e
);
1054 function selectionTogglePublished(cdm_mode
) {
1060 rows
= cdmGetSelectedArticles();
1062 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1065 if (rows
.length
== 0) {
1066 alert(__("No articles are selected."));
1070 for (i
= 0; i
< rows
.length
; i
++) {
1071 togglePub(rows
[i
], true, true);
1074 if (rows
.length
> 0) {
1076 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1077 param_escape(rows
.toString()) + "&cmode=2";
1079 query
= query
+ "&afid=" + getActiveFeedId();
1081 /* if (tagsAreDisplayed()) {
1082 query = query + "&omode=tl";
1084 query = query + "&omode=flc";
1087 query
= query
+ "&omode=lc";
1089 new Ajax
.Request(query
, {
1090 onComplete: function(transport
) {
1091 all_counters_callback2(transport
);
1097 exception_error("selectionToggleMarked", e
);
1101 function cdmGetSelectedArticles() {
1102 var sel_articles
= new Array();
1103 var container
= $("headlinesInnerContainer");
1105 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1106 var child
= container
.childNodes
[i
];
1108 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1109 var c_id
= child
.id
.replace("RROW-", "");
1110 sel_articles
.push(c_id
);
1114 return sel_articles
;
1117 function cdmGetVisibleArticles() {
1118 var sel_articles
= new Array();
1119 var container
= $("headlinesInnerContainer");
1121 if (!container
) return sel_articles
;
1123 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1124 var child
= container
.childNodes
[i
];
1126 if (child
.id
&& child
.id
.match("RROW-")) {
1127 var c_id
= child
.id
.replace("RROW-", "");
1128 sel_articles
.push(c_id
);
1132 return sel_articles
;
1135 function cdmGetUnreadArticles() {
1136 var sel_articles
= new Array();
1137 var container
= $("headlinesInnerContainer");
1139 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1140 var child
= container
.childNodes
[i
];
1142 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1143 var c_id
= child
.id
.replace("RROW-", "");
1144 sel_articles
.push(c_id
);
1148 return sel_articles
;
1152 // mode = all,none,unread
1153 function cdmSelectArticles(mode
) {
1154 var container
= $("headlinesInnerContainer");
1156 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1157 var child
= container
.childNodes
[i
];
1159 if (child
.id
&& child
.id
.match("RROW-")) {
1160 var aid
= child
.id
.replace("RROW-", "");
1162 var cb
= $("RCHK-" + aid
);
1164 if (mode
== "all") {
1165 if (!child
.className
.match("Selected")) {
1166 child
.className
= child
.className
+ "Selected";
1169 } else if (mode
== "unread") {
1170 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1171 child
.className
= child
.className
+ "Selected";
1175 child
.className
= child
.className
.replace("Selected", "");
1182 function catchupPage() {
1184 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1186 var str
= __("Mark all visible articles in %s as read?");
1188 str
= str
.replace("%s", fn
);
1190 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1194 if ($("headlinesList")) {
1195 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1196 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1197 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1199 cdmSelectArticles('all');
1200 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1201 cdmSelectArticles('none');
1205 function catchupSelection() {
1211 if ($("headlinesList")) {
1212 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1214 rows
= cdmGetSelectedArticles();
1217 if (rows
.length
== 0) {
1218 alert(__("No articles are selected."));
1223 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1225 var str
= __("Mark %d selected articles in %s as read?");
1227 str
= str
.replace("%d", rows
.length
);
1228 str
= str
.replace("%s", fn
);
1230 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1234 if ($("headlinesList")) {
1235 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1236 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1238 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1239 // cdmSelectArticles('none');
1243 exception_error("catchupSelection", e
);
1247 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1248 displayDlg('editArticleTags', id
);
1252 function tag_saved_callback(transport
) {
1254 debug("in tag_saved_callback");
1259 if (tagsAreDisplayed()) {
1260 _reload_feedlist_after_view
= true;
1264 if (transport
.responseXML
) {
1265 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1268 var id
= tags_str
.getAttribute("id");
1271 var tags
= $("ATSTR-" + id
);
1273 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1280 exception_error("tag_saved_callback", e
);
1284 function editTagsSave() {
1286 notify_progress("Saving article tags...");
1288 var form
= document
.forms
["tag_edit_form"];
1290 var query
= Form
.serialize("tag_edit_form");
1292 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1296 new Ajax
.Request(query
, {
1297 onComplete: function(transport
) {
1298 tag_saved_callback(transport
);
1303 function editTagsInsert() {
1306 var form
= document
.forms
["tag_edit_form"];
1308 var found_tags
= form
.found_tags
;
1309 var tags_str
= form
.tags_str
;
1311 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1313 if (tags_str
.value
.length
> 0 &&
1314 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1316 tags_str
.value
= tags_str
.value
+ ", ";
1319 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1321 found_tags
.selectedIndex
= 0;
1324 exception_error("editTagsInsert", e
);
1328 function cdmScrollViewport(where
) {
1329 debug("cdmScrollViewport: " + where
);
1331 var ctr
= $("headlinesInnerContainer");
1335 if (where
== "bottom") {
1336 ctr
.scrollTop
= ctr
.scrollHeight
;
1338 ctr
.scrollTop
= where
;
1342 function cdmArticleIsBelowViewport(id
) {
1344 var ctr
= $("headlinesInnerContainer");
1345 var e
= $("RROW-" + id
);
1347 if (!e
|| !ctr
) return;
1349 // article starts below viewport
1351 if (ctr
.scrollTop
< e
.offsetTop
) {
1358 exception_error("cdmArticleIsVisible", e
);
1362 function cdmArticleIsAboveViewport(id
) {
1364 var ctr
= $("headlinesInnerContainer");
1365 var e
= $("RROW-" + id
);
1367 if (!e
|| !ctr
) return;
1369 // article starts above viewport
1371 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1378 exception_error("cdmArticleIsVisible", e
);
1382 function cdmScrollToArticleId(id
) {
1384 var ctr
= $("headlinesInnerContainer");
1385 var e
= $("RROW-" + id
);
1387 if (!e
|| !ctr
) return;
1389 ctr
.scrollTop
= e
.offsetTop
;
1392 exception_error("cdmScrollToArticleId", e
);
1396 function cdmArticleIsActuallyVisible(id
) {
1398 var ctr
= $("headlinesInnerContainer");
1399 var e
= $("RROW-" + id
);
1401 if (!e
|| !ctr
) return;
1403 // article fits in viewport OR article is longer than viewport and
1404 // its bottom is visible
1406 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1407 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1411 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1412 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1413 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1422 exception_error("cdmArticleIsVisible", e
);
1426 function cdmWatchdog() {
1430 var ctr
= $("headlinesInnerContainer");
1434 var ids
= new Array();
1436 var e
= ctr
.firstChild
;
1439 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1440 e
.id
.match("RROW-")) {
1442 // article fits in viewport OR article is longer than viewport and
1443 // its bottom is visible
1445 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1446 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1448 // debug(e.id + " is visible " + e.offsetTop + "." +
1449 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1450 // (ctr.scrollTop + ctr.offsetHeight));
1452 ids
.push(e
.id
.replace("RROW-", ""));
1454 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1455 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1456 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1458 ids
.push(e
.id
.replace("RROW-", ""));
1462 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1464 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1465 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1467 ids.push(e.id.replace("RROW-", ""));
1476 debug("cdmWatchdog, ids= " + ids
.toString());
1478 if (ids
.length
> 0) {
1480 for (var i
= 0; i
< ids
.length
; i
++) {
1481 var e
= $("RROW-" + ids
[i
]);
1483 e
.className
= e
.className
.replace("Unread", "");
1487 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1488 param_escape(ids
.toString()) + "&cmode=0";
1490 new Ajax
.Request(query
, {
1491 onComplete: function(transport
) {
1492 all_counters_callback2(transport
);
1497 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1500 exception_error("cdmWatchdog", e
);
1506 function cache_inject(id
, article
, param
) {
1508 if (!cache_check_param(id
, param
)) {
1509 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1514 var date
= new Date();
1515 var ts
= Math
.round(date
.getTime() / 1000);
1517 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1518 [id
, article
, param
, ts
]);
1521 var cache_obj
= new Array();
1523 cache_obj
["id"] = id
;
1524 cache_obj
["data"] = article
;
1525 cache_obj
["param"] = param
;
1527 article_cache
.push(cache_obj
);
1531 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1534 exception_error("cache_inject", e
);
1538 function cache_find(id
) {
1541 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1544 if (rs
.isValidRow()) {
1545 var a
= rs
.field(0);
1553 for (var i
= 0; i
< article_cache
.length
; i
++) {
1554 if (article_cache
[i
]["id"] == id
) {
1555 return article_cache
[i
]["data"];
1562 function cache_find_param(id
, param
) {
1565 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1569 if (rs
.isValidRow()) {
1578 for (var i
= 0; i
< article_cache
.length
; i
++) {
1579 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1580 return article_cache
[i
]["data"];
1587 function cache_check(id
) {
1590 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1594 if (rs
.isValidRow()) {
1595 a
= rs
.field(0) != "0";
1603 for (var i
= 0; i
< article_cache
.length
; i
++) {
1604 if (article_cache
[i
]["id"] == id
) {
1612 function cache_check_param(id
, param
) {
1615 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1619 if (rs
.isValidRow()) {
1620 a
= rs
.field(0) != "0";
1628 for (var i
= 0; i
< article_cache
.length
; i
++) {
1629 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1637 function cache_expire() {
1639 var date
= new Date();
1640 var ts
= Math
.round(date
.getTime() / 1000);
1642 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1643 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1644 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1648 while (article_cache
.length
> 25) {
1649 article_cache
.shift();
1654 function cache_empty() {
1655 article_cache
= new Array();
1658 function cache_invalidate(id
) {
1662 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1663 return rs
.rowsAffected
!= 0;
1668 while (i
< article_cache
.length
) {
1669 if (article_cache
[i
]["id"] == id
) {
1670 debug("cache_invalidate: removed id " + id
);
1671 article_cache
.splice(i
, 1);
1678 debug("cache_invalidate: id not found: " + id
);
1681 exception_error("cache_invalidate", e
);
1685 function getActiveArticleId() {
1686 return active_post_id
;
1689 function cdmClicked(id
) {
1691 var elem
= $("RROW-" + id
);
1694 var id
= elem
.id
.replace("RROW-", "");
1695 active_post_id
= id
;
1697 // cdmSelectArticles("none");
1698 toggleUnread(id
, 0, true);
1699 // toggleSelected(id);
1703 exception_error("cdmClicked", e
);
1707 function preload_article_callback(transport
) {
1709 if (transport
.responseXML
) {
1710 var articles
= transport
.responseXML
.getElementsByTagName("article");
1712 for (var i
= 0; i
< articles
.length
; i
++) {
1713 var id
= articles
[i
].getAttribute("id");
1714 if (!cache_check(id
)) {
1715 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1716 debug("preloaded article: " + id
);
1721 exception_error("preload_article_callback", e
);
1725 function preloadArticleUnderPointer(id
) {
1727 if (getInitParam("bw_limit") == "1") return;
1729 if (post_under_pointer
== id
&& !cache_check(id
)) {
1731 debug("trying to preload article " + id
);
1733 var neighbor_ids
= getRelativePostIds(id
, 1);
1735 /* only request uncached articles */
1737 var cids_to_request
= Array();
1739 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1740 if (!cache_check(neighbor_ids
[i
])) {
1741 cids_to_request
.push(neighbor_ids
[i
]);
1744 debug("additional ids: " + cids_to_request
.toString());
1746 cids_to_request
.push(id
);
1748 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1749 cids_to_request
.toString();
1750 new Ajax
.Request(query
, {
1751 onComplete: function(transport
) {
1752 preload_article_callback(transport
);
1756 exception_error("preloadArticleUnderPointer", e
);
1760 function postMouseIn(id
) {
1762 if (post_under_pointer
!= id
) {
1763 post_under_pointer
= id
;
1765 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1770 exception_error("postMouseIn", e
);
1774 function postMouseOut(id
) {
1776 post_under_pointer
= false;
1778 exception_error("postMouseOut", e
);
1782 function headlines_scroll_handler() {
1785 var e
= $("headlinesInnerContainer");
1787 // don't do infinite scrolling when Limit == All
1789 var toolbar_form
= document
.forms
["main_toolbar_form"];
1791 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1792 if (limit
.value
!= 0) {
1794 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1795 _infscroll_disable
);
1797 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1798 if (!_infscroll_disable
) {
1799 debug("more cowbell!");
1806 exception_error("headlines_scroll_handler", e
);
1810 function catchupRelativeToArticle(below
) {
1815 if (!getActiveArticleId()) {
1816 alert(__("No article is selected."));
1822 if ($("headlinesList")) {
1823 visible_ids
= getVisibleHeadlineIds();
1825 visible_ids
= cdmGetVisibleArticles();
1828 var ids_to_mark
= new Array();
1831 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1832 if (visible_ids
[i
] != getActiveArticleId()) {
1833 var e
= $("RROW-" + visible_ids
[i
]);
1835 if (e
&& e
.className
.match("Unread")) {
1836 ids_to_mark
.push(visible_ids
[i
]);
1843 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1844 if (visible_ids
[i
] != getActiveArticleId()) {
1845 var e
= $("RROW-" + visible_ids
[i
]);
1847 if (e
&& e
.className
.match("Unread")) {
1848 ids_to_mark
.push(visible_ids
[i
]);
1856 if (ids_to_mark
.length
== 0) {
1857 alert(__("No articles found to mark"));
1859 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1863 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1864 var e
= $("RROW-" + ids_to_mark
[i
]);
1865 e
.className
= e
.className
.replace("Unread", "");
1868 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1869 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1871 new Ajax
.Request(query
, {
1872 onComplete: function(transport
) {
1873 catchup_callback2(transport
);
1880 exception_error("catchupRelativeToArticle", e
);
1884 function cdmExpandArticle(a_id
) {
1886 var id
= 'CICD-' + a_id
;
1889 Element
.hide("CEXC-" + a_id
);
1892 Effect
.Appear(id
, {duration
: 0.5,
1893 beforeStart: function(effect
) {
1894 var h_id
= 'CICH-' + a_id
;
1895 var h_elem
= $(h_id
);
1896 if (h_elem
) { h_elem
.style
.display
= "none"; }
1898 toggleUnread(a_id
, 0);
1903 exception_error("appearBlockElementF", e
);
1908 function fixHeadlinesOrder(ids
) {
1910 for (var i
= 0; i
< ids
.length
; i
++) {
1911 var e
= $("RROW-" + ids
[i
]);
1915 e
.className
= e
.className
.replace("even", "odd");
1917 e
.className
= e
.className
.replace("odd", "even");
1922 exception_error("fixHeadlinesOrder", e
);
1926 function hideReadHeadlines() {
1930 var vis_ids
= new Array();
1932 if ($("headlinesList")) {
1933 ids
= getVisibleHeadlineIds();
1935 ids
= cdmGetVisibleArticles();
1938 var read_headlines_visible
= true;
1940 for (var i
= 0; i
< ids
.length
; i
++) {
1941 var row
= $("RROW-" + ids
[i
]);
1943 if (row
&& row
.className
) {
1944 if (read_headlines_visible
) {
1945 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1947 vis_ids
.push(ids
[i
]);
1949 //Effect.Fade(row, {duration : 0.3});
1954 vis_ids
.push(ids
[i
]);
1959 fixHeadlinesOrder(vis_ids
);
1961 read_headlines_visible
= !read_headlines_visible
;
1964 exception_error("hideReadHeadlines", e
);
1968 function invertHeadlineSelection() {
1970 var rows
= new Array();
1974 r
= document
.getElementsByTagName("TR");
1976 r
= document
.getElementsByTagName("DIV");
1979 for (var i
= 0; i
< r
.length
; i
++) {
1980 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1985 for (var i
= 0; i
< rows
.length
; i
++) {
1986 var nc
= rows
[i
].className
;
1987 var id
= rows
[i
].id
.replace("RROW-", "");
1988 var cb
= $("RCHK-" + id
);
1990 if (!rows
[i
].className
.match("Selected")) {
1991 nc
= nc
+ "Selected";
1994 nc
= nc
.replace("Selected", "");
1998 rows
[i
].className
= nc
;
2003 exception_error("invertHeadlineSelection", e
);
2007 function getArticleUnderPointer() {
2008 return post_under_pointer
;
2011 function zoomToArticle(id
) {
2013 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
2015 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2018 exception_error("zoomToArticle", e
);
2022 function showOriginalArticleInline(id
) {
2025 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
2027 notify_progress("Loading, please wait...", true);
2029 new Ajax
.Request(query
, {
2030 onComplete: function(transport
) {
2032 if (transport
.responseXML
) {
2034 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2035 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2040 link
= link
.firstChild
.nodeValue
;
2042 var ci
= $("content-insert");
2044 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
2046 render_article(tmp
);
2053 exception_error("showOriginalArticleInline", e
);
2058 function scrollArticle(offset
) {
2061 var ci
= $("content-insert");
2063 ci
.scrollTop
+= offset
;
2066 var hi
= $("headlinesInnerContainer");
2068 hi
.scrollTop
+= offset
;
2073 exception_error("scrollArticle", e
);
2077 function show_labels_in_headlines(transport
) {
2079 if (transport
.responseXML
) {
2080 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2082 var elems
= info
.getElementsByTagName("entry");
2084 for (var l
= 0; l
< elems
.length
; l
++) {
2085 var e_id
= elems
[l
].getAttribute("id");
2089 var ctr
= $("HLLCTR-" + e_id
);
2092 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2100 exception_error("show_labels_in_headlines", e
);
2105 function toggleHeadlineActions() {
2107 var e
= $("headlineActionsBody");
2108 var p
= $("headlineActionsDrop");
2110 if (!Element
.visible(e
)) {
2117 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2118 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2121 exception_error("toggleHeadlineActions", e
);