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 var preload_id_batch = [];
19 var preload_timeout_id = false;
23 function catchup_callback2(transport, callback) {
25 console.log("catchup_callback2 " + transport + ", " + callback);
27 handle_rpc_reply(transport);
29 setTimeout(callback, 10);
32 exception_error("catchup_callback2", e, transport);
36 function clean_feed_selections() {
38 var feeds = $("feedList").getElementsByTagName("LI");
40 for (var i = 0; i < feeds.length; i++) {
41 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
42 feeds[i].className = feeds[i].className.replace("Selected", "");
44 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
45 feeds[i].className = feeds[i].className.replace("Selected", "");
49 exception_error("clean_feed_selections", e);
53 function headlines_callback2(transport, feed_cur_page) {
56 if (!handle_rpc_reply(transport)) return;
58 loading_set_progress(100);
60 console.log("headlines_callback2 [page=" + feed_cur_page + "]");
62 if (!transport_error_check(transport)) return;
64 clean_feed_selections();
69 if (transport.responseXML) {
70 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
72 is_cat = headlines.getAttribute("is_cat");
73 feed_id = headlines.getAttribute("id");
74 setActiveFeedId(feed_id, is_cat);
78 var ll = $('FLL-' + feed_id);
81 var feedr = $("FEEDR-" + feed_id);
82 if (feedr && !feedr.className.match("Selected")) {
83 feedr.className = feedr.className + "Selected";
85 if (feedr && ll) feedr.removeChild(ll);
87 var feedr = $("FCAT-" + feed_id);
88 if (feedr && !feedr.className.match("Selected")) {
89 feedr.className = feedr.className + "Selected";
92 var fcap = $("FCAP-" + feed_id);
93 if (fcap && ll) fcap.removeChild(ll);
97 var img = $('FIMG-' + feed_id);
103 var f = $("headlines-frame");
105 if (feed_cur_page == 0) {
106 //console.log("resetting headlines scrollTop");
111 if (transport.responseXML) {
112 var response = transport.responseXML;
114 var headlines = response.getElementsByTagName("headlines")[0];
115 var headlines_info = response.getElementsByTagName("headlines-info")[0];
118 headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
120 console.error("didn't find headlines-info object in response");
124 var headlines_count = headlines_info.count;
125 var headlines_unread = headlines_info.unread;
126 var disable_cache = headlines_info.disable_cache;
128 vgroup_last_feed = headlines_info.vgroup_last_feed;
130 if (headlines_count == 0) {
131 _infscroll_disable = 1;
133 _infscroll_disable = 0;
136 var counters = response.getElementsByTagName("counters")[0];
137 var articles = response.getElementsByTagName("article");
138 var runtime_info = response.getElementsByTagName("runtime-info");
140 if (feed_cur_page == 0) {
142 f.innerHTML = headlines.firstChild.nodeValue;
144 var cache_prefix = "";
152 cache_invalidate(cache_prefix + feed_id);
154 if (!disable_cache) {
155 cache_inject(cache_prefix + feed_id,
156 headlines.firstChild.nodeValue, headlines_unread);
160 console.warn("headlines_callback: returned no data");
161 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
166 if (headlines_count > 0) {
167 console.log("adding some more headlines...");
169 var c = $("headlinesList");
172 c = $("headlinesInnerContainer");
175 var ids = getSelectedArticleIds2();
177 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
179 console.log("restore selected ids: " + ids);
181 for (var i = 0; i < ids.length; i++) {
182 markHeadline(ids[i]);
186 console.log("no new headlines received");
189 console.warn("headlines_callback: returned no data");
190 notify_error("Error while trying to load more headlines");
196 for (var i = 0; i < articles.length; i++) {
197 var a_id = articles[i].getAttribute("id");
198 //console.log("found id: " + a_id);
199 cache_inject(a_id, articles[i].firstChild.nodeValue);
202 console.log("no cached articles received");
206 parse_counters(counters);
211 parse_runtime_info(runtime_info[0]);
215 console.warn("headlines_callback: returned no XML object");
216 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
220 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
222 if (!$("headlinesList") &&
223 getActiveFeedId() != -3 &&
224 getInitParam("cdm_auto_catchup") == 1) {
225 console.log("starting CDM watchdog");
226 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
227 _cdm_wd_vishist = new Array();
229 console.log("not in CDM mode or watchdog disabled");
232 _feed_cur_page = feed_cur_page;
233 _infscroll_request_sent = 0;
240 exception_error("headlines_callback2", e, transport);
244 function render_article(article) {
246 var f = $("content-frame");
251 var fi = $("content-insert");
257 fi.innerHTML = article;
259 // article.evalScripts();
262 exception_error("render_article", e);
266 function showArticleInHeadlines(id) {
270 cleanSelected("headlinesList");
272 var crow = $("RROW-" + id);
276 var article_is_unread = crow.className.match("Unread");
278 crow.className = crow.className.replace("Unread", "");
280 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
282 var upd_img_pic = $("FUPDPIC-" + id);
284 var cache_prefix = "";
286 if (activeFeedIsCat()) {
292 var view_mode = false;
295 view_mode = document.forms['main_toolbar_form'].view_mode;
296 view_mode = view_mode[view_mode.selectedIndex].value;
301 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
302 upd_img_pic.src.match("fresh_sign.png"))) {
304 upd_img_pic.src = "images/blank_icon.gif";
306 cache_invalidate(cache_prefix + getActiveFeedId());
308 cache_inject(cache_prefix + getActiveFeedId(),
309 $("headlines-frame").innerHTML,
310 get_feed_unread(getActiveFeedId()));
312 } else if (article_is_unread && view_mode == "all_articles") {
314 cache_invalidate(cache_prefix + getActiveFeedId());
316 cache_inject(cache_prefix + getActiveFeedId(),
317 $("headlines-frame").innerHTML,
318 get_feed_unread(getActiveFeedId())-1);
320 } else if (article_is_unread) {
321 cache_invalidate(cache_prefix + getActiveFeedId());
326 if (article_is_unread)
327 _force_scheduled_update = true;
330 exception_error("showArticleInHeadlines", e);
334 function article_callback2(transport, id) {
336 console.log("article_callback2 " + id);
338 if (!handle_rpc_reply(transport)) return;
340 if (transport.responseXML) {
342 if (!transport_error_check(transport)) return;
344 /* var ll = $('LL-' + id);
345 var content = $('HLC-' + id);
347 if (ll && content) content.removeChild(ll); */
349 var upic = $('FUPDPIC-' + id);
352 upic.src = 'images/blank_icon.gif';
355 if (id != last_requested_article) {
356 console.log("requested article id is out of sequence, aborting");
362 //console.log("looking for articles to cache...");
364 var articles = transport.responseXML.getElementsByTagName("article");
366 for (var i = 0; i < articles.length; i++) {
367 var a_id = articles[i].getAttribute("id");
369 //console.log("found id: " + a_id);
371 if (a_id == active_post_id) {
372 //console.log("active article, rendering...");
373 render_article(articles[i].firstChild.nodeValue);
376 cache_inject(a_id, articles[i].firstChild.nodeValue);
380 showArticleInHeadlines(id);
383 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
386 var reply = transport.responseXML.firstChild.firstChild;
389 console.warn("article_callback: returned no XML object");
390 //var f = $("content-frame");
391 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
394 var date = new Date();
395 last_article_view = date.getTime() / 1000;
397 if (_reload_feedlist_after_view) {
398 setTimeout('updateFeedList(false, false)', 50);
399 _reload_feedlist_after_view = false;
406 exception_error("article_callback2", e, transport);
412 console.log("loading article: " + id);
414 if (offline_mode) return view_offline(id);
416 var cached_article = cache_find(id);
418 console.log("cache check result: " + (cached_article != false));
423 var query = "?op=view&id=" + param_escape(id);
425 var neighbor_ids = getRelativePostIds(active_post_id);
427 /* only request uncached articles */
429 var cids_to_request = Array();
431 for (var i = 0; i < neighbor_ids.length; i++) {
432 if (!cache_check(neighbor_ids[i])) {
433 cids_to_request.push(neighbor_ids[i]);
437 console.log("additional ids: " + cids_to_request.toString());
439 /* additional info for piggyback counters */
441 if (tagsAreDisplayed()) {
442 query = query + "&omode=lt";
444 query = query + "&omode=flc";
447 query = query + "&cids=" + cids_to_request.toString();
449 var crow = $("RROW-" + id);
450 var article_is_unread = crow.className.match("Unread");
452 showArticleInHeadlines(id);
454 if (!cached_article) {
456 var upic = $('FUPDPIC-' + id);
459 upic.src = getInitParam("sign_progress");
462 } else if (cached_article && article_is_unread) {
464 query = query + "&mode=prefetch";
466 render_article(cached_article);
468 } else if (cached_article) {
470 query = query + "&mode=prefetch_old";
471 render_article(cached_article);
477 last_requested_article = id;
479 new Ajax.Request("backend.php", {
481 onComplete: function(transport) {
482 article_callback2(transport, 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 //console.log("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 //console.log("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 = "?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 = $("FMPIC-" + id);
550 if (!mark_img) return;
552 var vfeedu = $("FEEDU--1");
553 var crow = $("RROW-" + id);
555 if (mark_img.src.match("mark_unset")) {
556 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
557 mark_img.alt = __("Unstar article");
558 query = query + "&mark=1";
561 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
565 mark_img.alt = __("Please wait...");
566 query = query + "&mark=0";
568 if ($("headlinesList") && !no_effects) {
569 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
571 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
572 mark_img.alt = __("Star article");
576 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
581 if (!no_effects) update_local_feedlist_counters();
584 //console.log(query);
586 new Ajax.Request("backend.php", {
588 onComplete: function(transport) {
589 handle_rpc_reply(transport);
595 exception_error("toggleMark", e);
599 function togglePub(id, client_only, no_effects, note) {
603 var query = "?op=rpc&id=" + id + "&subop=publ";
605 query = query + "&afid=" + getActiveFeedId();
607 if (note != undefined) {
608 query = query + "¬e=" + param_escape(note);
610 query = query + "¬e=undefined";
613 if (tagsAreDisplayed()) {
614 query = query + "&omode=tl";
616 query = query + "&omode=flc";
619 var mark_img = $("FPPIC-" + id);
621 if (!mark_img) return;
623 var vfeedu = $("FEEDU--2");
624 var crow = $("RROW-" + id);
626 if (mark_img.src.match("pub_unset") || note != undefined) {
627 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
628 mark_img.alt = __("Unpublish article");
629 query = query + "&pub=1";
632 mark_img.alt = __("Please wait...");
633 query = query + "&pub=0";
635 if ($("headlinesList") && !no_effects) {
636 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
638 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
639 mark_img.alt = __("Publish article");
644 new Ajax.Request("backend.php", {
646 onComplete: function(transport) {
647 handle_rpc_reply(transport);
649 var note = transport.responseXML.getElementsByTagName("note")[0];
652 var note_id = note.getAttribute("id");
653 var note_size = note.getAttribute("size");
654 var note_content = note.firstChild.nodeValue;
656 var container = $('POSTNOTE-' + note_id);
658 cache_invalidate(note_id);
661 if (note_size == "0") {
662 Element.hide(container);
664 container.innerHTML = note_content;
665 Element.show(container);
674 exception_error("togglePub", e);
678 function correctHeadlinesOffset(id) {
682 var hlist = $("headlinesList");
683 var container = $("headlinesInnerContainer");
684 var row = $("RROW-" + id);
686 var viewport = container.offsetHeight;
688 var rel_offset_top = row.offsetTop - container.scrollTop;
689 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
691 console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
692 console.log("Vport: " + viewport);
694 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
695 container.scrollTop = row.offsetTop;
696 } else if (rel_offset_bottom > viewport) {
698 /* doesn't properly work with Opera in some cases because
699 Opera fucks up element scrolling */
701 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
705 exception_error("correctHeadlinesOffset", e);
710 function moveToPost(mode) {
717 rows = cdmGetVisibleArticles();
719 rows = getVisibleHeadlineIds();
725 if (!$('RROW-' + active_post_id)) {
726 active_post_id = false;
729 if (active_post_id == false) {
730 next_id = getFirstVisibleHeadlineId();
731 prev_id = getLastVisibleHeadlineId();
733 for (var i = 0; i < rows.length; i++) {
734 if (rows[i] == active_post_id) {
741 if (mode == "next") {
745 cdmExpandArticle(next_id);
746 cdmScrollToArticleId(next_id);
749 correctHeadlinesOffset(next_id);
750 view(next_id, getActiveFeedId());
755 if (mode == "prev") {
758 cdmExpandArticle(prev_id);
759 cdmScrollToArticleId(prev_id);
761 correctHeadlinesOffset(prev_id);
762 view(prev_id, getActiveFeedId());
768 exception_error("moveToPost", e);
772 function toggleSelected(id) {
775 var cb = $("RCHK-" + id);
777 var row = $("RROW-" + id);
779 var nc = row.className;
781 if (!nc.match("Selected")) {
782 nc = nc + "Selected";
787 // In CDM basically last selected article == active article
788 if (isCdmMode()) active_post_id = id;
790 nc = nc.replace("Selected", "");
800 exception_error("toggleSelected", e);
804 function toggleUnread_afh(effect) {
807 var elem = effect.element;
808 elem.style.backgroundColor = "";
811 exception_error("toggleUnread_afh", e);
815 function toggleUnread(id, cmode, effect) {
818 var row = $("RROW-" + id);
820 var nc = row.className;
821 var is_selected = row.className.match("Selected");
822 nc = nc.replace("Unread", "");
823 nc = nc.replace("Selected", "");
825 // since we are removing selection from the object, uncheck
826 // corresponding checkbox
828 var cb = $("RCHK-" + id);
833 // NOTE: I'm not sure that resetting selection here is a feature -fox
835 if (cmode == undefined || cmode == 2) {
836 if (row.className.match("Unread")) {
840 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
841 afterFinish: toggleUnread_afh,
842 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
846 row.className = nc + "Unread";
850 db.execute("UPDATE articles SET unread = not unread "+
851 "WHERE id = ?", [id]);
854 } else if (cmode == 0) {
858 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
859 afterFinish: toggleUnread_afh,
860 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
864 db.execute("UPDATE articles SET unread = 0 "+
865 "WHERE id = ?", [id]);
868 } else if (cmode == 1) {
869 row.className = nc + "Unread";
872 db.execute("UPDATE articles SET unread = 1 "+
873 "WHERE id = ?", [id]);
878 update_local_feedlist_counters();
880 // Disable unmarking as selected for the time being (16.05.08) -fox
881 if (is_selected) row.className = row.className + "Selected";
883 if (cmode == undefined) cmode = 2;
885 var query = "?op=rpc&subop=catchupSelected" +
886 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
888 // notify_progress("Loading, please wait...");
890 new Ajax.Request("backend.php", {
892 onComplete: function(transport) {
893 handle_rpc_reply(transport);
899 exception_error("toggleUnread", e);
903 function selectionRemoveLabel(id) {
906 var ids = getSelectedArticleIds2();
908 if (ids.length == 0) {
909 alert(__("No articles are selected."));
913 // var ok = confirm(__("Remove selected articles from label?"));
917 var query = "?op=rpc&subop=removeFromLabel&ids=" +
918 param_escape(ids.toString()) + "&lid=" + param_escape(id);
922 // notify_progress("Loading, please wait...");
924 cache_invalidate("F:" + (-11 - id));
926 new Ajax.Request("backend.php", {
928 onComplete: function(transport) {
929 show_labels_in_headlines(transport);
930 handle_rpc_reply(transport);
936 exception_error("selectionAssignLabel", e);
941 function selectionAssignLabel(id) {
944 var ids = getSelectedArticleIds2();
946 if (ids.length == 0) {
947 alert(__("No articles are selected."));
951 // var ok = confirm(__("Assign selected articles to label?"));
955 cache_invalidate("F:" + (-11 - id));
957 var query = "?op=rpc&subop=assignToLabel&ids=" +
958 param_escape(ids.toString()) + "&lid=" + param_escape(id);
962 // notify_progress("Loading, please wait...");
964 new Ajax.Request("backend.php", {
966 onComplete: function(transport) {
967 show_labels_in_headlines(transport);
968 handle_rpc_reply(transport);
974 exception_error("selectionAssignLabel", e);
979 function selectionToggleUnread(set_state, callback_func, no_error) {
981 var rows = getSelectedArticleIds2();
983 if (rows.length == 0 && !no_error) {
984 alert(__("No articles are selected."));
988 for (i = 0; i < rows.length; i++) {
989 var row = $("RROW-" + rows[i]);
991 var nc = row.className;
992 nc = nc.replace("Unread", "");
993 nc = nc.replace("Selected", "");
995 if (set_state == undefined) {
996 if (row.className.match("Unread")) {
997 row.className = nc + "Selected";
999 row.className = nc + "UnreadSelected";
1002 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1007 if (set_state == false) {
1008 row.className = nc + "Selected";
1010 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1015 if (set_state == true) {
1016 row.className = nc + "UnreadSelected";
1018 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1025 if (rows.length > 0) {
1027 update_local_feedlist_counters();
1031 if (set_state == undefined) {
1033 } else if (set_state == true) {
1035 } else if (set_state == false) {
1039 var query = "?op=rpc&subop=catchupSelected" +
1040 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
1042 notify_progress("Loading, please wait...");
1044 new Ajax.Request("backend.php", {
1046 onComplete: function(transport) {
1047 catchup_callback2(transport, callback_func);
1053 exception_error("selectionToggleUnread", e);
1057 function selectionToggleMarked() {
1060 var rows = getSelectedArticleIds2();
1062 if (rows.length == 0) {
1063 alert(__("No articles are selected."));
1067 for (i = 0; i < rows.length; i++) {
1068 toggleMark(rows[i], true, true);
1071 update_local_feedlist_counters();
1073 if (rows.length > 0) {
1075 var query = "?op=rpc&subop=markSelected&ids=" +
1076 param_escape(rows.toString()) + "&cmode=2";
1078 query = query + "&afid=" + getActiveFeedId();
1080 query = query + "&omode=lc";
1082 new Ajax.Request("backend.php", {
1084 onComplete: function(transport) {
1085 handle_rpc_reply(transport);
1091 exception_error("selectionToggleMarked", e);
1095 function selectionTogglePublished() {
1098 var rows = getSelectedArticleIds2();
1100 if (rows.length == 0) {
1101 alert(__("No articles are selected."));
1105 for (i = 0; i < rows.length; i++) {
1106 togglePub(rows[i], true, true);
1109 if (rows.length > 0) {
1111 var query = "?op=rpc&subop=publishSelected&ids=" +
1112 param_escape(rows.toString()) + "&cmode=2";
1114 query = query + "&afid=" + getActiveFeedId();
1116 query = query + "&omode=lc";
1118 new Ajax.Request("backend.php", {
1120 onComplete: function(transport) {
1121 handle_rpc_reply(transport);
1127 exception_error("selectionToggleMarked", e);
1131 function cdmGetSelectedArticles() {
1132 var sel_articles = new Array();
1133 var container = $("headlinesInnerContainer");
1135 for (i = 0; i < container.childNodes.length; i++) {
1136 var child = container.childNodes[i];
1138 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
1139 var c_id = child.id.replace("RROW-", "");
1140 sel_articles.push(c_id);
1144 return sel_articles;
1147 function cdmGetVisibleArticles() {
1148 var sel_articles = new Array();
1149 var container = $("headlinesInnerContainer");
1151 if (!container) return sel_articles;
1153 for (i = 0; i < container.childNodes.length; i++) {
1154 var child = container.childNodes[i];
1156 if (child.id && child.id.match("RROW-")) {
1157 var c_id = child.id.replace("RROW-", "");
1158 sel_articles.push(c_id);
1162 return sel_articles;
1165 function cdmGetUnreadArticles() {
1166 var sel_articles = new Array();
1167 var container = $("headlinesInnerContainer");
1169 for (i = 0; i < container.childNodes.length; i++) {
1170 var child = container.childNodes[i];
1172 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
1173 var c_id = child.id.replace("RROW-", "");
1174 sel_articles.push(c_id);
1178 return sel_articles;
1182 // mode = all,none,unread
1183 function cdmSelectArticles(mode) {
1184 var container = $("headlinesInnerContainer");
1186 for (i = 0; i < container.childNodes.length; i++) {
1187 var child = container.childNodes[i];
1189 if (child.id && child.id.match("RROW-")) {
1190 var aid = child.id.replace("RROW-", "");
1192 var cb = $("RCHK-" + aid);
1194 if (mode == "all") {
1195 if (!child.className.match("Selected")) {
1196 child.className = child.className + "Selected";
1199 } else if (mode == "unread") {
1200 if (child.className.match("Unread") && !child.className.match("Selected")) {
1201 child.className = child.className + "Selected";
1205 child.className = child.className.replace("Selected", "");
1212 function catchupPage() {
1214 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1216 var str = __("Mark all visible articles in %s as read?");
1218 str = str.replace("%s", fn);
1220 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1224 if ($("headlinesList")) {
1225 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1226 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1227 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1229 cdmSelectArticles('all');
1230 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1231 cdmSelectArticles('none');
1235 function deleteSelection() {
1239 var rows = getSelectedArticleIds2();
1241 if (rows.length == 0) {
1242 alert(__("No articles are selected."));
1246 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1250 if (getActiveFeedId() != 0) {
1251 str = __("Delete %d selected articles in %s?");
1253 str = __("Delete %d selected articles?");
1256 str = str.replace("%d", rows.length);
1257 str = str.replace("%s", fn);
1259 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1263 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
1267 new Ajax.Request("backend.php", {
1269 onComplete: function(transport) {
1274 exception_error("deleteSelection", e);
1278 function archiveSelection() {
1282 var rows = getSelectedArticleIds2();
1284 if (rows.length == 0) {
1285 alert(__("No articles are selected."));
1289 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1293 if (getActiveFeedId() != 0) {
1294 str = __("Archive %d selected articles in %s?");
1297 str = __("Move %d archived articles back?");
1301 str = str.replace("%d", rows.length);
1302 str = str.replace("%s", fn);
1304 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1308 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1312 for (var i = 0; i < rows.length; i++) {
1313 cache_invalidate(rows[i]);
1316 new Ajax.Request("backend.php", {
1318 onComplete: function(transport) {
1323 exception_error("archiveSelection", e);
1327 function catchupSelection() {
1331 var rows = getSelectedArticleIds2();
1333 if (rows.length == 0) {
1334 alert(__("No articles are selected."));
1338 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1340 var str = __("Mark %d selected articles in %s as read?");
1342 str = str.replace("%d", rows.length);
1343 str = str.replace("%s", fn);
1345 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1349 if ($("headlinesList")) {
1350 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1352 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1356 exception_error("catchupSelection", e);
1360 function editArticleTags(id, feed_id, cdm_enabled) {
1361 displayDlg('editArticleTags', id,
1363 $("tags_str").focus();
1365 new Ajax.Autocompleter('tags_str', 'tags_choices',
1366 "backend.php?op=rpc&subop=completeTags",
1367 { tokens: ',', paramName: "search" });
1371 function editTagsSave() {
1373 notify_progress("Saving article tags...");
1375 var form = document.forms["tag_edit_form"];
1377 var query = Form.serialize("tag_edit_form");
1379 query = "?op=rpc&subop=setArticleTags&" + query;
1381 //console.log(query);
1383 new Ajax.Request("backend.php", {
1385 onComplete: function(transport) {
1387 //console.log("tags saved...");
1392 if (tagsAreDisplayed()) {
1393 _reload_feedlist_after_view = true;
1396 if (transport.responseXML) {
1397 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1400 var id = tags_str.getAttribute("id");
1403 var tags = $("ATSTR-" + id);
1405 tags.innerHTML = tags_str.firstChild.nodeValue;
1408 cache_invalidate(id);
1414 exception_error("editTagsSave", e);
1419 function editTagsInsert() {
1422 var form = document.forms["tag_edit_form"];
1424 var found_tags = form.found_tags;
1425 var tags_str = form.tags_str;
1427 var tag = found_tags[found_tags.selectedIndex].value;
1429 if (tags_str.value.length > 0 &&
1430 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1432 tags_str.value = tags_str.value + ", ";
1435 tags_str.value = tags_str.value + tag + ", ";
1437 found_tags.selectedIndex = 0;
1440 exception_error("editTagsInsert", e);
1444 function cdmScrollViewport(where) {
1445 console.log("cdmScrollViewport: " + where);
1447 var ctr = $("headlinesInnerContainer");
1451 if (where == "bottom") {
1452 ctr.scrollTop = ctr.scrollHeight;
1454 ctr.scrollTop = where;
1458 function cdmArticleIsBelowViewport(id) {
1460 var ctr = $("headlinesInnerContainer");
1461 var e = $("RROW-" + id);
1463 if (!e || !ctr) return;
1465 // article starts below viewport
1467 if (ctr.scrollTop < e.offsetTop) {
1474 exception_error("cdmArticleIsVisible", e);
1478 function cdmArticleIsAboveViewport(id) {
1480 var ctr = $("headlinesInnerContainer");
1481 var e = $("RROW-" + id);
1483 if (!e || !ctr) return;
1485 // article starts above viewport
1487 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1494 exception_error("cdmArticleIsVisible", e);
1498 function cdmScrollToArticleId(id) {
1500 var ctr = $("headlinesInnerContainer");
1501 var e = $("RROW-" + id);
1503 if (!e || !ctr) return;
1505 ctr.scrollTop = e.offsetTop;
1508 exception_error("cdmScrollToArticleId", e);
1512 function cdmArticleIsActuallyVisible(id) {
1514 var ctr = $("headlinesInnerContainer");
1515 var e = $("RROW-" + id);
1517 if (!e || !ctr) return;
1519 // article fits in viewport OR article is longer than viewport and
1520 // its bottom is visible
1522 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1523 ctr.scrollTop + ctr.offsetHeight) {
1527 } else if (e.offsetHeight > ctr.offsetHeight &&
1528 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1529 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1538 exception_error("cdmArticleIsVisible", e);
1542 function cdmWatchdog() {
1546 var ctr = $("headlinesInnerContainer");
1550 var ids = new Array();
1552 var e = ctr.firstChild;
1555 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1556 e.id.match("RROW-")) {
1558 // article fits in viewport OR article is longer than viewport and
1559 // its bottom is visible
1561 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1562 ctr.scrollTop + ctr.offsetHeight) {
1564 // console.log(e.id + " is visible " + e.offsetTop + "." +
1565 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1566 // (ctr.scrollTop + ctr.offsetHeight));
1568 ids.push(e.id.replace("RROW-", ""));
1570 } else if (e.offsetHeight > ctr.offsetHeight &&
1571 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1572 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1574 ids.push(e.id.replace("RROW-", ""));
1578 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1580 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1581 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1583 ids.push(e.id.replace("RROW-", ""));
1592 console.log("cdmWatchdog, ids= " + ids.toString());
1594 if (ids.length > 0) {
1596 for (var i = 0; i < ids.length; i++) {
1597 var e = $("RROW-" + ids[i]);
1599 e.className = e.className.replace("Unread", "");
1603 var query = "?op=rpc&subop=catchupSelected" +
1604 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1606 new Ajax.Request("backend.php", {
1608 onComplete: function(transport) {
1609 handle_rpc_reply(transport);
1614 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1617 exception_error("cdmWatchdog", e);
1623 function cache_inject(id, article, param) {
1626 if (!cache_check_param(id, param)) {
1627 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1629 var date = new Date();
1630 var ts = Math.round(date.getTime() / 1000);
1634 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1635 [id, article, param, ts]);
1640 cache_obj["id"] = id;
1641 cache_obj["data"] = article;
1642 cache_obj["param"] = param;
1644 if (param) id = id + ":" + param;
1646 cache_added["TS:" + id] = ts;
1648 if (has_local_storage())
1649 localStorage.setItem(id, JSON.stringify(cache_obj));
1651 article_cache.push(cache_obj);
1655 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1658 exception_error("cache_inject", e);
1662 function cache_find(id) {
1665 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
1668 if (rs.isValidRow()) {
1669 var a = rs.field(0);
1678 if (has_local_storage()) {
1679 var cache_obj = localStorage.getItem(id);
1682 cache_obj = JSON.parse(cache_obj);
1685 return cache_obj['data'];
1689 for (var i = 0; i < article_cache.length; i++) {
1690 if (article_cache[i]["id"] == id) {
1691 return article_cache[i]["data"];
1699 function cache_find_param(id, param) {
1702 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1706 if (rs.isValidRow()) {
1716 if (has_local_storage()) {
1718 if (param) id = id + ":" + param;
1720 var cache_obj = localStorage.getItem(id);
1723 cache_obj = JSON.parse(cache_obj);
1726 return cache_obj['data'];
1730 for (var i = 0; i < article_cache.length; i++) {
1731 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1732 return article_cache[i]["data"];
1740 function cache_check(id) {
1743 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1747 if (rs.isValidRow()) {
1748 a = rs.field(0) != "0";
1756 if (has_local_storage()) {
1757 if (localStorage.getItem(id))
1760 for (var i = 0; i < article_cache.length; i++) {
1761 if (article_cache[i]["id"] == id) {
1770 function cache_check_param(id, param) {
1773 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1777 if (rs.isValidRow()) {
1778 a = rs.field(0) != "0";
1787 if (has_local_storage()) {
1789 if (param) id = id + ":" + param;
1791 if (localStorage.getItem(id))
1795 for (var i = 0; i < article_cache.length; i++) {
1796 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1805 function cache_expire() {
1807 var date = new Date();
1808 var ts = Math.round(date.getTime() / 1000);
1810 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1811 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1812 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1816 if (has_local_storage()) {
1818 var date = new Date();
1819 var timestamp = Math.round(date.getTime() / 1000);
1821 for (var i = 0; i < localStorage.length; i++) {
1823 var id = localStorage.key(i);
1825 if (timestamp - cache_added["TS:" + id] > 180) {
1826 localStorage.removeItem(id);
1831 while (article_cache.length > 25) {
1832 article_cache.shift();
1838 function cache_flush() {
1840 db.execute("DELETE FROM cache");
1841 } else if (has_local_storage()) {
1842 localStorage.clear();
1844 article_cache = new Array();
1848 function cache_invalidate(id) {
1852 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1853 return rs.rowsAffected != 0;
1856 if (has_local_storage()) {
1860 for (var i = 0; i < localStorage.length; i++) {
1861 var key = localStorage.key(i);
1863 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1865 if (key == id || key.indexOf(id + ":") == 0) {
1866 localStorage.removeItem(key);
1877 while (i < article_cache.length) {
1878 if (article_cache[i]["id"] == id) {
1879 //console.log("cache_invalidate: removed id " + id);
1880 article_cache.splice(i, 1);
1888 //console.log("cache_invalidate: id not found: " + id);
1891 exception_error("cache_invalidate", e);
1895 function getActiveArticleId() {
1896 return active_post_id;
1899 function preloadBatchedArticles() {
1902 var query = "?op=rpc&subop=getArticles&ids=" +
1903 preload_id_batch.toString();
1905 new Ajax.Request("backend.php", {
1907 onComplete: function(transport) {
1909 preload_id_batch = [];
1911 var articles = transport.responseXML.getElementsByTagName("article");
1913 for (var i = 0; i < articles.length; i++) {
1914 var id = articles[i].getAttribute("id");
1915 if (!cache_check(id)) {
1916 cache_inject(id, articles[i].firstChild.nodeValue);
1917 console.log("preloaded article: " + id);
1923 exception_error("preloadBatchedArticles", e);
1927 function preloadArticleUnderPointer(id) {
1929 if (getInitParam("bw_limit") == "1") return;
1931 if (post_under_pointer == id && !cache_check(id)) {
1933 console.log("trying to preload article " + id);
1935 var neighbor_ids = getRelativePostIds(id, 1);
1937 /* only request uncached articles */
1939 if (preload_id_batch.indexOf(id) == -1) {
1940 for (var i = 0; i < neighbor_ids.length; i++) {
1941 if (!cache_check(neighbor_ids[i])) {
1942 preload_id_batch.push(neighbor_ids[i]);
1947 if (preload_id_batch.indexOf(id) == -1)
1948 preload_id_batch.push(id);
1950 //console.log("preload ids batch: " + preload_id_batch.toString());
1952 window.clearTimeout(preload_timeout_id);
1953 preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
1957 exception_error("preloadArticleUnderPointer", e);
1961 function postMouseIn(id) {
1963 if (post_under_pointer != id) {
1964 post_under_pointer = id;
1966 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1971 exception_error("postMouseIn", e);
1975 function postMouseOut(id) {
1977 post_under_pointer = false;
1979 exception_error("postMouseOut", e);
1983 function headlines_scroll_handler() {
1986 var e = $("headlinesInnerContainer");
1988 var toolbar_form = document.forms["main_toolbar_form"];
1990 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1991 // _infscroll_disable);
1993 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1994 if (!_infscroll_disable) {
2000 exception_error("headlines_scroll_handler", e);
2004 function catchupRelativeToArticle(below) {
2009 if (!getActiveArticleId()) {
2010 alert(__("No article is selected."));
2016 if ($("headlinesList")) {
2017 visible_ids = getVisibleHeadlineIds();
2019 visible_ids = cdmGetVisibleArticles();
2022 var ids_to_mark = new Array();
2025 for (var i = 0; i < visible_ids.length; i++) {
2026 if (visible_ids[i] != getActiveArticleId()) {
2027 var e = $("RROW-" + visible_ids[i]);
2029 if (e && e.className.match("Unread")) {
2030 ids_to_mark.push(visible_ids[i]);
2037 for (var i = visible_ids.length-1; i >= 0; i--) {
2038 if (visible_ids[i] != getActiveArticleId()) {
2039 var e = $("RROW-" + visible_ids[i]);
2041 if (e && e.className.match("Unread")) {
2042 ids_to_mark.push(visible_ids[i]);
2050 if (ids_to_mark.length == 0) {
2051 alert(__("No articles found to mark"));
2053 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
2055 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
2057 for (var i = 0; i < ids_to_mark.length; i++) {
2058 var e = $("RROW-" + ids_to_mark[i]);
2059 e.className = e.className.replace("Unread", "");
2062 var query = "?op=rpc&subop=catchupSelected" +
2063 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
2065 new Ajax.Request("backend.php", {
2067 onComplete: function(transport) {
2068 catchup_callback2(transport);
2075 exception_error("catchupRelativeToArticle", e);
2079 function cdmExpandArticle(id) {
2082 var elem = $("CICD-" + active_post_id);
2084 if (id == active_post_id && Element.visible(elem))
2087 cdmSelectArticles("none");
2089 var old_offset = $("RROW-" + id).offsetTop;
2091 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
2093 Element.show("CEXC-" + active_post_id);
2096 active_post_id = id;
2098 elem = $("CICD-" + id);
2100 if (!Element.visible(elem)) {
2102 Element.hide("CEXC-" + id);
2105 var new_offset = $("RROW-" + id).offsetTop;
2107 $("headlinesInnerContainer").scrollTop += (new_offset-old_offset);
2109 if ($("RROW-" + id).offsetTop != old_offset)
2110 $("headlinesInnerContainer").scrollTop = new_offset;
2112 toggleUnread(id, 0, true);
2116 exception_error("cdmExpandArticle", e);
2122 function fixHeadlinesOrder(ids) {
2124 for (var i = 0; i < ids.length; i++) {
2125 var e = $("RROW-" + ids[i]);
2129 e.className = e.className.replace("even", "odd");
2131 e.className = e.className.replace("odd", "even");
2136 exception_error("fixHeadlinesOrder", e);
2140 function hideReadHeadlines() {
2144 var vis_ids = new Array();
2146 if ($("headlinesList")) {
2147 ids = getVisibleHeadlineIds();
2149 ids = cdmGetVisibleArticles();
2152 var read_headlines_visible = true;
2154 for (var i = 0; i < ids.length; i++) {
2155 var row = $("RROW-" + ids[i]);
2157 if (row && row.className) {
2158 if (read_headlines_visible) {
2159 if (row.className.match("Unread") || row.className.match("Selected")) {
2161 vis_ids.push(ids[i]);
2163 //Effect.Fade(row, {duration : 0.3});
2168 vis_ids.push(ids[i]);
2173 fixHeadlinesOrder(vis_ids);
2175 read_headlines_visible = !read_headlines_visible;
2178 exception_error("hideReadHeadlines", e);
2182 function invertHeadlineSelection() {
2184 var rows = new Array();
2188 r = document.getElementsByTagName("TR");
2190 r = document.getElementsByTagName("DIV");
2193 for (var i = 0; i < r.length; i++) {
2194 if (r[i].id && r[i].id.match("RROW-")) {
2199 for (var i = 0; i < rows.length; i++) {
2200 var nc = rows[i].className;
2201 var id = rows[i].id.replace("RROW-", "");
2202 var cb = $("RCHK-" + id);
2204 if (!rows[i].className.match("Selected")) {
2205 nc = nc + "Selected";
2208 nc = nc.replace("Selected", "");
2212 rows[i].className = nc;
2217 exception_error("invertHeadlineSelection", e);
2221 function getArticleUnderPointer() {
2222 return post_under_pointer;
2225 function zoomToArticle(id) {
2227 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2229 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2232 exception_error("zoomToArticle", e);
2236 function scrollArticle(offset) {
2239 var ci = $("content-insert");
2241 ci.scrollTop += offset;
2244 var hi = $("headlinesInnerContainer");
2246 hi.scrollTop += offset;
2251 exception_error("scrollArticle", e);
2255 function show_labels_in_headlines(transport) {
2257 if (transport.responseXML) {
2258 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2260 var elems = info.getElementsByTagName("entry");
2262 for (var l = 0; l < elems.length; l++) {
2263 var e_id = elems[l].getAttribute("id");
2267 var ctr = $("HLLCTR-" + e_id);
2270 ctr.innerHTML = elems[l].firstChild.nodeValue;
2278 exception_error("show_labels_in_headlines", e);
2283 function toggleHeadlineActions() {
2285 var e = $("headlineActionsBody");
2286 var p = $("headlineActionsDrop");
2288 if (!Element.visible(e)) {
2295 e.style.left = (p.offsetLeft + 1) + "px";
2296 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
2299 exception_error("toggleHeadlineActions", e);
2303 function publishWithNote(id, def_note) {
2305 if (!def_note) def_note = '';
2307 var note = prompt(__("Please enter a note for this article:"), def_note);
2309 if (note != undefined) {
2310 togglePub(id, false, false, note);
2314 exception_error("publishWithNote", e);
2318 function emailArticle(id) {
2321 var ids = getSelectedArticleIds2();
2323 if (ids.length == 0) {
2324 alert(__("No articles are selected."));
2328 id = ids.toString();
2331 displayDlg('emailArticle', id,
2333 document.forms['article_email_form'].destination.focus();
2335 new Ajax.Autocompleter('destination', 'destination_choices',
2336 "backend.php?op=rpc&subop=completeEmails",
2337 { tokens: '', paramName: "search" });
2342 exception_error("emailArticle", e);
2346 function emailArticleDo() {
2348 var f = document.forms['article_email_form'];
2350 if (f.destination.value == "") {
2351 alert("Please fill in the destination email.");
2355 if (f.subject.value == "") {
2356 alert("Please fill in the subject.");
2360 var query = Form.serialize("article_email_form");
2362 // console.log(query);
2364 new Ajax.Request("backend.php", {
2366 onComplete: function(transport) {
2369 var error = transport.responseXML.getElementsByTagName('error')[0];
2372 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
2374 notify_info('Your message has been sent.');
2379 exception_error("sendEmailDo", e);
2385 exception_error("emailArticleDo", e);
2389 function cdmDismissArticle(id) {
2391 var elem = $("RROW-" + id);
2393 toggleUnread(id, 0, true);
2395 new Effect.Fade(elem, {duration : 0.5});
2398 exception_error("cdmDismissArticle", e);
2402 function cdmDismissSelectedArticles() {
2405 var ids = getSelectedArticleIds2();
2407 for (var i = 0; i < ids.length; i++) {
2408 var elem = $("RROW-" + ids[i]);
2409 new Effect.Fade(elem, {duration : 0.5});
2413 selectionToggleUnread(false);
2416 exception_error("cdmDismissArticle", e);