1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _tag_active_post_id
= false;
6 var _tag_active_feed_id
= false;
7 var _tag_active_cdm
= false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll
= false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view
= false;
15 var _cdm_wd_timeout
= false;
16 var _cdm_wd_vishist
= new Array();
18 var article_cache
= new Array();
20 function catchup_callback() {
21 if (xmlhttp_rpc
.readyState
== 4) {
23 debug("catchup_callback");
25 all_counters_callback2(xmlhttp_rpc
);
26 if (_catchup_callback_func
) {
27 setTimeout(_catchup_callback_func
, 10);
30 exception_error("catchup_callback", e
);
35 function catchup_callback2(transport
, callback
) {
37 debug("catchup_callback2 " + transport
+ ", " + callback
);
39 all_counters_callback2(transport
);
41 setTimeout(callback
, 10);
44 exception_error("catchup_callback2", e
);
48 function clean_feed_selections() {
50 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
52 for (var i
= 0; i
< feeds
.length
; i
++) {
53 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
54 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
58 exception_error("clean_feed_selections", e
);
62 function headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
65 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
67 clean_feed_selections();
69 setActiveFeedId(active_feed_id
);
71 if (is_cat
!= undefined) {
72 active_feed_is_cat
= is_cat
;
76 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
77 if (feedr
&& !feedr
.className
.match("Selected")) {
78 feedr
.className
= feedr
.className
+ "Selected";
82 var f
= document
.getElementById("headlines-frame");
84 if (feed_cur_page
== 0) {
85 debug("resetting headlines scrollTop");
90 if (transport
.responseXML
) {
91 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
92 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
93 var headlines_unread_obj
= transport
.responseXML
.getElementsByTagName("headlines-unread")[0];
94 var disable_cache_obj
= transport
.responseXML
.getElementsByTagName("disable-cache")[0];
96 var headlines_count
= headlines_count_obj
.getAttribute("value");
97 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
98 var disable_cache
= disable_cache_obj
.getAttribute("value") != "0";
100 if (headlines_count
== 0) {
101 _infscroll_disable
= 1;
103 _infscroll_disable
= 0;
106 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
107 var articles
= transport
.responseXML
.getElementsByTagName("article");
108 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
110 if (feed_cur_page
== 0) {
112 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
114 var cache_prefix
= "";
122 cache_invalidate(cache_prefix
+ active_feed_id
);
124 if (!disable_cache
) {
125 cache_inject(cache_prefix
+ active_feed_id
,
126 headlines
.firstChild
.nodeValue
, headlines_unread
);
130 debug("headlines_callback: returned no data");
131 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
136 if (headlines_count
> 0) {
137 debug("adding some more headlines...");
139 var c
= document
.getElementById("headlinesList");
142 c
= document
.getElementById("headlinesInnerContainer");
145 var ids
= getSelectedArticleIds2();
147 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
149 debug("restore selected ids: " + ids
);
151 for (var i
= 0; i
< ids
.length
; i
++) {
152 markHeadline(ids
[i
]);
158 debug("no new headlines received");
161 debug("headlines_callback: returned no data");
162 notify_error("Error while trying to load more headlines");
168 for (var i
= 0; i
< articles
.length
; i
++) {
169 var a_id
= articles
[i
].getAttribute("id");
170 debug("found id: " + a_id
);
171 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
174 debug("no cached articles received");
178 debug("parsing piggybacked counters: " + counters
);
179 parse_counters(counters
, false);
181 debug("counters container not found in reply");
185 debug("parsing runtime info: " + runtime_info
[0]);
186 parse_runtime_info(runtime_info
[0]);
188 debug("counters container not found in reply");
192 debug("headlines_callback: returned no XML object");
193 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
196 if (typeof correctPNG
!= 'undefined') {
200 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
202 if (!document
.getElementById("headlinesList") &&
203 getInitParam("cdm_auto_catchup") == 1) {
204 debug("starting CDM watchdog");
205 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
206 _cdm_wd_vishist
= new Array();
208 debug("not in CDM mode or watchdog disabled");
211 if (_tag_cdm_scroll
) {
213 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
214 _tag_cdm_scroll
= false;
215 debug("resetting headlinesInner scrollTop");
220 _feed_cur_page
= feed_cur_page
;
221 _infscroll_request_sent
= 0;
225 exception_error("headlines_callback2", e
);
229 function render_article(article
) {
231 var f
= document
.getElementById("content-frame");
236 f
.innerHTML
= article
;
239 exception_error("render_article", e
);
243 function showArticleInHeadlines(id
) {
247 cleanSelected("headlinesList");
249 var crow
= document
.getElementById("RROW-" + id
);
253 var article_is_unread
= crow
.className
.match("Unread");
255 crow
.className
= crow
.className
.replace("Unread", "");
257 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
259 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
261 var cache_prefix
= "";
263 if (activeFeedIsCat()) {
269 var view_mode
= false;
272 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
273 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
275 exception_error("showArticleInHeadlines/viewmode", e
, true);
278 if (upd_img_pic
&& upd_img_pic
.src
.match("updated.png")) {
279 upd_img_pic
.src
= "images/blank_icon.gif";
281 cache_invalidate(cache_prefix
+ getActiveFeedId());
283 cache_inject(cache_prefix
+ getActiveFeedId(),
284 document
.getElementById("headlines-frame").innerHTML
,
285 get_feed_unread(getActiveFeedId()));
287 } else if (article_is_unread
&& view_mode
== "all_articles") {
289 cache_invalidate(cache_prefix
+ getActiveFeedId());
291 cache_inject(cache_prefix
+ getActiveFeedId(),
292 document
.getElementById("headlines-frame").innerHTML
,
293 get_feed_unread(getActiveFeedId())-1);
295 } else if (article_is_unread
) {
296 cache_invalidate(cache_prefix
+ getActiveFeedId());
302 exception_error("showArticleInHeadlines", e
);
306 function article_callback2(transport
, id
, feed_id
) {
308 debug("article_callback2 " + id
);
310 if (transport
.responseXML
) {
312 active_real_feed_id
= feed_id
;
315 showArticleInHeadlines(id
);
317 var reply
= transport
.responseXML
.firstChild
.firstChild
;
319 var articles
= transport
.responseXML
.getElementsByTagName("article");
321 for (var i
= 0; i
< articles
.length
; i
++) {
322 var a_id
= articles
[i
].getAttribute("id");
324 debug("found id: " + a_id
);
326 if (a_id
== active_post_id
) {
327 debug("active article, rendering...");
328 render_article(articles
[i
].firstChild
.nodeValue
);
331 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
335 debug("article_callback: returned no XML object");
336 var f
= document
.getElementById("content-frame");
337 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
340 var date
= new Date();
341 last_article_view
= date
.getTime() / 1000;
343 if (typeof correctPNG
!= 'undefined') {
347 if (_reload_feedlist_after_view
) {
348 setTimeout('updateFeedList(false, false)', 50);
349 _reload_feedlist_after_view
= false;
351 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
354 debug("parsing piggybacked counters: " + counters
);
355 parse_counters(counters
, false);
357 debug("counters container not found in reply");
363 exception_error("article_callback2", e
);
367 function view(id
, feed_id
, skip_history
) {
370 debug("loading article: " + id
+ "/" + feed_id
);
372 var cached_article
= cache_find(id
);
374 debug("cache check result: " + (cached_article
!= false));
378 //setActiveFeedId(feed_id);
380 var query
= "backend.php?op=view&id=" + param_escape(id
) +
381 "&feed=" + param_escape(feed_id
);
383 var date
= new Date();
385 var neighbor_ids
= getRelativePostIds(active_post_id
);
387 /* only request uncached articles */
389 var cids_to_request
= Array();
391 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
392 if (!cache_check(neighbor_ids
[i
])) {
393 cids_to_request
.push(neighbor_ids
[i
]);
397 debug("additional ids: " + cids_to_request
.toString());
399 /* additional info for piggyback counters */
401 if (tagsAreDisplayed()) {
402 query
= query
+ "&omode=lt";
404 query
= query
+ "&omode=flc";
407 var date
= new Date();
408 var timestamp
= Math
.round(date
.getTime() / 1000);
409 query
= query
+ "&ts=" + timestamp
;
411 query
= query
+ "&cids=" + cids_to_request
.toString();
413 var crow
= document
.getElementById("RROW-" + id
);
414 var article_is_unread
= crow
.className
.match("Unread");
416 showArticleInHeadlines(id
);
418 if (!cached_article
) {
420 notify_progress("Loading, please wait...");
422 } else if (cached_article
&& article_is_unread
) {
424 query
= query
+ "&mode=prefetch";
426 render_article(cached_article
);
428 } else if (cached_article
) {
430 query
= query
+ "&mode=prefetch_old";
431 render_article(cached_article
);
436 new Ajax
.Request(query
, {
437 onComplete: function(transport
) {
438 article_callback2(transport
, id
, feed_id
);
442 exception_error("view", e
);
447 return toggleMark(id
);
451 return togglePub(id
);
454 function tMark_afh_off(effect
) {
456 var elem
= effect
.effects
[0].element
;
458 debug("tMark_afh_off : " + elem
.id
);
461 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
462 elem
.alt
= __("Star article");
467 exception_error("tMark_afh_off", e
);
471 function tPub_afh_off(effect
) {
473 var elem
= effect
.effects
[0].element
;
475 debug("tPub_afh_off : " + elem
.id
);
478 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
479 elem
.alt
= __("Publish article");
484 exception_error("tPub_afh_off", e
);
488 function toggleMark(id
, client_only
, no_effects
) {
492 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
494 query
= query
+ "&afid=" + getActiveFeedId();
496 if (tagsAreDisplayed()) {
497 query
= query
+ "&omode=tl";
499 query
= query
+ "&omode=flc";
502 var mark_img
= document
.getElementById("FMPIC-" + id
);
503 var vfeedu
= document
.getElementById("FEEDU--1");
504 var crow
= document
.getElementById("RROW-" + id
);
506 if (mark_img
.src
.match("mark_unset")) {
507 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
508 mark_img
.alt
= __("Unstar article");
509 query
= query
+ "&mark=1";
511 /* if (vfeedu && crow.className.match("Unread")) {
512 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
516 //mark_img.src = "images/mark_unset.png";
517 mark_img
.alt
= __("Please wait...");
518 query
= query
+ "&mark=0";
520 /* if (vfeedu && crow.className.match("Unread")) {
521 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
524 if (document
.getElementById("headlinesList") && !no_effects
) {
525 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
527 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
528 mark_img
.alt
= __("Star article");
532 /* var vfeedctr = document.getElementById("FEEDCTR--1");
533 var vfeedr = document.getElementById("FEEDR--1");
535 if (vfeedu && vfeedctr) {
536 if ((+vfeedu.innerHTML) > 0) {
537 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
538 vfeedr.className = vfeedr.className + "Unread";
539 vfeedctr.className = "odd";
542 vfeedctr.className = "invisible";
543 vfeedr.className = vfeedr.className.replace("Unread", "");
547 debug("toggle starred for aid " + id);
549 //new Ajax.Request(query); */
554 new Ajax
.Request(query
, {
555 onComplete: function(transport
) {
556 all_counters_callback2(transport
);
562 exception_error("toggleMark", e
);
566 function togglePub(id
, client_only
, no_effects
) {
570 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
572 query
= query
+ "&afid=" + getActiveFeedId();
574 if (tagsAreDisplayed()) {
575 query
= query
+ "&omode=tl";
577 query
= query
+ "&omode=flc";
580 var mark_img
= document
.getElementById("FPPIC-" + id
);
581 var vfeedu
= document
.getElementById("FEEDU--2");
582 var crow
= document
.getElementById("RROW-" + id
);
584 if (mark_img
.src
.match("pub_unset")) {
585 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
586 mark_img
.alt
= __("Unpublish article");
587 query
= query
+ "&pub=1";
589 /* if (vfeedu && crow.className.match("Unread")) {
590 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
594 //mark_img.src = "images/pub_unset.png";
595 mark_img
.alt
= __("Please wait...");
596 query
= query
+ "&pub=0";
598 /* if (vfeedu && crow.className.match("Unread")) {
599 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
602 if (document
.getElementById("headlinesList") && !no_effects
) {
603 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
605 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
606 mark_img
.alt
= __("Publish article");
610 /* var vfeedctr = document.getElementById("FEEDCTR--2");
611 var vfeedr = document.getElementById("FEEDR--2");
613 if (vfeedu && vfeedctr) {
614 if ((+vfeedu.innerHTML) > 0) {
615 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
616 vfeedr.className = vfeedr.className + "Unread";
617 vfeedctr.className = "odd";
620 vfeedctr.className = "invisible";
621 vfeedr.className = vfeedr.className.replace("Unread", "");
625 debug("toggle published for aid " + id);
627 new Ajax.Request(query); */
630 new Ajax
.Request(query
, {
631 onComplete: function(transport
) {
632 all_counters_callback2(transport
);
638 exception_error("togglePub", e
);
642 function correctHeadlinesOffset(id
) {
646 var hlist
= document
.getElementById("headlinesList");
647 var container
= document
.getElementById("headlinesInnerContainer");
648 var row
= document
.getElementById("RROW-" + id
);
650 var viewport
= container
.offsetHeight
;
652 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
653 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
655 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
656 debug("Vport: " + viewport
);
658 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
659 container
.scrollTop
= row
.offsetTop
;
660 } else if (rel_offset_bottom
> viewport
) {
662 /* doesn't properly work with Opera in some cases because
663 Opera fucks up element scrolling */
665 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
669 exception_error("correctHeadlinesOffset", e
);
674 function moveToPost(mode
) {
678 // check for combined mode
679 if (document
.getElementById("headlinesList")) {
681 var rows
= getVisibleHeadlineIds();
686 if (!document
.getElementById('RROW-' + active_post_id
)) {
687 active_post_id
= false;
690 if (active_post_id
== false) {
691 next_id
= getFirstVisibleHeadlineId();
692 prev_id
= getLastVisibleHeadlineId();
694 for (var i
= 0; i
< rows
.length
; i
++) {
695 if (rows
[i
] == active_post_id
) {
702 if (mode
== "next") {
704 correctHeadlinesOffset(next_id
);
705 view(next_id
, getActiveFeedId());
709 if (mode
== "prev") {
711 correctHeadlinesOffset(prev_id
);
712 view(prev_id
, getActiveFeedId());
716 var rows
= cdmGetUnreadArticles();
718 if (mode
== "next") {
720 for (var i
= 0; i
< rows
.length
; i
++) {
722 if (cdmArticleIsActuallyVisible(rows
[i
]) ||
723 cdmArticleIsBelowViewport(rows
[i
])) {
725 if (!cdmArticleIsActuallyVisible(rows
[i
])) {
726 cdmScrollToArticleId(rows
[i
]);
728 //setTimeout("toggleUnread(" + rows[i] + ", undefined, true)", 500);
729 toggleUnread(rows
[i
], undefined, true);
735 cdmScrollViewport('bottom');
737 } else if (mode
== "prev") {
739 for (var i
= 0; i
< rows
.length
; i
++) {
741 if (cdmArticleIsAboveViewport(rows
[i
]) &&
742 !cdmArticleIsAboveViewport(rows
[i
+1])) {
744 cdmScrollToArticleId(rows
[i
]);
745 //setTimeout("toggleUnread(" + rows[i] + ", undefined, true)", 500);
746 toggleUnread(rows
[i
], undefined, true);
757 exception_error(e
, "moveToPost");
761 function toggleSelected(id
) {
764 var row
= document
.getElementById("RROW-" + id
);
766 var nc
= row
.className
;
768 if (!nc
.match("Selected")) {
769 nc
= nc
+ "Selected";
771 nc
= nc
.replace("Selected", "");
777 exception_error(e
, "toggleSelected");
781 function toggleUnread_afh(effect
) {
784 var elem
= effect
.element
;
785 elem
.style
.backgroundColor
= "";
788 exception_error(e
, "toggleUnread_afh");
792 function toggleUnread(id
, cmode
, effect
) {
795 var row
= document
.getElementById("RROW-" + id
);
797 var nc
= row
.className
;
798 nc
= nc
.replace("Unread", "");
799 nc
= nc
.replace("Selected", "");
801 // since we are removing selection from the object, uncheck
802 // corresponding checkbox
804 var cb
= document
.getElementById("RCHK-" + id
);
809 // NOTE: I'm not sure that resetting selection here is a feature -fox
811 if (cmode
== undefined || cmode
== 2) {
812 if (row
.className
.match("Unread")) {
816 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
817 afterFinish
: toggleUnread_afh
,
818 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
822 row
.className
= nc
+ "Unread";
824 } else if (cmode
== 0) {
828 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
829 afterFinish
: toggleUnread_afh
,
830 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
832 } else if (cmode
== 1) {
833 row
.className
= nc
+ "Unread";
836 if (cmode
== undefined) cmode
= 2;
838 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
839 param_escape(id
) + "&cmode=" + param_escape(cmode
);
841 // notify_progress("Loading, please wait...");
843 new Ajax
.Request(query
, {
844 onComplete: function(transport
) {
845 all_counters_callback2(transport
);
852 exception_error("toggleUnread", e
);
856 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
861 rows
= cdmGetSelectedArticles();
863 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
866 if (rows
.length
== 0 && !no_error
) {
867 alert(__("No articles are selected."));
871 for (i
= 0; i
< rows
.length
; i
++) {
872 var row
= document
.getElementById("RROW-" + rows
[i
]);
874 var nc
= row
.className
;
875 nc
= nc
.replace("Unread", "");
876 nc
= nc
.replace("Selected", "");
878 if (set_state
== undefined) {
879 if (row
.className
.match("Unread")) {
880 row
.className
= nc
+ "Selected";
882 row
.className
= nc
+ "UnreadSelected";
886 if (set_state
== false) {
887 row
.className
= nc
+ "Selected";
890 if (set_state
== true) {
891 row
.className
= nc
+ "UnreadSelected";
896 if (rows
.length
> 0) {
900 if (set_state
== undefined) {
902 } else if (set_state
== true) {
904 } else if (set_state
== false) {
908 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
909 param_escape(rows
.toString()) + "&cmode=" + cmode
;
911 notify_progress("Loading, please wait...");
913 new Ajax
.Request(query
, {
914 onComplete: function(transport
) {
915 catchup_callback2(transport
, callback_func
);
921 exception_error("selectionToggleUnread", e
);
925 function selectionToggleMarked(cdm_mode
) {
931 rows
= cdmGetSelectedArticles();
933 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
936 if (rows
.length
== 0) {
937 alert(__("No articles are selected."));
941 for (i
= 0; i
< rows
.length
; i
++) {
942 toggleMark(rows
[i
], true, true);
945 if (rows
.length
> 0) {
947 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
948 param_escape(rows
.toString()) + "&cmode=2";
950 query
= query
+ "&afid=" + getActiveFeedId();
952 /* if (tagsAreDisplayed()) {
953 query = query + "&omode=tl";
955 query = query + "&omode=flc";
958 query
= query
+ "&omode=lc";
960 new Ajax
.Request(query
, {
961 onComplete: function(transport
) {
962 all_counters_callback2(transport
);
968 exception_error("selectionToggleMarked", e
);
972 function selectionTogglePublished(cdm_mode
) {
978 rows
= cdmGetSelectedArticles();
980 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
983 if (rows
.length
== 0) {
984 alert(__("No articles are selected."));
988 for (i
= 0; i
< rows
.length
; i
++) {
989 togglePub(rows
[i
], true, true);
992 if (rows
.length
> 0) {
994 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
995 param_escape(rows
.toString()) + "&cmode=2";
997 query
= query
+ "&afid=" + getActiveFeedId();
999 /* if (tagsAreDisplayed()) {
1000 query = query + "&omode=tl";
1002 query = query + "&omode=flc";
1005 query
= query
+ "&omode=lc";
1007 new Ajax
.Request(query
, {
1008 onComplete: function(transport
) {
1009 all_counters_callback2(transport
);
1015 exception_error("selectionToggleMarked", e
);
1019 function cdmGetSelectedArticles() {
1020 var sel_articles
= new Array();
1021 var container
= document
.getElementById("headlinesInnerContainer");
1023 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1024 var child
= container
.childNodes
[i
];
1026 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1027 var c_id
= child
.id
.replace("RROW-", "");
1028 sel_articles
.push(c_id
);
1032 return sel_articles
;
1035 function cdmGetVisibleArticles() {
1036 var sel_articles
= new Array();
1037 var container
= document
.getElementById("headlinesInnerContainer");
1039 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1040 var child
= container
.childNodes
[i
];
1042 if (child
.id
.match("RROW-")) {
1043 var c_id
= child
.id
.replace("RROW-", "");
1044 sel_articles
.push(c_id
);
1048 return sel_articles
;
1051 function cdmGetUnreadArticles() {
1052 var sel_articles
= new Array();
1053 var container
= document
.getElementById("headlinesInnerContainer");
1055 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1056 var child
= container
.childNodes
[i
];
1058 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1059 var c_id
= child
.id
.replace("RROW-", "");
1060 sel_articles
.push(c_id
);
1064 return sel_articles
;
1068 // mode = all,none,unread
1069 function cdmSelectArticles(mode
) {
1070 var container
= document
.getElementById("headlinesInnerContainer");
1072 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1073 var child
= container
.childNodes
[i
];
1075 if (child
.id
.match("RROW-")) {
1076 var aid
= child
.id
.replace("RROW-", "");
1078 var cb
= document
.getElementById("RCHK-" + aid
);
1080 if (mode
== "all") {
1081 if (!child
.className
.match("Selected")) {
1082 child
.className
= child
.className
+ "Selected";
1085 } else if (mode
== "unread") {
1086 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1087 child
.className
= child
.className
+ "Selected";
1091 child
.className
= child
.className
.replace("Selected", "");
1098 function catchupPage() {
1100 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1102 var str
= __("Mark all visible articles in %s as read?");
1104 str
= str
.replace("%s", fn
);
1106 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1110 if (document
.getElementById("headlinesList")) {
1111 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1112 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1113 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1115 cdmSelectArticles('all');
1116 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1117 cdmSelectArticles('none');
1121 function catchupSelection() {
1127 if (document
.getElementById("headlinesList")) {
1128 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1130 rows
= cdmGetSelectedArticles();
1133 if (rows
.length
== 0) {
1134 alert(__("No articles are selected."));
1139 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
1141 var str
= __("Mark %d selected articles in %s as read?");
1143 str
= str
.replace("%d", rows
.length
);
1144 str
= str
.replace("%s", fn
);
1146 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1150 if (document
.getElementById("headlinesList")) {
1151 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1152 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1154 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1155 // cdmSelectArticles('none');
1159 exception_error("catchupSelection", e
);
1164 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1166 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1167 printLockingError();
1170 var title
= prompt(__("Please enter label title:"), "");
1174 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1175 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1176 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1177 "&title=" + param_escape(title
);
1179 debug("LFS: " + query
);
1181 new Ajax
.Request(query
, {
1182 onComplete: function(transport
) {
1183 dlg_frefresh_callback(transport
);
1188 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1189 _tag_active_post_id
= id
;
1190 _tag_active_feed_id
= feed_id
;
1191 _tag_active_cdm
= cdm_enabled
;
1193 cache_invalidate(id
);
1196 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1198 displayDlg('editArticleTags', id
);
1202 function tag_saved_callback(transport
) {
1204 debug("in tag_saved_callback");
1209 if (tagsAreDisplayed()) {
1210 _reload_feedlist_after_view
= true;
1213 if (!_tag_active_cdm
) {
1214 if (active_post_id
== _tag_active_post_id
) {
1215 debug("reloading current article");
1216 view(_tag_active_post_id
, _tag_active_feed_id
);
1219 debug("reloading current feed");
1224 exception_error("catchup_callback", e
);
1228 function editTagsSave() {
1230 notify_progress("Saving article tags...");
1232 var form
= document
.forms
["tag_edit_form"];
1234 var query
= Form
.serialize("tag_edit_form");
1236 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1240 new Ajax
.Request(query
, {
1241 onComplete: function(transport
) {
1242 tag_saved_callback(transport
);
1247 function editTagsInsert() {
1250 var form
= document
.forms
["tag_edit_form"];
1252 var found_tags
= form
.found_tags
;
1253 var tags_str
= form
.tags_str
;
1255 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1257 if (tags_str
.value
.length
> 0 &&
1258 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1260 tags_str
.value
= tags_str
.value
+ ", ";
1263 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1265 found_tags
.selectedIndex
= 0;
1268 exception_error(e
, "editTagsInsert");
1272 function cdmScrollViewport(where
) {
1273 debug("cdmScrollViewport: " + where
);
1275 var ctr
= document
.getElementById("headlinesInnerContainer");
1279 if (where
== "bottom") {
1280 ctr
.scrollTop
= ctr
.scrollHeight
;
1282 ctr
.scrollTop
= where
;
1286 function cdmArticleIsBelowViewport(id
) {
1288 var ctr
= document
.getElementById("headlinesInnerContainer");
1289 var e
= document
.getElementById("RROW-" + id
);
1291 if (!e
|| !ctr
) return;
1293 // article starts below viewport
1295 if (ctr
.scrollTop
< e
.offsetTop
) {
1302 exception_error(e
, "cdmArticleIsVisible");
1306 function cdmArticleIsAboveViewport(id
) {
1308 var ctr
= document
.getElementById("headlinesInnerContainer");
1309 var e
= document
.getElementById("RROW-" + id
);
1311 if (!e
|| !ctr
) return;
1313 // article starts above viewport
1315 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1322 exception_error(e
, "cdmArticleIsVisible");
1326 function cdmScrollToArticleId(id
) {
1328 var ctr
= document
.getElementById("headlinesInnerContainer");
1329 var e
= document
.getElementById("RROW-" + id
);
1331 if (!e
|| !ctr
) return;
1333 ctr
.scrollTop
= e
.offsetTop
;
1336 exception_error(e
, "cdmScrollToArticleId");
1340 function cdmArticleIsActuallyVisible(id
) {
1342 var ctr
= document
.getElementById("headlinesInnerContainer");
1343 var e
= document
.getElementById("RROW-" + id
);
1345 if (!e
|| !ctr
) return;
1347 // article fits in viewport OR article is longer than viewport and
1348 // its bottom is visible
1350 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1351 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1355 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1356 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1357 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1366 exception_error(e
, "cdmArticleIsVisible");
1370 function cdmWatchdog() {
1374 var ctr
= document
.getElementById("headlinesInnerContainer");
1378 var ids
= new Array();
1380 var e
= ctr
.firstChild
;
1383 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1384 e
.id
.match("RROW-")) {
1386 // article fits in viewport OR article is longer than viewport and
1387 // its bottom is visible
1389 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1390 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1392 // debug(e.id + " is visible " + e.offsetTop + "." +
1393 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1394 // (ctr.scrollTop + ctr.offsetHeight));
1396 ids
.push(e
.id
.replace("RROW-", ""));
1398 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1399 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1400 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1402 ids
.push(e
.id
.replace("RROW-", ""));
1406 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1408 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1409 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1411 ids.push(e.id.replace("RROW-", ""));
1420 debug("cdmWatchdog, ids= " + ids
.toString());
1422 if (ids
.length
> 0) {
1424 for (var i
= 0; i
< ids
.length
; i
++) {
1425 var e
= document
.getElementById("RROW-" + ids
[i
]);
1427 e
.className
= e
.className
.replace("Unread", "");
1431 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1432 param_escape(ids
.toString()) + "&cmode=0";
1434 new Ajax
.Request(query
, {
1435 onComplete: function(transport
) {
1436 all_counters_callback2(transport
);
1441 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1444 exception_error(e
, "cdmWatchdog");
1450 function cache_inject(id
, article
, param
) {
1451 if (!cache_check_param(id
, param
)) {
1452 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1454 var cache_obj
= new Array();
1456 cache_obj
["id"] = id
;
1457 cache_obj
["data"] = article
;
1458 cache_obj
["param"] = param
;
1460 article_cache
.push(cache_obj
);
1463 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1467 function cache_find(id
) {
1468 for (var i
= 0; i
< article_cache
.length
; i
++) {
1469 if (article_cache
[i
]["id"] == id
) {
1470 return article_cache
[i
]["data"];
1476 function cache_find_param(id
, param
) {
1477 for (var i
= 0; i
< article_cache
.length
; i
++) {
1478 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1479 return article_cache
[i
]["data"];
1485 function cache_check(id
) {
1486 for (var i
= 0; i
< article_cache
.length
; i
++) {
1487 if (article_cache
[i
]["id"] == id
) {
1494 function cache_check_param(id
, param
) {
1495 for (var i
= 0; i
< article_cache
.length
; i
++) {
1497 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1498 // article_cache[i]["param"] + " vs " + id + ":" + param);
1500 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1507 function cache_expire() {
1508 while (article_cache
.length
> 20) {
1509 article_cache
.shift();
1513 function cache_empty() {
1514 article_cache
= new Array();
1517 function cache_invalidate(id
) {
1522 while (i
< article_cache
.length
) {
1523 if (article_cache
[i
]["id"] == id
) {
1524 debug("cache_invalidate: removed id " + id
);
1525 article_cache
.splice(i
, 1);
1530 debug("cache_invalidate: id not found: " + id
);
1533 exception_error("cache_invalidate", e
);
1537 function getActiveArticleId() {
1538 return active_post_id
;
1541 function cdmMouseIn(elem
) {
1543 if (elem
.id
&& elem
.id
.match("RROW-")) {
1544 var id
= elem
.id
.replace("RROW-", "");
1545 active_post_id
= id
;
1548 exception_error("cdmMouseIn", e
);
1553 function cdmMouseOut(elem
) {
1554 active_post_id
= false;
1557 function headlines_scroll_handler() {
1560 var e
= document
.getElementById("headlinesInnerContainer");
1562 // don't do infinite scrolling when Limit == All
1564 var toolbar_form
= document
.forms
["main_toolbar_form"];
1566 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1567 if (limit
.value
!= 0) {
1569 debug((e
.scrollTop
+ e
.offsetHeight
) + " vs " + e
.scrollHeight
+ " dis? " +
1570 _infscroll_disable
);
1572 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1573 if (!_infscroll_disable
) {
1574 debug("more cowbell!");
1581 exception_error("headlines_scroll_handler", e
);
1585 function catchupRelativeToArticle(below
) {
1589 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1590 printLockingError();
1593 if (!getActiveArticleId()) {
1594 alert(__("No article is selected."));
1600 if (document
.getElementById("headlinesList")) {
1601 visible_ids
= getVisibleHeadlineIds();
1603 visible_ids
= cdmGetVisibleArticles();
1606 var ids_to_mark
= new Array();
1609 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1610 if (visible_ids
[i
] != getActiveArticleId()) {
1611 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1613 if (e
&& e
.className
.match("Unread")) {
1614 ids_to_mark
.push(visible_ids
[i
]);
1621 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1622 if (visible_ids
[i
] != getActiveArticleId()) {
1623 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1625 if (e
&& e
.className
.match("Unread")) {
1626 ids_to_mark
.push(visible_ids
[i
]);
1634 if (ids_to_mark
.length
== 0) {
1635 alert(__("No articles found to mark"));
1637 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1641 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1642 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1643 e
.className
= e
.className
.replace("Unread", "");
1646 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1647 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1649 new Ajax
.Request(query
, {
1650 onComplete: function(transport
) {
1651 catchup_callback2(transport
);
1658 exception_error("catchupRelativeToArticle", e
);
1662 function cdmExpandArticle(a_id
) {
1664 var id
= 'CICD-' + a_id
;
1666 Effect
.Appear(id
, {duration
: 0.5,
1667 beforeStart: function(effect
) {
1668 var h_id
= 'CICH-' + a_id
;
1669 var h_elem
= document
.getElementById(h_id
);
1670 if (h_elem
) { h_elem
.style
.display
= "none"; }
1672 toggleUnread(a_id
, 0);
1677 exception_error("appearBlockElementF", e
);
1682 function fixHeadlinesOrder(ids
) {
1684 for (var i
= 0; i
< ids
.length
; i
++) {
1685 var e
= document
.getElementById("RROW-" + ids
[i
]);
1689 e
.className
= e
.className
.replace("even", "odd");
1691 e
.className
= e
.className
.replace("odd", "even");
1696 exception_error("fixHeadlinesOrder", e
);
1700 function subtoolbarSearch() {
1704 var q
= document
.getElementById("subtoolbar_search_box");
1708 q
= q
.value
.toUpperCase();
1711 var vis_ids
= new Array();
1713 if (document
.getElementById("headlinesList")) {
1714 ids
= getVisibleHeadlineIds();
1716 ids
= cdmGetVisibleArticles();
1719 for (var i
= 0; i
< ids
.length
; i
++) {
1720 var title
= document
.getElementById("RTITLE-" + ids
[i
]);
1723 if (!title
.innerHTML
.toUpperCase().match(q
)) {
1724 Element
.hide(document
.getElementById("RROW-" + ids
[i
]));
1726 Element
.show(document
.getElementById("RROW-" + ids
[i
]));
1727 vis_ids
.push(ids
[i
]);
1732 fixHeadlinesOrder(vis_ids
);
1735 exception_error("subtoolbarSearch", e
);