1 var active_post_id
= false;
2 var _catchup_callback_func
= false;
3 var last_article_view
= false;
4 var active_real_feed_id
= false;
6 var _tag_active_post_id
= false;
7 var _tag_active_feed_id
= false;
8 var _tag_active_cdm
= false;
10 // FIXME: kludge, to restore scrollTop after tag editor terminates
11 var _tag_cdm_scroll
= false;
13 // FIXME: kludges, needs proper implementation
14 var _reload_feedlist_after_view
= false;
16 var _cdm_wd_timeout
= false;
17 var _cdm_wd_vishist
= new Array();
19 var article_cache
= new Array();
21 function catchup_callback() {
22 if (xmlhttp_rpc
.readyState
== 4) {
24 debug("catchup_callback");
26 all_counters_callback();
27 if (_catchup_callback_func
) {
28 setTimeout(_catchup_callback_func
, 10);
31 exception_error("catchup_callback", e
);
36 function headlines_callback() {
37 if (xmlhttp
.readyState
== 4) {
38 debug("headlines_callback");
39 var f
= document
.getElementById("headlines-frame");
41 if (feed_cur_page
== 0) {
42 debug("resetting headlines scrollTop");
47 if (xmlhttp
.responseXML
) {
48 var headlines
= xmlhttp
.responseXML
.getElementsByTagName("headlines")[0];
49 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
50 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
51 var runtime_info
= xmlhttp
.responseXML
.getElementsByTagName("runtime-info");
53 if (feed_cur_page
== 0) {
55 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
57 debug("headlines_callback: returned no data");
58 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
63 debug("adding some more headlines...");
65 var c
= document
.getElementById("headlinesList");
68 c
= document
.getElementById("headlinesInnerContainer");
71 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
73 debug("headlines_callback: returned no data");
74 notify_error("Error while trying to load more headlines");
80 for (var i
= 0; i
< articles
.length
; i
++) {
81 var a_id
= articles
[i
].getAttribute("id");
82 debug("found id: " + a_id
);
83 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
86 debug("no cached articles received");
90 debug("parsing piggybacked counters: " + counters
);
91 parse_counters(counters
, false);
93 debug("counters container not found in reply");
97 debug("parsing runtime info: " + runtime_info
[0]);
98 parse_runtime_info(runtime_info
[0]);
100 debug("counters container not found in reply");
104 debug("headlines_callback: returned no XML object");
105 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
108 if (typeof correctPNG
!= 'undefined') {
112 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
114 if (!document
.getElementById("headlinesList") &&
115 getInitParam("cdm_auto_catchup") == 1) {
116 debug("starting CDM watchdog");
117 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
118 _cdm_wd_vishist
= new Array();
120 debug("not in CDM mode or watchdog disabled");
123 if (_tag_cdm_scroll
) {
125 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
126 _tag_cdm_scroll
= false;
127 debug("resetting headlinesInner scrollTop");
136 function render_article(article
) {
138 var f
= document
.getElementById("content-frame");
143 f
.innerHTML
= article
;
146 exception_error("render_article", e
);
150 function article_callback() {
151 if (xmlhttp
.readyState
== 4) {
152 debug("article_callback");
155 if (xmlhttp
.responseXML
) {
156 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
158 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
160 for (var i
= 0; i
< articles
.length
; i
++) {
161 var a_id
= articles
[i
].getAttribute("id");
163 debug("found id: " + a_id
);
165 if (a_id
== active_post_id
) {
166 debug("active article, rendering...");
167 render_article(articles
[i
].firstChild
.nodeValue
);
170 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
174 debug("article_callback: returned no XML object");
175 var f
= document
.getElementById("content-frame");
176 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
179 exception_error("article_callback", e
);
182 var date
= new Date();
183 last_article_view
= date
.getTime() / 1000;
185 if (typeof correctPNG
!= 'undefined') {
189 if (_reload_feedlist_after_view
) {
190 setTimeout('updateFeedList(false, false)', 50);
191 _reload_feedlist_after_view
= false;
193 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
196 debug("parsing piggybacked counters: " + counters
);
197 parse_counters(counters
, false);
199 debug("counters container not found in reply");
207 function view(id
, feed_id
, skip_history
) {
210 debug("loading article: " + id
+ "/" + feed_id
);
212 active_real_feed_id
= feed_id
;
214 var cached_article
= cache_find(id
);
216 debug("cache check result: " + (cached_article
!= false));
220 //setActiveFeedId(feed_id);
222 var query
= "backend.php?op=view&id=" + param_escape(id
) +
223 "&feed=" + param_escape(feed_id
);
225 var date
= new Date();
227 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
228 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
231 debug("trying alternative reset method for Safari");
232 xmlhttp
= Ajax
.getTransport();
236 if (xmlhttp_ready(xmlhttp
)) {
240 cleanSelected("headlinesList");
242 var crow
= document
.getElementById("RROW-" + active_post_id
);
244 var article_is_unread
= crow
.className
.match("Unread");
245 debug("article is unread: " + article_is_unread
);
247 crow
.className
= crow
.className
.replace("Unread", "");
249 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
252 upd_img_pic
.src
= "images/blank_icon.gif";
255 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
256 markHeadline(active_post_id
);
258 var neighbor_ids
= getRelativePostIds(active_post_id
);
260 /* only request uncached articles */
262 var cids_to_request
= Array();
264 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
265 if (!cache_check(neighbor_ids
[i
])) {
266 cids_to_request
.push(neighbor_ids
[i
]);
270 debug("additional ids: " + cids_to_request
.toString());
272 /* additional info for piggyback counters */
274 if (tagsAreDisplayed()) {
275 query
= query
+ "&omode=lt";
277 query
= query
+ "&omode=flc";
280 var date
= new Date();
281 var timestamp
= Math
.round(date
.getTime() / 1000);
282 query
= query
+ "&ts=" + timestamp
;
284 query
= query
+ "&cids=" + cids_to_request
.toString();
286 if (!cached_article
) {
288 notify_progress("Loading, please wait...");
292 xmlhttp
.open("GET", query
, true);
293 xmlhttp
.onreadystatechange
=article_callback
;
295 } else if (cached_article
&& article_is_unread
) {
297 query
= query
+ "&mode=prefetch";
301 xmlhttp
.open("GET", query
, true);
302 xmlhttp
.onreadystatechange
=article_callback
;
305 render_article(cached_article
);
307 } else if (cached_article
) {
309 query
= query
+ "&mode=prefetch_old";
313 xmlhttp
.open("GET", query
, true);
314 xmlhttp
.onreadystatechange
=article_callback
;
317 render_article(cached_article
);
324 debug("xmlhttp busy (@view)");
329 exception_error("view", e
);
334 return toggleMark(id
);
338 return togglePub(id
);
341 function tMark_afh_off(effect
) {
343 var elem
= effect
.effects
[0].element
;
345 debug("tMark_afh_off : " + elem
.id
);
348 elem
.src
= "images/mark_unset.png";
349 elem
.alt
= "Set mark";
354 exception_error("tMark_afh_off", e
);
358 function tPub_afh_off(effect
) {
360 var elem
= effect
.effects
[0].element
;
362 debug("tPub_afh_off : " + elem
.id
);
365 elem
.src
= "images/pub_unset.png";
366 elem
.alt
= "Publish";
371 exception_error("tPub_afh_off", e
);
375 function toggleMark(id
) {
379 if (!xmlhttp_ready(xmlhttp_rpc
)) {
384 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
386 query
= query
+ "&afid=" + getActiveFeedId();
388 if (tagsAreDisplayed()) {
389 query
= query
+ "&omode=tl";
391 query
= query
+ "&omode=flc";
394 var mark_img
= document
.getElementById("FMPIC-" + id
);
395 var vfeedu
= document
.getElementById("FEEDU--1");
396 var crow
= document
.getElementById("RROW-" + id
);
398 if (mark_img
.alt
!= "Reset mark") {
399 mark_img
.src
= "images/mark_set.png";
400 mark_img
.alt
= "Reset mark";
401 query
= query
+ "&mark=1";
403 /* if (vfeedu && crow.className.match("Unread")) {
404 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
408 //mark_img.src = "images/mark_unset.png";
409 mark_img
.alt
= "Please wait...";
410 query
= query
+ "&mark=0";
412 /* if (vfeedu && crow.className.match("Unread")) {
413 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
416 if (document
.getElementById("headlinesList")) {
417 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
419 mark_img
.src
= "images/mark_unset.png";
420 mark_img
.alt
= "Set mark";
424 /* var vfeedctr = document.getElementById("FEEDCTR--1");
425 var vfeedr = document.getElementById("FEEDR--1");
427 if (vfeedu && vfeedctr) {
428 if ((+vfeedu.innerHTML) > 0) {
429 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
430 vfeedr.className = vfeedr.className + "Unread";
431 vfeedctr.className = "odd";
434 vfeedctr.className = "invisible";
435 vfeedr.className = vfeedr.className.replace("Unread", "");
439 debug("toggle starred for aid " + id);
441 //new Ajax.Request(query); */
445 xmlhttp_rpc
.open("GET", query
, true);
446 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
447 xmlhttp_rpc
.send(null);
450 exception_error("toggleMark", e
);
454 function togglePub(id
) {
458 if (!xmlhttp_ready(xmlhttp_rpc
)) {
463 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
465 query
= query
+ "&afid=" + getActiveFeedId();
467 if (tagsAreDisplayed()) {
468 query
= query
+ "&omode=tl";
470 query
= query
+ "&omode=flc";
473 var mark_img
= document
.getElementById("FPPIC-" + id
);
474 var vfeedu
= document
.getElementById("FEEDU--2");
475 var crow
= document
.getElementById("RROW-" + id
);
477 if (mark_img
.alt
!= "Unpublish") {
478 mark_img
.src
= "images/pub_set.png";
479 mark_img
.alt
= "Unpublish";
480 query
= query
+ "&pub=1";
482 /* if (vfeedu && crow.className.match("Unread")) {
483 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
487 //mark_img.src = "images/pub_unset.png";
488 mark_img
.alt
= "Please wait...";
489 query
= query
+ "&pub=0";
491 /* if (vfeedu && crow.className.match("Unread")) {
492 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
495 if (document
.getElementById("headlinesList")) {
496 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
498 mark_img
.src
= "images/pub_unset.png";
499 mark_img
.alt
= "Publish";
503 /* var vfeedctr = document.getElementById("FEEDCTR--2");
504 var vfeedr = document.getElementById("FEEDR--2");
506 if (vfeedu && vfeedctr) {
507 if ((+vfeedu.innerHTML) > 0) {
508 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
509 vfeedr.className = vfeedr.className + "Unread";
510 vfeedctr.className = "odd";
513 vfeedctr.className = "invisible";
514 vfeedr.className = vfeedr.className.replace("Unread", "");
518 debug("toggle published for aid " + id);
520 new Ajax.Request(query); */
522 xmlhttp_rpc
.open("GET", query
, true);
523 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
524 xmlhttp_rpc
.send(null);
528 exception_error("togglePub", e
);
532 function correctHeadlinesOffset(id
) {
536 var hlist
= document
.getElementById("headlinesList");
537 var container
= document
.getElementById("headlinesInnerContainer");
538 var row
= document
.getElementById("RROW-" + id
);
540 var viewport
= container
.offsetHeight
;
542 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
543 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
545 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
546 debug("Vport: " + viewport
);
548 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
549 container
.scrollTop
= row
.offsetTop
;
550 } else if (rel_offset_bottom
> viewport
) {
552 /* doesn't properly work with Opera in some cases because
553 Opera fucks up element scrolling */
555 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
559 exception_error("correctHeadlinesOffset", e
);
564 function moveToPost(mode
) {
566 // check for combined mode
567 if (!document
.getElementById("headlinesList"))
570 var rows
= getVisibleHeadlineIds();
575 if (!document
.getElementById('RROW-' + active_post_id
)) {
576 active_post_id
= false;
579 if (active_post_id
== false) {
580 next_id
= getFirstVisibleHeadlineId();
581 prev_id
= getLastVisibleHeadlineId();
583 for (var i
= 0; i
< rows
.length
; i
++) {
584 if (rows
[i
] == active_post_id
) {
591 if (mode
== "next") {
593 correctHeadlinesOffset(next_id
);
594 view(next_id
, getActiveFeedId());
598 if (mode
== "prev") {
600 correctHeadlinesOffset(prev_id
);
601 view(prev_id
, getActiveFeedId());
606 function toggleUnread(id
, cmode
) {
608 if (!xmlhttp_ready(xmlhttp_rpc
)) {
613 var row
= document
.getElementById("RROW-" + id
);
615 var nc
= row
.className
;
616 nc
= nc
.replace("Unread", "");
617 nc
= nc
.replace("Selected", "");
619 if (row
.className
.match("Unread")) {
622 row
.className
= nc
+ "Unread";
625 if (!cmode
) cmode
= 2;
627 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
628 param_escape(id
) + "&cmode=" + param_escape(cmode
);
630 notify_progress("Loading, please wait...");
632 xmlhttp_rpc
.open("GET", query
, true);
633 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
634 xmlhttp_rpc
.send(null);
640 exception_error("toggleUnread", e
);
644 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
646 if (!xmlhttp_ready(xmlhttp_rpc
)) {
654 rows
= cdmGetSelectedArticles();
656 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
659 if (rows
.length
== 0 && !no_error
) {
660 alert(__("No articles are selected."));
664 for (i
= 0; i
< rows
.length
; i
++) {
665 var row
= document
.getElementById("RROW-" + rows
[i
]);
667 var nc
= row
.className
;
668 nc
= nc
.replace("Unread", "");
669 nc
= nc
.replace("Selected", "");
671 if (set_state
== undefined) {
672 if (row
.className
.match("Unread")) {
673 row
.className
= nc
+ "Selected";
675 row
.className
= nc
+ "UnreadSelected";
679 if (set_state
== false) {
680 row
.className
= nc
+ "Selected";
683 if (set_state
== true) {
684 row
.className
= nc
+ "UnreadSelected";
689 if (rows
.length
> 0) {
693 if (set_state
== undefined) {
695 } else if (set_state
== true) {
697 } else if (set_state
== false) {
701 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
702 param_escape(rows
.toString()) + "&cmode=" + cmode
;
704 _catchup_callback_func
= callback_func
;
706 notify_progress("Loading, please wait...");
708 xmlhttp_rpc
.open("GET", query
, true);
709 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
710 xmlhttp_rpc
.send(null);
715 exception_error("selectionToggleUnread", e
);
719 function selectionToggleMarked(cdm_mode
) {
721 if (!xmlhttp_ready(xmlhttp_rpc
)) {
729 rows
= cdmGetSelectedArticles();
731 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
734 if (rows
.length
== 0) {
735 alert(__("No articles are selected."));
739 for (i
= 0; i
< rows
.length
; i
++) {
740 var row
= document
.getElementById("RROW-" + rows
[i
]);
741 var mark_img
= document
.getElementById("FMPIC-" + rows
[i
]);
743 if (row
&& mark_img
) {
745 if (mark_img
.alt
== "Set mark") {
746 mark_img
.src
= "images/mark_set.png";
747 mark_img
.alt
= "Reset mark";
748 //mark_img.setAttribute('onclick',
749 // 'javascript:toggleMark('+rows[i]+', false)');
752 mark_img
.src
= "images/mark_unset.png";
753 mark_img
.alt
= "Set mark";
755 //mark_img.alt = "Please wait...";
757 //mark_img.setAttribute('onclick',
758 // 'javascript:toggleMark('+rows[i]+', true)');
760 //Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
766 if (rows
.length
> 0) {
768 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
769 param_escape(rows
.toString()) + "&cmode=2";
771 query
= query
+ "&afid=" + getActiveFeedId();
773 if (tagsAreDisplayed()) {
774 query
= query
+ "&omode=tl";
776 query
= query
+ "&omode=flc";
779 xmlhttp_rpc
.open("GET", query
, true);
780 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
781 xmlhttp_rpc
.send(null);
786 exception_error("selectionToggleMarked", e
);
790 function selectionTogglePublished(cdm_mode
) {
792 if (!xmlhttp_ready(xmlhttp_rpc
)) {
800 rows
= cdmGetSelectedArticles();
802 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
805 if (rows
.length
== 0) {
806 alert(__("No articles are selected."));
810 for (i
= 0; i
< rows
.length
; i
++) {
811 var row
= document
.getElementById("RROW-" + rows
[i
]);
812 var mark_img
= document
.getElementById("FPPIC-" + rows
[i
]);
814 if (row
&& mark_img
) {
816 if (mark_img
.alt
== "Publish") {
817 mark_img
.src
= "images/pub_set.png";
818 mark_img
.alt
= "Unpublish";
819 // mark_img.setAttribute('onclick',
820 // 'javascript:togglePub('+rows[i]+', false)');
823 mark_img
.src
= "images/pub_unset.png";
824 mark_img
.alt
= "Publish";
825 // mark_img.setAttribute('onclick',
826 // 'javascript:togglePub('+rows[i]+', true)');
828 // Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
834 if (rows
.length
> 0) {
836 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
837 param_escape(rows
.toString()) + "&cmode=2";
839 query
= query
+ "&afid=" + getActiveFeedId();
841 if (tagsAreDisplayed()) {
842 query
= query
+ "&omode=tl";
844 query
= query
+ "&omode=flc";
847 xmlhttp_rpc
.open("GET", query
, true);
848 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
849 xmlhttp_rpc
.send(null);
854 exception_error("selectionToggleMarked", e
);
858 function cdmGetSelectedArticles() {
859 var sel_articles
= new Array();
860 var container
= document
.getElementById("headlinesInnerContainer");
862 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
863 var child
= container
.childNodes
[i
];
865 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
866 var c_id
= child
.id
.replace("RROW-", "");
867 sel_articles
.push(c_id
);
874 function cdmGetVisibleArticles() {
875 var sel_articles
= new Array();
876 var container
= document
.getElementById("headlinesInnerContainer");
878 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
879 var child
= container
.childNodes
[i
];
881 if (child
.id
.match("RROW-")) {
882 var c_id
= child
.id
.replace("RROW-", "");
883 sel_articles
.push(c_id
);
890 function cdmGetUnreadArticles() {
891 var sel_articles
= new Array();
892 var container
= document
.getElementById("headlinesInnerContainer");
894 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
895 var child
= container
.childNodes
[i
];
897 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
898 var c_id
= child
.id
.replace("RROW-", "");
899 sel_articles
.push(c_id
);
907 // mode = all,none,unread
908 function cdmSelectArticles(mode
) {
909 var container
= document
.getElementById("headlinesInnerContainer");
911 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
912 var child
= container
.childNodes
[i
];
914 if (child
.id
.match("RROW-")) {
915 var aid
= child
.id
.replace("RROW-", "");
917 var cb
= document
.getElementById("RCHK-" + aid
);
920 if (!child
.className
.match("Selected")) {
921 child
.className
= child
.className
+ "Selected";
924 } else if (mode
== "unread") {
925 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
926 child
.className
= child
.className
+ "Selected";
930 child
.className
= child
.className
.replace("Selected", "");
937 function catchupPage() {
939 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
941 var str
= __("Mark all visible articles in %s as read?");
943 str
= str
.replace("%s", fn
);
945 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
949 if (document
.getElementById("headlinesList")) {
950 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
951 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
952 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
954 cdmSelectArticles('all');
955 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
956 cdmSelectArticles('none');
960 function catchupSelection() {
966 if (document
.getElementById("headlinesList")) {
967 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
969 rows
= cdmGetSelectedArticles();
972 if (rows
.length
== 0) {
973 alert(__("No articles are selected."));
978 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
980 var str
= __("Mark all selected articles in %s as read?");
982 str
= str
.replace("%s", fn
);
984 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
988 if (document
.getElementById("headlinesList")) {
989 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
990 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
992 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
993 // cdmSelectArticles('none');
997 exception_error("catchupSelection", e
);
1002 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
1004 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1005 printLockingError();
1008 var title
= prompt(__("Please enter label title:"), "");
1012 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1013 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1014 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1015 "&title=" + param_escape(title
);
1017 debug("LFS: " + query
);
1019 xmlhttp_rpc
.open("GET", query
, true);
1020 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
1021 xmlhttp_rpc
.send(null);
1026 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1027 _tag_active_post_id
= id
;
1028 _tag_active_feed_id
= feed_id
;
1029 _tag_active_cdm
= cdm_enabled
;
1031 cache_invalidate(id
);
1034 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1036 displayDlg('editArticleTags', id
);
1040 function tag_saved_callback() {
1041 if (xmlhttp_rpc
.readyState
== 4) {
1043 debug("in tag_saved_callback");
1048 if (tagsAreDisplayed()) {
1049 _reload_feedlist_after_view
= true;
1052 if (!_tag_active_cdm
) {
1053 if (active_post_id
== _tag_active_post_id
) {
1054 debug("reloading current article");
1055 view(_tag_active_post_id
, _tag_active_feed_id
);
1058 debug("reloading current feed");
1063 exception_error("catchup_callback", e
);
1068 function editTagsSave() {
1070 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1071 printLockingError();
1074 notify_progress("Saving article tags...");
1076 var form
= document
.forms
["tag_edit_form"];
1078 var query
= Form
.serialize("tag_edit_form");
1080 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1084 xmlhttp_rpc
.open("GET", query
, true);
1085 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1086 xmlhttp_rpc
.send(null);
1090 function editTagsInsert() {
1093 var form
= document
.forms
["tag_edit_form"];
1095 var found_tags
= form
.found_tags
;
1096 var tags_str
= form
.tags_str
;
1098 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1100 if (tags_str
.value
.length
> 0 &&
1101 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1103 tags_str
.value
= tags_str
.value
+ ", ";
1106 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1108 found_tags
.selectedIndex
= 0;
1111 exception_error(e
, "editTagsInsert");
1115 function cdmWatchdog() {
1119 var ctr
= document
.getElementById("headlinesInnerContainer");
1123 var ids
= new Array();
1125 var e
= ctr
.firstChild
;
1128 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1129 e
.id
.match("RROW-")) {
1131 // article fits in viewport OR article is longer than viewport and
1132 // its bottom is visible
1134 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1135 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1137 // debug(e.id + " is visible " + e.offsetTop + "." +
1138 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1139 // (ctr.scrollTop + ctr.offsetHeight));
1141 ids
.push(e
.id
.replace("RROW-", ""));
1143 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1144 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1145 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1147 ids
.push(e
.id
.replace("RROW-", ""));
1151 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1153 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1154 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1156 ids.push(e.id.replace("RROW-", ""));
1165 debug("cdmWatchdog, ids= " + ids
.toString());
1167 if (ids
.length
> 0 && xmlhttp_ready(xmlhttp_rpc
)) {
1169 for (var i
= 0; i
< ids
.length
; i
++) {
1170 var e
= document
.getElementById("RROW-" + ids
[i
]);
1172 e
.className
= e
.className
.replace("Unread", "");
1176 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1177 param_escape(ids
.toString()) + "&cmode=0";
1179 xmlhttp_rpc
.open("GET", query
, true);
1180 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
1181 xmlhttp_rpc
.send(null);
1185 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1188 exception_error(e
, "cdmWatchdog");
1194 function cache_inject(id
, article
) {
1195 if (!cache_check(id
)) {
1196 debug("cache_article: miss: " + id
);
1198 var cache_obj
= new Array();
1200 cache_obj
["id"] = id
;
1201 cache_obj
["data"] = article
;
1203 article_cache
.push(cache_obj
);
1206 debug("cache_article: hit: " + id
);
1210 function cache_find(id
) {
1211 for (var i
= 0; i
< article_cache
.length
; i
++) {
1212 if (article_cache
[i
]["id"] == id
) {
1213 return article_cache
[i
]["data"];
1219 function cache_check(id
) {
1220 for (var i
= 0; i
< article_cache
.length
; i
++) {
1221 if (article_cache
[i
]["id"] == id
) {
1228 function cache_expire() {
1229 while (article_cache
.length
> 20) {
1230 article_cache
.shift();
1234 function cache_invalidate(id
) {
1239 while (i
< article_cache
.length
) {
1240 if (article_cache
[i
]["id"] == id
) {
1241 debug("cache_invalidate: removed id " + id
);
1242 article_cache
.splice(i
, 1);
1247 debug("cache_invalidate: id not found: " + id
);
1250 exception_error("cache_invalidate", e
);
1254 function getActiveArticleId() {
1255 return active_post_id
;
1258 function cdmMouseIn(elem
) {
1260 if (elem
.id
&& elem
.id
.match("RROW-")) {
1261 var id
= elem
.id
.replace("RROW-", "");
1262 active_post_id
= id
;
1265 exception_error("cdmMouseIn", e
);
1270 function cdmMouseOut(elem
) {
1271 active_post_id
= false;
1274 function headlines_scroll_handler() {
1277 var e
= document
.getElementById("headlinesInnerContainer");
1279 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1280 debug("more cowbell!");
1286 exception_error("headlines_scroll_handler", e
);
1290 function catchupRelativeToArticle(below
) {
1294 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1295 printLockingError();
1298 if (!getActiveArticleId()) {
1299 alert(__("No article is selected."));
1305 if (document
.getElementById("headlinesList")) {
1306 visible_ids
= getVisibleHeadlineIds();
1308 visible_ids
= cdmGetVisibleArticles();
1311 var ids_to_mark
= new Array();
1314 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1315 if (visible_ids
[i
] != getActiveArticleId()) {
1316 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1318 if (e
&& e
.className
.match("Unread")) {
1319 ids_to_mark
.push(visible_ids
[i
]);
1326 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1327 if (visible_ids
[i
] != getActiveArticleId()) {
1328 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1330 if (e
&& e
.className
.match("Unread")) {
1331 ids_to_mark
.push(visible_ids
[i
]);
1339 if (ids_to_mark
.length
== 0) {
1340 alert(__("No articles found to mark"));
1342 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1346 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1347 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1348 e
.className
= e
.className
.replace("Unread", "");
1351 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1352 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1354 xmlhttp_rpc
.open("GET", query
, true);
1355 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1356 xmlhttp_rpc
.send(null);
1362 exception_error("catchupRelativeToArticle", e
);