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 function catchup_callback() {
24 if (xmlhttp_rpc
.readyState
== 4) {
26 debug("catchup_callback");
28 all_counters_callback2(xmlhttp_rpc
);
29 if (_catchup_callback_func
) {
30 setTimeout(_catchup_callback_func
, 10);
33 exception_error("catchup_callback", e
);
38 function catchup_callback2(transport
, callback
) {
40 debug("catchup_callback2 " + transport
+ ", " + callback
);
42 all_counters_callback2(transport
);
44 setTimeout(callback
, 10);
47 exception_error("catchup_callback2", e
);
51 function clean_feed_selections() {
53 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
55 for (var i
= 0; i
< feeds
.length
; i
++) {
56 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
57 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 exception_error("clean_feed_selections", e
);
65 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
68 loading_set_progress(100);
70 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
72 clean_feed_selections();
74 setActiveFeedId(active_feed_id
);
76 if (is_cat
!= undefined) {
77 active_feed_is_cat
= is_cat
;
81 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
82 if (feedr
&& !feedr
.className
.match("Selected")) {
83 feedr
.className
= feedr
.className
+ "Selected";
87 var f
= document
.getElementById("headlines-frame");
89 if (feed_cur_page
== 0) {
90 debug("resetting headlines scrollTop");
95 if (transport
.responseXML
) {
96 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
97 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
98 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
99 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
101 var vgroup_last_feed_obj
= transport
.responseXML
.getElementsByTagName("vgroup-last-feed")[0];
103 var headlines_count
= headlines_count_obj
.getAttribute("value");
104 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
105 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
107 vgroup_last_feed
= vgroup_last_feed_obj
.getAttribute("value");
109 if (headlines_count
== 0) {
110 _infscroll_disable
= 1;
112 _infscroll_disable
= 0;
115 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
116 var articles
= transport
.responseXML
.getElementsByTagName("article");
117 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
119 if (feed_cur_page
== 0) {
121 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
123 var cache_prefix
= "";
131 cache_invalidate(cache_prefix
+ active_feed_id
);
133 if (!disable_cache
) {
134 cache_inject(cache_prefix
+ active_feed_id
,
135 headlines
.firstChild
.nodeValue
, headlines_unread
);
139 debug("headlines_callback: returned no data");
140 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
145 if (headlines_count
> 0) {
146 debug("adding some more headlines...");
148 var c
= document
.getElementById("headlinesList");
151 c
= document
.getElementById("headlinesInnerContainer");
154 var ids
= getSelectedArticleIds2();
156 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
158 debug("restore selected ids: " + ids
);
160 for (var i
= 0; i
< ids
.length
; i
++) {
161 markHeadline(ids
[i
]);
167 debug("no new headlines received");
170 debug("headlines_callback: returned no data");
171 notify_error("Error while trying to load more headlines");
177 for (var i
= 0; i
< articles
.length
; i
++) {
178 var a_id
= articles
[i
].getAttribute("id");
179 debug("found id: " + a_id
);
180 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
183 debug("no cached articles received");
187 debug("parsing piggybacked counters: " + counters
);
188 parse_counters(counters
, false);
190 debug("counters container not found in reply, requesting...");
195 debug("parsing runtime info: " + runtime_info
[0]);
196 parse_runtime_info(runtime_info
[0]);
198 debug("counters container not found in reply");
202 debug("headlines_callback: returned no XML object");
203 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
206 if (typeof correctPNG
!= 'undefined') {
210 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
212 if (!document
.getElementById("headlinesList") &&
213 getInitParam("cdm_auto_catchup") == 1) {
214 debug("starting CDM watchdog");
215 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
216 _cdm_wd_vishist
= new Array();
218 debug("not in CDM mode or watchdog disabled");
221 if (_tag_cdm_scroll
) {
223 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
224 _tag_cdm_scroll
= false;
225 debug("resetting headlinesInner scrollTop");
230 _feed_cur_page
= feed_cur_page
;
231 _infscroll_request_sent
= 0;
238 exception_error("headlines_callback2", e
);
242 function render_article(article
) {
244 var f
= document
.getElementById("content-frame");
249 f
.innerHTML
= article
;
252 exception_error("render_article", e
);
256 function showArticleInHeadlines(id
) {
260 cleanSelected("headlinesList");
262 var crow
= document
.getElementById("RROW-" + id
);
266 var article_is_unread
= crow
.className
.match("Unread");
268 crow
.className
= crow
.className
.replace("Unread", "");
270 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
272 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
274 var cache_prefix
= "";
276 if (activeFeedIsCat()) {
282 var view_mode
= false;
285 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
286 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
288 exception_error("showArticleInHeadlines/viewmode", e
, true);
291 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
292 upd_img_pic
.src
= "images/blank_icon.gif";
294 cache_invalidate(cache_prefix
+ getActiveFeedId());
296 cache_inject(cache_prefix
+ getActiveFeedId(),
297 document
.getElementById("headlines-frame").innerHTML
,
298 get_feed_unread(getActiveFeedId()));
300 } else if (article_is_unread
&& view_mode
== "all_articles") {
302 cache_invalidate(cache_prefix
+ getActiveFeedId());
304 cache_inject(cache_prefix
+ getActiveFeedId(),
305 document
.getElementById("headlines-frame").innerHTML
,
306 get_feed_unread(getActiveFeedId())-1);
308 } else if (article_is_unread
) {
309 cache_invalidate(cache_prefix
+ getActiveFeedId());
315 exception_error("showArticleInHeadlines", e
);
319 function article_callback2(transport
, id
, feed_id
) {
321 debug("article_callback2 " + id
);
323 if (transport
.responseXML
) {
325 active_real_feed_id
= feed_id
;
328 showArticleInHeadlines(id
);
330 var reply
= transport
.responseXML
.firstChild
.firstChild
;
332 var articles
= transport
.responseXML
.getElementsByTagName("article");
334 for (var i
= 0; i
< articles
.length
; i
++) {
335 var a_id
= articles
[i
].getAttribute("id");
337 debug("found id: " + a_id
);
339 if (a_id
== active_post_id
) {
340 debug("active article, rendering...");
341 render_article(articles
[i
].firstChild
.nodeValue
);
344 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
348 debug("article_callback: returned no XML object");
349 var f
= document
.getElementById("content-frame");
350 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
353 var date
= new Date();
354 last_article_view
= date
.getTime() / 1000;
356 if (typeof correctPNG
!= 'undefined') {
360 if (_reload_feedlist_after_view
) {
361 setTimeout('updateFeedList(false, false)', 50);
362 _reload_feedlist_after_view
= false;
364 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
367 debug("parsing piggybacked counters: " + counters
);
368 parse_counters(counters
, false);
370 debug("counters container not found in reply, requesting...");
377 exception_error("article_callback2", e
);
381 function view(id
, feed_id
, skip_history
) {
384 debug("loading article: " + id
+ "/" + feed_id
);
386 var cached_article
= cache_find(id
);
388 debug("cache check result: " + (cached_article
!= false));
392 //setActiveFeedId(feed_id);
394 var query
= "backend.php?op=view&id=" + param_escape(id
) +
395 "&feed=" + param_escape(feed_id
);
397 var date
= new Date();
399 var neighbor_ids
= getRelativePostIds(active_post_id
);
401 /* only request uncached articles */
403 var cids_to_request
= Array();
405 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
406 if (!cache_check(neighbor_ids
[i
])) {
407 cids_to_request
.push(neighbor_ids
[i
]);
411 debug("additional ids: " + cids_to_request
.toString());
413 /* additional info for piggyback counters */
415 if (tagsAreDisplayed()) {
416 query
= query
+ "&omode=lt";
418 query
= query
+ "&omode=flc";
421 var date
= new Date();
422 var timestamp
= Math
.round(date
.getTime() / 1000);
423 query
= query
+ "&ts=" + timestamp
;
425 query
= query
+ "&cids=" + cids_to_request
.toString();
427 var crow
= document
.getElementById("RROW-" + id
);
428 var article_is_unread
= crow
.className
.match("Unread");
430 if (!cached_article
) {
432 notify_progress("Loading, please wait...");
434 } else if (cached_article
&& article_is_unread
) {
436 query
= query
+ "&mode=prefetch";
438 render_article(cached_article
);
440 } else if (cached_article
) {
442 query
= query
+ "&mode=prefetch_old";
443 render_article(cached_article
);
444 showArticleInHeadlines(id
);
450 new Ajax
.Request(query
, {
451 onComplete: function(transport
) {
452 article_callback2(transport
, id
, feed_id
);
456 exception_error("view", e
);
461 return toggleMark(id
);
465 return togglePub(id
);
468 function tMark_afh_off(effect
) {
470 var elem
= effect
.effects
[0].element
;
472 debug("tMark_afh_off : " + elem
.id
);
475 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
476 elem
.alt
= __("Star article");
481 exception_error("tMark_afh_off", e
);
485 function tPub_afh_off(effect
) {
487 var elem
= effect
.effects
[0].element
;
489 debug("tPub_afh_off : " + elem
.id
);
492 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
493 elem
.alt
= __("Publish article");
498 exception_error("tPub_afh_off", e
);
502 function toggleMark(id
, client_only
, no_effects
) {
506 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
508 query
= query
+ "&afid=" + getActiveFeedId();
510 if (tagsAreDisplayed()) {
511 query
= query
+ "&omode=tl";
513 query
= query
+ "&omode=flc";
516 var mark_img
= document
.getElementById("FMPIC-" + id
);
517 var vfeedu
= document
.getElementById("FEEDU--1");
518 var crow
= document
.getElementById("RROW-" + id
);
520 if (mark_img
.src
.match("mark_unset")) {
521 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
522 mark_img
.alt
= __("Unstar article");
523 query
= query
+ "&mark=1";
526 //mark_img.src = "images/mark_unset.png";
527 mark_img
.alt
= __("Please wait...");
528 query
= query
+ "&mark=0";
530 if (document
.getElementById("headlinesList") && !no_effects
) {
531 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
533 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
534 mark_img
.alt
= __("Star article");
541 new Ajax
.Request(query
, {
542 onComplete: function(transport
) {
543 all_counters_callback2(transport
);
549 exception_error("toggleMark", e
);
553 function togglePub(id
, client_only
, no_effects
) {
557 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
559 query
= query
+ "&afid=" + getActiveFeedId();
561 if (tagsAreDisplayed()) {
562 query
= query
+ "&omode=tl";
564 query
= query
+ "&omode=flc";
567 var mark_img
= document
.getElementById("FPPIC-" + id
);
568 var vfeedu
= document
.getElementById("FEEDU--2");
569 var crow
= document
.getElementById("RROW-" + id
);
571 if (mark_img
.src
.match("pub_unset")) {
572 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
573 mark_img
.alt
= __("Unpublish article");
574 query
= query
+ "&pub=1";
578 //mark_img.src = "images/pub_unset.png";
579 mark_img
.alt
= __("Please wait...");
580 query
= query
+ "&pub=0";
582 if (document
.getElementById("headlinesList") && !no_effects
) {
583 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
585 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
586 mark_img
.alt
= __("Publish article");
591 new Ajax
.Request(query
, {
592 onComplete: function(transport
) {
593 all_counters_callback2(transport
);
599 exception_error("togglePub", e
);
603 function correctHeadlinesOffset(id
) {
607 var hlist
= document
.getElementById("headlinesList");
608 var container
= document
.getElementById("headlinesInnerContainer");
609 var row
= document
.getElementById("RROW-" + id
);
611 var viewport
= container
.offsetHeight
;
613 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
614 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
616 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
617 debug("Vport: " + viewport
);
619 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
620 container
.scrollTop
= row
.offsetTop
;
621 } else if (rel_offset_bottom
> viewport
) {
623 /* doesn't properly work with Opera in some cases because
624 Opera fucks up element scrolling */
626 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
630 exception_error("correctHeadlinesOffset", e
);
635 function moveToPost(mode
) {
642 rows
= cdmGetVisibleArticles();
644 rows
= getVisibleHeadlineIds();
650 if (!document
.getElementById('RROW-' + active_post_id
)) {
651 active_post_id
= false;
654 if (active_post_id
== false) {
655 next_id
= getFirstVisibleHeadlineId();
656 prev_id
= getLastVisibleHeadlineId();
658 for (var i
= 0; i
< rows
.length
; i
++) {
659 if (rows
[i
] == active_post_id
) {
666 if (mode
== "next") {
670 if (!cdmArticleIsActuallyVisible(next_id
)) {
671 cdmScrollToArticleId(next_id
);
673 cdmSelectArticles("none");
674 toggleUnread(next_id
, 0, true);
675 toggleSelected(next_id
);
678 correctHeadlinesOffset(next_id
);
679 view(next_id
, getActiveFeedId());
684 if (mode
== "prev") {
687 cdmScrollToArticleId(prev_id
);
688 cdmSelectArticles("none");
689 toggleUnread(prev_id
, 0, true);
690 toggleSelected(prev_id
);
692 correctHeadlinesOffset(prev_id
);
693 view(prev_id
, getActiveFeedId());
699 exception_error("moveToPost", e
);
703 function toggleSelected(id
) {
706 var cb
= document
.getElementById("RCHK-" + id
);
708 var row
= document
.getElementById("RROW-" + id
);
710 var nc
= row
.className
;
712 if (!nc
.match("Selected")) {
713 nc
= nc
+ "Selected";
718 // In CDM basically last selected article == active article
719 if (isCdmMode()) active_post_id
= id
;
721 nc
= nc
.replace("Selected", "");
731 exception_error("toggleSelected", e
);
735 function toggleUnread_afh(effect
) {
738 var elem
= effect
.element
;
739 elem
.style
.backgroundColor
= "";
742 exception_error("toggleUnread_afh", e
);
746 function toggleUnread(id
, cmode
, effect
) {
749 var row
= document
.getElementById("RROW-" + id
);
751 var nc
= row
.className
;
752 var is_selected
= row
.className
.match("Selected");
753 nc
= nc
.replace("Unread", "");
754 nc
= nc
.replace("Selected", "");
756 // since we are removing selection from the object, uncheck
757 // corresponding checkbox
759 var cb
= document
.getElementById("RCHK-" + id
);
764 // NOTE: I'm not sure that resetting selection here is a feature -fox
766 if (cmode
== undefined || cmode
== 2) {
767 if (row
.className
.match("Unread")) {
771 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
772 afterFinish
: toggleUnread_afh
,
773 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
777 row
.className
= nc
+ "Unread";
779 } else if (cmode
== 0) {
783 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
784 afterFinish
: toggleUnread_afh
,
785 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
787 } else if (cmode
== 1) {
788 row
.className
= nc
+ "Unread";
791 // Disable unmarking as selected for the time being (16.05.08) -fox
792 if (is_selected
) row
.className
= row
.className
+ "Selected";
794 if (cmode
== undefined) cmode
= 2;
796 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
797 param_escape(id
) + "&cmode=" + param_escape(cmode
);
799 // notify_progress("Loading, please wait...");
801 new Ajax
.Request(query
, {
802 onComplete: function(transport
) {
803 all_counters_callback2(transport
);
810 exception_error("toggleUnread", e
);
814 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
819 rows
= cdmGetSelectedArticles();
821 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
824 if (rows
.length
== 0 && !no_error
) {
825 alert(__("No articles are selected."));
829 for (i
= 0; i
< rows
.length
; i
++) {
830 var row
= document
.getElementById("RROW-" + rows
[i
]);
832 var nc
= row
.className
;
833 nc
= nc
.replace("Unread", "");
834 nc
= nc
.replace("Selected", "");
836 if (set_state
== undefined) {
837 if (row
.className
.match("Unread")) {
838 row
.className
= nc
+ "Selected";
840 row
.className
= nc
+ "UnreadSelected";
844 if (set_state
== false) {
845 row
.className
= nc
+ "Selected";
848 if (set_state
== true) {
849 row
.className
= nc
+ "UnreadSelected";
854 if (rows
.length
> 0) {
858 if (set_state
== undefined) {
860 } else if (set_state
== true) {
862 } else if (set_state
== false) {
866 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
867 param_escape(rows
.toString()) + "&cmode=" + cmode
;
869 notify_progress("Loading, please wait...");
871 new Ajax
.Request(query
, {
872 onComplete: function(transport
) {
873 catchup_callback2(transport
, callback_func
);
879 exception_error("selectionToggleUnread", e
);
883 function selectionToggleMarked(cdm_mode
) {
889 rows
= cdmGetSelectedArticles();
891 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
894 if (rows
.length
== 0) {
895 alert(__("No articles are selected."));
899 for (i
= 0; i
< rows
.length
; i
++) {
900 toggleMark(rows
[i
], true, true);
903 if (rows
.length
> 0) {
905 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
906 param_escape(rows
.toString()) + "&cmode=2";
908 query
= query
+ "&afid=" + getActiveFeedId();
910 /* if (tagsAreDisplayed()) {
911 query = query + "&omode=tl";
913 query = query + "&omode=flc";
916 query
= query
+ "&omode=lc";
918 new Ajax
.Request(query
, {
919 onComplete: function(transport
) {
920 all_counters_callback2(transport
);
926 exception_error("selectionToggleMarked", e
);
930 function selectionTogglePublished(cdm_mode
) {
936 rows
= cdmGetSelectedArticles();
938 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
941 if (rows
.length
== 0) {
942 alert(__("No articles are selected."));
946 for (i
= 0; i
< rows
.length
; i
++) {
947 togglePub(rows
[i
], true, true);
950 if (rows
.length
> 0) {
952 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
953 param_escape(rows
.toString()) + "&cmode=2";
955 query
= query
+ "&afid=" + getActiveFeedId();
957 /* if (tagsAreDisplayed()) {
958 query = query + "&omode=tl";
960 query = query + "&omode=flc";
963 query
= query
+ "&omode=lc";
965 new Ajax
.Request(query
, {
966 onComplete: function(transport
) {
967 all_counters_callback2(transport
);
973 exception_error("selectionToggleMarked", e
);
977 function cdmGetSelectedArticles() {
978 var sel_articles
= new Array();
979 var container
= document
.getElementById("headlinesInnerContainer");
981 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
982 var child
= container
.childNodes
[i
];
984 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
985 var c_id
= child
.id
.replace("RROW-", "");
986 sel_articles
.push(c_id
);
993 function cdmGetVisibleArticles() {
994 var sel_articles
= new Array();
995 var container
= document
.getElementById("headlinesInnerContainer");
997 if (!container
) return sel_articles
;
999 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1000 var child
= container
.childNodes
[i
];
1002 if (child
.id
.match("RROW-")) {
1003 var c_id
= child
.id
.replace("RROW-", "");
1004 sel_articles
.push(c_id
);
1008 return sel_articles
;
1011 function cdmGetUnreadArticles() {
1012 var sel_articles
= new Array();
1013 var container
= document
.getElementById("headlinesInnerContainer");
1015 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1016 var child
= container
.childNodes
[i
];
1018 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1019 var c_id
= child
.id
.replace("RROW-", "");
1020 sel_articles
.push(c_id
);
1024 return sel_articles
;
1028 // mode = all,none,unread
1029 function cdmSelectArticles(mode
) {
1030 var container
= document
.getElementById("headlinesInnerContainer");
1032 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1033 var child
= container
.childNodes
[i
];
1035 if (child
.id
.match("RROW-")) {
1036 var aid
= child
.id
.replace("RROW-", "");
1038 var cb
= document
.getElementById("RCHK-" + aid
);
1040 if (mode
== "all") {
1041 if (!child
.className
.match("Selected")) {
1042 child
.className
= child
.className
+ "Selected";
1045 } else if (mode
== "unread") {
1046 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1047 child
.className
= child
.className
+ "Selected";
1051 child
.className
= child
.className
.replace("Selected", "");
1058 function catchupPage() {
1060 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1062 var str
= __("Mark all visible articles in %s as read?");
1064 str
= str
.replace("%s", fn
);
1066 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1070 if (document
.getElementById("headlinesList")) {
1071 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1072 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1073 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1075 cdmSelectArticles('all');
1076 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1077 cdmSelectArticles('none');
1081 function catchupSelection() {
1087 if (document
.getElementById("headlinesList")) {
1088 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1090 rows
= cdmGetSelectedArticles();
1093 if (rows
.length
== 0) {
1094 alert(__("No articles are selected."));
1099 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1101 var str
= __("Mark %d selected articles in %s as read?");
1103 str
= str
.replace("%d", rows
.length
);
1104 str
= str
.replace("%s", fn
);
1106 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1110 if (document
.getElementById("headlinesList")) {
1111 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1112 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1114 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1115 // cdmSelectArticles('none');
1119 exception_error("catchupSelection", e
);
1124 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1126 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1127 printLockingError();
1130 var title
= prompt(__("Please enter label title:"), "");
1134 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1135 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1136 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1137 "&title=" + param_escape(title
);
1139 debug("LFS: " + query
);
1141 new Ajax
.Request(query
, {
1142 onComplete: function(transport
) {
1143 dlg_frefresh_callback(transport
);
1148 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1149 _tag_active_post_id
= id
;
1150 _tag_active_feed_id
= feed_id
;
1151 _tag_active_cdm
= cdm_enabled
;
1153 cache_invalidate(id
);
1156 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1158 displayDlg('editArticleTags', id
);
1162 function tag_saved_callback(transport
) {
1164 debug("in tag_saved_callback");
1169 if (tagsAreDisplayed()) {
1170 _reload_feedlist_after_view
= true;
1173 if (!_tag_active_cdm
) {
1174 if (active_post_id
== _tag_active_post_id
) {
1175 debug("reloading current article");
1176 view(_tag_active_post_id
, _tag_active_feed_id
);
1179 debug("reloading current feed");
1184 exception_error("catchup_callback", e
);
1188 function editTagsSave() {
1190 notify_progress("Saving article tags...");
1192 var form
= document
.forms
["tag_edit_form"];
1194 var query
= Form
.serialize("tag_edit_form");
1196 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1200 new Ajax
.Request(query
, {
1201 onComplete: function(transport
) {
1202 tag_saved_callback(transport
);
1207 function editTagsInsert() {
1210 var form
= document
.forms
["tag_edit_form"];
1212 var found_tags
= form
.found_tags
;
1213 var tags_str
= form
.tags_str
;
1215 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1217 if (tags_str
.value
.length
> 0 &&
1218 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1220 tags_str
.value
= tags_str
.value
+ ", ";
1223 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1225 found_tags
.selectedIndex
= 0;
1228 exception_error("editTagsInsert", e
);
1232 function cdmScrollViewport(where
) {
1233 debug("cdmScrollViewport: " + where
);
1235 var ctr
= document
.getElementById("headlinesInnerContainer");
1239 if (where
== "bottom") {
1240 ctr
.scrollTop
= ctr
.scrollHeight
;
1242 ctr
.scrollTop
= where
;
1246 function cdmArticleIsBelowViewport(id
) {
1248 var ctr
= document
.getElementById("headlinesInnerContainer");
1249 var e
= document
.getElementById("RROW-" + id
);
1251 if (!e
|| !ctr
) return;
1253 // article starts below viewport
1255 if (ctr
.scrollTop
< e
.offsetTop
) {
1262 exception_error("cdmArticleIsVisible", e
);
1266 function cdmArticleIsAboveViewport(id
) {
1268 var ctr
= document
.getElementById("headlinesInnerContainer");
1269 var e
= document
.getElementById("RROW-" + id
);
1271 if (!e
|| !ctr
) return;
1273 // article starts above viewport
1275 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1282 exception_error("cdmArticleIsVisible", e
);
1286 function cdmScrollToArticleId(id
) {
1288 var ctr
= document
.getElementById("headlinesInnerContainer");
1289 var e
= document
.getElementById("RROW-" + id
);
1291 if (!e
|| !ctr
) return;
1293 ctr
.scrollTop
= e
.offsetTop
;
1296 exception_error("cdmScrollToArticleId", e
);
1300 function cdmArticleIsActuallyVisible(id
) {
1302 var ctr
= document
.getElementById("headlinesInnerContainer");
1303 var e
= document
.getElementById("RROW-" + id
);
1305 if (!e
|| !ctr
) return;
1307 // article fits in viewport OR article is longer than viewport and
1308 // its bottom is visible
1310 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1311 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1315 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1316 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1317 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1326 exception_error("cdmArticleIsVisible", e
);
1330 function cdmWatchdog() {
1334 var ctr
= document
.getElementById("headlinesInnerContainer");
1338 var ids
= new Array();
1340 var e
= ctr
.firstChild
;
1343 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1344 e
.id
.match("RROW-")) {
1346 // article fits in viewport OR article is longer than viewport and
1347 // its bottom is visible
1349 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1350 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1352 // debug(e.id + " is visible " + e.offsetTop + "." +
1353 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1354 // (ctr.scrollTop + ctr.offsetHeight));
1356 ids
.push(e
.id
.replace("RROW-", ""));
1358 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1359 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1360 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1362 ids
.push(e
.id
.replace("RROW-", ""));
1366 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1368 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1369 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1371 ids.push(e.id.replace("RROW-", ""));
1380 debug("cdmWatchdog, ids= " + ids
.toString());
1382 if (ids
.length
> 0) {
1384 for (var i
= 0; i
< ids
.length
; i
++) {
1385 var e
= document
.getElementById("RROW-" + ids
[i
]);
1387 e
.className
= e
.className
.replace("Unread", "");
1391 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1392 param_escape(ids
.toString()) + "&cmode=0";
1394 new Ajax
.Request(query
, {
1395 onComplete: function(transport
) {
1396 all_counters_callback2(transport
);
1401 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1404 exception_error("cdmWatchdog", e
);
1410 function cache_inject(id
, article
, param
) {
1411 if (!cache_check_param(id
, param
)) {
1412 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1414 var cache_obj
= new Array();
1416 cache_obj
["id"] = id
;
1417 cache_obj
["data"] = article
;
1418 cache_obj
["param"] = param
;
1420 article_cache
.push(cache_obj
);
1423 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1427 function cache_find(id
) {
1428 for (var i
= 0; i
< article_cache
.length
; i
++) {
1429 if (article_cache
[i
]["id"] == id
) {
1430 return article_cache
[i
]["data"];
1436 function cache_find_param(id
, param
) {
1437 for (var i
= 0; i
< article_cache
.length
; i
++) {
1438 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1439 return article_cache
[i
]["data"];
1445 function cache_check(id
) {
1446 for (var i
= 0; i
< article_cache
.length
; i
++) {
1447 if (article_cache
[i
]["id"] == id
) {
1454 function cache_check_param(id
, param
) {
1455 for (var i
= 0; i
< article_cache
.length
; i
++) {
1457 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1458 // article_cache[i]["param"] + " vs " + id + ":" + param);
1460 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1467 function cache_expire() {
1468 while (article_cache
.length
> 25) {
1469 article_cache
.shift();
1473 function cache_empty() {
1474 article_cache
= new Array();
1477 function cache_invalidate(id
) {
1482 while (i
< article_cache
.length
) {
1483 if (article_cache
[i
]["id"] == id
) {
1484 debug("cache_invalidate: removed id " + id
);
1485 article_cache
.splice(i
, 1);
1490 debug("cache_invalidate: id not found: " + id
);
1493 exception_error("cache_invalidate", e
);
1497 function getActiveArticleId() {
1498 return active_post_id
;
1501 function cdmClicked(elem
) {
1503 if (elem
.id
&& elem
.id
.match("RROW-")) {
1504 var id
= elem
.id
.replace("RROW-", "");
1505 active_post_id
= id
;
1507 cdmSelectArticles("none");
1508 toggleUnread(id
, 0, true);
1513 exception_error("cdmClicked", e
);
1517 function preload_article_callback(transport
) {
1519 if (transport
.responseXML
) {
1520 var articles
= transport
.responseXML
.getElementsByTagName("article");
1522 for (var i
= 0; i
< articles
.length
; i
++) {
1523 var id
= articles
[i
].getAttribute("id");
1524 if (!cache_check(id
)) {
1525 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1526 debug("preloaded article: " + id
);
1531 exception_error("preload_article_callback", e
);
1535 function preloadArticleUnderPointer(id
) {
1537 if (post_under_pointer
== id
&& !cache_check(id
)) {
1539 debug("trying to preload article " + id
);
1541 var neighbor_ids
= getRelativePostIds(id
, 1);
1543 /* only request uncached articles */
1545 var cids_to_request
= Array();
1547 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1548 if (!cache_check(neighbor_ids
[i
])) {
1549 cids_to_request
.push(neighbor_ids
[i
]);
1552 debug("additional ids: " + cids_to_request
.toString());
1554 cids_to_request
.push(id
);
1556 var query
= "backend.php?op=rpc&subop=getArticles&ids=" +
1557 cids_to_request
.toString();
1558 new Ajax
.Request(query
, {
1559 onComplete: function(transport
) {
1560 preload_article_callback(transport
);
1564 exception_error("preloadArticleUnderPointer", e
);
1568 function postMouseIn(id
) {
1570 if (post_under_pointer
!= id
) {
1571 post_under_pointer
= id
;
1573 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1578 exception_error("postMouseIn", e
);
1582 function postMouseOut(id
) {
1584 post_under_pointer
= false;
1586 exception_error("postMouseOut", e
);
1590 function headlines_scroll_handler() {
1593 var e
= document
.getElementById("headlinesInnerContainer");
1595 // don't do infinite scrolling when Limit == All
1597 var toolbar_form
= document
.forms
["main_toolbar_form"];
1599 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1600 if (limit
.value
!= 0) {
1602 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1603 _infscroll_disable
);
1605 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1606 if (!_infscroll_disable
) {
1607 debug("more cowbell!");
1614 exception_error("headlines_scroll_handler", e
);
1618 function catchupRelativeToArticle(below
) {
1622 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1623 printLockingError();
1626 if (!getActiveArticleId()) {
1627 alert(__("No article is selected."));
1633 if (document
.getElementById("headlinesList")) {
1634 visible_ids
= getVisibleHeadlineIds();
1636 visible_ids
= cdmGetVisibleArticles();
1639 var ids_to_mark
= new Array();
1642 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1643 if (visible_ids
[i
] != getActiveArticleId()) {
1644 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1646 if (e
&& e
.className
.match("Unread")) {
1647 ids_to_mark
.push(visible_ids
[i
]);
1654 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1655 if (visible_ids
[i
] != getActiveArticleId()) {
1656 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1658 if (e
&& e
.className
.match("Unread")) {
1659 ids_to_mark
.push(visible_ids
[i
]);
1667 if (ids_to_mark
.length
== 0) {
1668 alert(__("No articles found to mark"));
1670 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1674 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1675 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1676 e
.className
= e
.className
.replace("Unread", "");
1679 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1680 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1682 new Ajax
.Request(query
, {
1683 onComplete: function(transport
) {
1684 catchup_callback2(transport
);
1691 exception_error("catchupRelativeToArticle", e
);
1695 function cdmExpandArticle(a_id
) {
1697 var id
= 'CICD-' + a_id
;
1699 Effect
.Appear(id
, {duration
: 0.5,
1700 beforeStart: function(effect
) {
1701 var h_id
= 'CICH-' + a_id
;
1702 var h_elem
= document
.getElementById(h_id
);
1703 if (h_elem
) { h_elem
.style
.display
= "none"; }
1705 toggleUnread(a_id
, 0);
1710 exception_error("appearBlockElementF", e
);
1715 function fixHeadlinesOrder(ids
) {
1717 for (var i
= 0; i
< ids
.length
; i
++) {
1718 var e
= document
.getElementById("RROW-" + ids
[i
]);
1722 e
.className
= e
.className
.replace("even", "odd");
1724 e
.className
= e
.className
.replace("odd", "even");
1729 exception_error("fixHeadlinesOrder", e
);
1733 function subtoolbarSearch() {
1736 var q
= document
.getElementById("subtoolbar_search_box");
1740 q
= q
.value
.toUpperCase();
1743 var vis_ids
= new Array();
1745 if (document
.getElementById("headlinesList")) {
1746 ids
= getVisibleHeadlineIds();
1748 ids
= cdmGetVisibleArticles();
1751 for (var i
= 0; i
< ids
.length
; i
++) {
1752 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1755 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1756 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1758 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1759 vis_ids
.push(ids
[i
]);
1764 fixHeadlinesOrder(vis_ids
);
1767 exception_error("subtoolbarSearch", e
);
1771 function getArticleUnderPointer() {
1772 return post_under_pointer
;