1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view = false;
8 var _cdm_wd_timeout = false;
9 var _cdm_wd_vishist = new Array();
11 var article_cache = new Array();
13 var vgroup_last_feed = false;
14 var post_under_pointer = false;
16 var last_requested_article = false;
18 function catchup_callback() {
19 if (xmlhttp_rpc.readyState == 4) {
21 debug("catchup_callback");
23 all_counters_callback2(xmlhttp_rpc);
24 if (_catchup_callback_func) {
25 setTimeout(_catchup_callback_func, 10);
28 exception_error("catchup_callback", e);
33 function catchup_callback2(transport, callback) {
35 debug("catchup_callback2 " + transport + ", " + callback);
37 all_counters_callback2(transport);
39 setTimeout(callback, 10);
42 exception_error("catchup_callback2", e, transport);
46 function clean_feed_selections() {
48 var feeds = document.getElementById("feedList").getElementsByTagName("LI");
50 for (var i = 0; i < feeds.length; i++) {
51 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
52 feeds[i].className = feeds[i].className.replace("Selected", "");
54 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
55 feeds[i].className = feeds[i].className.replace("Selected", "");
59 exception_error("clean_feed_selections", e);
63 function headlines_callback2(transport, feed_cur_page) {
66 loading_set_progress(100);
68 debug("headlines_callback2 [page=" + feed_cur_page + "]");
70 clean_feed_selections();
75 if (transport.responseXML) {
76 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
78 is_cat = headlines.getAttribute("is_cat");
79 feed_id = headlines.getAttribute("id");
80 setActiveFeedId(feed_id, is_cat);
85 var feedr = document.getElementById("FEEDR-" + feed_id);
86 if (feedr && !feedr.className.match("Selected")) {
87 feedr.className = feedr.className + "Selected";
90 var feedr = document.getElementById("FCAT-" + feed_id);
91 if (feedr && !feedr.className.match("Selected")) {
92 feedr.className = feedr.className + "Selected";
96 var f = document.getElementById("headlines-frame");
98 if (feed_cur_page == 0) {
99 debug("resetting headlines scrollTop");
104 if (transport.responseXML) {
105 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
106 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
107 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
108 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
110 var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
112 var headlines_count = headlines_count_obj.getAttribute("value");
113 var headlines_unread = headlines_unread_obj.getAttribute("value");
114 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
116 vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
118 if (headlines_count == 0) {
119 _infscroll_disable = 1;
121 _infscroll_disable = 0;
124 var counters = transport.responseXML.getElementsByTagName("counters")[0];
125 var articles = transport.responseXML.getElementsByTagName("article");
126 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
128 if (feed_cur_page == 0) {
130 f.innerHTML = headlines.firstChild.nodeValue;
132 var cache_prefix = "";
140 cache_invalidate(cache_prefix + feed_id);
142 if (!disable_cache) {
143 cache_inject(cache_prefix + feed_id,
144 headlines.firstChild.nodeValue, headlines_unread);
148 debug("headlines_callback: returned no data");
149 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
154 if (headlines_count > 0) {
155 debug("adding some more headlines...");
157 var c = document.getElementById("headlinesList");
160 c = document.getElementById("headlinesInnerContainer");
163 var ids = getSelectedArticleIds2();
165 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
167 debug("restore selected ids: " + ids);
169 for (var i = 0; i < ids.length; i++) {
170 markHeadline(ids[i]);
174 debug("no new headlines received");
177 debug("headlines_callback: returned no data");
178 notify_error("Error while trying to load more headlines");
184 for (var i = 0; i < articles.length; i++) {
185 var a_id = articles[i].getAttribute("id");
186 debug("found id: " + a_id);
187 cache_inject(a_id, articles[i].firstChild.nodeValue);
190 debug("no cached articles received");
194 debug("parsing piggybacked counters: " + counters);
195 parse_counters(counters, false);
197 debug("counters container not found in reply, requesting...");
202 debug("parsing runtime info: " + runtime_info[0]);
203 parse_runtime_info(runtime_info[0]);
205 debug("counters container not found in reply");
209 debug("headlines_callback: returned no XML object");
210 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
213 if (typeof correctPNG != 'undefined') {
217 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
219 if (!document.getElementById("headlinesList") &&
220 getActiveFeedId() != -3 &&
221 getInitParam("cdm_auto_catchup") == 1) {
222 debug("starting CDM watchdog");
223 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
224 _cdm_wd_vishist = new Array();
226 debug("not in CDM mode or watchdog disabled");
229 _feed_cur_page = feed_cur_page;
230 _infscroll_request_sent = 0;
237 exception_error("headlines_callback2", e, transport);
241 function render_article(article) {
243 var f = document.getElementById("content-frame");
248 var fi = document.getElementById("content-insert");
254 fi.innerHTML = article;
257 exception_error("render_article", e);
261 function showArticleInHeadlines(id) {
265 cleanSelected("headlinesList");
267 var crow = document.getElementById("RROW-" + id);
271 var article_is_unread = crow.className.match("Unread");
273 crow.className = crow.className.replace("Unread", "");
275 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
277 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
279 var cache_prefix = "";
281 if (activeFeedIsCat()) {
287 var view_mode = false;
290 view_mode = document.forms['main_toolbar_form'].view_mode;
291 view_mode = view_mode[view_mode.selectedIndex].value;
296 if (upd_img_pic && upd_img_pic.src.match("updated.png")) {
297 upd_img_pic.src = "images/blank_icon.gif";
299 cache_invalidate(cache_prefix + getActiveFeedId());
301 cache_inject(cache_prefix + getActiveFeedId(),
302 document.getElementById("headlines-frame").innerHTML,
303 get_feed_unread(getActiveFeedId()));
305 } else if (article_is_unread && view_mode == "all_articles") {
307 cache_invalidate(cache_prefix + getActiveFeedId());
309 cache_inject(cache_prefix + getActiveFeedId(),
310 document.getElementById("headlines-frame").innerHTML,
311 get_feed_unread(getActiveFeedId())-1);
313 } else if (article_is_unread) {
314 cache_invalidate(cache_prefix + getActiveFeedId());
320 exception_error("showArticleInHeadlines", e);
324 function article_callback2(transport, id, feed_id) {
326 debug("article_callback2 " + id);
328 if (transport.responseXML) {
330 debug("looking for articles to cache...");
332 var articles = transport.responseXML.getElementsByTagName("article");
334 for (var i = 0; i < articles.length; i++) {
335 var a_id = articles[i].getAttribute("id");
337 debug("found id: " + a_id);
339 if (a_id == active_post_id) {
340 debug("active article, rendering...");
341 render_article(articles[i].firstChild.nodeValue);
344 cache_inject(a_id, articles[i].firstChild.nodeValue);
347 if (id != last_requested_article) {
348 debug("requested article id is out of sequence, aborting");
352 active_real_feed_id = feed_id;
355 showArticleInHeadlines(id);
357 var reply = transport.responseXML.firstChild.firstChild;
360 debug("article_callback: returned no XML object");
361 //var f = document.getElementById("content-frame");
362 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
365 var date = new Date();
366 last_article_view = date.getTime() / 1000;
368 if (typeof correctPNG != 'undefined') {
372 if (_reload_feedlist_after_view) {
373 setTimeout('updateFeedList(false, false)', 50);
374 _reload_feedlist_after_view = false;
376 var counters = transport.responseXML.getElementsByTagName("counters")[0];
379 debug("parsing piggybacked counters: " + counters);
380 parse_counters(counters, false);
382 debug("counters container not found in reply, requesting...");
389 exception_error("article_callback2", e, transport);
393 function view(id, feed_id, skip_history) {
396 debug("loading article: " + id + "/" + feed_id);
398 var cached_article = cache_find(id);
400 debug("cache check result: " + (cached_article != false));
404 //setActiveFeedId(feed_id);
406 var query = "backend.php?op=view&id=" + param_escape(id) +
407 "&feed=" + param_escape(feed_id);
409 var date = new Date();
411 var neighbor_ids = getRelativePostIds(active_post_id);
413 /* only request uncached articles */
415 var cids_to_request = Array();
417 for (var i = 0; i < neighbor_ids.length; i++) {
418 if (!cache_check(neighbor_ids[i])) {
419 cids_to_request.push(neighbor_ids[i]);
423 debug("additional ids: " + cids_to_request.toString());
425 /* additional info for piggyback counters */
427 if (tagsAreDisplayed()) {
428 query = query + "&omode=lt";
430 query = query + "&omode=flc";
433 var date = new Date();
434 var timestamp = Math.round(date.getTime() / 1000);
435 query = query + "&ts=" + timestamp;
437 query = query + "&cids=" + cids_to_request.toString();
439 var crow = document.getElementById("RROW-" + id);
440 var article_is_unread = crow.className.match("Unread");
442 if (!async_counters_work) {
443 query = query + "&csync=true";
446 showArticleInHeadlines(id);
448 if (!cached_article) {
450 notify_progress("Loading, please wait...", true);
452 } else if (cached_article && article_is_unread) {
454 query = query + "&mode=prefetch";
456 render_article(cached_article);
458 } else if (cached_article) {
460 query = query + "&mode=prefetch_old";
461 render_article(cached_article);
467 last_requested_article = id;
469 new Ajax.Request(query, {
470 onComplete: function(transport) {
471 article_callback2(transport, id, feed_id);
477 exception_error("view", e);
482 return toggleMark(id);
486 return togglePub(id);
489 function tMark_afh_off(effect) {
491 var elem = effect.effects[0].element;
493 debug("tMark_afh_off : " + elem.id);
496 elem.src = elem.src.replace("mark_set", "mark_unset");
497 elem.alt = __("Star article");
502 exception_error("tMark_afh_off", e);
506 function tPub_afh_off(effect) {
508 var elem = effect.effects[0].element;
510 debug("tPub_afh_off : " + elem.id);
513 elem.src = elem.src.replace("pub_set", "pub_unset");
514 elem.alt = __("Publish article");
519 exception_error("tPub_afh_off", e);
523 function toggleMark(id, client_only, no_effects) {
527 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
529 query = query + "&afid=" + getActiveFeedId();
531 if (tagsAreDisplayed()) {
532 query = query + "&omode=tl";
534 query = query + "&omode=flc";
537 var mark_img = document.getElementById("FMPIC-" + id);
538 var vfeedu = document.getElementById("FEEDU--1");
539 var crow = document.getElementById("RROW-" + id);
541 if (mark_img.src.match("mark_unset")) {
542 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
543 mark_img.alt = __("Unstar article");
544 query = query + "&mark=1";
547 //mark_img.src = "images/mark_unset.png";
548 mark_img.alt = __("Please wait...");
549 query = query + "&mark=0";
551 if (document.getElementById("headlinesList") && !no_effects) {
552 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
554 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
555 mark_img.alt = __("Star article");
562 new Ajax.Request(query, {
563 onComplete: function(transport) {
564 all_counters_callback2(transport);
570 exception_error("toggleMark", e);
574 function togglePub(id, client_only, no_effects) {
578 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
580 query = query + "&afid=" + getActiveFeedId();
582 if (tagsAreDisplayed()) {
583 query = query + "&omode=tl";
585 query = query + "&omode=flc";
588 var mark_img = document.getElementById("FPPIC-" + id);
589 var vfeedu = document.getElementById("FEEDU--2");
590 var crow = document.getElementById("RROW-" + id);
592 if (mark_img.src.match("pub_unset")) {
593 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
594 mark_img.alt = __("Unpublish article");
595 query = query + "&pub=1";
599 //mark_img.src = "images/pub_unset.png";
600 mark_img.alt = __("Please wait...");
601 query = query + "&pub=0";
603 if (document.getElementById("headlinesList") && !no_effects) {
604 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
606 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
607 mark_img.alt = __("Publish article");
612 new Ajax.Request(query, {
613 onComplete: function(transport) {
614 all_counters_callback2(transport);
620 exception_error("togglePub", e);
624 function correctHeadlinesOffset(id) {
628 var hlist = document.getElementById("headlinesList");
629 var container = document.getElementById("headlinesInnerContainer");
630 var row = document.getElementById("RROW-" + id);
632 var viewport = container.offsetHeight;
634 var rel_offset_top = row.offsetTop - container.scrollTop;
635 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
637 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
638 debug("Vport: " + viewport);
640 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
641 container.scrollTop = row.offsetTop;
642 } else if (rel_offset_bottom > viewport) {
644 /* doesn't properly work with Opera in some cases because
645 Opera fucks up element scrolling */
647 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
651 exception_error("correctHeadlinesOffset", e);
656 function moveToPost(mode) {
663 rows = cdmGetVisibleArticles();
665 rows = getVisibleHeadlineIds();
671 if (!document.getElementById('RROW-' + active_post_id)) {
672 active_post_id = false;
675 if (active_post_id == false) {
676 next_id = getFirstVisibleHeadlineId();
677 prev_id = getLastVisibleHeadlineId();
679 for (var i = 0; i < rows.length; i++) {
680 if (rows[i] == active_post_id) {
687 if (mode == "next") {
691 if (!cdmArticleIsActuallyVisible(next_id)) {
692 cdmScrollToArticleId(next_id);
694 cdmSelectArticles("none");
695 toggleUnread(next_id, 0, true);
696 toggleSelected(next_id);
699 correctHeadlinesOffset(next_id);
700 view(next_id, getActiveFeedId());
705 if (mode == "prev") {
708 cdmScrollToArticleId(prev_id);
709 cdmSelectArticles("none");
710 toggleUnread(prev_id, 0, true);
711 toggleSelected(prev_id);
713 correctHeadlinesOffset(prev_id);
714 view(prev_id, getActiveFeedId());
720 exception_error("moveToPost", e);
724 function toggleSelected(id) {
727 var cb = document.getElementById("RCHK-" + id);
729 var row = document.getElementById("RROW-" + id);
731 var nc = row.className;
733 if (!nc.match("Selected")) {
734 nc = nc + "Selected";
739 // In CDM basically last selected article == active article
740 if (isCdmMode()) active_post_id = id;
742 nc = nc.replace("Selected", "");
752 exception_error("toggleSelected", e);
756 function toggleUnread_afh(effect) {
759 var elem = effect.element;
760 elem.style.backgroundColor = "";
763 exception_error("toggleUnread_afh", e);
767 function toggleUnread(id, cmode, effect) {
770 var row = document.getElementById("RROW-" + id);
772 var nc = row.className;
773 var is_selected = row.className.match("Selected");
774 nc = nc.replace("Unread", "");
775 nc = nc.replace("Selected", "");
777 // since we are removing selection from the object, uncheck
778 // corresponding checkbox
780 var cb = document.getElementById("RCHK-" + id);
785 // NOTE: I'm not sure that resetting selection here is a feature -fox
787 if (cmode == undefined || cmode == 2) {
788 if (row.className.match("Unread")) {
792 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
793 afterFinish: toggleUnread_afh,
794 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
798 row.className = nc + "Unread";
800 } else if (cmode == 0) {
804 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
805 afterFinish: toggleUnread_afh,
806 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
808 } else if (cmode == 1) {
809 row.className = nc + "Unread";
812 // Disable unmarking as selected for the time being (16.05.08) -fox
813 if (is_selected) row.className = row.className + "Selected";
815 if (cmode == undefined) cmode = 2;
817 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
818 param_escape(id) + "&cmode=" + param_escape(cmode);
820 // notify_progress("Loading, please wait...");
822 new Ajax.Request(query, {
823 onComplete: function(transport) {
824 all_counters_callback2(transport);
831 exception_error("toggleUnread", e);
835 function selectionRemoveLabel(id) {
838 var ids = getSelectedArticleIds2();
840 if (ids.length == 0) {
841 alert(__("No articles are selected."));
845 // var ok = confirm(__("Remove selected articles from label?"));
849 var query = "backend.php?op=rpc&subop=removeFromLabel&ids=" +
850 param_escape(ids.toString()) + "&lid=" + param_escape(id);
852 // notify_progress("Loading, please wait...");
854 cache_invalidate("F:" + (-11 - id));
856 new Ajax.Request(query, {
857 onComplete: function(transport) {
858 show_labels_in_headlines(transport);
859 all_counters_callback2(transport);
865 exception_error("selectionAssignLabel", e);
870 function selectionAssignLabel(id) {
873 var ids = getSelectedArticleIds2();
875 if (ids.length == 0) {
876 alert(__("No articles are selected."));
880 // var ok = confirm(__("Assign selected articles to label?"));
884 cache_invalidate("F:" + (-11 - id));
886 var query = "backend.php?op=rpc&subop=assignToLabel&ids=" +
887 param_escape(ids.toString()) + "&lid=" + param_escape(id);
889 // notify_progress("Loading, please wait...");
891 new Ajax.Request(query, {
892 onComplete: function(transport) {
893 show_labels_in_headlines(transport);
894 all_counters_callback2(transport);
900 exception_error("selectionAssignLabel", e);
905 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
910 rows = cdmGetSelectedArticles();
912 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
915 if (rows.length == 0 && !no_error) {
916 alert(__("No articles are selected."));
920 for (i = 0; i < rows.length; i++) {
921 var row = document.getElementById("RROW-" + rows[i]);
923 var nc = row.className;
924 nc = nc.replace("Unread", "");
925 nc = nc.replace("Selected", "");
927 if (set_state == undefined) {
928 if (row.className.match("Unread")) {
929 row.className = nc + "Selected";
931 row.className = nc + "UnreadSelected";
935 if (set_state == false) {
936 row.className = nc + "Selected";
939 if (set_state == true) {
940 row.className = nc + "UnreadSelected";
945 if (rows.length > 0) {
949 if (set_state == undefined) {
951 } else if (set_state == true) {
953 } else if (set_state == false) {
957 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
958 param_escape(rows.toString()) + "&cmode=" + cmode;
960 notify_progress("Loading, please wait...");
962 new Ajax.Request(query, {
963 onComplete: function(transport) {
964 catchup_callback2(transport, callback_func);
970 exception_error("selectionToggleUnread", e);
974 function selectionToggleMarked(cdm_mode) {
980 rows = cdmGetSelectedArticles();
982 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
985 if (rows.length == 0) {
986 alert(__("No articles are selected."));
990 for (i = 0; i < rows.length; i++) {
991 toggleMark(rows[i], true, true);
994 if (rows.length > 0) {
996 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
997 param_escape(rows.toString()) + "&cmode=2";
999 query = query + "&afid=" + getActiveFeedId();
1001 /* if (tagsAreDisplayed()) {
1002 query = query + "&omode=tl";
1004 query = query + "&omode=flc";
1007 query = query + "&omode=lc";
1009 new Ajax.Request(query, {
1010 onComplete: function(transport) {
1011 all_counters_callback2(transport);
1017 exception_error("selectionToggleMarked", e);
1021 function selectionTogglePublished(cdm_mode) {
1027 rows = cdmGetSelectedArticles();
1029 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1032 if (rows.length == 0) {
1033 alert(__("No articles are selected."));
1037 for (i = 0; i < rows.length; i++) {
1038 togglePub(rows[i], true, true);
1041 if (rows.length > 0) {
1043 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
1044 param_escape(rows.toString()) + "&cmode=2";
1046 query = query + "&afid=" + getActiveFeedId();
1048 /* if (tagsAreDisplayed()) {
1049 query = query + "&omode=tl";
1051 query = query + "&omode=flc";
1054 query = query + "&omode=lc";
1056 new Ajax.Request(query, {
1057 onComplete: function(transport) {
1058 all_counters_callback2(transport);
1064 exception_error("selectionToggleMarked", e);
1068 function cdmGetSelectedArticles() {
1069 var sel_articles = new Array();
1070 var container = document.getElementById("headlinesInnerContainer");
1072 for (i = 0; i < container.childNodes.length; i++) {
1073 var child = container.childNodes[i];
1075 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1076 var c_id = child.id.replace("RROW-", "");
1077 sel_articles.push(c_id);
1081 return sel_articles;
1084 function cdmGetVisibleArticles() {
1085 var sel_articles = new Array();
1086 var container = document.getElementById("headlinesInnerContainer");
1088 if (!container) return sel_articles;
1090 for (i = 0; i < container.childNodes.length; i++) {
1091 var child = container.childNodes[i];
1093 if (child.id && child.id.match("RROW-")) {
1094 var c_id = child.id.replace("RROW-", "");
1095 sel_articles.push(c_id);
1099 return sel_articles;
1102 function cdmGetUnreadArticles() {
1103 var sel_articles = new Array();
1104 var container = document.getElementById("headlinesInnerContainer");
1106 for (i = 0; i < container.childNodes.length; i++) {
1107 var child = container.childNodes[i];
1109 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1110 var c_id = child.id.replace("RROW-", "");
1111 sel_articles.push(c_id);
1115 return sel_articles;
1119 // mode = all,none,unread
1120 function cdmSelectArticles(mode) {
1121 var container = document.getElementById("headlinesInnerContainer");
1123 for (i = 0; i < container.childNodes.length; i++) {
1124 var child = container.childNodes[i];
1126 if (child.id && child.id.match("RROW-")) {
1127 var aid = child.id.replace("RROW-", "");
1129 var cb = document.getElementById("RCHK-" + aid);
1131 if (mode == "all") {
1132 if (!child.className.match("Selected")) {
1133 child.className = child.className + "Selected";
1136 } else if (mode == "unread") {
1137 if (child.className.match("Unread") && !child.className.match("Selected")) {
1138 child.className = child.className + "Selected";
1142 child.className = child.className.replace("Selected", "");
1149 function catchupPage() {
1151 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1153 var str = __("Mark all visible articles in %s as read?");
1155 str = str.replace("%s", fn);
1157 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1161 if (document.getElementById("headlinesList")) {
1162 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1163 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1164 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1166 cdmSelectArticles('all');
1167 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1168 cdmSelectArticles('none');
1172 function catchupSelection() {
1178 if (document.getElementById("headlinesList")) {
1179 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1181 rows = cdmGetSelectedArticles();
1184 if (rows.length == 0) {
1185 alert(__("No articles are selected."));
1190 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1192 var str = __("Mark %d selected articles in %s as read?");
1194 str = str.replace("%d", rows.length);
1195 str = str.replace("%s", fn);
1197 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1201 if (document.getElementById("headlinesList")) {
1202 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1203 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1205 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1206 // cdmSelectArticles('none');
1210 exception_error("catchupSelection", e);
1214 function editArticleTags(id, feed_id, cdm_enabled) {
1215 displayDlg('editArticleTags', id);
1219 function tag_saved_callback(transport) {
1221 debug("in tag_saved_callback");
1226 if (tagsAreDisplayed()) {
1227 _reload_feedlist_after_view = true;
1231 if (transport.responseXML) {
1232 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1235 var id = tags_str.getAttribute("id");
1238 var tags = document.getElementById("ATSTR-" + id);
1240 tags.innerHTML = tags_str.firstChild.nodeValue;
1247 exception_error("tag_saved_callback", e);
1251 function editTagsSave() {
1253 notify_progress("Saving article tags...");
1255 var form = document.forms["tag_edit_form"];
1257 var query = Form.serialize("tag_edit_form");
1259 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1263 new Ajax.Request(query, {
1264 onComplete: function(transport) {
1265 tag_saved_callback(transport);
1270 function editTagsInsert() {
1273 var form = document.forms["tag_edit_form"];
1275 var found_tags = form.found_tags;
1276 var tags_str = form.tags_str;
1278 var tag = found_tags[found_tags.selectedIndex].value;
1280 if (tags_str.value.length > 0 &&
1281 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1283 tags_str.value = tags_str.value + ", ";
1286 tags_str.value = tags_str.value + tag + ", ";
1288 found_tags.selectedIndex = 0;
1291 exception_error("editTagsInsert", e);
1295 function cdmScrollViewport(where) {
1296 debug("cdmScrollViewport: " + where);
1298 var ctr = document.getElementById("headlinesInnerContainer");
1302 if (where == "bottom") {
1303 ctr.scrollTop = ctr.scrollHeight;
1305 ctr.scrollTop = where;
1309 function cdmArticleIsBelowViewport(id) {
1311 var ctr = document.getElementById("headlinesInnerContainer");
1312 var e = document.getElementById("RROW-" + id);
1314 if (!e || !ctr) return;
1316 // article starts below viewport
1318 if (ctr.scrollTop < e.offsetTop) {
1325 exception_error("cdmArticleIsVisible", e);
1329 function cdmArticleIsAboveViewport(id) {
1331 var ctr = document.getElementById("headlinesInnerContainer");
1332 var e = document.getElementById("RROW-" + id);
1334 if (!e || !ctr) return;
1336 // article starts above viewport
1338 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1345 exception_error("cdmArticleIsVisible", e);
1349 function cdmScrollToArticleId(id) {
1351 var ctr = document.getElementById("headlinesInnerContainer");
1352 var e = document.getElementById("RROW-" + id);
1354 if (!e || !ctr) return;
1356 ctr.scrollTop = e.offsetTop;
1359 exception_error("cdmScrollToArticleId", e);
1363 function cdmArticleIsActuallyVisible(id) {
1365 var ctr = document.getElementById("headlinesInnerContainer");
1366 var e = document.getElementById("RROW-" + id);
1368 if (!e || !ctr) return;
1370 // article fits in viewport OR article is longer than viewport and
1371 // its bottom is visible
1373 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1374 ctr.scrollTop + ctr.offsetHeight) {
1378 } else if (e.offsetHeight > ctr.offsetHeight &&
1379 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1380 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1389 exception_error("cdmArticleIsVisible", e);
1393 function cdmWatchdog() {
1397 var ctr = document.getElementById("headlinesInnerContainer");
1401 var ids = new Array();
1403 var e = ctr.firstChild;
1406 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1407 e.id.match("RROW-")) {
1409 // article fits in viewport OR article is longer than viewport and
1410 // its bottom is visible
1412 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1413 ctr.scrollTop + ctr.offsetHeight) {
1415 // debug(e.id + " is visible " + e.offsetTop + "." +
1416 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1417 // (ctr.scrollTop + ctr.offsetHeight));
1419 ids.push(e.id.replace("RROW-", ""));
1421 } else if (e.offsetHeight > ctr.offsetHeight &&
1422 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1423 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1425 ids.push(e.id.replace("RROW-", ""));
1429 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1431 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1432 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1434 ids.push(e.id.replace("RROW-", ""));
1443 debug("cdmWatchdog, ids= " + ids.toString());
1445 if (ids.length > 0) {
1447 for (var i = 0; i < ids.length; i++) {
1448 var e = document.getElementById("RROW-" + ids[i]);
1450 e.className = e.className.replace("Unread", "");
1454 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1455 param_escape(ids.toString()) + "&cmode=0";
1457 new Ajax.Request(query, {
1458 onComplete: function(transport) {
1459 all_counters_callback2(transport);
1464 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1467 exception_error("cdmWatchdog", e);
1473 function cache_inject(id, article, param) {
1474 if (!cache_check_param(id, param)) {
1475 debug("cache_article: miss: " + id + " [p=" + param + "]");
1477 var cache_obj = new Array();
1479 cache_obj["id"] = id;
1480 cache_obj["data"] = article;
1481 cache_obj["param"] = param;
1483 article_cache.push(cache_obj);
1486 debug("cache_article: hit: " + id + " [p=" + param + "]");
1490 function cache_find(id) {
1491 for (var i = 0; i < article_cache.length; i++) {
1492 if (article_cache[i]["id"] == id) {
1493 return article_cache[i]["data"];
1499 function cache_find_param(id, param) {
1500 for (var i = 0; i < article_cache.length; i++) {
1501 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1502 return article_cache[i]["data"];
1508 function cache_check(id) {
1509 for (var i = 0; i < article_cache.length; i++) {
1510 if (article_cache[i]["id"] == id) {
1517 function cache_check_param(id, param) {
1518 for (var i = 0; i < article_cache.length; i++) {
1520 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1521 // article_cache[i]["param"] + " vs " + id + ":" + param);
1523 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1530 function cache_expire() {
1531 while (article_cache.length > 25) {
1532 article_cache.shift();
1536 function cache_empty() {
1537 article_cache = new Array();
1540 function cache_invalidate(id) {
1545 while (i < article_cache.length) {
1546 if (article_cache[i]["id"] == id) {
1547 debug("cache_invalidate: removed id " + id);
1548 article_cache.splice(i, 1);
1553 debug("cache_invalidate: id not found: " + id);
1556 exception_error("cache_invalidate", e);
1560 function getActiveArticleId() {
1561 return active_post_id;
1564 function cdmClicked(id) {
1566 var elem = document.getElementById("RROW-" + id);
1569 var id = elem.id.replace("RROW-", "");
1570 active_post_id = id;
1572 cdmSelectArticles("none");
1573 toggleUnread(id, 0, true);
1578 exception_error("cdmClicked", e);
1582 function preload_article_callback(transport) {
1584 if (transport.responseXML) {
1585 var articles = transport.responseXML.getElementsByTagName("article");
1587 for (var i = 0; i < articles.length; i++) {
1588 var id = articles[i].getAttribute("id");
1589 if (!cache_check(id)) {
1590 cache_inject(id, articles[i].firstChild.nodeValue);
1591 debug("preloaded article: " + id);
1596 exception_error("preload_article_callback", e);
1600 function preloadArticleUnderPointer(id) {
1602 if (getInitParam("bw_limit") == "1") return;
1604 if (post_under_pointer == id && !cache_check(id)) {
1606 debug("trying to preload article " + id);
1608 var neighbor_ids = getRelativePostIds(id, 1);
1610 /* only request uncached articles */
1612 var cids_to_request = Array();
1614 for (var i = 0; i < neighbor_ids.length; i++) {
1615 if (!cache_check(neighbor_ids[i])) {
1616 cids_to_request.push(neighbor_ids[i]);
1619 debug("additional ids: " + cids_to_request.toString());
1621 cids_to_request.push(id);
1623 var query = "backend.php?op=rpc&subop=getArticles&ids=" +
1624 cids_to_request.toString();
1625 new Ajax.Request(query, {
1626 onComplete: function(transport) {
1627 preload_article_callback(transport);
1631 exception_error("preloadArticleUnderPointer", e);
1635 function postMouseIn(id) {
1637 if (post_under_pointer != id) {
1638 post_under_pointer = id;
1640 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1645 exception_error("postMouseIn", e);
1649 function postMouseOut(id) {
1651 post_under_pointer = false;
1653 exception_error("postMouseOut", e);
1657 function headlines_scroll_handler() {
1660 var e = document.getElementById("headlinesInnerContainer");
1662 // don't do infinite scrolling when Limit == All
1664 var toolbar_form = document.forms["main_toolbar_form"];
1666 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1667 if (limit.value != 0) {
1669 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1670 _infscroll_disable);
1672 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1673 if (!_infscroll_disable) {
1674 debug("more cowbell!");
1681 exception_error("headlines_scroll_handler", e);
1685 function catchupRelativeToArticle(below) {
1689 if (!xmlhttp_ready(xmlhttp_rpc)) {
1690 printLockingError();
1693 if (!getActiveArticleId()) {
1694 alert(__("No article is selected."));
1700 if (document.getElementById("headlinesList")) {
1701 visible_ids = getVisibleHeadlineIds();
1703 visible_ids = cdmGetVisibleArticles();
1706 var ids_to_mark = new Array();
1709 for (var i = 0; i < visible_ids.length; i++) {
1710 if (visible_ids[i] != getActiveArticleId()) {
1711 var e = document.getElementById("RROW-" + visible_ids[i]);
1713 if (e && e.className.match("Unread")) {
1714 ids_to_mark.push(visible_ids[i]);
1721 for (var i = visible_ids.length-1; i >= 0; i--) {
1722 if (visible_ids[i] != getActiveArticleId()) {
1723 var e = document.getElementById("RROW-" + visible_ids[i]);
1725 if (e && e.className.match("Unread")) {
1726 ids_to_mark.push(visible_ids[i]);
1734 if (ids_to_mark.length == 0) {
1735 alert(__("No articles found to mark"));
1737 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1741 for (var i = 0; i < ids_to_mark.length; i++) {
1742 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1743 e.className = e.className.replace("Unread", "");
1746 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1747 param_escape(ids_to_mark.toString()) + "&cmode=0";
1749 new Ajax.Request(query, {
1750 onComplete: function(transport) {
1751 catchup_callback2(transport);
1758 exception_error("catchupRelativeToArticle", e);
1762 function cdmExpandArticle(a_id) {
1764 var id = 'CICD-' + a_id;
1767 Element.hide("CEXC-" + a_id);
1770 Effect.Appear(id, {duration : 0.5,
1771 beforeStart: function(effect) {
1772 var h_id = 'CICH-' + a_id;
1773 var h_elem = document.getElementById(h_id);
1774 if (h_elem) { h_elem.style.display = "none"; }
1776 toggleUnread(a_id, 0);
1781 exception_error("appearBlockElementF", e);
1786 function fixHeadlinesOrder(ids) {
1788 for (var i = 0; i < ids.length; i++) {
1789 var e = document.getElementById("RROW-" + ids[i]);
1793 e.className = e.className.replace("even", "odd");
1795 e.className = e.className.replace("odd", "even");
1800 exception_error("fixHeadlinesOrder", e);
1804 function hideReadHeadlines() {
1808 var vis_ids = new Array();
1810 if (document.getElementById("headlinesList")) {
1811 ids = getVisibleHeadlineIds();
1813 ids = cdmGetVisibleArticles();
1816 var read_headlines_visible = true;
1818 for (var i = 0; i < ids.length; i++) {
1819 var row = document.getElementById("RROW-" + ids[i]);
1821 if (row && row.className) {
1822 if (read_headlines_visible) {
1823 if (row.className.match("Unread") || row.className.match("Selected")) {
1825 vis_ids.push(ids[i]);
1827 //Effect.Fade(row, {duration : 0.3});
1832 vis_ids.push(ids[i]);
1837 fixHeadlinesOrder(vis_ids);
1839 read_headlines_visible = !read_headlines_visible;
1842 exception_error("hideReadHeadlines", e);
1846 function invertHeadlineSelection() {
1848 var rows = new Array();
1852 r = document.getElementsByTagName("TR");
1854 r = document.getElementsByTagName("DIV");
1857 for (var i = 0; i < r.length; i++) {
1858 if (r[i].id && r[i].id.match("RROW-")) {
1863 for (var i = 0; i < rows.length; i++) {
1864 var nc = rows[i].className;
1865 var id = rows[i].id.replace("RROW-", "");
1866 var cb = document.getElementById("RCHK-" + id);
1868 if (!rows[i].className.match("Selected")) {
1869 nc = nc + "Selected";
1872 nc = nc.replace("Selected", "");
1876 rows[i].className = nc;
1881 exception_error("invertHeadlineSelection", e);
1885 function getArticleUnderPointer() {
1886 return post_under_pointer;
1889 function zoomToArticle(id) {
1891 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
1893 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1896 exception_error("zoomToArticle", e);
1900 function showOriginalArticleInline(id) {
1903 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1905 notify_progress("Loading, please wait...", true);
1907 new Ajax.Request(query, {
1908 onComplete: function(transport) {
1910 if (transport.responseXML) {
1912 var link = transport.responseXML.getElementsByTagName("link")[0];
1913 var id = transport.responseXML.getElementsByTagName("id")[0];
1918 link = link.firstChild.nodeValue;
1920 var ci = document.getElementById("content-insert");
1922 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
1924 render_article(tmp);
1931 exception_error("showOriginalArticleInline", e);
1936 function scrollArticle(offset) {
1939 var ci = document.getElementById("content-insert");
1941 ci.scrollTop += offset;
1944 var hi = document.getElementById("headlinesInnerContainer");
1946 hi.scrollTop += offset;
1951 exception_error("scrollArticle", e);
1955 function show_labels_in_headlines(transport) {
1957 if (transport.responseXML) {
1958 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
1960 var elems = info.getElementsByTagName("entry");
1962 for (var l = 0; l < elems.length; l++) {
1963 var e_id = elems[l].getAttribute("id");
1967 var ctr = document.getElementById("HLLCTR-" + e_id);
1970 ctr.innerHTML = elems[l].firstChild.nodeValue;
1978 exception_error("show_labels_in_headlines", e);
1983 function toggleHeadlineActions() {
1985 var e = document.getElementById("headlineActionsBody");
1986 var p = document.getElementById("headlineActionsDrop");
1988 if (!Element.visible(e)) {
1995 e.style.left = (p.offsetLeft + 1) + "px";
1996 // e.style.top = (p.offsetTop + p.offsetHeight - 1) + "px";
1999 exception_error("toggleHeadlineActions", e);