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
= document
.getElementById("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
= document
.getElementById("FEEDR-" + feed_id
);
73 if (feedr
&& !feedr
.className
.match("Selected")) {
74 feedr
.className
= feedr
.className
+ "Selected";
77 var feedr
= document
.getElementById("FCAT-" + feed_id
);
78 if (feedr
&& !feedr
.className
.match("Selected")) {
79 feedr
.className
= feedr
.className
+ "Selected";
83 var f
= document
.getElementById("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
= document
.getElementById("headlinesList");
147 c
= document
.getElementById("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 (!document
.getElementById("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
= document
.getElementById("content-frame");
235 var fi
= document
.getElementById("content-insert");
241 fi
.innerHTML
= article
;
244 exception_error("render_article", e
);
248 function showArticleInHeadlines(id
) {
252 cleanSelected("headlinesList");
254 var crow
= document
.getElementById("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
= document
.getElementById("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 document
.getElementById("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 document
.getElementById("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 = document.getElementById("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
= document
.getElementById("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
= document
.getElementById("FMPIC-" + id
);
536 if (!mark_img
) return;
538 var vfeedu
= document
.getElementById("FEEDU--1");
539 var crow
= document
.getElementById("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 (document
.getElementById("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
= document
.getElementById("FPPIC-" + id
);
601 if (!mark_img
) return;
603 var vfeedu
= document
.getElementById("FEEDU--2");
604 var crow
= document
.getElementById("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 (document
.getElementById("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
= document
.getElementById("headlinesList");
643 var container
= document
.getElementById("headlinesInnerContainer");
644 var row
= document
.getElementById("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 (!document
.getElementById('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
= document
.getElementById("RCHK-" + id
);
743 var row
= document
.getElementById("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
= document
.getElementById("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
= document
.getElementById("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";
814 } else if (cmode
== 0) {
818 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
819 afterFinish
: toggleUnread_afh
,
820 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
822 } else if (cmode
== 1) {
823 row
.className
= nc
+ "Unread";
826 // Disable unmarking as selected for the time being (16.05.08) -fox
827 if (is_selected
) row
.className
= row
.className
+ "Selected";
829 if (cmode
== undefined) cmode
= 2;
831 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
832 param_escape(id
) + "&cmode=" + param_escape(cmode
);
834 // notify_progress("Loading, please wait...");
836 new Ajax
.Request(query
, {
837 onComplete: function(transport
) {
838 all_counters_callback2(transport
);
845 exception_error("toggleUnread", e
);
849 function selectionRemoveLabel(id
) {
852 var ids
= getSelectedArticleIds2();
854 if (ids
.length
== 0) {
855 alert(__("No articles are selected."));
859 // var ok = confirm(__("Remove selected articles from label?"));
863 var query
= "backend.php?op=rpc&subop=removeFromLabel&ids=" +
864 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
866 // notify_progress("Loading, please wait...");
868 cache_invalidate("F:" + (-11 - id
));
870 new Ajax
.Request(query
, {
871 onComplete: function(transport
) {
872 show_labels_in_headlines(transport
);
873 all_counters_callback2(transport
);
879 exception_error("selectionAssignLabel", e
);
884 function selectionAssignLabel(id
) {
887 var ids
= getSelectedArticleIds2();
889 if (ids
.length
== 0) {
890 alert(__("No articles are selected."));
894 // var ok = confirm(__("Assign selected articles to label?"));
898 cache_invalidate("F:" + (-11 - id
));
900 var query
= "backend.php?op=rpc&subop=assignToLabel&ids=" +
901 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
903 // notify_progress("Loading, please wait...");
905 new Ajax
.Request(query
, {
906 onComplete: function(transport
) {
907 show_labels_in_headlines(transport
);
908 all_counters_callback2(transport
);
914 exception_error("selectionAssignLabel", e
);
919 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
924 rows
= cdmGetSelectedArticles();
926 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
929 if (rows
.length
== 0 && !no_error
) {
930 alert(__("No articles are selected."));
934 for (i
= 0; i
< rows
.length
; i
++) {
935 var row
= document
.getElementById("RROW-" + rows
[i
]);
937 var nc
= row
.className
;
938 nc
= nc
.replace("Unread", "");
939 nc
= nc
.replace("Selected", "");
941 if (set_state
== undefined) {
942 if (row
.className
.match("Unread")) {
943 row
.className
= nc
+ "Selected";
945 row
.className
= nc
+ "UnreadSelected";
949 if (set_state
== false) {
950 row
.className
= nc
+ "Selected";
953 if (set_state
== true) {
954 row
.className
= nc
+ "UnreadSelected";
959 if (rows
.length
> 0) {
963 if (set_state
== undefined) {
965 } else if (set_state
== true) {
967 } else if (set_state
== false) {
971 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
972 param_escape(rows
.toString()) + "&cmode=" + cmode
;
974 notify_progress("Loading, please wait...");
976 new Ajax
.Request(query
, {
977 onComplete: function(transport
) {
978 catchup_callback2(transport
, callback_func
);
984 exception_error("selectionToggleUnread", e
);
988 function selectionToggleMarked(cdm_mode
) {
994 rows
= cdmGetSelectedArticles();
996 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
999 if (rows
.length
== 0) {
1000 alert(__("No articles are selected."));
1004 for (i
= 0; i
< rows
.length
; i
++) {
1005 toggleMark(rows
[i
], true, true);
1008 if (rows
.length
> 0) {
1010 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
1011 param_escape(rows
.toString()) + "&cmode=2";
1013 query
= query
+ "&afid=" + getActiveFeedId();
1015 /* if (tagsAreDisplayed()) {
1016 query = query + "&omode=tl";
1018 query = query + "&omode=flc";
1021 query
= query
+ "&omode=lc";
1023 new Ajax
.Request(query
, {
1024 onComplete: function(transport
) {
1025 all_counters_callback2(transport
);
1031 exception_error("selectionToggleMarked", e
);
1035 function selectionTogglePublished(cdm_mode
) {
1041 rows
= cdmGetSelectedArticles();
1043 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1046 if (rows
.length
== 0) {
1047 alert(__("No articles are selected."));
1051 for (i
= 0; i
< rows
.length
; i
++) {
1052 togglePub(rows
[i
], true, true);
1055 if (rows
.length
> 0) {
1057 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
1058 param_escape(rows
.toString()) + "&cmode=2";
1060 query
= query
+ "&afid=" + getActiveFeedId();
1062 /* if (tagsAreDisplayed()) {
1063 query = query + "&omode=tl";
1065 query = query + "&omode=flc";
1068 query
= query
+ "&omode=lc";
1070 new Ajax
.Request(query
, {
1071 onComplete: function(transport
) {
1072 all_counters_callback2(transport
);
1078 exception_error("selectionToggleMarked", e
);
1082 function cdmGetSelectedArticles() {
1083 var sel_articles
= new Array();
1084 var container
= document
.getElementById("headlinesInnerContainer");
1086 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1087 var child
= container
.childNodes
[i
];
1089 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1090 var c_id
= child
.id
.replace("RROW-", "");
1091 sel_articles
.push(c_id
);
1095 return sel_articles
;
1098 function cdmGetVisibleArticles() {
1099 var sel_articles
= new Array();
1100 var container
= document
.getElementById("headlinesInnerContainer");
1102 if (!container
) return sel_articles
;
1104 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1105 var child
= container
.childNodes
[i
];
1107 if (child
.id
&& child
.id
.match("RROW-")) {
1108 var c_id
= child
.id
.replace("RROW-", "");
1109 sel_articles
.push(c_id
);
1113 return sel_articles
;
1116 function cdmGetUnreadArticles() {
1117 var sel_articles
= new Array();
1118 var container
= document
.getElementById("headlinesInnerContainer");
1120 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1121 var child
= container
.childNodes
[i
];
1123 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1124 var c_id
= child
.id
.replace("RROW-", "");
1125 sel_articles
.push(c_id
);
1129 return sel_articles
;
1133 // mode = all,none,unread
1134 function cdmSelectArticles(mode
) {
1135 var container
= document
.getElementById("headlinesInnerContainer");
1137 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1138 var child
= container
.childNodes
[i
];
1140 if (child
.id
&& child
.id
.match("RROW-")) {
1141 var aid
= child
.id
.replace("RROW-", "");
1143 var cb
= document
.getElementById("RCHK-" + aid
);
1145 if (mode
== "all") {
1146 if (!child
.className
.match("Selected")) {
1147 child
.className
= child
.className
+ "Selected";
1150 } else if (mode
== "unread") {
1151 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1152 child
.className
= child
.className
+ "Selected";
1156 child
.className
= child
.className
.replace("Selected", "");
1163 function catchupPage() {
1165 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1167 var str
= __("Mark all visible articles in %s as read?");
1169 str
= str
.replace("%s", fn
);
1171 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1175 if (document
.getElementById("headlinesList")) {
1176 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1177 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1178 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1180 cdmSelectArticles('all');
1181 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1182 cdmSelectArticles('none');
1186 function catchupSelection() {
1192 if (document
.getElementById("headlinesList")) {
1193 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1195 rows
= cdmGetSelectedArticles();
1198 if (rows
.length
== 0) {
1199 alert(__("No articles are selected."));
1204 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1206 var str
= __("Mark %d selected articles in %s as read?");
1208 str
= str
.replace("%d", rows
.length
);
1209 str
= str
.replace("%s", fn
);
1211 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1215 if (document
.getElementById("headlinesList")) {
1216 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1217 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1219 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1220 // cdmSelectArticles('none');
1224 exception_error("catchupSelection", e
);
1228 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1229 displayDlg('editArticleTags', id
);
1233 function tag_saved_callback(transport
) {
1235 debug("in tag_saved_callback");
1240 if (tagsAreDisplayed()) {
1241 _reload_feedlist_after_view
= true;
1245 if (transport
.responseXML
) {
1246 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1249 var id
= tags_str
.getAttribute("id");
1252 var tags
= document
.getElementById("ATSTR-" + id
);
1254 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1261 exception_error("tag_saved_callback", e
);
1265 function editTagsSave() {
1267 notify_progress("Saving article tags...");
1269 var form
= document
.forms
["tag_edit_form"];
1271 var query
= Form
.serialize("tag_edit_form");
1273 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1277 new Ajax
.Request(query
, {
1278 onComplete: function(transport
) {
1279 tag_saved_callback(transport
);
1284 function editTagsInsert() {
1287 var form
= document
.forms
["tag_edit_form"];
1289 var found_tags
= form
.found_tags
;
1290 var tags_str
= form
.tags_str
;
1292 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1294 if (tags_str
.value
.length
> 0 &&
1295 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1297 tags_str
.value
= tags_str
.value
+ ", ";
1300 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1302 found_tags
.selectedIndex
= 0;
1305 exception_error("editTagsInsert", e
);
1309 function cdmScrollViewport(where
) {
1310 debug("cdmScrollViewport: " + where
);
1312 var ctr
= document
.getElementById("headlinesInnerContainer");
1316 if (where
== "bottom") {
1317 ctr
.scrollTop
= ctr
.scrollHeight
;
1319 ctr
.scrollTop
= where
;
1323 function cdmArticleIsBelowViewport(id
) {
1325 var ctr
= document
.getElementById("headlinesInnerContainer");
1326 var e
= document
.getElementById("RROW-" + id
);
1328 if (!e
|| !ctr
) return;
1330 // article starts below viewport
1332 if (ctr
.scrollTop
< e
.offsetTop
) {
1339 exception_error("cdmArticleIsVisible", e
);
1343 function cdmArticleIsAboveViewport(id
) {
1345 var ctr
= document
.getElementById("headlinesInnerContainer");
1346 var e
= document
.getElementById("RROW-" + id
);
1348 if (!e
|| !ctr
) return;
1350 // article starts above viewport
1352 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1359 exception_error("cdmArticleIsVisible", e
);
1363 function cdmScrollToArticleId(id
) {
1365 var ctr
= document
.getElementById("headlinesInnerContainer");
1366 var e
= document
.getElementById("RROW-" + id
);
1368 if (!e
|| !ctr
) return;
1370 ctr
.scrollTop
= e
.offsetTop
;
1373 exception_error("cdmScrollToArticleId", e
);
1377 function cdmArticleIsActuallyVisible(id
) {
1379 var ctr
= document
.getElementById("headlinesInnerContainer");
1380 var e
= document
.getElementById("RROW-" + id
);
1382 if (!e
|| !ctr
) return;
1384 // article fits in viewport OR article is longer than viewport and
1385 // its bottom is visible
1387 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1388 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1392 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1393 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1394 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1403 exception_error("cdmArticleIsVisible", e
);
1407 function cdmWatchdog() {
1411 var ctr
= document
.getElementById("headlinesInnerContainer");
1415 var ids
= new Array();
1417 var e
= ctr
.firstChild
;
1420 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1421 e
.id
.match("RROW-")) {
1423 // article fits in viewport OR article is longer than viewport and
1424 // its bottom is visible
1426 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1427 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1429 // debug(e.id + " is visible " + e.offsetTop + "." +
1430 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1431 // (ctr.scrollTop + ctr.offsetHeight));
1433 ids
.push(e
.id
.replace("RROW-", ""));
1435 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1436 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1437 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1439 ids
.push(e
.id
.replace("RROW-", ""));
1443 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1445 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1446 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1448 ids.push(e.id.replace("RROW-", ""));
1457 debug("cdmWatchdog, ids= " + ids
.toString());
1459 if (ids
.length
> 0) {
1461 for (var i
= 0; i
< ids
.length
; i
++) {
1462 var e
= document
.getElementById("RROW-" + ids
[i
]);
1464 e
.className
= e
.className
.replace("Unread", "");
1468 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1469 param_escape(ids
.toString()) + "&cmode=0";
1471 new Ajax
.Request(query
, {
1472 onComplete: function(transport
) {
1473 all_counters_callback2(transport
);
1478 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1481 exception_error("cdmWatchdog", e
);
1487 function cache_inject(id
, article
, param
) {
1489 if (!cache_check_param(id
, param
)) {
1490 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1495 var date
= new Date();
1496 var ts
= Math
.round(date
.getTime() / 1000);
1498 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1499 [id
, article
, param
, ts
]);
1502 var cache_obj
= new Array();
1504 cache_obj
["id"] = id
;
1505 cache_obj
["data"] = article
;
1506 cache_obj
["param"] = param
;
1508 article_cache
.push(cache_obj
);
1512 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1515 exception_error("cache_inject", e
);
1519 function cache_find(id
) {
1522 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1524 if (rs
.isValidRow()) {
1529 for (var i
= 0; i
< article_cache
.length
; i
++) {
1530 if (article_cache
[i
]["id"] == id
) {
1531 return article_cache
[i
]["data"];
1538 function cache_find_param(id
, param
) {
1541 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1544 if (rs
.isValidRow()) {
1549 for (var i
= 0; i
< article_cache
.length
; i
++) {
1550 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1551 return article_cache
[i
]["data"];
1558 function cache_check(id
) {
1561 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1564 if (rs
.isValidRow()) {
1565 return rs
.field(0) != "0";
1569 for (var i
= 0; i
< article_cache
.length
; i
++) {
1570 if (article_cache
[i
]["id"] == id
) {
1578 function cache_check_param(id
, param
) {
1581 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1584 if (rs
.isValidRow()) {
1585 return rs
.field(0) != "0";
1589 for (var i
= 0; i
< article_cache
.length
; i
++) {
1590 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1598 function cache_expire() {
1600 var date
= new Date();
1601 var ts
= Math
.round(date
.getTime() / 1000);
1603 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1604 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1605 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1609 while (article_cache
.length
> 25) {
1610 article_cache
.shift();
1615 function cache_empty() {
1616 article_cache
= new Array();
1619 function cache_invalidate(id
) {
1623 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1624 return rs
.rowsAffected
!= 0;
1629 while (i
< article_cache
.length
) {
1630 if (article_cache
[i
]["id"] == id
) {
1631 debug("cache_invalidate: removed id " + id
);
1632 article_cache
.splice(i
, 1);
1639 debug("cache_invalidate: id not found: " + id
);
1642 exception_error("cache_invalidate", e
);
1646 function getActiveArticleId() {
1647 return active_post_id
;
1650 function cdmClicked(id
) {
1652 var elem
= document
.getElementById("RROW-" + id
);
1655 var id
= elem
.id
.replace("RROW-", "");
1656 active_post_id
= id
;
1658 cdmSelectArticles("none");
1659 toggleUnread(id
, 0, true);
1664 exception_error("cdmClicked", e
);
1668 function preload_article_callback(transport
) {
1670 if (transport
.responseXML
) {
1671 var articles
= transport
.responseXML
.getElementsByTagName("article");
1673 for (var i
= 0; i
< articles
.length
; i
++) {
1674 var id
= articles
[i
].getAttribute("id");
1675 if (!cache_check(id
)) {
1676 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1677 debug("preloaded article: " + id
);
1682 exception_error("preload_article_callback", e
);
1686 function preloadArticleUnderPointer(id
) {
1688 if (getInitParam("bw_limit") == "1") return;
1690 if (post_under_pointer
== id
&& !cache_check(id
)) {
1692 debug("trying to preload article " + id
);
1694 var neighbor_ids
= getRelativePostIds(id
, 1);
1696 /* only request uncached articles */
1698 var cids_to_request
= Array();
1700 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1701 if (!cache_check(neighbor_ids
[i
])) {
1702 cids_to_request
.push(neighbor_ids
[i
]);
1705 debug("additional ids: " + cids_to_request
.toString());
1707 cids_to_request
.push(id
);
1709 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1710 cids_to_request
.toString();
1711 new Ajax
.Request(query
, {
1712 onComplete: function(transport
) {
1713 preload_article_callback(transport
);
1717 exception_error("preloadArticleUnderPointer", e
);
1721 function postMouseIn(id
) {
1723 if (post_under_pointer
!= id
) {
1724 post_under_pointer
= id
;
1726 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1731 exception_error("postMouseIn", e
);
1735 function postMouseOut(id
) {
1737 post_under_pointer
= false;
1739 exception_error("postMouseOut", e
);
1743 function headlines_scroll_handler() {
1746 var e
= document
.getElementById("headlinesInnerContainer");
1748 // don't do infinite scrolling when Limit == All
1750 var toolbar_form
= document
.forms
["main_toolbar_form"];
1752 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1753 if (limit
.value
!= 0) {
1755 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1756 _infscroll_disable
);
1758 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1759 if (!_infscroll_disable
) {
1760 debug("more cowbell!");
1767 exception_error("headlines_scroll_handler", e
);
1771 function catchupRelativeToArticle(below
) {
1776 if (!getActiveArticleId()) {
1777 alert(__("No article is selected."));
1783 if (document
.getElementById("headlinesList")) {
1784 visible_ids
= getVisibleHeadlineIds();
1786 visible_ids
= cdmGetVisibleArticles();
1789 var ids_to_mark
= new Array();
1792 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1793 if (visible_ids
[i
] != getActiveArticleId()) {
1794 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1796 if (e
&& e
.className
.match("Unread")) {
1797 ids_to_mark
.push(visible_ids
[i
]);
1804 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1805 if (visible_ids
[i
] != getActiveArticleId()) {
1806 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1808 if (e
&& e
.className
.match("Unread")) {
1809 ids_to_mark
.push(visible_ids
[i
]);
1817 if (ids_to_mark
.length
== 0) {
1818 alert(__("No articles found to mark"));
1820 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1824 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1825 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1826 e
.className
= e
.className
.replace("Unread", "");
1829 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1830 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1832 new Ajax
.Request(query
, {
1833 onComplete: function(transport
) {
1834 catchup_callback2(transport
);
1841 exception_error("catchupRelativeToArticle", e
);
1845 function cdmExpandArticle(a_id
) {
1847 var id
= 'CICD-' + a_id
;
1850 Element
.hide("CEXC-" + a_id
);
1853 Effect
.Appear(id
, {duration
: 0.5,
1854 beforeStart: function(effect
) {
1855 var h_id
= 'CICH-' + a_id
;
1856 var h_elem
= document
.getElementById(h_id
);
1857 if (h_elem
) { h_elem
.style
.display
= "none"; }
1859 toggleUnread(a_id
, 0);
1864 exception_error("appearBlockElementF", e
);
1869 function fixHeadlinesOrder(ids
) {
1871 for (var i
= 0; i
< ids
.length
; i
++) {
1872 var e
= document
.getElementById("RROW-" + ids
[i
]);
1876 e
.className
= e
.className
.replace("even", "odd");
1878 e
.className
= e
.className
.replace("odd", "even");
1883 exception_error("fixHeadlinesOrder", e
);
1887 function hideReadHeadlines() {
1891 var vis_ids
= new Array();
1893 if (document
.getElementById("headlinesList")) {
1894 ids
= getVisibleHeadlineIds();
1896 ids
= cdmGetVisibleArticles();
1899 var read_headlines_visible
= true;
1901 for (var i
= 0; i
< ids
.length
; i
++) {
1902 var row
= document
.getElementById("RROW-" + ids
[i
]);
1904 if (row
&& row
.className
) {
1905 if (read_headlines_visible
) {
1906 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
1908 vis_ids
.push(ids
[i
]);
1910 //Effect.Fade(row, {duration : 0.3});
1915 vis_ids
.push(ids
[i
]);
1920 fixHeadlinesOrder(vis_ids
);
1922 read_headlines_visible
= !read_headlines_visible
;
1925 exception_error("hideReadHeadlines", e
);
1929 function invertHeadlineSelection() {
1931 var rows
= new Array();
1935 r
= document
.getElementsByTagName("TR");
1937 r
= document
.getElementsByTagName("DIV");
1940 for (var i
= 0; i
< r
.length
; i
++) {
1941 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
1946 for (var i
= 0; i
< rows
.length
; i
++) {
1947 var nc
= rows
[i
].className
;
1948 var id
= rows
[i
].id
.replace("RROW-", "");
1949 var cb
= document
.getElementById("RCHK-" + id
);
1951 if (!rows
[i
].className
.match("Selected")) {
1952 nc
= nc
+ "Selected";
1955 nc
= nc
.replace("Selected", "");
1959 rows
[i
].className
= nc
;
1964 exception_error("invertHeadlineSelection", e
);
1968 function getArticleUnderPointer() {
1969 return post_under_pointer
;
1972 function zoomToArticle(id
) {
1974 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1976 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1979 exception_error("zoomToArticle", e
);
1983 function showOriginalArticleInline(id
) {
1986 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1988 notify_progress("Loading, please wait...", true);
1990 new Ajax
.Request(query
, {
1991 onComplete: function(transport
) {
1993 if (transport
.responseXML
) {
1995 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1996 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2001 link
= link
.firstChild
.nodeValue
;
2003 var ci
= document
.getElementById("content-insert");
2005 var tmp
= "<iframe id=\"inline_orig_article\" width=\""+ci
.offsetWidth
+"\" height=\""+ci
.offsetHeight
+"\" style=\"border-width : 0px;\" src=\""+link
+"\"></iframe>";
2007 render_article(tmp
);
2014 exception_error("showOriginalArticleInline", e
);
2019 function scrollArticle(offset
) {
2022 var ci
= document
.getElementById("content-insert");
2024 ci
.scrollTop
+= offset
;
2027 var hi
= document
.getElementById("headlinesInnerContainer");
2029 hi
.scrollTop
+= offset
;
2034 exception_error("scrollArticle", e
);
2038 function show_labels_in_headlines(transport
) {
2040 if (transport
.responseXML
) {
2041 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2043 var elems
= info
.getElementsByTagName("entry");
2045 for (var l
= 0; l
< elems
.length
; l
++) {
2046 var e_id
= elems
[l
].getAttribute("id");
2050 var ctr
= document
.getElementById("HLLCTR-" + e_id
);
2053 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2061 exception_error("show_labels_in_headlines", e
);
2066 function toggleHeadlineActions() {
2068 var e
= document
.getElementById("headlineActionsBody");
2069 var p
= document
.getElementById("headlineActionsDrop");
2071 if (!Element
.visible(e
)) {
2078 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2079 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
2082 exception_error("toggleHeadlineActions", e
);