1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
5 var _tag_active_post_id = false;
6 var _tag_active_feed_id = false;
7 var _tag_active_cdm = false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll = false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view = false;
15 var _cdm_wd_timeout = false;
16 var _cdm_wd_vishist = new Array();
18 var article_cache = new Array();
20 var vgroup_last_feed = false;
21 var post_under_pointer = false;
23 var last_requested_article = false;
25 function catchup_callback() {
26 if (xmlhttp_rpc.readyState == 4) {
28 debug("catchup_callback");
30 all_counters_callback2(xmlhttp_rpc);
31 if (_catchup_callback_func) {
32 setTimeout(_catchup_callback_func, 10);
35 exception_error("catchup_callback", e);
40 function catchup_callback2(transport, callback) {
42 debug("catchup_callback2 " + transport + ", " + callback);
44 all_counters_callback2(transport);
46 setTimeout(callback, 10);
49 exception_error("catchup_callback2", e);
53 function clean_feed_selections() {
55 var feeds = document.getElementById("feedList").getElementsByTagName("LI");
57 for (var i = 0; i < feeds.length; i++) {
58 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
59 feeds[i].className = feeds[i].className.replace("Selected", "");
61 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
62 feeds[i].className = feeds[i].className.replace("Selected", "");
66 exception_error("clean_feed_selections", e);
70 function headlines_callback2(transport, active_feed_id, is_cat, feed_cur_page) {
73 loading_set_progress(100);
75 debug("headlines_callback2 [page=" + feed_cur_page + "]");
77 clean_feed_selections();
79 setActiveFeedId(active_feed_id);
81 if (is_cat != undefined) {
82 active_feed_is_cat = is_cat;
86 var feedr = document.getElementById("FEEDR-" + active_feed_id);
87 if (feedr && !feedr.className.match("Selected")) {
88 feedr.className = feedr.className + "Selected";
91 var feedr = document.getElementById("FCAT-" + active_feed_id);
92 if (feedr && !feedr.className.match("Selected")) {
93 feedr.className = feedr.className + "Selected";
97 var f = document.getElementById("headlines-frame");
99 if (feed_cur_page == 0) {
100 debug("resetting headlines scrollTop");
105 if (transport.responseXML) {
106 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
107 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
108 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
109 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
111 var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
113 var headlines_count = headlines_count_obj.getAttribute("value");
114 var headlines_unread = headlines_unread_obj.getAttribute("value");
115 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
117 vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
119 if (headlines_count == 0) {
120 _infscroll_disable = 1;
122 _infscroll_disable = 0;
125 var counters = transport.responseXML.getElementsByTagName("counters")[0];
126 var articles = transport.responseXML.getElementsByTagName("article");
127 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
129 if (feed_cur_page == 0) {
131 f.innerHTML = headlines.firstChild.nodeValue;
133 var cache_prefix = "";
141 cache_invalidate(cache_prefix + active_feed_id);
143 if (!disable_cache) {
144 cache_inject(cache_prefix + active_feed_id,
145 headlines.firstChild.nodeValue, headlines_unread);
149 debug("headlines_callback: returned no data");
150 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
155 if (headlines_count > 0) {
156 debug("adding some more headlines...");
158 var c = document.getElementById("headlinesList");
161 c = document.getElementById("headlinesInnerContainer");
164 var ids = getSelectedArticleIds2();
166 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
168 debug("restore selected ids: " + ids);
170 for (var i = 0; i < ids.length; i++) {
171 markHeadline(ids[i]);
177 debug("no new headlines received");
180 debug("headlines_callback: returned no data");
181 notify_error("Error while trying to load more headlines");
187 for (var i = 0; i < articles.length; i++) {
188 var a_id = articles[i].getAttribute("id");
189 debug("found id: " + a_id);
190 cache_inject(a_id, articles[i].firstChild.nodeValue);
193 debug("no cached articles received");
197 debug("parsing piggybacked counters: " + counters);
198 parse_counters(counters, false);
200 debug("counters container not found in reply, requesting...");
205 debug("parsing runtime info: " + runtime_info[0]);
206 parse_runtime_info(runtime_info[0]);
208 debug("counters container not found in reply");
212 debug("headlines_callback: returned no XML object");
213 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
216 if (typeof correctPNG != 'undefined') {
220 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
222 if (!document.getElementById("headlinesList") &&
223 getInitParam("cdm_auto_catchup") == 1) {
224 debug("starting CDM watchdog");
225 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
226 _cdm_wd_vishist = new Array();
228 debug("not in CDM mode or watchdog disabled");
231 if (_tag_cdm_scroll) {
233 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
234 _tag_cdm_scroll = false;
235 debug("resetting headlinesInner scrollTop");
240 _feed_cur_page = feed_cur_page;
241 _infscroll_request_sent = 0;
248 exception_error("headlines_callback2", e);
252 function render_article(article) {
254 var f = document.getElementById("content-frame");
259 var fi = document.getElementById("content-insert");
265 fi.innerHTML = article;
268 exception_error("render_article", e);
272 function showArticleInHeadlines(id) {
276 cleanSelected("headlinesList");
278 var crow = document.getElementById("RROW-" + id);
282 var article_is_unread = crow.className.match("Unread");
284 crow.className = crow.className.replace("Unread", "");
286 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
288 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
290 var cache_prefix = "";
292 if (activeFeedIsCat()) {
298 var view_mode = false;
301 view_mode = document.forms['main_toolbar_form'].view_mode;
302 view_mode = view_mode[view_mode.selectedIndex].value;
304 exception_error("showArticleInHeadlines/viewmode", e, true);
307 if (upd_img_pic && upd_img_pic.src.match("updated.png")) {
308 upd_img_pic.src = "images/blank_icon.gif";
310 cache_invalidate(cache_prefix + getActiveFeedId());
312 cache_inject(cache_prefix + getActiveFeedId(),
313 document.getElementById("headlines-frame").innerHTML,
314 get_feed_unread(getActiveFeedId()));
316 } else if (article_is_unread && view_mode == "all_articles") {
318 cache_invalidate(cache_prefix + getActiveFeedId());
320 cache_inject(cache_prefix + getActiveFeedId(),
321 document.getElementById("headlines-frame").innerHTML,
322 get_feed_unread(getActiveFeedId())-1);
324 } else if (article_is_unread) {
325 cache_invalidate(cache_prefix + getActiveFeedId());
331 exception_error("showArticleInHeadlines", e);
335 function article_callback2(transport, id, feed_id) {
337 debug("article_callback2 " + id);
339 if (transport.responseXML) {
341 debug("looking for articles to cache...");
343 var articles = transport.responseXML.getElementsByTagName("article");
345 for (var i = 0; i < articles.length; i++) {
346 var a_id = articles[i].getAttribute("id");
348 debug("found id: " + a_id);
350 if (a_id == active_post_id) {
351 debug("active article, rendering...");
352 render_article(articles[i].firstChild.nodeValue);
355 cache_inject(a_id, articles[i].firstChild.nodeValue);
358 if (id != last_requested_article) {
359 debug("requested article id is out of sequence, aborting");
363 active_real_feed_id = feed_id;
366 showArticleInHeadlines(id);
368 var reply = transport.responseXML.firstChild.firstChild;
371 debug("article_callback: returned no XML object");
372 //var f = document.getElementById("content-frame");
373 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
376 var date = new Date();
377 last_article_view = date.getTime() / 1000;
379 if (typeof correctPNG != 'undefined') {
383 if (_reload_feedlist_after_view) {
384 setTimeout('updateFeedList(false, false)', 50);
385 _reload_feedlist_after_view = false;
387 var counters = transport.responseXML.getElementsByTagName("counters")[0];
390 debug("parsing piggybacked counters: " + counters);
391 parse_counters(counters, false);
393 debug("counters container not found in reply, requesting...");
400 exception_error("article_callback2", e);
404 function view(id, feed_id, skip_history) {
407 debug("loading article: " + id + "/" + feed_id);
409 var cached_article = cache_find(id);
411 debug("cache check result: " + (cached_article != false));
415 //setActiveFeedId(feed_id);
417 var query = "backend.php?op=view&id=" + param_escape(id) +
418 "&feed=" + param_escape(feed_id);
420 var date = new Date();
422 var neighbor_ids = getRelativePostIds(active_post_id);
424 /* only request uncached articles */
426 var cids_to_request = Array();
428 for (var i = 0; i < neighbor_ids.length; i++) {
429 if (!cache_check(neighbor_ids[i])) {
430 cids_to_request.push(neighbor_ids[i]);
434 debug("additional ids: " + cids_to_request.toString());
436 /* additional info for piggyback counters */
438 if (tagsAreDisplayed()) {
439 query = query + "&omode=lt";
441 query = query + "&omode=flc";
444 var date = new Date();
445 var timestamp = Math.round(date.getTime() / 1000);
446 query = query + "&ts=" + timestamp;
448 query = query + "&cids=" + cids_to_request.toString();
450 var crow = document.getElementById("RROW-" + id);
451 var article_is_unread = crow.className.match("Unread");
453 if (!async_counters_work) {
454 query = query + "&csync=true";
457 showArticleInHeadlines(id);
459 if (!cached_article) {
461 notify_progress("Loading, please wait...", true);
463 } else if (cached_article && article_is_unread) {
465 query = query + "&mode=prefetch";
467 render_article(cached_article);
469 } else if (cached_article) {
471 query = query + "&mode=prefetch_old";
472 render_article(cached_article);
478 last_requested_article = id;
480 new Ajax.Request(query, {
481 onComplete: function(transport) {
482 article_callback2(transport, id, feed_id);
488 exception_error("view", e);
493 return toggleMark(id);
497 return togglePub(id);
500 function tMark_afh_off(effect) {
502 var elem = effect.effects[0].element;
504 debug("tMark_afh_off : " + elem.id);
507 elem.src = elem.src.replace("mark_set", "mark_unset");
508 elem.alt = __("Star article");
513 exception_error("tMark_afh_off", e);
517 function tPub_afh_off(effect) {
519 var elem = effect.effects[0].element;
521 debug("tPub_afh_off : " + elem.id);
524 elem.src = elem.src.replace("pub_set", "pub_unset");
525 elem.alt = __("Publish article");
530 exception_error("tPub_afh_off", e);
534 function toggleMark(id, client_only, no_effects) {
538 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
540 query = query + "&afid=" + getActiveFeedId();
542 if (tagsAreDisplayed()) {
543 query = query + "&omode=tl";
545 query = query + "&omode=flc";
548 var mark_img = document.getElementById("FMPIC-" + id);
549 var vfeedu = document.getElementById("FEEDU--1");
550 var crow = document.getElementById("RROW-" + id);
552 if (mark_img.src.match("mark_unset")) {
553 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
554 mark_img.alt = __("Unstar article");
555 query = query + "&mark=1";
558 //mark_img.src = "images/mark_unset.png";
559 mark_img.alt = __("Please wait...");
560 query = query + "&mark=0";
562 if (document.getElementById("headlinesList") && !no_effects) {
563 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
565 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
566 mark_img.alt = __("Star article");
573 new Ajax.Request(query, {
574 onComplete: function(transport) {
575 all_counters_callback2(transport);
581 exception_error("toggleMark", e);
585 function togglePub(id, client_only, no_effects) {
589 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
591 query = query + "&afid=" + getActiveFeedId();
593 if (tagsAreDisplayed()) {
594 query = query + "&omode=tl";
596 query = query + "&omode=flc";
599 var mark_img = document.getElementById("FPPIC-" + id);
600 var vfeedu = document.getElementById("FEEDU--2");
601 var crow = document.getElementById("RROW-" + id);
603 if (mark_img.src.match("pub_unset")) {
604 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
605 mark_img.alt = __("Unpublish article");
606 query = query + "&pub=1";
610 //mark_img.src = "images/pub_unset.png";
611 mark_img.alt = __("Please wait...");
612 query = query + "&pub=0";
614 if (document.getElementById("headlinesList") && !no_effects) {
615 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
617 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
618 mark_img.alt = __("Publish article");
623 new Ajax.Request(query, {
624 onComplete: function(transport) {
625 all_counters_callback2(transport);
631 exception_error("togglePub", e);
635 function correctHeadlinesOffset(id) {
639 var hlist = document.getElementById("headlinesList");
640 var container = document.getElementById("headlinesInnerContainer");
641 var row = document.getElementById("RROW-" + id);
643 var viewport = container.offsetHeight;
645 var rel_offset_top = row.offsetTop - container.scrollTop;
646 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
648 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
649 debug("Vport: " + viewport);
651 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
652 container.scrollTop = row.offsetTop;
653 } else if (rel_offset_bottom > viewport) {
655 /* doesn't properly work with Opera in some cases because
656 Opera fucks up element scrolling */
658 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
662 exception_error("correctHeadlinesOffset", e);
667 function moveToPost(mode) {
674 rows = cdmGetVisibleArticles();
676 rows = getVisibleHeadlineIds();
682 if (!document.getElementById('RROW-' + active_post_id)) {
683 active_post_id = false;
686 if (active_post_id == false) {
687 next_id = getFirstVisibleHeadlineId();
688 prev_id = getLastVisibleHeadlineId();
690 for (var i = 0; i < rows.length; i++) {
691 if (rows[i] == active_post_id) {
698 if (mode == "next") {
702 if (!cdmArticleIsActuallyVisible(next_id)) {
703 cdmScrollToArticleId(next_id);
705 cdmSelectArticles("none");
706 toggleUnread(next_id, 0, true);
707 toggleSelected(next_id);
710 correctHeadlinesOffset(next_id);
711 view(next_id, getActiveFeedId());
716 if (mode == "prev") {
719 cdmScrollToArticleId(prev_id);
720 cdmSelectArticles("none");
721 toggleUnread(prev_id, 0, true);
722 toggleSelected(prev_id);
724 correctHeadlinesOffset(prev_id);
725 view(prev_id, getActiveFeedId());
731 exception_error("moveToPost", e);
735 function toggleSelected(id) {
738 var cb = document.getElementById("RCHK-" + id);
740 var row = document.getElementById("RROW-" + id);
742 var nc = row.className;
744 if (!nc.match("Selected")) {
745 nc = nc + "Selected";
750 // In CDM basically last selected article == active article
751 if (isCdmMode()) active_post_id = id;
753 nc = nc.replace("Selected", "");
763 exception_error("toggleSelected", e);
767 function toggleUnread_afh(effect) {
770 var elem = effect.element;
771 elem.style.backgroundColor = "";
774 exception_error("toggleUnread_afh", e);
778 function toggleUnread(id, cmode, effect) {
781 var row = document.getElementById("RROW-" + id);
783 var nc = row.className;
784 var is_selected = row.className.match("Selected");
785 nc = nc.replace("Unread", "");
786 nc = nc.replace("Selected", "");
788 // since we are removing selection from the object, uncheck
789 // corresponding checkbox
791 var cb = document.getElementById("RCHK-" + id);
796 // NOTE: I'm not sure that resetting selection here is a feature -fox
798 if (cmode == undefined || cmode == 2) {
799 if (row.className.match("Unread")) {
803 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
804 afterFinish: toggleUnread_afh,
805 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
809 row.className = nc + "Unread";
811 } else if (cmode == 0) {
815 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
816 afterFinish: toggleUnread_afh,
817 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
819 } else if (cmode == 1) {
820 row.className = nc + "Unread";
823 // Disable unmarking as selected for the time being (16.05.08) -fox
824 if (is_selected) row.className = row.className + "Selected";
826 if (cmode == undefined) cmode = 2;
828 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
829 param_escape(id) + "&cmode=" + param_escape(cmode);
831 // notify_progress("Loading, please wait...");
833 new Ajax.Request(query, {
834 onComplete: function(transport) {
835 all_counters_callback2(transport);
842 exception_error("toggleUnread", e);
846 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
851 rows = cdmGetSelectedArticles();
853 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
856 if (rows.length == 0 && !no_error) {
857 alert(__("No articles are selected."));
861 for (i = 0; i < rows.length; i++) {
862 var row = document.getElementById("RROW-" + rows[i]);
864 var nc = row.className;
865 nc = nc.replace("Unread", "");
866 nc = nc.replace("Selected", "");
868 if (set_state == undefined) {
869 if (row.className.match("Unread")) {
870 row.className = nc + "Selected";
872 row.className = nc + "UnreadSelected";
876 if (set_state == false) {
877 row.className = nc + "Selected";
880 if (set_state == true) {
881 row.className = nc + "UnreadSelected";
886 if (rows.length > 0) {
890 if (set_state == undefined) {
892 } else if (set_state == true) {
894 } else if (set_state == false) {
898 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
899 param_escape(rows.toString()) + "&cmode=" + cmode;
901 notify_progress("Loading, please wait...");
903 new Ajax.Request(query, {
904 onComplete: function(transport) {
905 catchup_callback2(transport, callback_func);
911 exception_error("selectionToggleUnread", e);
915 function selectionToggleMarked(cdm_mode) {
921 rows = cdmGetSelectedArticles();
923 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
926 if (rows.length == 0) {
927 alert(__("No articles are selected."));
931 for (i = 0; i < rows.length; i++) {
932 toggleMark(rows[i], true, true);
935 if (rows.length > 0) {
937 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
938 param_escape(rows.toString()) + "&cmode=2";
940 query = query + "&afid=" + getActiveFeedId();
942 /* if (tagsAreDisplayed()) {
943 query = query + "&omode=tl";
945 query = query + "&omode=flc";
948 query = query + "&omode=lc";
950 new Ajax.Request(query, {
951 onComplete: function(transport) {
952 all_counters_callback2(transport);
958 exception_error("selectionToggleMarked", e);
962 function selectionTogglePublished(cdm_mode) {
968 rows = cdmGetSelectedArticles();
970 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
973 if (rows.length == 0) {
974 alert(__("No articles are selected."));
978 for (i = 0; i < rows.length; i++) {
979 togglePub(rows[i], true, true);
982 if (rows.length > 0) {
984 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
985 param_escape(rows.toString()) + "&cmode=2";
987 query = query + "&afid=" + getActiveFeedId();
989 /* if (tagsAreDisplayed()) {
990 query = query + "&omode=tl";
992 query = query + "&omode=flc";
995 query = query + "&omode=lc";
997 new Ajax.Request(query, {
998 onComplete: function(transport) {
999 all_counters_callback2(transport);
1005 exception_error("selectionToggleMarked", e);
1009 function cdmGetSelectedArticles() {
1010 var sel_articles = new Array();
1011 var container = document.getElementById("headlinesInnerContainer");
1013 for (i = 0; i < container.childNodes.length; i++) {
1014 var child = container.childNodes[i];
1016 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1017 var c_id = child.id.replace("RROW-", "");
1018 sel_articles.push(c_id);
1022 return sel_articles;
1025 function cdmGetVisibleArticles() {
1026 var sel_articles = new Array();
1027 var container = document.getElementById("headlinesInnerContainer");
1029 if (!container) return sel_articles;
1031 for (i = 0; i < container.childNodes.length; i++) {
1032 var child = container.childNodes[i];
1034 if (child.id && child.id.match("RROW-")) {
1035 var c_id = child.id.replace("RROW-", "");
1036 sel_articles.push(c_id);
1040 return sel_articles;
1043 function cdmGetUnreadArticles() {
1044 var sel_articles = new Array();
1045 var container = document.getElementById("headlinesInnerContainer");
1047 for (i = 0; i < container.childNodes.length; i++) {
1048 var child = container.childNodes[i];
1050 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1051 var c_id = child.id.replace("RROW-", "");
1052 sel_articles.push(c_id);
1056 return sel_articles;
1060 // mode = all,none,unread
1061 function cdmSelectArticles(mode) {
1062 var container = document.getElementById("headlinesInnerContainer");
1064 for (i = 0; i < container.childNodes.length; i++) {
1065 var child = container.childNodes[i];
1067 if (child.id && child.id.match("RROW-")) {
1068 var aid = child.id.replace("RROW-", "");
1070 var cb = document.getElementById("RCHK-" + aid);
1072 if (mode == "all") {
1073 if (!child.className.match("Selected")) {
1074 child.className = child.className + "Selected";
1077 } else if (mode == "unread") {
1078 if (child.className.match("Unread") && !child.className.match("Selected")) {
1079 child.className = child.className + "Selected";
1083 child.className = child.className.replace("Selected", "");
1090 function catchupPage() {
1092 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
1094 var str = __("Mark all visible articles in %s as read?");
1096 str = str.replace("%s", fn);
1098 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1102 if (document.getElementById("headlinesList")) {
1103 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1104 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1105 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1107 cdmSelectArticles('all');
1108 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1109 cdmSelectArticles('none');
1113 function catchupSelection() {
1119 if (document.getElementById("headlinesList")) {
1120 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1122 rows = cdmGetSelectedArticles();
1125 if (rows.length == 0) {
1126 alert(__("No articles are selected."));
1131 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
1133 var str = __("Mark %d selected articles in %s as read?");
1135 str = str.replace("%d", rows.length);
1136 str = str.replace("%s", fn);
1138 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1142 if (document.getElementById("headlinesList")) {
1143 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1144 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1146 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1147 // cdmSelectArticles('none');
1151 exception_error("catchupSelection", e);
1156 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
1158 if (!xmlhttp_ready(xmlhttp_rpc)) {
1159 printLockingError();
1162 var title = prompt(__("Please enter label title:"), "");
1166 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
1167 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
1168 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
1169 "&title=" + param_escape(title);
1171 debug("LFS: " + query);
1173 new Ajax.Request(query, {
1174 onComplete: function(transport) {
1175 dlg_frefresh_callback(transport);
1180 function editArticleTags(id, feed_id, cdm_enabled) {
1181 _tag_active_post_id = id;
1182 _tag_active_feed_id = feed_id;
1183 _tag_active_cdm = cdm_enabled;
1185 cache_invalidate(id);
1188 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
1190 displayDlg('editArticleTags', id);
1194 function tag_saved_callback(transport) {
1196 debug("in tag_saved_callback");
1201 if (tagsAreDisplayed()) {
1202 _reload_feedlist_after_view = true;
1205 if (!_tag_active_cdm) {
1206 if (active_post_id == _tag_active_post_id) {
1207 debug("reloading current article");
1208 view(_tag_active_post_id, _tag_active_feed_id);
1211 debug("reloading current feed");
1216 exception_error("catchup_callback", e);
1220 function editTagsSave() {
1222 notify_progress("Saving article tags...");
1224 var form = document.forms["tag_edit_form"];
1226 var query = Form.serialize("tag_edit_form");
1228 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1232 new Ajax.Request(query, {
1233 onComplete: function(transport) {
1234 tag_saved_callback(transport);
1239 function editTagsInsert() {
1242 var form = document.forms["tag_edit_form"];
1244 var found_tags = form.found_tags;
1245 var tags_str = form.tags_str;
1247 var tag = found_tags[found_tags.selectedIndex].value;
1249 if (tags_str.value.length > 0 &&
1250 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1252 tags_str.value = tags_str.value + ", ";
1255 tags_str.value = tags_str.value + tag + ", ";
1257 found_tags.selectedIndex = 0;
1260 exception_error("editTagsInsert", e);
1264 function cdmScrollViewport(where) {
1265 debug("cdmScrollViewport: " + where);
1267 var ctr = document.getElementById("headlinesInnerContainer");
1271 if (where == "bottom") {
1272 ctr.scrollTop = ctr.scrollHeight;
1274 ctr.scrollTop = where;
1278 function cdmArticleIsBelowViewport(id) {
1280 var ctr = document.getElementById("headlinesInnerContainer");
1281 var e = document.getElementById("RROW-" + id);
1283 if (!e || !ctr) return;
1285 // article starts below viewport
1287 if (ctr.scrollTop < e.offsetTop) {
1294 exception_error("cdmArticleIsVisible", e);
1298 function cdmArticleIsAboveViewport(id) {
1300 var ctr = document.getElementById("headlinesInnerContainer");
1301 var e = document.getElementById("RROW-" + id);
1303 if (!e || !ctr) return;
1305 // article starts above viewport
1307 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1314 exception_error("cdmArticleIsVisible", e);
1318 function cdmScrollToArticleId(id) {
1320 var ctr = document.getElementById("headlinesInnerContainer");
1321 var e = document.getElementById("RROW-" + id);
1323 if (!e || !ctr) return;
1325 ctr.scrollTop = e.offsetTop;
1328 exception_error("cdmScrollToArticleId", e);
1332 function cdmArticleIsActuallyVisible(id) {
1334 var ctr = document.getElementById("headlinesInnerContainer");
1335 var e = document.getElementById("RROW-" + id);
1337 if (!e || !ctr) return;
1339 // article fits in viewport OR article is longer than viewport and
1340 // its bottom is visible
1342 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1343 ctr.scrollTop + ctr.offsetHeight) {
1347 } else if (e.offsetHeight > ctr.offsetHeight &&
1348 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1349 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1358 exception_error("cdmArticleIsVisible", e);
1362 function cdmWatchdog() {
1366 var ctr = document.getElementById("headlinesInnerContainer");
1370 var ids = new Array();
1372 var e = ctr.firstChild;
1375 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1376 e.id.match("RROW-")) {
1378 // article fits in viewport OR article is longer than viewport and
1379 // its bottom is visible
1381 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1382 ctr.scrollTop + ctr.offsetHeight) {
1384 // debug(e.id + " is visible " + e.offsetTop + "." +
1385 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1386 // (ctr.scrollTop + ctr.offsetHeight));
1388 ids.push(e.id.replace("RROW-", ""));
1390 } else if (e.offsetHeight > ctr.offsetHeight &&
1391 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1392 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1394 ids.push(e.id.replace("RROW-", ""));
1398 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1400 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1401 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1403 ids.push(e.id.replace("RROW-", ""));
1412 debug("cdmWatchdog, ids= " + ids.toString());
1414 if (ids.length > 0) {
1416 for (var i = 0; i < ids.length; i++) {
1417 var e = document.getElementById("RROW-" + ids[i]);
1419 e.className = e.className.replace("Unread", "");
1423 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1424 param_escape(ids.toString()) + "&cmode=0";
1426 new Ajax.Request(query, {
1427 onComplete: function(transport) {
1428 all_counters_callback2(transport);
1433 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1436 exception_error("cdmWatchdog", e);
1442 function cache_inject(id, article, param) {
1443 if (!cache_check_param(id, param)) {
1444 debug("cache_article: miss: " + id + " [p=" + param + "]");
1446 var cache_obj = new Array();
1448 cache_obj["id"] = id;
1449 cache_obj["data"] = article;
1450 cache_obj["param"] = param;
1452 article_cache.push(cache_obj);
1455 debug("cache_article: hit: " + id + " [p=" + param + "]");
1459 function cache_find(id) {
1460 for (var i = 0; i < article_cache.length; i++) {
1461 if (article_cache[i]["id"] == id) {
1462 return article_cache[i]["data"];
1468 function cache_find_param(id, param) {
1469 for (var i = 0; i < article_cache.length; i++) {
1470 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1471 return article_cache[i]["data"];
1477 function cache_check(id) {
1478 for (var i = 0; i < article_cache.length; i++) {
1479 if (article_cache[i]["id"] == id) {
1486 function cache_check_param(id, param) {
1487 for (var i = 0; i < article_cache.length; i++) {
1489 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1490 // article_cache[i]["param"] + " vs " + id + ":" + param);
1492 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1499 function cache_expire() {
1500 while (article_cache.length > 25) {
1501 article_cache.shift();
1505 function cache_empty() {
1506 article_cache = new Array();
1509 function cache_invalidate(id) {
1514 while (i < article_cache.length) {
1515 if (article_cache[i]["id"] == id) {
1516 debug("cache_invalidate: removed id " + id);
1517 article_cache.splice(i, 1);
1522 debug("cache_invalidate: id not found: " + id);
1525 exception_error("cache_invalidate", e);
1529 function getActiveArticleId() {
1530 return active_post_id;
1533 function cdmClicked(id) {
1535 var elem = document.getElementById("RROW-" + id);
1538 var id = elem.id.replace("RROW-", "");
1539 active_post_id = id;
1541 cdmSelectArticles("none");
1542 toggleUnread(id, 0, true);
1547 exception_error("cdmClicked", e);
1551 function preload_article_callback(transport) {
1553 if (transport.responseXML) {
1554 var articles = transport.responseXML.getElementsByTagName("article");
1556 for (var i = 0; i < articles.length; i++) {
1557 var id = articles[i].getAttribute("id");
1558 if (!cache_check(id)) {
1559 cache_inject(id, articles[i].firstChild.nodeValue);
1560 debug("preloaded article: " + id);
1565 exception_error("preload_article_callback", e);
1569 function preloadArticleUnderPointer(id) {
1571 if (getInitParam("bw_limit") == "1") return;
1573 if (post_under_pointer == id && !cache_check(id)) {
1575 debug("trying to preload article " + id);
1577 var neighbor_ids = getRelativePostIds(id, 1);
1579 /* only request uncached articles */
1581 var cids_to_request = Array();
1583 for (var i = 0; i < neighbor_ids.length; i++) {
1584 if (!cache_check(neighbor_ids[i])) {
1585 cids_to_request.push(neighbor_ids[i]);
1588 debug("additional ids: " + cids_to_request.toString());
1590 cids_to_request.push(id);
1592 var query = "backend.php?op=rpc&subop=getArticles&ids=" +
1593 cids_to_request.toString();
1594 new Ajax.Request(query, {
1595 onComplete: function(transport) {
1596 preload_article_callback(transport);
1600 exception_error("preloadArticleUnderPointer", e);
1604 function postMouseIn(id) {
1606 if (post_under_pointer != id) {
1607 post_under_pointer = id;
1609 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1614 exception_error("postMouseIn", e);
1618 function postMouseOut(id) {
1620 post_under_pointer = false;
1622 exception_error("postMouseOut", e);
1626 function headlines_scroll_handler() {
1629 var e = document.getElementById("headlinesInnerContainer");
1631 // don't do infinite scrolling when Limit == All
1633 var toolbar_form = document.forms["main_toolbar_form"];
1635 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1636 if (limit.value != 0) {
1638 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1639 _infscroll_disable);
1641 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1642 if (!_infscroll_disable) {
1643 debug("more cowbell!");
1650 exception_error("headlines_scroll_handler", e);
1654 function catchupRelativeToArticle(below) {
1658 if (!xmlhttp_ready(xmlhttp_rpc)) {
1659 printLockingError();
1662 if (!getActiveArticleId()) {
1663 alert(__("No article is selected."));
1669 if (document.getElementById("headlinesList")) {
1670 visible_ids = getVisibleHeadlineIds();
1672 visible_ids = cdmGetVisibleArticles();
1675 var ids_to_mark = new Array();
1678 for (var i = 0; i < visible_ids.length; i++) {
1679 if (visible_ids[i] != getActiveArticleId()) {
1680 var e = document.getElementById("RROW-" + visible_ids[i]);
1682 if (e && e.className.match("Unread")) {
1683 ids_to_mark.push(visible_ids[i]);
1690 for (var i = visible_ids.length-1; i >= 0; i--) {
1691 if (visible_ids[i] != getActiveArticleId()) {
1692 var e = document.getElementById("RROW-" + visible_ids[i]);
1694 if (e && e.className.match("Unread")) {
1695 ids_to_mark.push(visible_ids[i]);
1703 if (ids_to_mark.length == 0) {
1704 alert(__("No articles found to mark"));
1706 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1710 for (var i = 0; i < ids_to_mark.length; i++) {
1711 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1712 e.className = e.className.replace("Unread", "");
1715 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1716 param_escape(ids_to_mark.toString()) + "&cmode=0";
1718 new Ajax.Request(query, {
1719 onComplete: function(transport) {
1720 catchup_callback2(transport);
1727 exception_error("catchupRelativeToArticle", e);
1731 function cdmExpandArticle(a_id) {
1733 var id = 'CICD-' + a_id;
1736 Element.hide("CEXC-" + a_id);
1739 Effect.Appear(id, {duration : 0.5,
1740 beforeStart: function(effect) {
1741 var h_id = 'CICH-' + a_id;
1742 var h_elem = document.getElementById(h_id);
1743 if (h_elem) { h_elem.style.display = "none"; }
1745 toggleUnread(a_id, 0);
1750 exception_error("appearBlockElementF", e);
1755 function fixHeadlinesOrder(ids) {
1757 for (var i = 0; i < ids.length; i++) {
1758 var e = document.getElementById("RROW-" + ids[i]);
1762 e.className = e.className.replace("even", "odd");
1764 e.className = e.className.replace("odd", "even");
1769 exception_error("fixHeadlinesOrder", e);
1773 function subtoolbarSearch() {
1776 var q = document.getElementById("subtoolbar_search_box");
1780 q = q.value.toUpperCase();
1783 var vis_ids = new Array();
1785 if (document.getElementById("headlinesList")) {
1786 ids = getVisibleHeadlineIds();
1788 ids = cdmGetVisibleArticles();
1791 for (var i = 0; i < ids.length; i++) {
1792 var title = document.getElementById("RTITLE-" + ids[i]);
1795 if (!title.innerHTML.toUpperCase().match(q)) {
1796 Element.hide(document.getElementById("RROW-" + ids[i]));
1798 Element.show(document.getElementById("RROW-" + ids[i]));
1799 vis_ids.push(ids[i]);
1804 fixHeadlinesOrder(vis_ids);
1807 exception_error("subtoolbarSearch", e);
1811 function hideReadHeadlines() {
1815 var vis_ids = new Array();
1817 if (document.getElementById("headlinesList")) {
1818 ids = getVisibleHeadlineIds();
1820 ids = cdmGetVisibleArticles();
1823 var read_headlines_visible = true;
1825 for (var i = 0; i < ids.length; i++) {
1826 var row = document.getElementById("RROW-" + ids[i]);
1828 if (row && row.className) {
1829 if (read_headlines_visible) {
1830 if (row.className.match("Unread") || row.className.match("Selected")) {
1832 vis_ids.push(ids[i]);
1834 //Effect.Fade(row, {duration : 0.3});
1839 vis_ids.push(ids[i]);
1844 fixHeadlinesOrder(vis_ids);
1846 read_headlines_visible = !read_headlines_visible;
1849 exception_error("hideReadHeadlines", e);
1853 function invertHeadlineSelection() {
1855 var rows = new Array();
1859 r = document.getElementsByTagName("TR");
1861 r = document.getElementsByTagName("DIV");
1864 for (var i = 0; i < r.length; i++) {
1865 if (r[i].id && r[i].id.match("RROW-")) {
1870 for (var i = 0; i < rows.length; i++) {
1871 var nc = rows[i].className;
1872 var id = rows[i].id.replace("RROW-", "");
1873 var cb = document.getElementById("RCHK-" + id);
1875 if (!rows[i].className.match("Selected")) {
1876 nc = nc + "Selected";
1879 nc = nc.replace("Selected", "");
1883 rows[i].className = nc;
1888 exception_error("invertHeadlineSelection", e);
1892 function getArticleUnderPointer() {
1893 return post_under_pointer;
1896 function zoomToArticle(id) {
1898 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
1900 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1903 exception_error("zoomToArticle", e);
1907 function scrollArticle(offset) {
1910 var ci = document.getElementById("content-insert");
1912 ci.scrollTop += offset;
1915 var hi = document.getElementById("headlinesInnerContainer");
1917 hi.scrollTop += offset;
1922 exception_error("scrollArticle", e);