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
= elem
.src
.replace("mark_set", "mark_unset");
349 elem
.alt
= __("Star article");
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
= elem
.src
.replace("pub_set", "pub_unset");
366 elem
.alt
= __("Publish article");
371 exception_error("tPub_afh_off", e
);
375 function toggleMark(id
, client_only
, no_effects
) {
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
.src
.match("mark_unset")) {
399 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
400 mark_img
.alt
= __("Unstar article");
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") && !no_effects
) {
417 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
419 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
420 mark_img
.alt
= __("Star article");
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); */
446 xmlhttp_rpc
.open("GET", query
, true);
447 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
448 xmlhttp_rpc
.send(null);
452 exception_error("toggleMark", e
);
456 function togglePub(id
, client_only
, no_effects
) {
460 if (!xmlhttp_ready(xmlhttp_rpc
)) {
465 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
467 query
= query
+ "&afid=" + getActiveFeedId();
469 if (tagsAreDisplayed()) {
470 query
= query
+ "&omode=tl";
472 query
= query
+ "&omode=flc";
475 var mark_img
= document
.getElementById("FPPIC-" + id
);
476 var vfeedu
= document
.getElementById("FEEDU--2");
477 var crow
= document
.getElementById("RROW-" + id
);
479 if (mark_img
.src
.match("pub_unset")) {
480 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
481 mark_img
.alt
= __("Unpublish article");
482 query
= query
+ "&pub=1";
484 /* if (vfeedu && crow.className.match("Unread")) {
485 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
489 //mark_img.src = "images/pub_unset.png";
490 mark_img
.alt
= __("Please wait...");
491 query
= query
+ "&pub=0";
493 /* if (vfeedu && crow.className.match("Unread")) {
494 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
497 if (document
.getElementById("headlinesList") && !no_effects
) {
498 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
500 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
501 mark_img
.alt
= __("Publish article");
505 /* var vfeedctr = document.getElementById("FEEDCTR--2");
506 var vfeedr = document.getElementById("FEEDR--2");
508 if (vfeedu && vfeedctr) {
509 if ((+vfeedu.innerHTML) > 0) {
510 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
511 vfeedr.className = vfeedr.className + "Unread";
512 vfeedctr.className = "odd";
515 vfeedctr.className = "invisible";
516 vfeedr.className = vfeedr.className.replace("Unread", "");
520 debug("toggle published for aid " + id);
522 new Ajax.Request(query); */
525 xmlhttp_rpc
.open("GET", query
, true);
526 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
527 xmlhttp_rpc
.send(null);
532 exception_error("togglePub", e
);
536 function correctHeadlinesOffset(id
) {
540 var hlist
= document
.getElementById("headlinesList");
541 var container
= document
.getElementById("headlinesInnerContainer");
542 var row
= document
.getElementById("RROW-" + id
);
544 var viewport
= container
.offsetHeight
;
546 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
547 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
549 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
550 debug("Vport: " + viewport
);
552 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
553 container
.scrollTop
= row
.offsetTop
;
554 } else if (rel_offset_bottom
> viewport
) {
556 /* doesn't properly work with Opera in some cases because
557 Opera fucks up element scrolling */
559 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
563 exception_error("correctHeadlinesOffset", e
);
568 function moveToPost(mode
) {
570 // check for combined mode
571 if (!document
.getElementById("headlinesList"))
574 var rows
= getVisibleHeadlineIds();
579 if (!document
.getElementById('RROW-' + active_post_id
)) {
580 active_post_id
= false;
583 if (active_post_id
== false) {
584 next_id
= getFirstVisibleHeadlineId();
585 prev_id
= getLastVisibleHeadlineId();
587 for (var i
= 0; i
< rows
.length
; i
++) {
588 if (rows
[i
] == active_post_id
) {
595 if (mode
== "next") {
597 correctHeadlinesOffset(next_id
);
598 view(next_id
, getActiveFeedId());
602 if (mode
== "prev") {
604 correctHeadlinesOffset(prev_id
);
605 view(prev_id
, getActiveFeedId());
610 function toggleUnread(id
, cmode
) {
612 if (!xmlhttp_ready(xmlhttp_rpc
)) {
617 var row
= document
.getElementById("RROW-" + id
);
619 var nc
= row
.className
;
620 nc
= nc
.replace("Unread", "");
621 nc
= nc
.replace("Selected", "");
623 if (row
.className
.match("Unread")) {
626 row
.className
= nc
+ "Unread";
629 if (!cmode
) cmode
= 2;
631 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
632 param_escape(id
) + "&cmode=" + param_escape(cmode
);
634 notify_progress("Loading, please wait...");
636 xmlhttp_rpc
.open("GET", query
, true);
637 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
638 xmlhttp_rpc
.send(null);
644 exception_error("toggleUnread", e
);
648 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
650 if (!xmlhttp_ready(xmlhttp_rpc
)) {
658 rows
= cdmGetSelectedArticles();
660 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
663 if (rows
.length
== 0 && !no_error
) {
664 alert(__("No articles are selected."));
668 for (i
= 0; i
< rows
.length
; i
++) {
669 var row
= document
.getElementById("RROW-" + rows
[i
]);
671 var nc
= row
.className
;
672 nc
= nc
.replace("Unread", "");
673 nc
= nc
.replace("Selected", "");
675 if (set_state
== undefined) {
676 if (row
.className
.match("Unread")) {
677 row
.className
= nc
+ "Selected";
679 row
.className
= nc
+ "UnreadSelected";
683 if (set_state
== false) {
684 row
.className
= nc
+ "Selected";
687 if (set_state
== true) {
688 row
.className
= nc
+ "UnreadSelected";
693 if (rows
.length
> 0) {
697 if (set_state
== undefined) {
699 } else if (set_state
== true) {
701 } else if (set_state
== false) {
705 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
706 param_escape(rows
.toString()) + "&cmode=" + cmode
;
708 _catchup_callback_func
= callback_func
;
710 notify_progress("Loading, please wait...");
712 xmlhttp_rpc
.open("GET", query
, true);
713 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
714 xmlhttp_rpc
.send(null);
719 exception_error("selectionToggleUnread", e
);
723 function selectionToggleMarked(cdm_mode
) {
725 if (!xmlhttp_ready(xmlhttp_rpc
)) {
733 rows
= cdmGetSelectedArticles();
735 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
738 if (rows
.length
== 0) {
739 alert(__("No articles are selected."));
743 for (i
= 0; i
< rows
.length
; i
++) {
744 toggleMark(rows
[i
], true, true);
747 if (rows
.length
> 0) {
749 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
750 param_escape(rows
.toString()) + "&cmode=2";
752 query
= query
+ "&afid=" + getActiveFeedId();
754 if (tagsAreDisplayed()) {
755 query
= query
+ "&omode=tl";
757 query
= query
+ "&omode=flc";
760 xmlhttp_rpc
.open("GET", query
, true);
761 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
762 xmlhttp_rpc
.send(null);
767 exception_error("selectionToggleMarked", e
);
771 function selectionTogglePublished(cdm_mode
) {
773 if (!xmlhttp_ready(xmlhttp_rpc
)) {
781 rows
= cdmGetSelectedArticles();
783 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
786 if (rows
.length
== 0) {
787 alert(__("No articles are selected."));
791 for (i
= 0; i
< rows
.length
; i
++) {
792 togglePub(rows
[i
], true, true);
795 if (rows
.length
> 0) {
797 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
798 param_escape(rows
.toString()) + "&cmode=2";
800 query
= query
+ "&afid=" + getActiveFeedId();
802 if (tagsAreDisplayed()) {
803 query
= query
+ "&omode=tl";
805 query
= query
+ "&omode=flc";
808 xmlhttp_rpc
.open("GET", query
, true);
809 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
810 xmlhttp_rpc
.send(null);
815 exception_error("selectionToggleMarked", e
);
819 function cdmGetSelectedArticles() {
820 var sel_articles
= new Array();
821 var container
= document
.getElementById("headlinesInnerContainer");
823 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
824 var child
= container
.childNodes
[i
];
826 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
827 var c_id
= child
.id
.replace("RROW-", "");
828 sel_articles
.push(c_id
);
835 function cdmGetVisibleArticles() {
836 var sel_articles
= new Array();
837 var container
= document
.getElementById("headlinesInnerContainer");
839 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
840 var child
= container
.childNodes
[i
];
842 if (child
.id
.match("RROW-")) {
843 var c_id
= child
.id
.replace("RROW-", "");
844 sel_articles
.push(c_id
);
851 function cdmGetUnreadArticles() {
852 var sel_articles
= new Array();
853 var container
= document
.getElementById("headlinesInnerContainer");
855 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
856 var child
= container
.childNodes
[i
];
858 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
859 var c_id
= child
.id
.replace("RROW-", "");
860 sel_articles
.push(c_id
);
868 // mode = all,none,unread
869 function cdmSelectArticles(mode
) {
870 var container
= document
.getElementById("headlinesInnerContainer");
872 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
873 var child
= container
.childNodes
[i
];
875 if (child
.id
.match("RROW-")) {
876 var aid
= child
.id
.replace("RROW-", "");
878 var cb
= document
.getElementById("RCHK-" + aid
);
881 if (!child
.className
.match("Selected")) {
882 child
.className
= child
.className
+ "Selected";
885 } else if (mode
== "unread") {
886 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
887 child
.className
= child
.className
+ "Selected";
891 child
.className
= child
.className
.replace("Selected", "");
898 function catchupPage() {
900 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
902 var str
= __("Mark all visible articles in %s as read?");
904 str
= str
.replace("%s", fn
);
906 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
910 if (document
.getElementById("headlinesList")) {
911 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
912 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
913 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
915 cdmSelectArticles('all');
916 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
917 cdmSelectArticles('none');
921 function catchupSelection() {
927 if (document
.getElementById("headlinesList")) {
928 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
930 rows
= cdmGetSelectedArticles();
933 if (rows
.length
== 0) {
934 alert(__("No articles are selected."));
939 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
941 var str
= __("Mark all selected 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 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
951 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
953 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
954 // cdmSelectArticles('none');
958 exception_error("catchupSelection", e
);
963 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
965 if (!xmlhttp_ready(xmlhttp_rpc
)) {
969 var title
= prompt(__("Please enter label title:"), "");
973 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
974 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
975 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
976 "&title=" + param_escape(title
);
978 debug("LFS: " + query
);
980 xmlhttp_rpc
.open("GET", query
, true);
981 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
982 xmlhttp_rpc
.send(null);
987 function editArticleTags(id
, feed_id
, cdm_enabled
) {
988 _tag_active_post_id
= id
;
989 _tag_active_feed_id
= feed_id
;
990 _tag_active_cdm
= cdm_enabled
;
992 cache_invalidate(id
);
995 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
997 displayDlg('editArticleTags', id
);
1001 function tag_saved_callback() {
1002 if (xmlhttp_rpc
.readyState
== 4) {
1004 debug("in tag_saved_callback");
1009 if (tagsAreDisplayed()) {
1010 _reload_feedlist_after_view
= true;
1013 if (!_tag_active_cdm
) {
1014 if (active_post_id
== _tag_active_post_id
) {
1015 debug("reloading current article");
1016 view(_tag_active_post_id
, _tag_active_feed_id
);
1019 debug("reloading current feed");
1024 exception_error("catchup_callback", e
);
1029 function editTagsSave() {
1031 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1032 printLockingError();
1035 notify_progress("Saving article tags...");
1037 var form
= document
.forms
["tag_edit_form"];
1039 var query
= Form
.serialize("tag_edit_form");
1041 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1045 xmlhttp_rpc
.open("GET", query
, true);
1046 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1047 xmlhttp_rpc
.send(null);
1051 function editTagsInsert() {
1054 var form
= document
.forms
["tag_edit_form"];
1056 var found_tags
= form
.found_tags
;
1057 var tags_str
= form
.tags_str
;
1059 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1061 if (tags_str
.value
.length
> 0 &&
1062 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1064 tags_str
.value
= tags_str
.value
+ ", ";
1067 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1069 found_tags
.selectedIndex
= 0;
1072 exception_error(e
, "editTagsInsert");
1076 function cdmWatchdog() {
1080 var ctr
= document
.getElementById("headlinesInnerContainer");
1084 var ids
= new Array();
1086 var e
= ctr
.firstChild
;
1089 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1090 e
.id
.match("RROW-")) {
1092 // article fits in viewport OR article is longer than viewport and
1093 // its bottom is visible
1095 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1096 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1098 // debug(e.id + " is visible " + e.offsetTop + "." +
1099 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1100 // (ctr.scrollTop + ctr.offsetHeight));
1102 ids
.push(e
.id
.replace("RROW-", ""));
1104 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1105 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1106 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1108 ids
.push(e
.id
.replace("RROW-", ""));
1112 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1114 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1115 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1117 ids.push(e.id.replace("RROW-", ""));
1126 debug("cdmWatchdog, ids= " + ids
.toString());
1128 if (ids
.length
> 0 && xmlhttp_ready(xmlhttp_rpc
)) {
1130 for (var i
= 0; i
< ids
.length
; i
++) {
1131 var e
= document
.getElementById("RROW-" + ids
[i
]);
1133 e
.className
= e
.className
.replace("Unread", "");
1137 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1138 param_escape(ids
.toString()) + "&cmode=0";
1140 xmlhttp_rpc
.open("GET", query
, true);
1141 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
1142 xmlhttp_rpc
.send(null);
1146 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1149 exception_error(e
, "cdmWatchdog");
1155 function cache_inject(id
, article
) {
1156 if (!cache_check(id
)) {
1157 debug("cache_article: miss: " + id
);
1159 var cache_obj
= new Array();
1161 cache_obj
["id"] = id
;
1162 cache_obj
["data"] = article
;
1164 article_cache
.push(cache_obj
);
1167 debug("cache_article: hit: " + id
);
1171 function cache_find(id
) {
1172 for (var i
= 0; i
< article_cache
.length
; i
++) {
1173 if (article_cache
[i
]["id"] == id
) {
1174 return article_cache
[i
]["data"];
1180 function cache_check(id
) {
1181 for (var i
= 0; i
< article_cache
.length
; i
++) {
1182 if (article_cache
[i
]["id"] == id
) {
1189 function cache_expire() {
1190 while (article_cache
.length
> 20) {
1191 article_cache
.shift();
1195 function cache_invalidate(id
) {
1200 while (i
< article_cache
.length
) {
1201 if (article_cache
[i
]["id"] == id
) {
1202 debug("cache_invalidate: removed id " + id
);
1203 article_cache
.splice(i
, 1);
1208 debug("cache_invalidate: id not found: " + id
);
1211 exception_error("cache_invalidate", e
);
1215 function getActiveArticleId() {
1216 return active_post_id
;
1219 function cdmMouseIn(elem
) {
1221 if (elem
.id
&& elem
.id
.match("RROW-")) {
1222 var id
= elem
.id
.replace("RROW-", "");
1223 active_post_id
= id
;
1226 exception_error("cdmMouseIn", e
);
1231 function cdmMouseOut(elem
) {
1232 active_post_id
= false;
1235 function headlines_scroll_handler() {
1238 var e
= document
.getElementById("headlinesInnerContainer");
1240 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1241 debug("more cowbell!");
1247 exception_error("headlines_scroll_handler", e
);
1251 function catchupRelativeToArticle(below
) {
1255 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1256 printLockingError();
1259 if (!getActiveArticleId()) {
1260 alert(__("No article is selected."));
1266 if (document
.getElementById("headlinesList")) {
1267 visible_ids
= getVisibleHeadlineIds();
1269 visible_ids
= cdmGetVisibleArticles();
1272 var ids_to_mark
= new Array();
1275 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1276 if (visible_ids
[i
] != getActiveArticleId()) {
1277 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1279 if (e
&& e
.className
.match("Unread")) {
1280 ids_to_mark
.push(visible_ids
[i
]);
1287 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1288 if (visible_ids
[i
] != getActiveArticleId()) {
1289 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1291 if (e
&& e
.className
.match("Unread")) {
1292 ids_to_mark
.push(visible_ids
[i
]);
1300 if (ids_to_mark
.length
== 0) {
1301 alert(__("No articles found to mark"));
1303 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1307 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1308 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1309 e
.className
= e
.className
.replace("Unread", "");
1312 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1313 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1315 xmlhttp_rpc
.open("GET", query
, true);
1316 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1317 xmlhttp_rpc
.send(null);
1323 exception_error("catchupRelativeToArticle", e
);