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_callback2(transport, callback) {
20 console.log("catchup_callback2 " + transport + ", " + callback);
22 all_counters_callback2(transport);
24 setTimeout(callback, 10);
27 exception_error("catchup_callback2", e, transport);
31 function clean_feed_selections() {
33 var feeds = $("feedList").getElementsByTagName("LI");
35 for (var i = 0; i < feeds.length; i++) {
36 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
37 feeds[i].className = feeds[i].className.replace("Selected", "");
39 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
40 feeds[i].className = feeds[i].className.replace("Selected", "");
44 exception_error("clean_feed_selections", e);
48 function headlines_callback2(transport, feed_cur_page) {
51 if (!transport.responseText && db) {
52 offlineConfirmModeChange();
56 loading_set_progress(100);
58 console.log("headlines_callback2 [page=" + feed_cur_page + "]");
60 if (!transport_error_check(transport)) return;
62 clean_feed_selections();
67 if (transport.responseXML) {
68 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
70 is_cat = headlines.getAttribute("is_cat");
71 feed_id = headlines.getAttribute("id");
72 setActiveFeedId(feed_id, is_cat);
76 var ll = $('FLL-' + feed_id);
79 var feedr = $("FEEDR-" + feed_id);
80 if (feedr && !feedr.className.match("Selected")) {
81 feedr.className = feedr.className + "Selected";
83 if (feedr && ll) feedr.removeChild(ll);
85 var feedr = $("FCAT-" + feed_id);
86 if (feedr && !feedr.className.match("Selected")) {
87 feedr.className = feedr.className + "Selected";
90 var fcap = $("FCAP-" + feed_id);
91 if (fcap && ll) fcap.removeChild(ll);
95 var img = $('FIMG-' + feed_id);
101 var f = $("headlines-frame");
103 if (feed_cur_page == 0) {
104 console.log("resetting headlines scrollTop");
109 if (transport.responseXML) {
110 var response = transport.responseXML;
112 var headlines = response.getElementsByTagName("headlines")[0];
113 var headlines_info = response.getElementsByTagName("headlines-info")[0];
116 headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
118 console.log("didn't find headlines-info object in response");
120 var headlines_count = headlines_info.count;
121 var headlines_unread = headlines_info.unread;
122 var disable_cache = headlines_info.disable_cache;
124 vgroup_last_feed = headlines_info.vgroup_last_feed;
126 if (headlines_count == 0) {
127 _infscroll_disable = 1;
129 _infscroll_disable = 0;
132 var counters = response.getElementsByTagName("counters")[0];
133 var articles = response.getElementsByTagName("article");
134 var runtime_info = response.getElementsByTagName("runtime-info");
136 if (feed_cur_page == 0) {
138 f.innerHTML = headlines.firstChild.nodeValue;
140 var cache_prefix = "";
148 cache_invalidate(cache_prefix + feed_id);
150 if (!disable_cache) {
151 cache_inject(cache_prefix + feed_id,
152 headlines.firstChild.nodeValue, headlines_unread);
156 console.log("headlines_callback: returned no data");
157 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
162 if (headlines_count > 0) {
163 console.log("adding some more headlines...");
165 var c = $("headlinesList");
168 c = $("headlinesInnerContainer");
171 var ids = getSelectedArticleIds2();
173 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
175 console.log("restore selected ids: " + ids);
177 for (var i = 0; i < ids.length; i++) {
178 markHeadline(ids[i]);
182 console.log("no new headlines received");
185 console.log("headlines_callback: returned no data");
186 notify_error("Error while trying to load more headlines");
192 for (var i = 0; i < articles.length; i++) {
193 var a_id = articles[i].getAttribute("id");
194 console.log("found id: " + a_id);
195 cache_inject(a_id, articles[i].firstChild.nodeValue);
198 console.log("no cached articles received");
202 console.log("parsing piggybacked counters: " + counters);
203 parse_counters(counters, false);
205 console.log("counters container not found in reply, requesting...");
210 console.log("parsing runtime info: " + runtime_info[0]);
211 parse_runtime_info(runtime_info[0]);
213 console.log("counters container not found in reply");
217 console.log("headlines_callback: returned no XML object");
218 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
222 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
224 if (!$("headlinesList") &&
225 getActiveFeedId() != -3 &&
226 getInitParam("cdm_auto_catchup") == 1) {
227 console.log("starting CDM watchdog");
228 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
229 _cdm_wd_vishist = new Array();
231 console.log("not in CDM mode or watchdog disabled");
234 _feed_cur_page = feed_cur_page;
235 _infscroll_request_sent = 0;
242 exception_error("headlines_callback2", e, transport);
246 function render_article(article) {
248 var f = $("content-frame");
253 var fi = $("content-insert");
259 fi.innerHTML = article;
261 // article.evalScripts();
264 exception_error("render_article", e);
268 function showArticleInHeadlines(id) {
272 cleanSelected("headlinesList");
274 var crow = $("RROW-" + id);
278 var article_is_unread = crow.className.match("Unread");
280 crow.className = crow.className.replace("Unread", "");
282 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
284 var upd_img_pic = $("FUPDPIC-" + id);
286 var cache_prefix = "";
288 if (activeFeedIsCat()) {
294 var view_mode = false;
297 view_mode = document.forms['main_toolbar_form'].view_mode;
298 view_mode = view_mode[view_mode.selectedIndex].value;
303 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
304 upd_img_pic.src.match("fresh_sign.png"))) {
306 upd_img_pic.src = "images/blank_icon.gif";
308 cache_invalidate(cache_prefix + getActiveFeedId());
310 cache_inject(cache_prefix + getActiveFeedId(),
311 $("headlines-frame").innerHTML,
312 get_feed_unread(getActiveFeedId()));
314 } else if (article_is_unread && view_mode == "all_articles") {
316 cache_invalidate(cache_prefix + getActiveFeedId());
318 cache_inject(cache_prefix + getActiveFeedId(),
319 $("headlines-frame").innerHTML,
320 get_feed_unread(getActiveFeedId())-1);
322 } else if (article_is_unread) {
323 cache_invalidate(cache_prefix + getActiveFeedId());
329 exception_error("showArticleInHeadlines", e);
333 function article_callback2(transport, id) {
335 console.log("article_callback2 " + id);
337 if (!transport.responseText && db) {
338 offlineConfirmModeChange();
342 if (transport.responseXML) {
344 if (!transport_error_check(transport)) return;
346 /* var ll = $('LL-' + id);
347 var content = $('HLC-' + id);
349 if (ll && content) content.removeChild(ll); */
351 var upic = $('FUPDPIC-' + id);
354 upic.src = 'images/blank_icon.gif';
357 if (id != last_requested_article) {
358 console.log("requested article id is out of sequence, aborting");
364 console.log("looking for articles to cache...");
366 var articles = transport.responseXML.getElementsByTagName("article");
368 for (var i = 0; i < articles.length; i++) {
369 var a_id = articles[i].getAttribute("id");
371 console.log("found id: " + a_id);
373 if (a_id == active_post_id) {
374 console.log("active article, rendering...");
375 render_article(articles[i].firstChild.nodeValue);
378 cache_inject(a_id, articles[i].firstChild.nodeValue);
382 showArticleInHeadlines(id);
385 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
388 var reply = transport.responseXML.firstChild.firstChild;
391 console.log("article_callback: returned no XML object");
392 //var f = $("content-frame");
393 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
396 var date = new Date();
397 last_article_view = date.getTime() / 1000;
399 if (_reload_feedlist_after_view) {
400 setTimeout('updateFeedList(false, false)', 50);
401 _reload_feedlist_after_view = false;
403 if (transport.responseXML) {
404 var counters = transport.responseXML.getElementsByTagName("counters")[0];
407 console.log("parsing piggybacked counters: " + counters);
408 parse_counters(counters, false);
410 console.log("counters container not found in reply, requesting...");
418 exception_error("article_callback2", e, transport);
424 console.log("loading article: " + id);
426 if (offline_mode) return view_offline(id);
428 var cached_article = cache_find(id);
430 console.log("cache check result: " + (cached_article != false));
435 var query = "?op=view&id=" + param_escape(id);
437 var neighbor_ids = getRelativePostIds(active_post_id);
439 /* only request uncached articles */
441 var cids_to_request = Array();
443 for (var i = 0; i < neighbor_ids.length; i++) {
444 if (!cache_check(neighbor_ids[i])) {
445 cids_to_request.push(neighbor_ids[i]);
449 console.log("additional ids: " + cids_to_request.toString());
451 /* additional info for piggyback counters */
453 if (tagsAreDisplayed()) {
454 query = query + "&omode=lt";
456 query = query + "&omode=flc";
459 query = query + "&cids=" + cids_to_request.toString();
461 var crow = $("RROW-" + id);
462 var article_is_unread = crow.className.match("Unread");
464 showArticleInHeadlines(id);
466 if (!cached_article) {
468 var upic = $('FUPDPIC-' + id);
471 upic.src = getInitParam("sign_progress");
474 } else if (cached_article && article_is_unread) {
476 query = query + "&mode=prefetch";
478 render_article(cached_article);
480 } else if (cached_article) {
482 query = query + "&mode=prefetch_old";
483 render_article(cached_article);
489 last_requested_article = id;
491 new Ajax.Request("backend.php", {
493 onComplete: function(transport) {
494 article_callback2(transport, id);
500 exception_error("view", e);
505 return toggleMark(id);
509 return togglePub(id);
512 function tMark_afh_off(effect) {
514 var elem = effect.effects[0].element;
516 console.log("tMark_afh_off : " + elem.id);
519 elem.src = elem.src.replace("mark_set", "mark_unset");
520 elem.alt = __("Star article");
525 exception_error("tMark_afh_off", e);
529 function tPub_afh_off(effect) {
531 var elem = effect.effects[0].element;
533 console.log("tPub_afh_off : " + elem.id);
536 elem.src = elem.src.replace("pub_set", "pub_unset");
537 elem.alt = __("Publish article");
542 exception_error("tPub_afh_off", e);
546 function toggleMark(id, client_only, no_effects) {
550 var query = "?op=rpc&id=" + id + "&subop=mark";
552 query = query + "&afid=" + getActiveFeedId();
554 if (tagsAreDisplayed()) {
555 query = query + "&omode=tl";
557 query = query + "&omode=flc";
560 var mark_img = $("FMPIC-" + id);
562 if (!mark_img) return;
564 var vfeedu = $("FEEDU--1");
565 var crow = $("RROW-" + id);
567 if (mark_img.src.match("mark_unset")) {
568 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
569 mark_img.alt = __("Unstar article");
570 query = query + "&mark=1";
573 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
577 mark_img.alt = __("Please wait...");
578 query = query + "&mark=0";
580 if ($("headlinesList") && !no_effects) {
581 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
583 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
584 mark_img.alt = __("Star article");
588 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
593 if (!no_effects) update_local_feedlist_counters();
598 new Ajax.Request("backend.php", {
600 onComplete: function(transport) {
601 all_counters_callback2(transport);
607 exception_error("toggleMark", e);
611 function togglePub(id, client_only, no_effects, note) {
615 var query = "?op=rpc&id=" + id + "&subop=publ";
617 query = query + "&afid=" + getActiveFeedId();
619 if (note != undefined) {
620 query = query + "¬e=" + param_escape(note);
622 query = query + "¬e=undefined";
625 if (tagsAreDisplayed()) {
626 query = query + "&omode=tl";
628 query = query + "&omode=flc";
631 var mark_img = $("FPPIC-" + id);
633 if (!mark_img) return;
635 var vfeedu = $("FEEDU--2");
636 var crow = $("RROW-" + id);
638 if (mark_img.src.match("pub_unset") || note != undefined) {
639 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
640 mark_img.alt = __("Unpublish article");
641 query = query + "&pub=1";
644 mark_img.alt = __("Please wait...");
645 query = query + "&pub=0";
647 if ($("headlinesList") && !no_effects) {
648 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
650 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
651 mark_img.alt = __("Publish article");
656 new Ajax.Request("backend.php", {
658 onComplete: function(transport) {
659 all_counters_callback2(transport);
661 var note = transport.responseXML.getElementsByTagName("note")[0];
664 var note_id = note.getAttribute("id");
665 var note_size = note.getAttribute("size");
666 var note_content = note.firstChild.nodeValue;
668 var container = $('POSTNOTE-' + note_id);
670 cache_invalidate(note_id);
673 if (note_size == "0") {
674 Element.hide(container);
676 container.innerHTML = note_content;
677 Element.show(container);
686 exception_error("togglePub", e);
690 function correctHeadlinesOffset(id) {
694 var hlist = $("headlinesList");
695 var container = $("headlinesInnerContainer");
696 var row = $("RROW-" + id);
698 var viewport = container.offsetHeight;
700 var rel_offset_top = row.offsetTop - container.scrollTop;
701 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
703 console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
704 console.log("Vport: " + viewport);
706 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
707 container.scrollTop = row.offsetTop;
708 } else if (rel_offset_bottom > viewport) {
710 /* doesn't properly work with Opera in some cases because
711 Opera fucks up element scrolling */
713 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
717 exception_error("correctHeadlinesOffset", e);
722 function moveToPost(mode) {
729 rows = cdmGetVisibleArticles();
731 rows = getVisibleHeadlineIds();
737 if (!$('RROW-' + active_post_id)) {
738 active_post_id = false;
741 if (active_post_id == false) {
742 next_id = getFirstVisibleHeadlineId();
743 prev_id = getLastVisibleHeadlineId();
745 for (var i = 0; i < rows.length; i++) {
746 if (rows[i] == active_post_id) {
753 if (mode == "next") {
757 cdmExpandArticle(next_id);
758 cdmScrollToArticleId(next_id);
761 correctHeadlinesOffset(next_id);
762 view(next_id, getActiveFeedId());
767 if (mode == "prev") {
770 cdmExpandArticle(prev_id);
771 cdmScrollToArticleId(prev_id);
773 correctHeadlinesOffset(prev_id);
774 view(prev_id, getActiveFeedId());
780 exception_error("moveToPost", e);
784 function toggleSelected(id) {
787 var cb = $("RCHK-" + id);
789 var row = $("RROW-" + id);
791 var nc = row.className;
793 if (!nc.match("Selected")) {
794 nc = nc + "Selected";
799 // In CDM basically last selected article == active article
800 if (isCdmMode()) active_post_id = id;
802 nc = nc.replace("Selected", "");
812 exception_error("toggleSelected", e);
816 function toggleUnread_afh(effect) {
819 var elem = effect.element;
820 elem.style.backgroundColor = "";
823 exception_error("toggleUnread_afh", e);
827 function toggleUnread(id, cmode, effect) {
830 var row = $("RROW-" + id);
832 var nc = row.className;
833 var is_selected = row.className.match("Selected");
834 nc = nc.replace("Unread", "");
835 nc = nc.replace("Selected", "");
837 // since we are removing selection from the object, uncheck
838 // corresponding checkbox
840 var cb = $("RCHK-" + id);
845 // NOTE: I'm not sure that resetting selection here is a feature -fox
847 if (cmode == undefined || cmode == 2) {
848 if (row.className.match("Unread")) {
852 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
853 afterFinish: toggleUnread_afh,
854 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
858 row.className = nc + "Unread";
862 db.execute("UPDATE articles SET unread = not unread "+
863 "WHERE id = ?", [id]);
866 } else if (cmode == 0) {
870 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
871 afterFinish: toggleUnread_afh,
872 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
876 db.execute("UPDATE articles SET unread = 0 "+
877 "WHERE id = ?", [id]);
880 } else if (cmode == 1) {
881 row.className = nc + "Unread";
884 db.execute("UPDATE articles SET unread = 1 "+
885 "WHERE id = ?", [id]);
890 update_local_feedlist_counters();
892 // Disable unmarking as selected for the time being (16.05.08) -fox
893 if (is_selected) row.className = row.className + "Selected";
895 if (cmode == undefined) cmode = 2;
897 var query = "?op=rpc&subop=catchupSelected" +
898 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
900 // notify_progress("Loading, please wait...");
902 new Ajax.Request("backend.php", {
904 onComplete: function(transport) {
905 all_counters_callback2(transport);
911 exception_error("toggleUnread", e);
915 function selectionRemoveLabel(id) {
918 var ids = getSelectedArticleIds2();
920 if (ids.length == 0) {
921 alert(__("No articles are selected."));
925 // var ok = confirm(__("Remove selected articles from label?"));
929 var query = "?op=rpc&subop=removeFromLabel&ids=" +
930 param_escape(ids.toString()) + "&lid=" + param_escape(id);
932 // notify_progress("Loading, please wait...");
934 cache_invalidate("F:" + (-11 - id));
936 new Ajax.Request("backend.php", {
938 onComplete: function(transport) {
939 show_labels_in_headlines(transport);
940 all_counters_callback2(transport);
946 exception_error("selectionAssignLabel", e);
951 function selectionAssignLabel(id) {
954 var ids = getSelectedArticleIds2();
956 if (ids.length == 0) {
957 alert(__("No articles are selected."));
961 // var ok = confirm(__("Assign selected articles to label?"));
965 cache_invalidate("F:" + (-11 - id));
967 var query = "?op=rpc&subop=assignToLabel&ids=" +
968 param_escape(ids.toString()) + "&lid=" + param_escape(id);
970 // notify_progress("Loading, please wait...");
972 new Ajax.Request("backend.php", {
974 onComplete: function(transport) {
975 show_labels_in_headlines(transport);
976 all_counters_callback2(transport);
982 exception_error("selectionAssignLabel", e);
987 function selectionToggleUnread(set_state, callback_func, no_error) {
989 var rows = getSelectedArticleIds2();
991 if (rows.length == 0 && !no_error) {
992 alert(__("No articles are selected."));
996 for (i = 0; i < rows.length; i++) {
997 var row = $("RROW-" + rows[i]);
999 var nc = row.className;
1000 nc = nc.replace("Unread", "");
1001 nc = nc.replace("Selected", "");
1003 if (set_state == undefined) {
1004 if (row.className.match("Unread")) {
1005 row.className = nc + "Selected";
1007 row.className = nc + "UnreadSelected";
1010 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1015 if (set_state == false) {
1016 row.className = nc + "Selected";
1018 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1023 if (set_state == true) {
1024 row.className = nc + "UnreadSelected";
1026 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1033 if (rows.length > 0) {
1035 update_local_feedlist_counters();
1039 if (set_state == undefined) {
1041 } else if (set_state == true) {
1043 } else if (set_state == false) {
1047 var query = "?op=rpc&subop=catchupSelected" +
1048 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
1050 notify_progress("Loading, please wait...");
1052 new Ajax.Request("backend.php", {
1054 onComplete: function(transport) {
1055 catchup_callback2(transport, callback_func);
1061 exception_error("selectionToggleUnread", e);
1065 function selectionToggleMarked() {
1068 var rows = getSelectedArticleIds2();
1070 if (rows.length == 0) {
1071 alert(__("No articles are selected."));
1075 for (i = 0; i < rows.length; i++) {
1076 toggleMark(rows[i], true, true);
1079 update_local_feedlist_counters();
1081 if (rows.length > 0) {
1083 var query = "?op=rpc&subop=markSelected&ids=" +
1084 param_escape(rows.toString()) + "&cmode=2";
1086 query = query + "&afid=" + getActiveFeedId();
1088 query = query + "&omode=lc";
1090 new Ajax.Request("backend.php", {
1092 onComplete: function(transport) {
1093 all_counters_callback2(transport);
1099 exception_error("selectionToggleMarked", e);
1103 function selectionTogglePublished() {
1106 var rows = getSelectedArticleIds2();
1108 if (rows.length == 0) {
1109 alert(__("No articles are selected."));
1113 for (i = 0; i < rows.length; i++) {
1114 togglePub(rows[i], true, true);
1117 if (rows.length > 0) {
1119 var query = "?op=rpc&subop=publishSelected&ids=" +
1120 param_escape(rows.toString()) + "&cmode=2";
1122 query = query + "&afid=" + getActiveFeedId();
1124 query = query + "&omode=lc";
1126 new Ajax.Request("backend.php", {
1128 onComplete: function(transport) {
1129 all_counters_callback2(transport);
1135 exception_error("selectionToggleMarked", e);
1139 function cdmGetSelectedArticles() {
1140 var sel_articles = new Array();
1141 var container = $("headlinesInnerContainer");
1143 for (i = 0; i < container.childNodes.length; i++) {
1144 var child = container.childNodes[i];
1146 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1147 var c_id = child.id.replace("RROW-", "");
1148 sel_articles.push(c_id);
1152 return sel_articles;
1155 function cdmGetVisibleArticles() {
1156 var sel_articles = new Array();
1157 var container = $("headlinesInnerContainer");
1159 if (!container) return sel_articles;
1161 for (i = 0; i < container.childNodes.length; i++) {
1162 var child = container.childNodes[i];
1164 if (child.id && child.id.match("RROW-")) {
1165 var c_id = child.id.replace("RROW-", "");
1166 sel_articles.push(c_id);
1170 return sel_articles;
1173 function cdmGetUnreadArticles() {
1174 var sel_articles = new Array();
1175 var container = $("headlinesInnerContainer");
1177 for (i = 0; i < container.childNodes.length; i++) {
1178 var child = container.childNodes[i];
1180 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1181 var c_id = child.id.replace("RROW-", "");
1182 sel_articles.push(c_id);
1186 return sel_articles;
1190 // mode = all,none,unread
1191 function cdmSelectArticles(mode) {
1192 var container = $("headlinesInnerContainer");
1194 for (i = 0; i < container.childNodes.length; i++) {
1195 var child = container.childNodes[i];
1197 if (child.id && child.id.match("RROW-")) {
1198 var aid = child.id.replace("RROW-", "");
1200 var cb = $("RCHK-" + aid);
1202 if (mode == "all") {
1203 if (!child.className.match("Selected")) {
1204 child.className = child.className + "Selected";
1207 } else if (mode == "unread") {
1208 if (child.className.match("Unread") && !child.className.match("Selected")) {
1209 child.className = child.className + "Selected";
1213 child.className = child.className.replace("Selected", "");
1220 function catchupPage() {
1222 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1224 var str = __("Mark all visible articles in %s as read?");
1226 str = str.replace("%s", fn);
1228 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1232 if ($("headlinesList")) {
1233 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1234 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1235 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1237 cdmSelectArticles('all');
1238 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1239 cdmSelectArticles('none');
1243 function deleteSelection() {
1247 var rows = getSelectedArticleIds2();
1249 if (rows.length == 0) {
1250 alert(__("No articles are selected."));
1254 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1258 if (getActiveFeedId() != 0) {
1259 str = __("Delete %d selected articles in %s?");
1261 str = __("Delete %d selected articles?");
1264 str = str.replace("%d", rows.length);
1265 str = str.replace("%s", fn);
1267 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1271 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
1275 new Ajax.Request("backend.php", {
1277 onComplete: function(transport) {
1282 exception_error("deleteSelection", e);
1286 function archiveSelection() {
1290 var rows = getSelectedArticleIds2();
1292 if (rows.length == 0) {
1293 alert(__("No articles are selected."));
1297 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1301 if (getActiveFeedId() != 0) {
1302 str = __("Archive %d selected articles in %s?");
1305 str = __("Move %d archived articles back?");
1309 str = str.replace("%d", rows.length);
1310 str = str.replace("%s", fn);
1312 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1316 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1320 for (var i = 0; i < rows.length; i++) {
1321 cache_invalidate(rows[i]);
1324 new Ajax.Request("backend.php", {
1326 onComplete: function(transport) {
1331 exception_error("archiveSelection", e);
1335 function catchupSelection() {
1339 var rows = getSelectedArticleIds2();
1341 if (rows.length == 0) {
1342 alert(__("No articles are selected."));
1346 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1348 var str = __("Mark %d selected articles in %s as read?");
1350 str = str.replace("%d", rows.length);
1351 str = str.replace("%s", fn);
1353 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1357 if ($("headlinesList")) {
1358 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1360 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1364 exception_error("catchupSelection", e);
1368 function editArticleTags(id, feed_id, cdm_enabled) {
1369 displayDlg('editArticleTags', id,
1371 $("tags_str").focus();
1373 new Ajax.Autocompleter('tags_str', 'tags_choices',
1374 "backend.php?op=rpc&subop=completeTags",
1375 { tokens: ',', paramName: "search" });
1379 function editTagsSave() {
1381 notify_progress("Saving article tags...");
1383 var form = document.forms["tag_edit_form"];
1385 var query = Form.serialize("tag_edit_form");
1387 query = "?op=rpc&subop=setArticleTags&" + query;
1391 new Ajax.Request("backend.php", {
1393 onComplete: function(transport) {
1395 console.log("tags saved...");
1400 if (tagsAreDisplayed()) {
1401 _reload_feedlist_after_view = true;
1404 if (transport.responseXML) {
1405 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1408 var id = tags_str.getAttribute("id");
1411 var tags = $("ATSTR-" + id);
1413 tags.innerHTML = tags_str.firstChild.nodeValue;
1416 cache_invalidate(id);
1422 exception_error("editTagsSave", e);
1427 function editTagsInsert() {
1430 var form = document.forms["tag_edit_form"];
1432 var found_tags = form.found_tags;
1433 var tags_str = form.tags_str;
1435 var tag = found_tags[found_tags.selectedIndex].value;
1437 if (tags_str.value.length > 0 &&
1438 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1440 tags_str.value = tags_str.value + ", ";
1443 tags_str.value = tags_str.value + tag + ", ";
1445 found_tags.selectedIndex = 0;
1448 exception_error("editTagsInsert", e);
1452 function cdmScrollViewport(where) {
1453 console.log("cdmScrollViewport: " + where);
1455 var ctr = $("headlinesInnerContainer");
1459 if (where == "bottom") {
1460 ctr.scrollTop = ctr.scrollHeight;
1462 ctr.scrollTop = where;
1466 function cdmArticleIsBelowViewport(id) {
1468 var ctr = $("headlinesInnerContainer");
1469 var e = $("RROW-" + id);
1471 if (!e || !ctr) return;
1473 // article starts below viewport
1475 if (ctr.scrollTop < e.offsetTop) {
1482 exception_error("cdmArticleIsVisible", e);
1486 function cdmArticleIsAboveViewport(id) {
1488 var ctr = $("headlinesInnerContainer");
1489 var e = $("RROW-" + id);
1491 if (!e || !ctr) return;
1493 // article starts above viewport
1495 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1502 exception_error("cdmArticleIsVisible", e);
1506 function cdmScrollToArticleId(id) {
1508 var ctr = $("headlinesInnerContainer");
1509 var e = $("RROW-" + id);
1511 if (!e || !ctr) return;
1513 ctr.scrollTop = e.offsetTop;
1516 exception_error("cdmScrollToArticleId", e);
1520 function cdmArticleIsActuallyVisible(id) {
1522 var ctr = $("headlinesInnerContainer");
1523 var e = $("RROW-" + id);
1525 if (!e || !ctr) return;
1527 // article fits in viewport OR article is longer than viewport and
1528 // its bottom is visible
1530 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1531 ctr.scrollTop + ctr.offsetHeight) {
1535 } else if (e.offsetHeight > ctr.offsetHeight &&
1536 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1537 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1546 exception_error("cdmArticleIsVisible", e);
1550 function cdmWatchdog() {
1554 var ctr = $("headlinesInnerContainer");
1558 var ids = new Array();
1560 var e = ctr.firstChild;
1563 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1564 e.id.match("RROW-")) {
1566 // article fits in viewport OR article is longer than viewport and
1567 // its bottom is visible
1569 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1570 ctr.scrollTop + ctr.offsetHeight) {
1572 // console.log(e.id + " is visible " + e.offsetTop + "." +
1573 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1574 // (ctr.scrollTop + ctr.offsetHeight));
1576 ids.push(e.id.replace("RROW-", ""));
1578 } else if (e.offsetHeight > ctr.offsetHeight &&
1579 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1580 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1582 ids.push(e.id.replace("RROW-", ""));
1586 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1588 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1589 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1591 ids.push(e.id.replace("RROW-", ""));
1600 console.log("cdmWatchdog, ids= " + ids.toString());
1602 if (ids.length > 0) {
1604 for (var i = 0; i < ids.length; i++) {
1605 var e = $("RROW-" + ids[i]);
1607 e.className = e.className.replace("Unread", "");
1611 var query = "?op=rpc&subop=catchupSelected" +
1612 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1614 new Ajax.Request("backend.php", {
1616 onComplete: function(transport) {
1617 all_counters_callback2(transport);
1622 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1625 exception_error("cdmWatchdog", e);
1631 function cache_inject(id, article, param) {
1633 if (!cache_check_param(id, param)) {
1634 console.log("cache_article: miss: " + id + " [p=" + param + "]");
1638 var date = new Date();
1639 var ts = Math.round(date.getTime() / 1000);
1641 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1642 [id, article, param, ts]);
1647 cache_obj["id"] = id;
1648 cache_obj["data"] = article;
1649 cache_obj["param"] = param;
1650 cache_obj["added"] = new Date();
1652 if (param) id = id + ":" + param;
1654 if (has_local_storage())
1655 localStorage.setItem(id, JSON.stringify(cache_obj));
1657 article_cache.push(cache_obj);
1661 console.log("cache_article: hit: " + id + " [p=" + param + "]");
1664 exception_error("cache_inject", e);
1668 function cache_find(id) {
1671 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1674 if (rs.isValidRow()) {
1675 var a = rs.field(0);
1684 if (has_local_storage()) {
1685 var cache_obj = localStorage.getItem(id);
1688 cache_obj = JSON.parse(cache_obj);
1691 return cache_obj['data'];
1695 for (var i = 0; i < article_cache.length; i++) {
1696 if (article_cache[i]["id"] == id) {
1697 return article_cache[i]["data"];
1705 function cache_find_param(id, param) {
1708 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1712 if (rs.isValidRow()) {
1722 if (has_local_storage()) {
1723 var cache_obj = localStorage.getItem(id + ":" + param);
1726 cache_obj = JSON.parse(cache_obj);
1729 return cache_obj['data'];
1733 for (var i = 0; i < article_cache.length; i++) {
1734 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1735 return article_cache[i]["data"];
1743 function cache_check(id) {
1746 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1750 if (rs.isValidRow()) {
1751 a = rs.field(0) != "0";
1759 if (has_local_storage) {
1760 if (localStorage.getItem(id))
1763 for (var i = 0; i < article_cache.length; i++) {
1764 if (article_cache[i]["id"] == id) {
1773 function cache_check_param(id, param) {
1776 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1780 if (rs.isValidRow()) {
1781 a = rs.field(0) != "0";
1790 if (has_local_storage) {
1791 if (localStorage.getItem(id + ':' + param))
1794 for (var i = 0; i < article_cache.length; i++) {
1795 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1804 function cache_expire() {
1806 var date = new Date();
1807 var ts = Math.round(date.getTime() / 1000);
1809 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1810 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1811 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1815 if (has_local_storage()) {
1816 while (localStorage.length > 25) {
1817 localStorage.removeItem(localStorage.key(0));
1820 while (article_cache.length > 25) {
1821 article_cache.shift();
1827 function cache_flush() {
1829 db.execute("DELETE FROM cache");
1830 } else if (has_local_storage()) {
1831 localStorage.clear();
1833 article_cache = new Array();
1837 function cache_invalidate(id) {
1841 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1842 return rs.rowsAffected != 0;
1845 if (has_local_storage()) {
1846 for (var i = 0; i < localStorage.length; i++) {
1847 var key = localStorage.key(i);
1849 if (key == id || key.indexOf(id + ":") == 0)
1850 localStorage.removeItem(key);
1856 while (i < article_cache.length) {
1857 if (article_cache[i]["id"] == id) {
1858 console.log("cache_invalidate: removed id " + id);
1859 article_cache.splice(i, 1);
1867 console.log("cache_invalidate: id not found: " + id);
1870 exception_error("cache_invalidate", e);
1874 function getActiveArticleId() {
1875 return active_post_id;
1878 function preloadArticleUnderPointer(id) {
1880 if (getInitParam("bw_limit") == "1") return;
1882 if (post_under_pointer == id && !cache_check(id)) {
1884 console.log("trying to preload article " + id);
1886 var neighbor_ids = getRelativePostIds(id, 1);
1888 /* only request uncached articles */
1890 var cids_to_request = Array();
1892 for (var i = 0; i < neighbor_ids.length; i++) {
1893 if (!cache_check(neighbor_ids[i])) {
1894 cids_to_request.push(neighbor_ids[i]);
1897 console.log("additional ids: " + cids_to_request.toString());
1899 cids_to_request.push(id);
1901 var query = "?op=rpc&subop=getArticles&ids=" +
1902 cids_to_request.toString();
1904 new Ajax.Request("backend.php", {
1906 onComplete: function(transport) {
1907 var articles = transport.responseXML.getElementsByTagName("article");
1909 for (var i = 0; i < articles.length; i++) {
1910 var id = articles[i].getAttribute("id");
1911 if (!cache_check(id)) {
1912 cache_inject(id, articles[i].firstChild.nodeValue);
1913 console.log("preloaded article: " + id);
1919 exception_error("preloadArticleUnderPointer", e);
1923 function postMouseIn(id) {
1925 if (post_under_pointer != id) {
1926 post_under_pointer = id;
1928 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1933 exception_error("postMouseIn", e);
1937 function postMouseOut(id) {
1939 post_under_pointer = false;
1941 exception_error("postMouseOut", e);
1945 function headlines_scroll_handler() {
1948 var e = $("headlinesInnerContainer");
1950 var toolbar_form = document.forms["main_toolbar_form"];
1952 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1953 // _infscroll_disable);
1955 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1956 if (!_infscroll_disable) {
1957 console.log("more cowbell!");
1963 exception_error("headlines_scroll_handler", e);
1967 function catchupRelativeToArticle(below) {
1972 if (!getActiveArticleId()) {
1973 alert(__("No article is selected."));
1979 if ($("headlinesList")) {
1980 visible_ids = getVisibleHeadlineIds();
1982 visible_ids = cdmGetVisibleArticles();
1985 var ids_to_mark = new Array();
1988 for (var i = 0; i < visible_ids.length; i++) {
1989 if (visible_ids[i] != getActiveArticleId()) {
1990 var e = $("RROW-" + visible_ids[i]);
1992 if (e && e.className.match("Unread")) {
1993 ids_to_mark.push(visible_ids[i]);
2000 for (var i = visible_ids.length-1; i >= 0; i--) {
2001 if (visible_ids[i] != getActiveArticleId()) {
2002 var e = $("RROW-" + visible_ids[i]);
2004 if (e && e.className.match("Unread")) {
2005 ids_to_mark.push(visible_ids[i]);
2013 if (ids_to_mark.length == 0) {
2014 alert(__("No articles found to mark"));
2016 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
2018 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
2020 for (var i = 0; i < ids_to_mark.length; i++) {
2021 var e = $("RROW-" + ids_to_mark[i]);
2022 e.className = e.className.replace("Unread", "");
2025 var query = "?op=rpc&subop=catchupSelected" +
2026 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
2028 new Ajax.Request("backend.php", {
2030 onComplete: function(transport) {
2031 catchup_callback2(transport);
2038 exception_error("catchupRelativeToArticle", e);
2042 function cdmExpandArticle(id) {
2045 var elem = $("CICD-" + active_post_id);
2047 if (id == active_post_id && Element.visible(elem))
2050 cdmSelectArticles("none");
2052 var old_offset = $("RROW-" + id).offsetTop;
2054 if (active_post_id && elem) {
2056 Element.show("CEXC-" + active_post_id);
2059 active_post_id = id;
2061 elem = $("CICD-" + id);
2063 if (!Element.visible(elem)) {
2065 Element.hide("CEXC-" + id);
2068 var new_offset = $("RROW-" + id).offsetTop;
2070 $("headlinesInnerContainer").scrollTop += (new_offset-old_offset);
2072 if ($("RROW-" + id).offsetTop != old_offset)
2073 $("headlinesInnerContainer").scrollTop = new_offset;
2075 toggleUnread(id, 0, true);
2079 exception_error("cdmExpandArticle", e);
2085 function fixHeadlinesOrder(ids) {
2087 for (var i = 0; i < ids.length; i++) {
2088 var e = $("RROW-" + ids[i]);
2092 e.className = e.className.replace("even", "odd");
2094 e.className = e.className.replace("odd", "even");
2099 exception_error("fixHeadlinesOrder", e);
2103 function hideReadHeadlines() {
2107 var vis_ids = new Array();
2109 if ($("headlinesList")) {
2110 ids = getVisibleHeadlineIds();
2112 ids = cdmGetVisibleArticles();
2115 var read_headlines_visible = true;
2117 for (var i = 0; i < ids.length; i++) {
2118 var row = $("RROW-" + ids[i]);
2120 if (row && row.className) {
2121 if (read_headlines_visible) {
2122 if (row.className.match("Unread") || row.className.match("Selected")) {
2124 vis_ids.push(ids[i]);
2126 //Effect.Fade(row, {duration : 0.3});
2131 vis_ids.push(ids[i]);
2136 fixHeadlinesOrder(vis_ids);
2138 read_headlines_visible = !read_headlines_visible;
2141 exception_error("hideReadHeadlines", e);
2145 function invertHeadlineSelection() {
2147 var rows = new Array();
2151 r = document.getElementsByTagName("TR");
2153 r = document.getElementsByTagName("DIV");
2156 for (var i = 0; i < r.length; i++) {
2157 if (r[i].id && r[i].id.match("RROW-")) {
2162 for (var i = 0; i < rows.length; i++) {
2163 var nc = rows[i].className;
2164 var id = rows[i].id.replace("RROW-", "");
2165 var cb = $("RCHK-" + id);
2167 if (!rows[i].className.match("Selected")) {
2168 nc = nc + "Selected";
2171 nc = nc.replace("Selected", "");
2175 rows[i].className = nc;
2180 exception_error("invertHeadlineSelection", e);
2184 function getArticleUnderPointer() {
2185 return post_under_pointer;
2188 function zoomToArticle(id) {
2190 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2192 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2195 exception_error("zoomToArticle", e);
2199 function scrollArticle(offset) {
2202 var ci = $("content-insert");
2204 ci.scrollTop += offset;
2207 var hi = $("headlinesInnerContainer");
2209 hi.scrollTop += offset;
2214 exception_error("scrollArticle", e);
2218 function show_labels_in_headlines(transport) {
2220 if (transport.responseXML) {
2221 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2223 var elems = info.getElementsByTagName("entry");
2225 for (var l = 0; l < elems.length; l++) {
2226 var e_id = elems[l].getAttribute("id");
2230 var ctr = $("HLLCTR-" + e_id);
2233 ctr.innerHTML = elems[l].firstChild.nodeValue;
2241 exception_error("show_labels_in_headlines", e);
2246 function toggleHeadlineActions() {
2248 var e = $("headlineActionsBody");
2249 var p = $("headlineActionsDrop");
2251 if (!Element.visible(e)) {
2258 e.style.left = (p.offsetLeft + 1) + "px";
2259 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
2262 exception_error("toggleHeadlineActions", e);
2266 function publishWithNote(id, def_note) {
2268 if (!def_note) def_note = '';
2270 var note = prompt(__("Please enter a note for this article:"), def_note);
2272 if (note != undefined) {
2273 togglePub(id, false, false, note);
2277 exception_error("publishWithNote", e);
2281 function emailArticle(id) {
2284 var ids = getSelectedArticleIds2();
2286 if (ids.length == 0) {
2287 alert(__("No articles are selected."));
2291 id = ids.toString();
2294 displayDlg('emailArticle', id,
2296 document.forms['article_email_form'].destination.focus();
2298 new Ajax.Autocompleter('destination', 'destination_choices',
2299 "backend.php?op=rpc&subop=completeEmails",
2300 { tokens: '', paramName: "search" });
2305 exception_error("emailArticle", e);
2309 function emailArticleDo() {
2311 var f = document.forms['article_email_form'];
2313 if (f.destination.value == "") {
2314 alert("Please fill in the destination email.");
2318 if (f.subject.value == "") {
2319 alert("Please fill in the subject.");
2323 var query = Form.serialize("article_email_form");
2325 // console.log(query);
2327 new Ajax.Request("backend.php", {
2329 onComplete: function(transport) {
2332 var error = transport.responseXML.getElementsByTagName('error')[0];
2335 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
2337 notify_info('Your message has been sent.');
2342 exception_error("sendEmailDo", e);
2348 exception_error("emailArticleDo", e);
2352 function cdmDismissArticle(id) {
2354 var elem = $("RROW-" + id);
2356 toggleUnread(id, 0, true);
2358 new Effect.Fade(elem, {duration : 0.5});
2361 exception_error("cdmDismissArticle", e);
2365 function cdmDismissSelectedArticles() {
2368 var ids = getSelectedArticleIds2();
2370 for (var i = 0; i < ids.length; i++) {
2371 var elem = $("RROW-" + ids[i]);
2372 new Effect.Fade(elem, {duration : 0.5});
2376 selectionToggleUnread(false);
2379 exception_error("cdmDismissArticle", e);