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 headlines_callback2(transport
, active_feed_id
, is_cat
, feed_cur_page
) {
51 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
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 setActiveFeedId(active_feed_id
);
63 if (is_cat
!= undefined) {
64 active_feed_is_cat
= is_cat
;
68 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
69 if (feedr
&& !feedr
.className
.match("Selected")) {
70 feedr
.className
= feedr
.className
+ "Selected";
74 var f
= document
.getElementById("headlines-frame");
76 if (feed_cur_page
== 0) {
77 debug("resetting headlines scrollTop");
82 if (transport
.responseXML
) {
83 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
84 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
86 var headlines_count
= headlines_count_obj
.getAttribute("value");
88 if (headlines_count
== 0) _infscroll_disable
= 1;
90 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
91 var articles
= transport
.responseXML
.getElementsByTagName("article");
92 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
94 if (feed_cur_page
== 0) {
96 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
98 debug("headlines_callback: returned no data");
99 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
104 if (headlines_count
> 0) {
105 debug("adding some more headlines...");
107 var c
= document
.getElementById("headlinesList");
110 c
= document
.getElementById("headlinesInnerContainer");
113 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
115 debug("no new headlines received");
118 debug("headlines_callback: returned no data");
119 notify_error("Error while trying to load more headlines");
125 for (var i
= 0; i
< articles
.length
; i
++) {
126 var a_id
= articles
[i
].getAttribute("id");
127 debug("found id: " + a_id
);
128 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
131 debug("no cached articles received");
135 debug("parsing piggybacked counters: " + counters
);
136 parse_counters(counters
, false);
138 debug("counters container not found in reply");
142 debug("parsing runtime info: " + runtime_info
[0]);
143 parse_runtime_info(runtime_info
[0]);
145 debug("counters container not found in reply");
149 debug("headlines_callback: returned no XML object");
150 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
153 if (typeof correctPNG
!= 'undefined') {
157 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
159 if (!document
.getElementById("headlinesList") &&
160 getInitParam("cdm_auto_catchup") == 1) {
161 debug("starting CDM watchdog");
162 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
163 _cdm_wd_vishist
= new Array();
165 debug("not in CDM mode or watchdog disabled");
168 if (_tag_cdm_scroll
) {
170 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
171 _tag_cdm_scroll
= false;
172 debug("resetting headlinesInner scrollTop");
177 _feed_cur_page
= feed_cur_page
;
181 exception_error("headlines_callback2", e
);
185 function render_article(article
) {
187 var f
= document
.getElementById("content-frame");
192 f
.innerHTML
= article
;
195 exception_error("render_article", e
);
199 function article_callback() {
200 if (xmlhttp
.readyState
== 4) {
201 debug("article_callback");
204 if (xmlhttp
.responseXML
) {
205 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
207 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
209 for (var i
= 0; i
< articles
.length
; i
++) {
210 var a_id
= articles
[i
].getAttribute("id");
212 debug("found id: " + a_id
);
214 if (a_id
== active_post_id
) {
215 debug("active article, rendering...");
216 render_article(articles
[i
].firstChild
.nodeValue
);
219 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
223 debug("article_callback: returned no XML object");
224 var f
= document
.getElementById("content-frame");
225 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
228 exception_error("article_callback", e
);
231 var date
= new Date();
232 last_article_view
= date
.getTime() / 1000;
234 if (typeof correctPNG
!= 'undefined') {
238 if (_reload_feedlist_after_view
) {
239 setTimeout('updateFeedList(false, false)', 50);
240 _reload_feedlist_after_view
= false;
242 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
245 debug("parsing piggybacked counters: " + counters
);
246 parse_counters(counters
, false);
248 debug("counters container not found in reply");
256 function view(id
, feed_id
, skip_history
) {
259 debug("loading article: " + id
+ "/" + feed_id
);
261 active_real_feed_id
= feed_id
;
263 var cached_article
= cache_find(id
);
265 debug("cache check result: " + (cached_article
!= false));
269 //setActiveFeedId(feed_id);
271 var query
= "backend.php?op=view&id=" + param_escape(id
) +
272 "&feed=" + param_escape(feed_id
);
274 var date
= new Date();
276 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
277 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
280 debug("trying alternative reset method for Safari");
281 xmlhttp
= Ajax
.getTransport();
285 if (xmlhttp_ready(xmlhttp
)) {
289 cleanSelected("headlinesList");
291 var crow
= document
.getElementById("RROW-" + active_post_id
);
293 var article_is_unread
= crow
.className
.match("Unread");
294 debug("article is unread: " + article_is_unread
);
296 crow
.className
= crow
.className
.replace("Unread", "");
298 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
301 upd_img_pic
.src
= "images/blank_icon.gif";
304 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
305 markHeadline(active_post_id
);
307 var neighbor_ids
= getRelativePostIds(active_post_id
);
309 /* only request uncached articles */
311 var cids_to_request
= Array();
313 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
314 if (!cache_check(neighbor_ids
[i
])) {
315 cids_to_request
.push(neighbor_ids
[i
]);
319 debug("additional ids: " + cids_to_request
.toString());
321 /* additional info for piggyback counters */
323 if (tagsAreDisplayed()) {
324 query
= query
+ "&omode=lt";
326 query
= query
+ "&omode=flc";
329 var date
= new Date();
330 var timestamp
= Math
.round(date
.getTime() / 1000);
331 query
= query
+ "&ts=" + timestamp
;
333 query
= query
+ "&cids=" + cids_to_request
.toString();
335 if (!cached_article
) {
337 notify_progress("Loading, please wait...");
341 xmlhttp
.open("GET", query
, true);
342 xmlhttp
.onreadystatechange
=article_callback
;
344 } else if (cached_article
&& article_is_unread
) {
346 query
= query
+ "&mode=prefetch";
350 xmlhttp
.open("GET", query
, true);
351 xmlhttp
.onreadystatechange
=article_callback
;
354 render_article(cached_article
);
356 } else if (cached_article
) {
358 query
= query
+ "&mode=prefetch_old";
362 xmlhttp
.open("GET", query
, true);
363 xmlhttp
.onreadystatechange
=article_callback
;
366 render_article(cached_article
);
373 debug("xmlhttp busy (@view)");
378 exception_error("view", e
);
383 return toggleMark(id
);
387 return togglePub(id
);
390 function tMark_afh_off(effect
) {
392 var elem
= effect
.effects
[0].element
;
394 debug("tMark_afh_off : " + elem
.id
);
397 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
398 elem
.alt
= __("Star article");
403 exception_error("tMark_afh_off", e
);
407 function tPub_afh_off(effect
) {
409 var elem
= effect
.effects
[0].element
;
411 debug("tPub_afh_off : " + elem
.id
);
414 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
415 elem
.alt
= __("Publish article");
420 exception_error("tPub_afh_off", e
);
424 function toggleMark(id
, client_only
, no_effects
) {
428 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
430 query
= query
+ "&afid=" + getActiveFeedId();
432 if (tagsAreDisplayed()) {
433 query
= query
+ "&omode=tl";
435 query
= query
+ "&omode=flc";
438 var mark_img
= document
.getElementById("FMPIC-" + id
);
439 var vfeedu
= document
.getElementById("FEEDU--1");
440 var crow
= document
.getElementById("RROW-" + id
);
442 if (mark_img
.src
.match("mark_unset")) {
443 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
444 mark_img
.alt
= __("Unstar article");
445 query
= query
+ "&mark=1";
447 /* if (vfeedu && crow.className.match("Unread")) {
448 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
452 //mark_img.src = "images/mark_unset.png";
453 mark_img
.alt
= __("Please wait...");
454 query
= query
+ "&mark=0";
456 /* if (vfeedu && crow.className.match("Unread")) {
457 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
460 if (document
.getElementById("headlinesList") && !no_effects
) {
461 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
463 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
464 mark_img
.alt
= __("Star article");
468 /* var vfeedctr = document.getElementById("FEEDCTR--1");
469 var vfeedr = document.getElementById("FEEDR--1");
471 if (vfeedu && vfeedctr) {
472 if ((+vfeedu.innerHTML) > 0) {
473 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
474 vfeedr.className = vfeedr.className + "Unread";
475 vfeedctr.className = "odd";
478 vfeedctr.className = "invisible";
479 vfeedr.className = vfeedr.className.replace("Unread", "");
483 debug("toggle starred for aid " + id);
485 //new Ajax.Request(query); */
490 new Ajax
.Request(query
, {
491 onComplete: function(transport
) {
492 all_counters_callback2(transport
);
498 exception_error("toggleMark", e
);
502 function togglePub(id
, client_only
, no_effects
) {
506 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
508 query
= query
+ "&afid=" + getActiveFeedId();
510 if (tagsAreDisplayed()) {
511 query
= query
+ "&omode=tl";
513 query
= query
+ "&omode=flc";
516 var mark_img
= document
.getElementById("FPPIC-" + id
);
517 var vfeedu
= document
.getElementById("FEEDU--2");
518 var crow
= document
.getElementById("RROW-" + id
);
520 if (mark_img
.src
.match("pub_unset")) {
521 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
522 mark_img
.alt
= __("Unpublish article");
523 query
= query
+ "&pub=1";
525 /* if (vfeedu && crow.className.match("Unread")) {
526 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
530 //mark_img.src = "images/pub_unset.png";
531 mark_img
.alt
= __("Please wait...");
532 query
= query
+ "&pub=0";
534 /* if (vfeedu && crow.className.match("Unread")) {
535 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
538 if (document
.getElementById("headlinesList") && !no_effects
) {
539 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
541 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
542 mark_img
.alt
= __("Publish article");
546 /* var vfeedctr = document.getElementById("FEEDCTR--2");
547 var vfeedr = document.getElementById("FEEDR--2");
549 if (vfeedu && vfeedctr) {
550 if ((+vfeedu.innerHTML) > 0) {
551 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
552 vfeedr.className = vfeedr.className + "Unread";
553 vfeedctr.className = "odd";
556 vfeedctr.className = "invisible";
557 vfeedr.className = vfeedr.className.replace("Unread", "");
561 debug("toggle published for aid " + id);
563 new Ajax.Request(query); */
566 new Ajax
.Request(query
, {
567 onComplete: function(transport
) {
568 all_counters_callback2(transport
);
574 exception_error("togglePub", e
);
578 function correctHeadlinesOffset(id
) {
582 var hlist
= document
.getElementById("headlinesList");
583 var container
= document
.getElementById("headlinesInnerContainer");
584 var row
= document
.getElementById("RROW-" + id
);
586 var viewport
= container
.offsetHeight
;
588 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
589 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
591 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
592 debug("Vport: " + viewport
);
594 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
595 container
.scrollTop
= row
.offsetTop
;
596 } else if (rel_offset_bottom
> viewport
) {
598 /* doesn't properly work with Opera in some cases because
599 Opera fucks up element scrolling */
601 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
605 exception_error("correctHeadlinesOffset", e
);
610 function moveToPost(mode
) {
612 // check for combined mode
613 if (!document
.getElementById("headlinesList"))
616 var rows
= getVisibleHeadlineIds();
621 if (!document
.getElementById('RROW-' + active_post_id
)) {
622 active_post_id
= false;
625 if (active_post_id
== false) {
626 next_id
= getFirstVisibleHeadlineId();
627 prev_id
= getLastVisibleHeadlineId();
629 for (var i
= 0; i
< rows
.length
; i
++) {
630 if (rows
[i
] == active_post_id
) {
637 if (mode
== "next") {
639 correctHeadlinesOffset(next_id
);
640 view(next_id
, getActiveFeedId());
644 if (mode
== "prev") {
646 correctHeadlinesOffset(prev_id
);
647 view(prev_id
, getActiveFeedId());
652 function toggleUnread(id
, cmode
) {
655 var row
= document
.getElementById("RROW-" + id
);
657 var nc
= row
.className
;
658 nc
= nc
.replace("Unread", "");
659 nc
= nc
.replace("Selected", "");
661 if (row
.className
.match("Unread")) {
664 row
.className
= nc
+ "Unread";
667 if (!cmode
) cmode
= 2;
669 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
670 param_escape(id
) + "&cmode=" + param_escape(cmode
);
672 // notify_progress("Loading, please wait...");
674 new Ajax
.Request(query
, {
675 onComplete: function(transport
) {
676 all_counters_callback2(transport
);
683 exception_error("toggleUnread", e
);
687 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
689 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
697 rows
= cdmGetSelectedArticles();
699 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
702 if (rows
.length
== 0 && !no_error
) {
703 alert(__("No articles are selected."));
707 for (i
= 0; i
< rows
.length
; i
++) {
708 var row
= document
.getElementById("RROW-" + rows
[i
]);
710 var nc
= row
.className
;
711 nc
= nc
.replace("Unread", "");
712 nc
= nc
.replace("Selected", "");
714 if (set_state
== undefined) {
715 if (row
.className
.match("Unread")) {
716 row
.className
= nc
+ "Selected";
718 row
.className
= nc
+ "UnreadSelected";
722 if (set_state
== false) {
723 row
.className
= nc
+ "Selected";
726 if (set_state
== true) {
727 row
.className
= nc
+ "UnreadSelected";
732 if (rows
.length
> 0) {
736 if (set_state
== undefined) {
738 } else if (set_state
== true) {
740 } else if (set_state
== false) {
744 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
745 param_escape(rows
.toString()) + "&cmode=" + cmode
;
747 // _catchup_callback_func = callback_func;
749 debug(callback_func
);
751 notify_progress("Loading, please wait...");
753 /* xmlhttp_rpc.open("GET", query, true);
754 xmlhttp_rpc.onreadystatechange=catchup_callback;
755 xmlhttp_rpc.send(null); */
757 new Ajax
.Request(query
, {
758 onComplete: function(transport
) {
759 catchup_callback2(transport
, callback_func
);
765 exception_error("selectionToggleUnread", e
);
769 function selectionToggleMarked(cdm_mode
) {
775 rows
= cdmGetSelectedArticles();
777 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
780 if (rows
.length
== 0) {
781 alert(__("No articles are selected."));
785 for (i
= 0; i
< rows
.length
; i
++) {
786 toggleMark(rows
[i
], true, true);
789 if (rows
.length
> 0) {
791 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
792 param_escape(rows
.toString()) + "&cmode=2";
794 query
= query
+ "&afid=" + getActiveFeedId();
796 /* if (tagsAreDisplayed()) {
797 query = query + "&omode=tl";
799 query = query + "&omode=flc";
802 query
= query
+ "&omode=lc";
804 new Ajax
.Request(query
, {
805 onComplete: function(transport
) {
806 all_counters_callback2(transport
);
812 exception_error("selectionToggleMarked", e
);
816 function selectionTogglePublished(cdm_mode
) {
822 rows
= cdmGetSelectedArticles();
824 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
827 if (rows
.length
== 0) {
828 alert(__("No articles are selected."));
832 for (i
= 0; i
< rows
.length
; i
++) {
833 togglePub(rows
[i
], true, true);
836 if (rows
.length
> 0) {
838 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
839 param_escape(rows
.toString()) + "&cmode=2";
841 query
= query
+ "&afid=" + getActiveFeedId();
843 /* if (tagsAreDisplayed()) {
844 query = query + "&omode=tl";
846 query = query + "&omode=flc";
849 query
= query
+ "&omode=lc";
851 new Ajax
.Request(query
, {
852 onComplete: function(transport
) {
853 all_counters_callback2(transport
);
859 exception_error("selectionToggleMarked", e
);
863 function cdmGetSelectedArticles() {
864 var sel_articles
= new Array();
865 var container
= document
.getElementById("headlinesInnerContainer");
867 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
868 var child
= container
.childNodes
[i
];
870 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
871 var c_id
= child
.id
.replace("RROW-", "");
872 sel_articles
.push(c_id
);
879 function cdmGetVisibleArticles() {
880 var sel_articles
= new Array();
881 var container
= document
.getElementById("headlinesInnerContainer");
883 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
884 var child
= container
.childNodes
[i
];
886 if (child
.id
.match("RROW-")) {
887 var c_id
= child
.id
.replace("RROW-", "");
888 sel_articles
.push(c_id
);
895 function cdmGetUnreadArticles() {
896 var sel_articles
= new Array();
897 var container
= document
.getElementById("headlinesInnerContainer");
899 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
900 var child
= container
.childNodes
[i
];
902 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
903 var c_id
= child
.id
.replace("RROW-", "");
904 sel_articles
.push(c_id
);
912 // mode = all,none,unread
913 function cdmSelectArticles(mode
) {
914 var container
= document
.getElementById("headlinesInnerContainer");
916 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
917 var child
= container
.childNodes
[i
];
919 if (child
.id
.match("RROW-")) {
920 var aid
= child
.id
.replace("RROW-", "");
922 var cb
= document
.getElementById("RCHK-" + aid
);
925 if (!child
.className
.match("Selected")) {
926 child
.className
= child
.className
+ "Selected";
929 } else if (mode
== "unread") {
930 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
931 child
.className
= child
.className
+ "Selected";
935 child
.className
= child
.className
.replace("Selected", "");
942 function catchupPage() {
944 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
946 var str
= __("Mark all visible articles in %s as read?");
948 str
= str
.replace("%s", fn
);
950 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
954 if (document
.getElementById("headlinesList")) {
955 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
956 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
957 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
959 cdmSelectArticles('all');
960 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
961 cdmSelectArticles('none');
965 function catchupSelection() {
971 if (document
.getElementById("headlinesList")) {
972 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
974 rows
= cdmGetSelectedArticles();
977 if (rows
.length
== 0) {
978 alert(__("No articles are selected."));
983 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
985 var str
= __("Mark all selected articles in %s as read?");
987 str
= str
.replace("%s", fn
);
989 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
993 if (document
.getElementById("headlinesList")) {
994 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
995 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
997 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
998 // cdmSelectArticles('none');
1002 exception_error("catchupSelection", e
);
1007 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1009 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1010 printLockingError();
1013 var title
= prompt(__("Please enter label title:"), "");
1017 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1018 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1019 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1020 "&title=" + param_escape(title
);
1022 debug("LFS: " + query
);
1024 xmlhttp_rpc
.open("GET", query
, true);
1025 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
1026 xmlhttp_rpc
.send(null);
1031 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1032 _tag_active_post_id
= id
;
1033 _tag_active_feed_id
= feed_id
;
1034 _tag_active_cdm
= cdm_enabled
;
1036 cache_invalidate(id
);
1039 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1041 displayDlg('editArticleTags', id
);
1045 function tag_saved_callback() {
1046 if (xmlhttp_rpc
.readyState
== 4) {
1048 debug("in tag_saved_callback");
1053 if (tagsAreDisplayed()) {
1054 _reload_feedlist_after_view
= true;
1057 if (!_tag_active_cdm
) {
1058 if (active_post_id
== _tag_active_post_id
) {
1059 debug("reloading current article");
1060 view(_tag_active_post_id
, _tag_active_feed_id
);
1063 debug("reloading current feed");
1068 exception_error("catchup_callback", e
);
1073 function editTagsSave() {
1075 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1076 printLockingError();
1079 notify_progress("Saving article tags...");
1081 var form
= document
.forms
["tag_edit_form"];
1083 var query
= Form
.serialize("tag_edit_form");
1085 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1089 xmlhttp_rpc
.open("GET", query
, true);
1090 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1091 xmlhttp_rpc
.send(null);
1095 function editTagsInsert() {
1098 var form
= document
.forms
["tag_edit_form"];
1100 var found_tags
= form
.found_tags
;
1101 var tags_str
= form
.tags_str
;
1103 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1105 if (tags_str
.value
.length
> 0 &&
1106 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1108 tags_str
.value
= tags_str
.value
+ ", ";
1111 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1113 found_tags
.selectedIndex
= 0;
1116 exception_error(e
, "editTagsInsert");
1120 function cdmWatchdog() {
1124 var ctr
= document
.getElementById("headlinesInnerContainer");
1128 var ids
= new Array();
1130 var e
= ctr
.firstChild
;
1133 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1134 e
.id
.match("RROW-")) {
1136 // article fits in viewport OR article is longer than viewport and
1137 // its bottom is visible
1139 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1140 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1142 // debug(e.id + " is visible " + e.offsetTop + "." +
1143 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1144 // (ctr.scrollTop + ctr.offsetHeight));
1146 ids
.push(e
.id
.replace("RROW-", ""));
1148 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1149 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1150 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1152 ids
.push(e
.id
.replace("RROW-", ""));
1156 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1158 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1159 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1161 ids.push(e.id.replace("RROW-", ""));
1170 debug("cdmWatchdog, ids= " + ids
.toString());
1172 if (ids
.length
> 0) {
1174 for (var i
= 0; i
< ids
.length
; i
++) {
1175 var e
= document
.getElementById("RROW-" + ids
[i
]);
1177 e
.className
= e
.className
.replace("Unread", "");
1181 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1182 param_escape(ids
.toString()) + "&cmode=0";
1184 new Ajax
.Request(query
, {
1185 onComplete: function(transport
) {
1186 all_counters_callback2(transport
);
1191 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1194 exception_error(e
, "cdmWatchdog");
1200 function cache_inject(id
, article
) {
1201 if (!cache_check(id
)) {
1202 debug("cache_article: miss: " + id
);
1204 var cache_obj
= new Array();
1206 cache_obj
["id"] = id
;
1207 cache_obj
["data"] = article
;
1209 article_cache
.push(cache_obj
);
1212 debug("cache_article: hit: " + id
);
1216 function cache_find(id
) {
1217 for (var i
= 0; i
< article_cache
.length
; i
++) {
1218 if (article_cache
[i
]["id"] == id
) {
1219 return article_cache
[i
]["data"];
1225 function cache_check(id
) {
1226 for (var i
= 0; i
< article_cache
.length
; i
++) {
1227 if (article_cache
[i
]["id"] == id
) {
1234 function cache_expire() {
1235 while (article_cache
.length
> 20) {
1236 article_cache
.shift();
1240 function cache_invalidate(id
) {
1245 while (i
< article_cache
.length
) {
1246 if (article_cache
[i
]["id"] == id
) {
1247 debug("cache_invalidate: removed id " + id
);
1248 article_cache
.splice(i
, 1);
1253 debug("cache_invalidate: id not found: " + id
);
1256 exception_error("cache_invalidate", e
);
1260 function getActiveArticleId() {
1261 return active_post_id
;
1264 function cdmMouseIn(elem
) {
1266 if (elem
.id
&& elem
.id
.match("RROW-")) {
1267 var id
= elem
.id
.replace("RROW-", "");
1268 active_post_id
= id
;
1271 exception_error("cdmMouseIn", e
);
1276 function cdmMouseOut(elem
) {
1277 active_post_id
= false;
1280 function headlines_scroll_handler() {
1283 var e
= document
.getElementById("headlinesInnerContainer");
1285 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1286 if (!_infscroll_disable
) {
1287 debug("more cowbell!");
1293 exception_error("headlines_scroll_handler", e
);
1297 function catchupRelativeToArticle(below
) {
1301 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1302 printLockingError();
1305 if (!getActiveArticleId()) {
1306 alert(__("No article is selected."));
1312 if (document
.getElementById("headlinesList")) {
1313 visible_ids
= getVisibleHeadlineIds();
1315 visible_ids
= cdmGetVisibleArticles();
1318 var ids_to_mark
= new Array();
1321 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1322 if (visible_ids
[i
] != getActiveArticleId()) {
1323 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1325 if (e
&& e
.className
.match("Unread")) {
1326 ids_to_mark
.push(visible_ids
[i
]);
1333 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1334 if (visible_ids
[i
] != getActiveArticleId()) {
1335 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1337 if (e
&& e
.className
.match("Unread")) {
1338 ids_to_mark
.push(visible_ids
[i
]);
1346 if (ids_to_mark
.length
== 0) {
1347 alert(__("No articles found to mark"));
1349 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1353 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1354 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1355 e
.className
= e
.className
.replace("Unread", "");
1358 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1359 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1361 xmlhttp_rpc
.open("GET", query
, true);
1362 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1363 xmlhttp_rpc
.send(null);
1369 exception_error("catchupRelativeToArticle", e
);