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 getActiveFeedId() != -3 &&
224 getInitParam("cdm_auto_catchup") == 1) {
225 debug("starting CDM watchdog");
226 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
227 _cdm_wd_vishist = new Array();
229 debug("not in CDM mode or watchdog disabled");
232 if (_tag_cdm_scroll) {
234 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
235 _tag_cdm_scroll = false;
236 debug("resetting headlinesInner scrollTop");
241 _feed_cur_page = feed_cur_page;
242 _infscroll_request_sent = 0;
249 exception_error("headlines_callback2", e);
253 function render_article(article) {
255 var f = document.getElementById("content-frame");
260 var fi = document.getElementById("content-insert");
266 fi.innerHTML = article;
269 exception_error("render_article", e);
273 function showArticleInHeadlines(id) {
277 cleanSelected("headlinesList");
279 var crow = document.getElementById("RROW-" + id);
283 var article_is_unread = crow.className.match("Unread");
285 crow.className = crow.className.replace("Unread", "");
287 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
289 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
291 var cache_prefix = "";
293 if (activeFeedIsCat()) {
299 var view_mode = false;
302 view_mode = document.forms['main_toolbar_form'].view_mode;
303 view_mode = view_mode[view_mode.selectedIndex].value;
305 exception_error("showArticleInHeadlines/viewmode", e, true);
308 if (upd_img_pic && upd_img_pic.src.match("updated.png")) {
309 upd_img_pic.src = "images/blank_icon.gif";
311 cache_invalidate(cache_prefix + getActiveFeedId());
313 cache_inject(cache_prefix + getActiveFeedId(),
314 document.getElementById("headlines-frame").innerHTML,
315 get_feed_unread(getActiveFeedId()));
317 } else if (article_is_unread && view_mode == "all_articles") {
319 cache_invalidate(cache_prefix + getActiveFeedId());
321 cache_inject(cache_prefix + getActiveFeedId(),
322 document.getElementById("headlines-frame").innerHTML,
323 get_feed_unread(getActiveFeedId())-1);
325 } else if (article_is_unread) {
326 cache_invalidate(cache_prefix + getActiveFeedId());
332 exception_error("showArticleInHeadlines", e);
336 function article_callback2(transport, id, feed_id) {
338 debug("article_callback2 " + id);
340 if (transport.responseXML) {
342 debug("looking for articles to cache...");
344 var articles = transport.responseXML.getElementsByTagName("article");
346 for (var i = 0; i < articles.length; i++) {
347 var a_id = articles[i].getAttribute("id");
349 debug("found id: " + a_id);
351 if (a_id == active_post_id) {
352 debug("active article, rendering...");
353 render_article(articles[i].firstChild.nodeValue);
356 cache_inject(a_id, articles[i].firstChild.nodeValue);
359 if (id != last_requested_article) {
360 debug("requested article id is out of sequence, aborting");
364 active_real_feed_id = feed_id;
367 showArticleInHeadlines(id);
369 var reply = transport.responseXML.firstChild.firstChild;
372 debug("article_callback: returned no XML object");
373 //var f = document.getElementById("content-frame");
374 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
377 var date = new Date();
378 last_article_view = date.getTime() / 1000;
380 if (typeof correctPNG != 'undefined') {
384 if (_reload_feedlist_after_view) {
385 setTimeout('updateFeedList(false, false)', 50);
386 _reload_feedlist_after_view = false;
388 var counters = transport.responseXML.getElementsByTagName("counters")[0];
391 debug("parsing piggybacked counters: " + counters);
392 parse_counters(counters, false);
394 debug("counters container not found in reply, requesting...");
401 exception_error("article_callback2", e);
405 function view(id, feed_id, skip_history) {
408 debug("loading article: " + id + "/" + feed_id);
410 var cached_article = cache_find(id);
412 debug("cache check result: " + (cached_article != false));
416 //setActiveFeedId(feed_id);
418 var query = "backend.php?op=view&id=" + param_escape(id) +
419 "&feed=" + param_escape(feed_id);
421 var date = new Date();
423 var neighbor_ids = getRelativePostIds(active_post_id);
425 /* only request uncached articles */
427 var cids_to_request = Array();
429 for (var i = 0; i < neighbor_ids.length; i++) {
430 if (!cache_check(neighbor_ids[i])) {
431 cids_to_request.push(neighbor_ids[i]);
435 debug("additional ids: " + cids_to_request.toString());
437 /* additional info for piggyback counters */
439 if (tagsAreDisplayed()) {
440 query = query + "&omode=lt";
442 query = query + "&omode=flc";
445 var date = new Date();
446 var timestamp = Math.round(date.getTime() / 1000);
447 query = query + "&ts=" + timestamp;
449 query = query + "&cids=" + cids_to_request.toString();
451 var crow = document.getElementById("RROW-" + id);
452 var article_is_unread = crow.className.match("Unread");
454 if (!async_counters_work) {
455 query = query + "&csync=true";
458 showArticleInHeadlines(id);
460 if (!cached_article) {
462 notify_progress("Loading, please wait...", true);
464 } else if (cached_article && article_is_unread) {
466 query = query + "&mode=prefetch";
468 render_article(cached_article);
470 } else if (cached_article) {
472 query = query + "&mode=prefetch_old";
473 render_article(cached_article);
479 last_requested_article = id;
481 new Ajax.Request(query, {
482 onComplete: function(transport) {
483 article_callback2(transport, id, feed_id);
489 exception_error("view", e);
494 return toggleMark(id);
498 return togglePub(id);
501 function tMark_afh_off(effect) {
503 var elem = effect.effects[0].element;
505 debug("tMark_afh_off : " + elem.id);
508 elem.src = elem.src.replace("mark_set", "mark_unset");
509 elem.alt = __("Star article");
514 exception_error("tMark_afh_off", e);
518 function tPub_afh_off(effect) {
520 var elem = effect.effects[0].element;
522 debug("tPub_afh_off : " + elem.id);
525 elem.src = elem.src.replace("pub_set", "pub_unset");
526 elem.alt = __("Publish article");
531 exception_error("tPub_afh_off", e);
535 function toggleMark(id, client_only, no_effects) {
539 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
541 query = query + "&afid=" + getActiveFeedId();
543 if (tagsAreDisplayed()) {
544 query = query + "&omode=tl";
546 query = query + "&omode=flc";
549 var mark_img = document.getElementById("FMPIC-" + id);
550 var vfeedu = document.getElementById("FEEDU--1");
551 var crow = document.getElementById("RROW-" + id);
553 if (mark_img.src.match("mark_unset")) {
554 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
555 mark_img.alt = __("Unstar article");
556 query = query + "&mark=1";
559 //mark_img.src = "images/mark_unset.png";
560 mark_img.alt = __("Please wait...");
561 query = query + "&mark=0";
563 if (document.getElementById("headlinesList") && !no_effects) {
564 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
566 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
567 mark_img.alt = __("Star article");
574 new Ajax.Request(query, {
575 onComplete: function(transport) {
576 all_counters_callback2(transport);
582 exception_error("toggleMark", e);
586 function togglePub(id, client_only, no_effects) {
590 var query = "backend.php?op=rpc&id=" + id + "&subop=publ";
592 query = query + "&afid=" + getActiveFeedId();
594 if (tagsAreDisplayed()) {
595 query = query + "&omode=tl";
597 query = query + "&omode=flc";
600 var mark_img = document.getElementById("FPPIC-" + id);
601 var vfeedu = document.getElementById("FEEDU--2");
602 var crow = document.getElementById("RROW-" + id);
604 if (mark_img.src.match("pub_unset")) {
605 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
606 mark_img.alt = __("Unpublish article");
607 query = query + "&pub=1";
611 //mark_img.src = "images/pub_unset.png";
612 mark_img.alt = __("Please wait...");
613 query = query + "&pub=0";
615 if (document.getElementById("headlinesList") && !no_effects) {
616 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
618 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
619 mark_img.alt = __("Publish article");
624 new Ajax.Request(query, {
625 onComplete: function(transport) {
626 all_counters_callback2(transport);
632 exception_error("togglePub", e);
636 function correctHeadlinesOffset(id) {
640 var hlist = document.getElementById("headlinesList");
641 var container = document.getElementById("headlinesInnerContainer");
642 var row = document.getElementById("RROW-" + id);
644 var viewport = container.offsetHeight;
646 var rel_offset_top = row.offsetTop - container.scrollTop;
647 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
649 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
650 debug("Vport: " + viewport);
652 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
653 container.scrollTop = row.offsetTop;
654 } else if (rel_offset_bottom > viewport) {
656 /* doesn't properly work with Opera in some cases because
657 Opera fucks up element scrolling */
659 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
663 exception_error("correctHeadlinesOffset", e);
668 function moveToPost(mode) {
675 rows = cdmGetVisibleArticles();
677 rows = getVisibleHeadlineIds();
683 if (!document.getElementById('RROW-' + active_post_id)) {
684 active_post_id = false;
687 if (active_post_id == false) {
688 next_id = getFirstVisibleHeadlineId();
689 prev_id = getLastVisibleHeadlineId();
691 for (var i = 0; i < rows.length; i++) {
692 if (rows[i] == active_post_id) {
699 if (mode == "next") {
703 if (!cdmArticleIsActuallyVisible(next_id)) {
704 cdmScrollToArticleId(next_id);
706 cdmSelectArticles("none");
707 toggleUnread(next_id, 0, true);
708 toggleSelected(next_id);
711 correctHeadlinesOffset(next_id);
712 view(next_id, getActiveFeedId());
717 if (mode == "prev") {
720 cdmScrollToArticleId(prev_id);
721 cdmSelectArticles("none");
722 toggleUnread(prev_id, 0, true);
723 toggleSelected(prev_id);
725 correctHeadlinesOffset(prev_id);
726 view(prev_id, getActiveFeedId());
732 exception_error("moveToPost", e);
736 function toggleSelected(id) {
739 var cb = document.getElementById("RCHK-" + id);
741 var row = document.getElementById("RROW-" + id);
743 var nc = row.className;
745 if (!nc.match("Selected")) {
746 nc = nc + "Selected";
751 // In CDM basically last selected article == active article
752 if (isCdmMode()) active_post_id = id;
754 nc = nc.replace("Selected", "");
764 exception_error("toggleSelected", e);
768 function toggleUnread_afh(effect) {
771 var elem = effect.element;
772 elem.style.backgroundColor = "";
775 exception_error("toggleUnread_afh", e);
779 function toggleUnread(id, cmode, effect) {
782 var row = document.getElementById("RROW-" + id);
784 var nc = row.className;
785 var is_selected = row.className.match("Selected");
786 nc = nc.replace("Unread", "");
787 nc = nc.replace("Selected", "");
789 // since we are removing selection from the object, uncheck
790 // corresponding checkbox
792 var cb = document.getElementById("RCHK-" + id);
797 // NOTE: I'm not sure that resetting selection here is a feature -fox
799 if (cmode == undefined || cmode == 2) {
800 if (row.className.match("Unread")) {
804 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
805 afterFinish: toggleUnread_afh,
806 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
810 row.className = nc + "Unread";
812 } else if (cmode == 0) {
816 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
817 afterFinish: toggleUnread_afh,
818 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
820 } else if (cmode == 1) {
821 row.className = nc + "Unread";
824 // Disable unmarking as selected for the time being (16.05.08) -fox
825 if (is_selected) row.className = row.className + "Selected";
827 if (cmode == undefined) cmode = 2;
829 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
830 param_escape(id) + "&cmode=" + param_escape(cmode);
832 // notify_progress("Loading, please wait...");
834 new Ajax.Request(query, {
835 onComplete: function(transport) {
836 all_counters_callback2(transport);
843 exception_error("toggleUnread", e);
847 function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
852 rows = cdmGetSelectedArticles();
854 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
857 if (rows.length == 0 && !no_error) {
858 alert(__("No articles are selected."));
862 for (i = 0; i < rows.length; i++) {
863 var row = document.getElementById("RROW-" + rows[i]);
865 var nc = row.className;
866 nc = nc.replace("Unread", "");
867 nc = nc.replace("Selected", "");
869 if (set_state == undefined) {
870 if (row.className.match("Unread")) {
871 row.className = nc + "Selected";
873 row.className = nc + "UnreadSelected";
877 if (set_state == false) {
878 row.className = nc + "Selected";
881 if (set_state == true) {
882 row.className = nc + "UnreadSelected";
887 if (rows.length > 0) {
891 if (set_state == undefined) {
893 } else if (set_state == true) {
895 } else if (set_state == false) {
899 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
900 param_escape(rows.toString()) + "&cmode=" + cmode;
902 notify_progress("Loading, please wait...");
904 new Ajax.Request(query, {
905 onComplete: function(transport) {
906 catchup_callback2(transport, callback_func);
912 exception_error("selectionToggleUnread", e);
916 function selectionToggleMarked(cdm_mode) {
922 rows = cdmGetSelectedArticles();
924 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
927 if (rows.length == 0) {
928 alert(__("No articles are selected."));
932 for (i = 0; i < rows.length; i++) {
933 toggleMark(rows[i], true, true);
936 if (rows.length > 0) {
938 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
939 param_escape(rows.toString()) + "&cmode=2";
941 query = query + "&afid=" + getActiveFeedId();
943 /* if (tagsAreDisplayed()) {
944 query = query + "&omode=tl";
946 query = query + "&omode=flc";
949 query = query + "&omode=lc";
951 new Ajax.Request(query, {
952 onComplete: function(transport) {
953 all_counters_callback2(transport);
959 exception_error("selectionToggleMarked", e);
963 function selectionTogglePublished(cdm_mode) {
969 rows = cdmGetSelectedArticles();
971 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
974 if (rows.length == 0) {
975 alert(__("No articles are selected."));
979 for (i = 0; i < rows.length; i++) {
980 togglePub(rows[i], true, true);
983 if (rows.length > 0) {
985 var query = "backend.php?op=rpc&subop=publishSelected&ids=" +
986 param_escape(rows.toString()) + "&cmode=2";
988 query = query + "&afid=" + getActiveFeedId();
990 /* if (tagsAreDisplayed()) {
991 query = query + "&omode=tl";
993 query = query + "&omode=flc";
996 query = query + "&omode=lc";
998 new Ajax.Request(query, {
999 onComplete: function(transport) {
1000 all_counters_callback2(transport);
1006 exception_error("selectionToggleMarked", e);
1010 function cdmGetSelectedArticles() {
1011 var sel_articles = new Array();
1012 var container = document.getElementById("headlinesInnerContainer");
1014 for (i = 0; i < container.childNodes.length; i++) {
1015 var child = container.childNodes[i];
1017 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1018 var c_id = child.id.replace("RROW-", "");
1019 sel_articles.push(c_id);
1023 return sel_articles;
1026 function cdmGetVisibleArticles() {
1027 var sel_articles = new Array();
1028 var container = document.getElementById("headlinesInnerContainer");
1030 if (!container) return sel_articles;
1032 for (i = 0; i < container.childNodes.length; i++) {
1033 var child = container.childNodes[i];
1035 if (child.id && child.id.match("RROW-")) {
1036 var c_id = child.id.replace("RROW-", "");
1037 sel_articles.push(c_id);
1041 return sel_articles;
1044 function cdmGetUnreadArticles() {
1045 var sel_articles = new Array();
1046 var container = document.getElementById("headlinesInnerContainer");
1048 for (i = 0; i < container.childNodes.length; i++) {
1049 var child = container.childNodes[i];
1051 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1052 var c_id = child.id.replace("RROW-", "");
1053 sel_articles.push(c_id);
1057 return sel_articles;
1061 // mode = all,none,unread
1062 function cdmSelectArticles(mode) {
1063 var container = document.getElementById("headlinesInnerContainer");
1065 for (i = 0; i < container.childNodes.length; i++) {
1066 var child = container.childNodes[i];
1068 if (child.id && child.id.match("RROW-")) {
1069 var aid = child.id.replace("RROW-", "");
1071 var cb = document.getElementById("RCHK-" + aid);
1073 if (mode == "all") {
1074 if (!child.className.match("Selected")) {
1075 child.className = child.className + "Selected";
1078 } else if (mode == "unread") {
1079 if (child.className.match("Unread") && !child.className.match("Selected")) {
1080 child.className = child.className + "Selected";
1084 child.className = child.className.replace("Selected", "");
1091 function catchupPage() {
1093 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
1095 var str = __("Mark all visible articles in %s as read?");
1097 str = str.replace("%s", fn);
1099 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1103 if (document.getElementById("headlinesList")) {
1104 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1105 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1106 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1108 cdmSelectArticles('all');
1109 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1110 cdmSelectArticles('none');
1114 function catchupSelection() {
1120 if (document.getElementById("headlinesList")) {
1121 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1123 rows = cdmGetSelectedArticles();
1126 if (rows.length == 0) {
1127 alert(__("No articles are selected."));
1132 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
1134 var str = __("Mark %d selected articles in %s as read?");
1136 str = str.replace("%d", rows.length);
1137 str = str.replace("%s", fn);
1139 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1143 if (document.getElementById("headlinesList")) {
1144 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1145 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1147 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1148 // cdmSelectArticles('none');
1152 exception_error("catchupSelection", e);
1157 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
1159 if (!xmlhttp_ready(xmlhttp_rpc)) {
1160 printLockingError();
1163 var title = prompt(__("Please enter label title:"), "");
1167 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
1168 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
1169 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
1170 "&title=" + param_escape(title);
1172 debug("LFS: " + query);
1174 new Ajax.Request(query, {
1175 onComplete: function(transport) {
1176 dlg_frefresh_callback(transport);
1181 function editArticleTags(id, feed_id, cdm_enabled) {
1182 _tag_active_post_id = id;
1183 _tag_active_feed_id = feed_id;
1184 _tag_active_cdm = cdm_enabled;
1186 cache_invalidate(id);
1189 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
1191 displayDlg('editArticleTags', id);
1195 function tag_saved_callback(transport) {
1197 debug("in tag_saved_callback");
1202 if (tagsAreDisplayed()) {
1203 _reload_feedlist_after_view = true;
1206 if (!_tag_active_cdm) {
1207 if (active_post_id == _tag_active_post_id) {
1208 debug("reloading current article");
1209 view(_tag_active_post_id, _tag_active_feed_id);
1212 debug("reloading current feed");
1217 exception_error("catchup_callback", e);
1221 function editTagsSave() {
1223 notify_progress("Saving article tags...");
1225 var form = document.forms["tag_edit_form"];
1227 var query = Form.serialize("tag_edit_form");
1229 query = "backend.php?op=rpc&subop=setArticleTags&" + query;
1233 new Ajax.Request(query, {
1234 onComplete: function(transport) {
1235 tag_saved_callback(transport);
1240 function editTagsInsert() {
1243 var form = document.forms["tag_edit_form"];
1245 var found_tags = form.found_tags;
1246 var tags_str = form.tags_str;
1248 var tag = found_tags[found_tags.selectedIndex].value;
1250 if (tags_str.value.length > 0 &&
1251 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1253 tags_str.value = tags_str.value + ", ";
1256 tags_str.value = tags_str.value + tag + ", ";
1258 found_tags.selectedIndex = 0;
1261 exception_error("editTagsInsert", e);
1265 function cdmScrollViewport(where) {
1266 debug("cdmScrollViewport: " + where);
1268 var ctr = document.getElementById("headlinesInnerContainer");
1272 if (where == "bottom") {
1273 ctr.scrollTop = ctr.scrollHeight;
1275 ctr.scrollTop = where;
1279 function cdmArticleIsBelowViewport(id) {
1281 var ctr = document.getElementById("headlinesInnerContainer");
1282 var e = document.getElementById("RROW-" + id);
1284 if (!e || !ctr) return;
1286 // article starts below viewport
1288 if (ctr.scrollTop < e.offsetTop) {
1295 exception_error("cdmArticleIsVisible", e);
1299 function cdmArticleIsAboveViewport(id) {
1301 var ctr = document.getElementById("headlinesInnerContainer");
1302 var e = document.getElementById("RROW-" + id);
1304 if (!e || !ctr) return;
1306 // article starts above viewport
1308 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1315 exception_error("cdmArticleIsVisible", e);
1319 function cdmScrollToArticleId(id) {
1321 var ctr = document.getElementById("headlinesInnerContainer");
1322 var e = document.getElementById("RROW-" + id);
1324 if (!e || !ctr) return;
1326 ctr.scrollTop = e.offsetTop;
1329 exception_error("cdmScrollToArticleId", e);
1333 function cdmArticleIsActuallyVisible(id) {
1335 var ctr = document.getElementById("headlinesInnerContainer");
1336 var e = document.getElementById("RROW-" + id);
1338 if (!e || !ctr) return;
1340 // article fits in viewport OR article is longer than viewport and
1341 // its bottom is visible
1343 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1344 ctr.scrollTop + ctr.offsetHeight) {
1348 } else if (e.offsetHeight > ctr.offsetHeight &&
1349 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1350 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1359 exception_error("cdmArticleIsVisible", e);
1363 function cdmWatchdog() {
1367 var ctr = document.getElementById("headlinesInnerContainer");
1371 var ids = new Array();
1373 var e = ctr.firstChild;
1376 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1377 e.id.match("RROW-")) {
1379 // article fits in viewport OR article is longer than viewport and
1380 // its bottom is visible
1382 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1383 ctr.scrollTop + ctr.offsetHeight) {
1385 // debug(e.id + " is visible " + e.offsetTop + "." +
1386 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1387 // (ctr.scrollTop + ctr.offsetHeight));
1389 ids.push(e.id.replace("RROW-", ""));
1391 } else if (e.offsetHeight > ctr.offsetHeight &&
1392 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1393 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1395 ids.push(e.id.replace("RROW-", ""));
1399 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1401 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1402 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1404 ids.push(e.id.replace("RROW-", ""));
1413 debug("cdmWatchdog, ids= " + ids.toString());
1415 if (ids.length > 0) {
1417 for (var i = 0; i < ids.length; i++) {
1418 var e = document.getElementById("RROW-" + ids[i]);
1420 e.className = e.className.replace("Unread", "");
1424 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1425 param_escape(ids.toString()) + "&cmode=0";
1427 new Ajax.Request(query, {
1428 onComplete: function(transport) {
1429 all_counters_callback2(transport);
1434 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1437 exception_error("cdmWatchdog", e);
1443 function cache_inject(id, article, param) {
1444 if (!cache_check_param(id, param)) {
1445 debug("cache_article: miss: " + id + " [p=" + param + "]");
1447 var cache_obj = new Array();
1449 cache_obj["id"] = id;
1450 cache_obj["data"] = article;
1451 cache_obj["param"] = param;
1453 article_cache.push(cache_obj);
1456 debug("cache_article: hit: " + id + " [p=" + param + "]");
1460 function cache_find(id) {
1461 for (var i = 0; i < article_cache.length; i++) {
1462 if (article_cache[i]["id"] == id) {
1463 return article_cache[i]["data"];
1469 function cache_find_param(id, param) {
1470 for (var i = 0; i < article_cache.length; i++) {
1471 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1472 return article_cache[i]["data"];
1478 function cache_check(id) {
1479 for (var i = 0; i < article_cache.length; i++) {
1480 if (article_cache[i]["id"] == id) {
1487 function cache_check_param(id, param) {
1488 for (var i = 0; i < article_cache.length; i++) {
1490 // debug("cache_check_param " + article_cache[i]["id"] + ":" +
1491 // article_cache[i]["param"] + " vs " + id + ":" + param);
1493 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1500 function cache_expire() {
1501 while (article_cache.length > 25) {
1502 article_cache.shift();
1506 function cache_empty() {
1507 article_cache = new Array();
1510 function cache_invalidate(id) {
1515 while (i < article_cache.length) {
1516 if (article_cache[i]["id"] == id) {
1517 debug("cache_invalidate: removed id " + id);
1518 article_cache.splice(i, 1);
1523 debug("cache_invalidate: id not found: " + id);
1526 exception_error("cache_invalidate", e);
1530 function getActiveArticleId() {
1531 return active_post_id;
1534 function cdmClicked(id) {
1536 var elem = document.getElementById("RROW-" + id);
1539 var id = elem.id.replace("RROW-", "");
1540 active_post_id = id;
1542 cdmSelectArticles("none");
1543 toggleUnread(id, 0, true);
1548 exception_error("cdmClicked", e);
1552 function preload_article_callback(transport) {
1554 if (transport.responseXML) {
1555 var articles = transport.responseXML.getElementsByTagName("article");
1557 for (var i = 0; i < articles.length; i++) {
1558 var id = articles[i].getAttribute("id");
1559 if (!cache_check(id)) {
1560 cache_inject(id, articles[i].firstChild.nodeValue);
1561 debug("preloaded article: " + id);
1566 exception_error("preload_article_callback", e);
1570 function preloadArticleUnderPointer(id) {
1572 if (getInitParam("bw_limit") == "1") return;
1574 if (post_under_pointer == id && !cache_check(id)) {
1576 debug("trying to preload article " + id);
1578 var neighbor_ids = getRelativePostIds(id, 1);
1580 /* only request uncached articles */
1582 var cids_to_request = Array();
1584 for (var i = 0; i < neighbor_ids.length; i++) {
1585 if (!cache_check(neighbor_ids[i])) {
1586 cids_to_request.push(neighbor_ids[i]);
1589 debug("additional ids: " + cids_to_request.toString());
1591 cids_to_request.push(id);
1593 var query = "backend.php?op=rpc&subop=getArticles&ids=" +
1594 cids_to_request.toString();
1595 new Ajax.Request(query, {
1596 onComplete: function(transport) {
1597 preload_article_callback(transport);
1601 exception_error("preloadArticleUnderPointer", e);
1605 function postMouseIn(id) {
1607 if (post_under_pointer != id) {
1608 post_under_pointer = id;
1610 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1615 exception_error("postMouseIn", e);
1619 function postMouseOut(id) {
1621 post_under_pointer = false;
1623 exception_error("postMouseOut", e);
1627 function headlines_scroll_handler() {
1630 var e = document.getElementById("headlinesInnerContainer");
1632 // don't do infinite scrolling when Limit == All
1634 var toolbar_form = document.forms["main_toolbar_form"];
1636 var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex];
1637 if (limit.value != 0) {
1639 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1640 _infscroll_disable);
1642 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1643 if (!_infscroll_disable) {
1644 debug("more cowbell!");
1651 exception_error("headlines_scroll_handler", e);
1655 function catchupRelativeToArticle(below) {
1659 if (!xmlhttp_ready(xmlhttp_rpc)) {
1660 printLockingError();
1663 if (!getActiveArticleId()) {
1664 alert(__("No article is selected."));
1670 if (document.getElementById("headlinesList")) {
1671 visible_ids = getVisibleHeadlineIds();
1673 visible_ids = cdmGetVisibleArticles();
1676 var ids_to_mark = new Array();
1679 for (var i = 0; i < visible_ids.length; i++) {
1680 if (visible_ids[i] != getActiveArticleId()) {
1681 var e = document.getElementById("RROW-" + visible_ids[i]);
1683 if (e && e.className.match("Unread")) {
1684 ids_to_mark.push(visible_ids[i]);
1691 for (var i = visible_ids.length-1; i >= 0; i--) {
1692 if (visible_ids[i] != getActiveArticleId()) {
1693 var e = document.getElementById("RROW-" + visible_ids[i]);
1695 if (e && e.className.match("Unread")) {
1696 ids_to_mark.push(visible_ids[i]);
1704 if (ids_to_mark.length == 0) {
1705 alert(__("No articles found to mark"));
1707 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1711 for (var i = 0; i < ids_to_mark.length; i++) {
1712 var e = document.getElementById("RROW-" + ids_to_mark[i]);
1713 e.className = e.className.replace("Unread", "");
1716 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
1717 param_escape(ids_to_mark.toString()) + "&cmode=0";
1719 new Ajax.Request(query, {
1720 onComplete: function(transport) {
1721 catchup_callback2(transport);
1728 exception_error("catchupRelativeToArticle", e);
1732 function cdmExpandArticle(a_id) {
1734 var id = 'CICD-' + a_id;
1737 Element.hide("CEXC-" + a_id);
1740 Effect.Appear(id, {duration : 0.5,
1741 beforeStart: function(effect) {
1742 var h_id = 'CICH-' + a_id;
1743 var h_elem = document.getElementById(h_id);
1744 if (h_elem) { h_elem.style.display = "none"; }
1746 toggleUnread(a_id, 0);
1751 exception_error("appearBlockElementF", e);
1756 function fixHeadlinesOrder(ids) {
1758 for (var i = 0; i < ids.length; i++) {
1759 var e = document.getElementById("RROW-" + ids[i]);
1763 e.className = e.className.replace("even", "odd");
1765 e.className = e.className.replace("odd", "even");
1770 exception_error("fixHeadlinesOrder", e);
1774 function subtoolbarSearch() {
1777 var q = document.getElementById("subtoolbar_search_box");
1781 q = q.value.toUpperCase();
1784 var vis_ids = new Array();
1786 if (document.getElementById("headlinesList")) {
1787 ids = getVisibleHeadlineIds();
1789 ids = cdmGetVisibleArticles();
1792 for (var i = 0; i < ids.length; i++) {
1793 var title = document.getElementById("RTITLE-" + ids[i]);
1796 if (!title.innerHTML.toUpperCase().match(q)) {
1797 Element.hide(document.getElementById("RROW-" + ids[i]));
1799 Element.show(document.getElementById("RROW-" + ids[i]));
1800 vis_ids.push(ids[i]);
1805 fixHeadlinesOrder(vis_ids);
1808 exception_error("subtoolbarSearch", e);
1812 function hideReadHeadlines() {
1816 var vis_ids = new Array();
1818 if (document.getElementById("headlinesList")) {
1819 ids = getVisibleHeadlineIds();
1821 ids = cdmGetVisibleArticles();
1824 var read_headlines_visible = true;
1826 for (var i = 0; i < ids.length; i++) {
1827 var row = document.getElementById("RROW-" + ids[i]);
1829 if (row && row.className) {
1830 if (read_headlines_visible) {
1831 if (row.className.match("Unread") || row.className.match("Selected")) {
1833 vis_ids.push(ids[i]);
1835 //Effect.Fade(row, {duration : 0.3});
1840 vis_ids.push(ids[i]);
1845 fixHeadlinesOrder(vis_ids);
1847 read_headlines_visible = !read_headlines_visible;
1850 exception_error("hideReadHeadlines", e);
1854 function invertHeadlineSelection() {
1856 var rows = new Array();
1860 r = document.getElementsByTagName("TR");
1862 r = document.getElementsByTagName("DIV");
1865 for (var i = 0; i < r.length; i++) {
1866 if (r[i].id && r[i].id.match("RROW-")) {
1871 for (var i = 0; i < rows.length; i++) {
1872 var nc = rows[i].className;
1873 var id = rows[i].id.replace("RROW-", "");
1874 var cb = document.getElementById("RCHK-" + id);
1876 if (!rows[i].className.match("Selected")) {
1877 nc = nc + "Selected";
1880 nc = nc.replace("Selected", "");
1884 rows[i].className = nc;
1889 exception_error("invertHeadlineSelection", e);
1893 function getArticleUnderPointer() {
1894 return post_under_pointer;
1897 function zoomToArticle(id) {
1899 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
1901 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1904 exception_error("zoomToArticle", e);
1908 function showOriginalArticleInline(id) {
1911 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1913 notify_progress("Loading, please wait...", true);
1915 new Ajax.Request(query, {
1916 onComplete: function(transport) {
1918 if (transport.responseXML) {
1920 var link = transport.responseXML.getElementsByTagName("link")[0];
1921 var id = transport.responseXML.getElementsByTagName("id")[0];
1926 link = link.firstChild.nodeValue;
1928 var ci = document.getElementById("content-insert");
1930 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
1932 render_article(tmp);
1939 exception_error("showOriginalArticleInline", e);
1944 function scrollArticle(offset) {
1947 var ci = document.getElementById("content-insert");
1949 ci.scrollTop += offset;
1952 var hi = document.getElementById("headlinesInnerContainer");
1954 hi.scrollTop += offset;
1959 exception_error("scrollArticle", e);