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];
95 var headlines_count
= headlines_count_obj
.getAttribute("value");
96 var headlines_unread
= headlines_unread_obj
.getAttribute("value");
98 if (headlines_count
== 0) _infscroll_disable
= 1;
100 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
101 var articles
= transport
.responseXML
.getElementsByTagName("article");
102 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
104 if (feed_cur_page
== 0) {
106 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
108 cache_inject("F:" + active_feed_id
,
109 headlines
.firstChild
.nodeValue
, headlines_unread
);
112 debug("headlines_callback: returned no data");
113 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
118 if (headlines_count
> 0) {
119 debug("adding some more headlines...");
121 var c
= document
.getElementById("headlinesList");
124 c
= document
.getElementById("headlinesInnerContainer");
127 var ids
= getSelectedArticleIds2();
129 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
131 debug("restore selected ids: " + ids
);
133 for (var i
= 0; i
< ids
.length
; i
++) {
134 markHeadline(ids
[i
]);
138 debug("no new headlines received");
141 debug("headlines_callback: returned no data");
142 notify_error("Error while trying to load more headlines");
148 for (var i
= 0; i
< articles
.length
; i
++) {
149 var a_id
= articles
[i
].getAttribute("id");
150 debug("found id: " + a_id
);
151 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
154 debug("no cached articles received");
158 debug("parsing piggybacked counters: " + counters
);
159 parse_counters(counters
, false);
161 debug("counters container not found in reply");
165 debug("parsing runtime info: " + runtime_info
[0]);
166 parse_runtime_info(runtime_info
[0]);
168 debug("counters container not found in reply");
172 debug("headlines_callback: returned no XML object");
173 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
176 if (typeof correctPNG
!= 'undefined') {
180 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
182 if (!document
.getElementById("headlinesList") &&
183 getInitParam("cdm_auto_catchup") == 1) {
184 debug("starting CDM watchdog");
185 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
186 _cdm_wd_vishist
= new Array();
188 debug("not in CDM mode or watchdog disabled");
191 if (_tag_cdm_scroll
) {
193 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
194 _tag_cdm_scroll
= false;
195 debug("resetting headlinesInner scrollTop");
200 _feed_cur_page
= feed_cur_page
;
201 _infscroll_request_sent
= 0;
205 exception_error("headlines_callback2", e
);
209 function render_article(article
) {
211 var f
= document
.getElementById("content-frame");
216 f
.innerHTML
= article
;
219 exception_error("render_article", e
);
223 function showArticleInHeadlines(id
) {
227 cleanSelected("headlinesList");
229 var crow
= document
.getElementById("RROW-" + id
);
233 var article_is_unread
= crow
.className
.match("Unread");
235 crow
.className
= crow
.className
.replace("Unread", "");
237 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
240 upd_img_pic
.src
= "images/blank_icon.gif";
243 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
247 exception_error("showArticleInHeadlines", e
);
251 function article_callback2(transport
, id
, feed_id
) {
253 debug("article_callback2 " + id
);
255 if (transport
.responseXML
) {
257 active_real_feed_id
= feed_id
;
260 showArticleInHeadlines(id
);
262 var reply
= transport
.responseXML
.firstChild
.firstChild
;
264 var articles
= transport
.responseXML
.getElementsByTagName("article");
266 for (var i
= 0; i
< articles
.length
; i
++) {
267 var a_id
= articles
[i
].getAttribute("id");
269 debug("found id: " + a_id
);
271 if (a_id
== active_post_id
) {
272 debug("active article, rendering...");
273 render_article(articles
[i
].firstChild
.nodeValue
);
276 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
280 debug("article_callback: returned no XML object");
281 var f
= document
.getElementById("content-frame");
282 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
285 var date
= new Date();
286 last_article_view
= date
.getTime() / 1000;
288 if (typeof correctPNG
!= 'undefined') {
292 if (_reload_feedlist_after_view
) {
293 setTimeout('updateFeedList(false, false)', 50);
294 _reload_feedlist_after_view
= false;
296 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
299 debug("parsing piggybacked counters: " + counters
);
300 parse_counters(counters
, false);
302 debug("counters container not found in reply");
308 exception_error("article_callback2", e
);
312 function view(id
, feed_id
, skip_history
) {
315 debug("loading article: " + id
+ "/" + feed_id
);
317 var cached_article
= cache_find(id
);
319 debug("cache check result: " + (cached_article
!= false));
323 //setActiveFeedId(feed_id);
325 var query
= "backend.php?op=view&id=" + param_escape(id
) +
326 "&feed=" + param_escape(feed_id
);
328 var date
= new Date();
330 var neighbor_ids
= getRelativePostIds(active_post_id
);
332 /* only request uncached articles */
334 var cids_to_request
= Array();
336 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
337 if (!cache_check(neighbor_ids
[i
])) {
338 cids_to_request
.push(neighbor_ids
[i
]);
342 debug("additional ids: " + cids_to_request
.toString());
344 /* additional info for piggyback counters */
346 if (tagsAreDisplayed()) {
347 query
= query
+ "&omode=lt";
349 query
= query
+ "&omode=flc";
352 var date
= new Date();
353 var timestamp
= Math
.round(date
.getTime() / 1000);
354 query
= query
+ "&ts=" + timestamp
;
356 query
= query
+ "&cids=" + cids_to_request
.toString();
358 var crow
= document
.getElementById("RROW-" + id
);
359 var article_is_unread
= crow
.className
.match("Unread");
361 showArticleInHeadlines(id
);
363 if (!cached_article
) {
365 notify_progress("Loading, please wait...");
367 } else if (cached_article
&& article_is_unread
) {
369 query
= query
+ "&mode=prefetch";
371 render_article(cached_article
);
373 } else if (cached_article
) {
375 query
= query
+ "&mode=prefetch_old";
376 render_article(cached_article
);
381 new Ajax
.Request(query
, {
382 onComplete: function(transport
) {
383 article_callback2(transport
, id
, feed_id
);
387 exception_error("view", e
);
392 return toggleMark(id
);
396 return togglePub(id
);
399 function tMark_afh_off(effect
) {
401 var elem
= effect
.effects
[0].element
;
403 debug("tMark_afh_off : " + elem
.id
);
406 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
407 elem
.alt
= __("Star article");
412 exception_error("tMark_afh_off", e
);
416 function tPub_afh_off(effect
) {
418 var elem
= effect
.effects
[0].element
;
420 debug("tPub_afh_off : " + elem
.id
);
423 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
424 elem
.alt
= __("Publish article");
429 exception_error("tPub_afh_off", e
);
433 function toggleMark(id
, client_only
, no_effects
) {
437 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
439 query
= query
+ "&afid=" + getActiveFeedId();
441 if (tagsAreDisplayed()) {
442 query
= query
+ "&omode=tl";
444 query
= query
+ "&omode=flc";
447 var mark_img
= document
.getElementById("FMPIC-" + id
);
448 var vfeedu
= document
.getElementById("FEEDU--1");
449 var crow
= document
.getElementById("RROW-" + id
);
451 if (mark_img
.src
.match("mark_unset")) {
452 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
453 mark_img
.alt
= __("Unstar article");
454 query
= query
+ "&mark=1";
456 /* if (vfeedu && crow.className.match("Unread")) {
457 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
461 //mark_img.src = "images/mark_unset.png";
462 mark_img
.alt
= __("Please wait...");
463 query
= query
+ "&mark=0";
465 /* if (vfeedu && crow.className.match("Unread")) {
466 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
469 if (document
.getElementById("headlinesList") && !no_effects
) {
470 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
472 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
473 mark_img
.alt
= __("Star article");
477 /* var vfeedctr = document.getElementById("FEEDCTR--1");
478 var vfeedr = document.getElementById("FEEDR--1");
480 if (vfeedu && vfeedctr) {
481 if ((+vfeedu.innerHTML) > 0) {
482 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
483 vfeedr.className = vfeedr.className + "Unread";
484 vfeedctr.className = "odd";
487 vfeedctr.className = "invisible";
488 vfeedr.className = vfeedr.className.replace("Unread", "");
492 debug("toggle starred for aid " + id);
494 //new Ajax.Request(query); */
499 new Ajax
.Request(query
, {
500 onComplete: function(transport
) {
501 all_counters_callback2(transport
);
507 exception_error("toggleMark", e
);
511 function togglePub(id
, client_only
, no_effects
) {
515 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
517 query
= query
+ "&afid=" + getActiveFeedId();
519 if (tagsAreDisplayed()) {
520 query
= query
+ "&omode=tl";
522 query
= query
+ "&omode=flc";
525 var mark_img
= document
.getElementById("FPPIC-" + id
);
526 var vfeedu
= document
.getElementById("FEEDU--2");
527 var crow
= document
.getElementById("RROW-" + id
);
529 if (mark_img
.src
.match("pub_unset")) {
530 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
531 mark_img
.alt
= __("Unpublish article");
532 query
= query
+ "&pub=1";
534 /* if (vfeedu && crow.className.match("Unread")) {
535 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
539 //mark_img.src = "images/pub_unset.png";
540 mark_img
.alt
= __("Please wait...");
541 query
= query
+ "&pub=0";
543 /* if (vfeedu && crow.className.match("Unread")) {
544 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
547 if (document
.getElementById("headlinesList") && !no_effects
) {
548 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
550 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
551 mark_img
.alt
= __("Publish article");
555 /* var vfeedctr = document.getElementById("FEEDCTR--2");
556 var vfeedr = document.getElementById("FEEDR--2");
558 if (vfeedu && vfeedctr) {
559 if ((+vfeedu.innerHTML) > 0) {
560 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
561 vfeedr.className = vfeedr.className + "Unread";
562 vfeedctr.className = "odd";
565 vfeedctr.className = "invisible";
566 vfeedr.className = vfeedr.className.replace("Unread", "");
570 debug("toggle published for aid " + id);
572 new Ajax.Request(query); */
575 new Ajax
.Request(query
, {
576 onComplete: function(transport
) {
577 all_counters_callback2(transport
);
583 exception_error("togglePub", e
);
587 function correctHeadlinesOffset(id
) {
591 var hlist
= document
.getElementById("headlinesList");
592 var container
= document
.getElementById("headlinesInnerContainer");
593 var row
= document
.getElementById("RROW-" + id
);
595 var viewport
= container
.offsetHeight
;
597 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
598 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
600 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
601 debug("Vport: " + viewport
);
603 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
604 container
.scrollTop
= row
.offsetTop
;
605 } else if (rel_offset_bottom
> viewport
) {
607 /* doesn't properly work with Opera in some cases because
608 Opera fucks up element scrolling */
610 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
614 exception_error("correctHeadlinesOffset", e
);
619 function moveToPost(mode
) {
621 // check for combined mode
622 if (!document
.getElementById("headlinesList"))
625 var rows
= getVisibleHeadlineIds();
630 if (!document
.getElementById('RROW-' + active_post_id
)) {
631 active_post_id
= false;
634 if (active_post_id
== false) {
635 next_id
= getFirstVisibleHeadlineId();
636 prev_id
= getLastVisibleHeadlineId();
638 for (var i
= 0; i
< rows
.length
; i
++) {
639 if (rows
[i
] == active_post_id
) {
646 if (mode
== "next") {
648 correctHeadlinesOffset(next_id
);
649 view(next_id
, getActiveFeedId());
653 if (mode
== "prev") {
655 correctHeadlinesOffset(prev_id
);
656 view(prev_id
, getActiveFeedId());
661 function toggleUnread(id
, cmode
) {
664 var row
= document
.getElementById("RROW-" + id
);
666 var nc
= row
.className
;
667 nc
= nc
.replace("Unread", "");
668 nc
= nc
.replace("Selected", "");
670 if (cmode
== undefined || cmode
== 2) {
671 if (row
.className
.match("Unread")) {
674 row
.className
= nc
+ "Unread";
676 } else if (cmode
== 0) {
678 } else if (cmode
== 1) {
679 row
.className
= nc
+ "Unread";
682 if (cmode
== undefined) cmode
= 2;
684 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
685 param_escape(id
) + "&cmode=" + param_escape(cmode
);
687 // notify_progress("Loading, please wait...");
689 new Ajax
.Request(query
, {
690 onComplete: function(transport
) {
691 all_counters_callback2(transport
);
698 exception_error("toggleUnread", e
);
702 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
707 rows
= cdmGetSelectedArticles();
709 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
712 if (rows
.length
== 0 && !no_error
) {
713 alert(__("No articles are selected."));
717 for (i
= 0; i
< rows
.length
; i
++) {
718 var row
= document
.getElementById("RROW-" + rows
[i
]);
720 var nc
= row
.className
;
721 nc
= nc
.replace("Unread", "");
722 nc
= nc
.replace("Selected", "");
724 if (set_state
== undefined) {
725 if (row
.className
.match("Unread")) {
726 row
.className
= nc
+ "Selected";
728 row
.className
= nc
+ "UnreadSelected";
732 if (set_state
== false) {
733 row
.className
= nc
+ "Selected";
736 if (set_state
== true) {
737 row
.className
= nc
+ "UnreadSelected";
742 if (rows
.length
> 0) {
746 if (set_state
== undefined) {
748 } else if (set_state
== true) {
750 } else if (set_state
== false) {
754 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
755 param_escape(rows
.toString()) + "&cmode=" + cmode
;
757 notify_progress("Loading, please wait...");
759 new Ajax
.Request(query
, {
760 onComplete: function(transport
) {
761 catchup_callback2(transport
, callback_func
);
767 exception_error("selectionToggleUnread", e
);
771 function selectionToggleMarked(cdm_mode
) {
777 rows
= cdmGetSelectedArticles();
779 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
782 if (rows
.length
== 0) {
783 alert(__("No articles are selected."));
787 for (i
= 0; i
< rows
.length
; i
++) {
788 toggleMark(rows
[i
], true, true);
791 if (rows
.length
> 0) {
793 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
794 param_escape(rows
.toString()) + "&cmode=2";
796 query
= query
+ "&afid=" + getActiveFeedId();
798 /* if (tagsAreDisplayed()) {
799 query = query + "&omode=tl";
801 query = query + "&omode=flc";
804 query
= query
+ "&omode=lc";
806 new Ajax
.Request(query
, {
807 onComplete: function(transport
) {
808 all_counters_callback2(transport
);
814 exception_error("selectionToggleMarked", e
);
818 function selectionTogglePublished(cdm_mode
) {
824 rows
= cdmGetSelectedArticles();
826 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
829 if (rows
.length
== 0) {
830 alert(__("No articles are selected."));
834 for (i
= 0; i
< rows
.length
; i
++) {
835 togglePub(rows
[i
], true, true);
838 if (rows
.length
> 0) {
840 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
841 param_escape(rows
.toString()) + "&cmode=2";
843 query
= query
+ "&afid=" + getActiveFeedId();
845 /* if (tagsAreDisplayed()) {
846 query = query + "&omode=tl";
848 query = query + "&omode=flc";
851 query
= query
+ "&omode=lc";
853 new Ajax
.Request(query
, {
854 onComplete: function(transport
) {
855 all_counters_callback2(transport
);
861 exception_error("selectionToggleMarked", e
);
865 function cdmGetSelectedArticles() {
866 var sel_articles
= new Array();
867 var container
= document
.getElementById("headlinesInnerContainer");
869 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
870 var child
= container
.childNodes
[i
];
872 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
873 var c_id
= child
.id
.replace("RROW-", "");
874 sel_articles
.push(c_id
);
881 function cdmGetVisibleArticles() {
882 var sel_articles
= new Array();
883 var container
= document
.getElementById("headlinesInnerContainer");
885 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
886 var child
= container
.childNodes
[i
];
888 if (child
.id
.match("RROW-")) {
889 var c_id
= child
.id
.replace("RROW-", "");
890 sel_articles
.push(c_id
);
897 function cdmGetUnreadArticles() {
898 var sel_articles
= new Array();
899 var container
= document
.getElementById("headlinesInnerContainer");
901 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
902 var child
= container
.childNodes
[i
];
904 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
905 var c_id
= child
.id
.replace("RROW-", "");
906 sel_articles
.push(c_id
);
914 // mode = all,none,unread
915 function cdmSelectArticles(mode
) {
916 var container
= document
.getElementById("headlinesInnerContainer");
918 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
919 var child
= container
.childNodes
[i
];
921 if (child
.id
.match("RROW-")) {
922 var aid
= child
.id
.replace("RROW-", "");
924 var cb
= document
.getElementById("RCHK-" + aid
);
927 if (!child
.className
.match("Selected")) {
928 child
.className
= child
.className
+ "Selected";
931 } else if (mode
== "unread") {
932 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
933 child
.className
= child
.className
+ "Selected";
937 child
.className
= child
.className
.replace("Selected", "");
944 function catchupPage() {
946 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
948 var str
= __("Mark all visible articles in %s as read?");
950 str
= str
.replace("%s", fn
);
952 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
956 if (document
.getElementById("headlinesList")) {
957 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
958 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
959 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
961 cdmSelectArticles('all');
962 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
963 cdmSelectArticles('none');
967 function catchupSelection() {
973 if (document
.getElementById("headlinesList")) {
974 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
976 rows
= cdmGetSelectedArticles();
979 if (rows
.length
== 0) {
980 alert(__("No articles are selected."));
985 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
987 var str
= __("Mark %d selected articles in %s as read?");
989 str
= str
.replace("%d", rows
.length
);
990 str
= str
.replace("%s", fn
);
992 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
996 if (document
.getElementById("headlinesList")) {
997 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
998 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1000 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1001 // cdmSelectArticles('none');
1005 exception_error("catchupSelection", e
);
1010 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1012 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1013 printLockingError();
1016 var title
= prompt(__("Please enter label title:"), "");
1020 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1021 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1022 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1023 "&title=" + param_escape(title
);
1025 debug("LFS: " + query
);
1027 new Ajax
.Request(query
, {
1028 onComplete: function(transport
) {
1029 dlg_frefresh_callback(transport
);
1034 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1035 _tag_active_post_id
= id
;
1036 _tag_active_feed_id
= feed_id
;
1037 _tag_active_cdm
= cdm_enabled
;
1039 cache_invalidate(id
);
1042 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1044 displayDlg('editArticleTags', id
);
1048 function tag_saved_callback(transport
) {
1050 debug("in tag_saved_callback");
1055 if (tagsAreDisplayed()) {
1056 _reload_feedlist_after_view
= true;
1059 if (!_tag_active_cdm
) {
1060 if (active_post_id
== _tag_active_post_id
) {
1061 debug("reloading current article");
1062 view(_tag_active_post_id
, _tag_active_feed_id
);
1065 debug("reloading current feed");
1070 exception_error("catchup_callback", e
);
1074 function editTagsSave() {
1076 notify_progress("Saving article tags...");
1078 var form
= document
.forms
["tag_edit_form"];
1080 var query
= Form
.serialize("tag_edit_form");
1082 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1086 new Ajax
.Request(query
, {
1087 onComplete: function(transport
) {
1088 tag_saved_callback(transport
);
1093 function editTagsInsert() {
1096 var form
= document
.forms
["tag_edit_form"];
1098 var found_tags
= form
.found_tags
;
1099 var tags_str
= form
.tags_str
;
1101 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1103 if (tags_str
.value
.length
> 0 &&
1104 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1106 tags_str
.value
= tags_str
.value
+ ", ";
1109 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1111 found_tags
.selectedIndex
= 0;
1114 exception_error(e
, "editTagsInsert");
1118 function cdmWatchdog() {
1122 var ctr
= document
.getElementById("headlinesInnerContainer");
1126 var ids
= new Array();
1128 var e
= ctr
.firstChild
;
1131 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1132 e
.id
.match("RROW-")) {
1134 // article fits in viewport OR article is longer than viewport and
1135 // its bottom is visible
1137 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1138 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1140 // debug(e.id + " is visible " + e.offsetTop + "." +
1141 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1142 // (ctr.scrollTop + ctr.offsetHeight));
1144 ids
.push(e
.id
.replace("RROW-", ""));
1146 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1147 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1148 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1150 ids
.push(e
.id
.replace("RROW-", ""));
1154 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1156 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1157 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1159 ids.push(e.id.replace("RROW-", ""));
1168 debug("cdmWatchdog, ids= " + ids
.toString());
1170 if (ids
.length
> 0) {
1172 for (var i
= 0; i
< ids
.length
; i
++) {
1173 var e
= document
.getElementById("RROW-" + ids
[i
]);
1175 e
.className
= e
.className
.replace("Unread", "");
1179 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1180 param_escape(ids
.toString()) + "&cmode=0";
1182 new Ajax
.Request(query
, {
1183 onComplete: function(transport
) {
1184 all_counters_callback2(transport
);
1189 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1192 exception_error(e
, "cdmWatchdog");
1198 function cache_inject(id
, article
, param
) {
1199 if (!cache_check(id
, param
)) {
1200 debug("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1202 var cache_obj
= new Array();
1204 cache_obj
["id"] = id
;
1205 cache_obj
["data"] = article
;
1206 cache_obj
["param"] = param
;
1208 article_cache
.push(cache_obj
);
1211 debug("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1215 function cache_find(id
) {
1216 for (var i
= 0; i
< article_cache
.length
; i
++) {
1217 if (article_cache
[i
]["id"] == id
) {
1218 return article_cache
[i
]["data"];
1224 function cache_get_param(id
) {
1225 for (var i
= 0; i
< article_cache
.length
; i
++) {
1226 if (article_cache
[i
]["id"] == id
) {
1227 return article_cache
[i
]["param"];
1233 function cache_check(id
) {
1234 for (var i
= 0; i
< article_cache
.length
; i
++) {
1235 if (article_cache
[i
]["id"] == id
) {
1242 function cache_check_param(id
, param
) {
1243 for (var i
= 0; i
< article_cache
.length
; i
++) {
1244 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1251 function cache_expire() {
1252 while (article_cache
.length
> 20) {
1253 article_cache
.shift();
1257 function cache_invalidate(id
) {
1262 while (i
< article_cache
.length
) {
1263 if (article_cache
[i
]["id"] == id
) {
1264 debug("cache_invalidate: removed id " + id
);
1265 article_cache
.splice(i
, 1);
1270 debug("cache_invalidate: id not found: " + id
);
1273 exception_error("cache_invalidate", e
);
1277 function getActiveArticleId() {
1278 return active_post_id
;
1281 function cdmMouseIn(elem
) {
1283 if (elem
.id
&& elem
.id
.match("RROW-")) {
1284 var id
= elem
.id
.replace("RROW-", "");
1285 active_post_id
= id
;
1288 exception_error("cdmMouseIn", e
);
1293 function cdmMouseOut(elem
) {
1294 active_post_id
= false;
1297 function headlines_scroll_handler() {
1300 var e
= document
.getElementById("headlinesInnerContainer");
1302 // don't do infinite scrolling when Limit == All
1304 var toolbar_form
= document
.forms
["main_toolbar_form"];
1306 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1307 if (limit
.value
!= 0) {
1308 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1309 if (!_infscroll_disable
) {
1310 debug("more cowbell!");
1317 exception_error("headlines_scroll_handler", e
);
1321 function catchupRelativeToArticle(below
) {
1325 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1326 printLockingError();
1329 if (!getActiveArticleId()) {
1330 alert(__("No article is selected."));
1336 if (document
.getElementById("headlinesList")) {
1337 visible_ids
= getVisibleHeadlineIds();
1339 visible_ids
= cdmGetVisibleArticles();
1342 var ids_to_mark
= new Array();
1345 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1346 if (visible_ids
[i
] != getActiveArticleId()) {
1347 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1349 if (e
&& e
.className
.match("Unread")) {
1350 ids_to_mark
.push(visible_ids
[i
]);
1357 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1358 if (visible_ids
[i
] != getActiveArticleId()) {
1359 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1361 if (e
&& e
.className
.match("Unread")) {
1362 ids_to_mark
.push(visible_ids
[i
]);
1370 if (ids_to_mark
.length
== 0) {
1371 alert(__("No articles found to mark"));
1373 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1377 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1378 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1379 e
.className
= e
.className
.replace("Unread", "");
1382 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1383 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1385 new Ajax
.Request(query
, {
1386 onComplete: function(transport
) {
1387 catchup_callback2(transport
);
1394 exception_error("catchupRelativeToArticle", e
);
1398 function cdmExpandArticle(a_id
) {
1400 var id
= 'CICD-' + a_id
;
1402 Effect
.Appear(id
, {duration
: 0.5,
1403 beforeStart: function(effect
) {
1404 var h_id
= 'CICH-' + a_id
;
1405 var h_elem
= document
.getElementById(h_id
);
1406 if (h_elem
) { h_elem
.style
.display
= "none"; }
1408 toggleUnread(a_id
, 0);
1413 exception_error("appearBlockElementF", e
);