1 var active_post_id = false;
2 var last_article_view = false;
3 var active_real_feed_id = false;
5 var _cdm_wd_timeout = false;
6 var _cdm_wd_vishist = new Array();
8 var article_cache = new Array();
10 var vgroup_last_feed = false;
11 var post_under_pointer = false;
13 var last_requested_article = false;
15 var preload_id_batch = [];
16 var preload_timeout_id = false;
20 function catchup_callback2(transport, callback) {
22 console.log("catchup_callback2 " + transport + ", " + callback);
24 handle_rpc_reply(transport);
26 setTimeout(callback, 10);
29 exception_error("catchup_callback2", e, transport);
33 function headlines_callback2(transport, feed_cur_page) {
36 if (!handle_rpc_reply(transport)) return;
38 loading_set_progress(100);
40 console.log("headlines_callback2 [page=" + feed_cur_page + "]");
42 if (!transport_error_check(transport)) return;
47 if (transport.responseXML) {
48 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
50 is_cat = headlines.getAttribute("is_cat");
51 feed_id = headlines.getAttribute("id");
52 setActiveFeedId(feed_id, is_cat);
56 var update_btn = document.forms["main_toolbar_form"].update;
58 update_btn.disabled = !(feed_id >= 0 && !is_cat);
61 if (feed_cur_page == 0) {
62 $("headlines-frame").scrollTop = 0;
66 if (transport.responseXML) {
67 var response = transport.responseXML;
69 var headlines = response.getElementsByTagName("headlines")[0];
71 var headlines_content = headlines.getElementsByTagName("content")[0];
72 var headlines_toolbar = headlines.getElementsByTagName("toolbar")[0];
74 var headlines_info = response.getElementsByTagName("headlines-info")[0];
77 headlines_info = JSON.parse(headlines_info.firstChild.nodeValue);
79 console.error("didn't find headlines-info object in response");
83 var headlines_count = headlines_info.count;
84 var headlines_unread = headlines_info.unread;
85 var disable_cache = headlines_info.disable_cache;
87 vgroup_last_feed = headlines_info.vgroup_last_feed;
89 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
90 _infscroll_disable = 1;
92 _infscroll_disable = 0;
95 var counters = response.getElementsByTagName("counters")[0];
96 var articles = response.getElementsByTagName("article");
97 var runtime_info = response.getElementsByTagName("runtime-info");
99 if (feed_cur_page == 0) {
101 $("headlinesInnerContainer").innerHTML = headlines_content.firstChild.nodeValue;
102 $("headlines-toolbar").innerHTML = headlines_toolbar.firstChild.nodeValue;
104 dojo.parser.parse("headlines-toolbar");
105 //dijit.byId("main").resize();
107 var cache_prefix = "";
115 cache_invalidate(cache_prefix + feed_id);
117 if (!disable_cache) {
118 cache_inject(cache_prefix + feed_id,
119 $("headlines-frame").innerHTML, headlines_unread);
123 console.warn("headlines_callback: returned no data");
124 $('headlinesInnerContainer').innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
129 if (headlines_count > 0) {
130 console.log("adding some more headlines...");
132 c = $("headlinesInnerContainer");
134 var ids = getSelectedArticleIds2();
136 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
138 console.log("restore selected ids: " + ids);
140 for (var i = 0; i < ids.length; i++) {
141 markHeadline(ids[i]);
145 console.log("no new headlines received");
148 console.warn("headlines_callback: returned no data");
149 notify_error("Error while trying to load more headlines");
155 for (var i = 0; i < articles.length; i++) {
156 var a_id = articles[i].getAttribute("id");
157 //console.log("found id: " + a_id);
158 cache_inject(a_id, articles[i].firstChild.nodeValue);
161 console.log("no cached articles received");
165 parse_counters(counters);
170 parse_runtime_info(runtime_info[0]);
174 console.warn("headlines_callback: returned no XML object");
175 $('headlinesInnerContainer').innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
179 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
182 getActiveFeedId() != -3 &&
183 getInitParam("cdm_auto_catchup") == 1) {
184 console.log("starting CDM watchdog");
185 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
186 _cdm_wd_vishist = new Array();
188 console.log("not in CDM mode or watchdog disabled");
191 _feed_cur_page = feed_cur_page;
192 _infscroll_request_sent = 0;
199 exception_error("headlines_callback2", e, transport);
203 function render_article(article) {
205 var f = $("content-frame");
210 dijit.byId("headlines-wrap-inner").addChild(
211 dijit.byId("content-insert"));
213 var fi = $("content-insert");
219 fi.innerHTML = article;
221 // article.evalScripts();
224 exception_error("render_article", e);
228 function showArticleInHeadlines(id) {
232 selectArticles("none");
234 var crow = $("RROW-" + id);
238 var article_is_unread = crow.hasClassName("Unread");
240 crow.removeClassName("Unread");
242 selectArticles('none');
244 var upd_img_pic = $("FUPDPIC-" + id);
246 var cache_prefix = "";
248 if (activeFeedIsCat()) {
254 var view_mode = false;
257 view_mode = document.forms['main_toolbar_form'].view_mode;
258 view_mode = view_mode[view_mode.selectedIndex].value;
263 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
264 upd_img_pic.src.match("fresh_sign.png"))) {
266 upd_img_pic.src = "images/blank_icon.gif";
268 cache_invalidate(cache_prefix + getActiveFeedId());
270 cache_inject(cache_prefix + getActiveFeedId(),
271 $("headlines-frame").innerHTML,
272 get_feed_unread(getActiveFeedId()));
274 } else if (article_is_unread && view_mode == "all_articles") {
276 cache_invalidate(cache_prefix + getActiveFeedId());
278 cache_inject(cache_prefix + getActiveFeedId(),
279 $("headlines-frame").innerHTML,
280 get_feed_unread(getActiveFeedId())-1);
282 } else if (article_is_unread) {
283 cache_invalidate(cache_prefix + getActiveFeedId());
288 if (article_is_unread)
289 _force_scheduled_update = true;
292 exception_error("showArticleInHeadlines", e);
296 function article_callback2(transport, id) {
298 console.log("article_callback2 " + id);
300 if (!handle_rpc_reply(transport)) return;
302 if (transport.responseXML) {
304 if (!transport_error_check(transport)) return;
306 var upic = $('FUPDPIC-' + id);
309 upic.src = 'images/blank_icon.gif';
312 if (id != last_requested_article) {
313 console.log("requested article id is out of sequence, aborting");
317 // active_post_id = id;
319 //console.log("looking for articles to cache...");
321 var articles = transport.responseXML.getElementsByTagName("article");
323 for (var i = 0; i < articles.length; i++) {
324 var a_id = articles[i].getAttribute("id");
326 //console.log("found id: " + a_id);
328 if (a_id == active_post_id) {
329 //console.log("active article, rendering...");
330 render_article(articles[i].firstChild.nodeValue);
333 cache_inject(a_id, articles[i].firstChild.nodeValue);
337 // showArticleInHeadlines(id);
339 var reply = transport.responseXML.firstChild.firstChild;
342 console.warn("article_callback: returned no XML object");
343 //var f = $("content-frame");
344 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
347 var date = new Date();
348 last_article_view = date.getTime() / 1000;
354 exception_error("article_callback2", e, transport);
360 console.log("loading article: " + id);
362 var cached_article = cache_find(id);
364 console.log("cache check result: " + (cached_article != false));
369 var query = "?op=view&id=" + param_escape(id);
371 var neighbor_ids = getRelativePostIds(active_post_id);
373 /* only request uncached articles */
375 var cids_to_request = Array();
377 for (var i = 0; i < neighbor_ids.length; i++) {
378 if (!cache_check(neighbor_ids[i])) {
379 cids_to_request.push(neighbor_ids[i]);
383 console.log("additional ids: " + cids_to_request.toString());
385 query = query + "&cids=" + cids_to_request.toString();
387 var crow = $("RROW-" + id);
388 var article_is_unread = crow.hasClassName("Unread");
391 showArticleInHeadlines(id);
393 if (!cached_article) {
395 var upic = $('FUPDPIC-' + id);
398 upic.src = getInitParam("sign_progress");
401 } else if (cached_article && article_is_unread) {
403 query = query + "&mode=prefetch";
405 render_article(cached_article);
407 } else if (cached_article) {
409 query = query + "&mode=prefetch_old";
410 render_article(cached_article);
416 last_requested_article = id;
418 new Ajax.Request("backend.php", {
420 onComplete: function(transport) {
421 article_callback2(transport, id);
427 exception_error("view", e);
432 return toggleMark(id);
436 return togglePub(id);
439 function toggleMark(id, client_only) {
441 var query = "?op=rpc&id=" + id + "&subop=mark";
443 var img = $("FMPIC-" + id);
447 if (img.src.match("mark_unset")) {
448 img.src = img.src.replace("mark_unset", "mark_set");
449 img.alt = __("Unstar article");
450 query = query + "&mark=1";
453 img.src = img.src.replace("mark_set", "mark_unset");
454 img.alt = __("Star article");
455 query = query + "&mark=0";
459 new Ajax.Request("backend.php", {
461 onComplete: function(transport) {
462 handle_rpc_reply(transport);
467 exception_error("toggleMark", e);
471 function togglePub(id, client_only, no_effects, note) {
473 var query = "?op=rpc&id=" + id + "&subop=publ";
475 if (note != undefined) {
476 query = query + "¬e=" + param_escape(note);
478 query = query + "¬e=undefined";
481 var img = $("FPPIC-" + id);
485 if (img.src.match("pub_unset") || note != undefined) {
486 img.src = img.src.replace("pub_unset", "pub_set");
487 img.alt = __("Unpublish article");
488 query = query + "&pub=1";
491 img.src = img.src.replace("pub_set", "pub_unset");
492 img.alt = __("Publish article");
494 query = query + "&pub=0";
498 new Ajax.Request("backend.php", {
500 onComplete: function(transport) {
501 handle_rpc_reply(transport);
503 var note = transport.responseXML.getElementsByTagName("note")[0];
506 var note_id = note.getAttribute("id");
507 var note_size = note.getAttribute("size");
508 var note_content = note.firstChild.nodeValue;
510 var container = $('POSTNOTE-' + note_id);
512 cache_invalidate(note_id);
515 if (note_size == "0") {
516 Element.hide(container);
518 container.innerHTML = note_content;
519 Element.show(container);
528 exception_error("togglePub", e);
532 function moveToPost(mode) {
536 var rows = getVisibleArticleIds();
541 if (!$('RROW-' + active_post_id)) {
542 active_post_id = false;
545 if (active_post_id == false) {
546 next_id = getFirstVisibleHeadlineId();
547 prev_id = getLastVisibleHeadlineId();
549 for (var i = 0; i < rows.length; i++) {
550 if (rows[i] == active_post_id) {
557 if (mode == "next") {
561 cdmExpandArticle(next_id);
562 cdmScrollToArticleId(next_id);
565 correctHeadlinesOffset(next_id);
566 view(next_id, getActiveFeedId());
571 if (mode == "prev") {
574 cdmExpandArticle(prev_id);
575 cdmScrollToArticleId(prev_id);
577 correctHeadlinesOffset(prev_id);
578 view(prev_id, getActiveFeedId());
584 exception_error("moveToPost", e);
588 function toggleSelected(id, force_on) {
591 var cb = $("RCHK-" + id);
592 var row = $("RROW-" + id);
595 if (row.hasClassName('Selected') && !force_on) {
596 row.removeClassName('Selected');
597 if (cb) cb.checked = false;
599 row.addClassName('Selected');
600 if (cb) cb.checked = true;
604 exception_error("toggleSelected", e);
608 function toggleUnread_afh(effect) {
611 var elem = effect.element;
612 elem.style.backgroundColor = "";
615 exception_error("toggleUnread_afh", e);
619 function toggleUnread(id, cmode, effect) {
622 var row = $("RROW-" + id);
624 if (cmode == undefined || cmode == 2) {
625 if (row.hasClassName("Unread")) {
626 row.removeClassName("Unread");
629 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
630 afterFinish: toggleUnread_afh,
631 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
635 row.addClassName("Unread");
638 } else if (cmode == 0) {
640 row.removeClassName("Unread");
643 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
644 afterFinish: toggleUnread_afh,
645 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
648 } else if (cmode == 1) {
649 row.addClassName("Unread");
652 if (cmode == undefined) cmode = 2;
654 var query = "?op=rpc&subop=catchupSelected" +
655 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
657 // notify_progress("Loading, please wait...");
659 new Ajax.Request("backend.php", {
661 onComplete: function(transport) {
662 handle_rpc_reply(transport);
668 exception_error("toggleUnread", e);
672 function selectionRemoveLabel(id) {
675 var ids = getSelectedArticleIds2();
677 if (ids.length == 0) {
678 alert(__("No articles are selected."));
682 // var ok = confirm(__("Remove selected articles from label?"));
686 var query = "?op=rpc&subop=removeFromLabel&ids=" +
687 param_escape(ids.toString()) + "&lid=" + param_escape(id);
691 // notify_progress("Loading, please wait...");
693 cache_invalidate("F:" + (-11 - id));
695 new Ajax.Request("backend.php", {
697 onComplete: function(transport) {
698 show_labels_in_headlines(transport);
699 handle_rpc_reply(transport);
705 exception_error("selectionAssignLabel", e);
710 function selectionAssignLabel(id) {
713 var ids = getSelectedArticleIds2();
715 if (ids.length == 0) {
716 alert(__("No articles are selected."));
720 // var ok = confirm(__("Assign selected articles to label?"));
724 cache_invalidate("F:" + (-11 - id));
726 var query = "?op=rpc&subop=assignToLabel&ids=" +
727 param_escape(ids.toString()) + "&lid=" + param_escape(id);
731 // notify_progress("Loading, please wait...");
733 new Ajax.Request("backend.php", {
735 onComplete: function(transport) {
736 show_labels_in_headlines(transport);
737 handle_rpc_reply(transport);
743 exception_error("selectionAssignLabel", e);
748 function selectionToggleUnread(set_state, callback_func, no_error) {
750 var rows = getSelectedArticleIds2();
752 if (rows.length == 0 && !no_error) {
753 alert(__("No articles are selected."));
757 for (i = 0; i < rows.length; i++) {
758 var row = $("RROW-" + rows[i]);
760 if (set_state == undefined) {
761 if (row.hasClassName("Unread")) {
762 row.removeClassName("Unread");
764 row.addClassName("Unread");
768 if (set_state == false) {
769 row.removeClassName("Unread");
772 if (set_state == true) {
773 row.addClassName("Unread");
778 if (rows.length > 0) {
782 if (set_state == undefined) {
784 } else if (set_state == true) {
786 } else if (set_state == false) {
790 var query = "?op=rpc&subop=catchupSelected" +
791 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
793 notify_progress("Loading, please wait...");
795 new Ajax.Request("backend.php", {
797 onComplete: function(transport) {
798 catchup_callback2(transport, callback_func);
804 exception_error("selectionToggleUnread", e);
808 function selectionToggleMarked() {
811 var rows = getSelectedArticleIds2();
813 if (rows.length == 0) {
814 alert(__("No articles are selected."));
818 for (i = 0; i < rows.length; i++) {
819 toggleMark(rows[i], true, true);
822 if (rows.length > 0) {
824 var query = "?op=rpc&subop=markSelected&ids=" +
825 param_escape(rows.toString()) + "&cmode=2";
827 new Ajax.Request("backend.php", {
829 onComplete: function(transport) {
830 handle_rpc_reply(transport);
836 exception_error("selectionToggleMarked", e);
840 function selectionTogglePublished() {
843 var rows = getSelectedArticleIds2();
845 if (rows.length == 0) {
846 alert(__("No articles are selected."));
850 for (i = 0; i < rows.length; i++) {
851 togglePub(rows[i], true, true);
854 if (rows.length > 0) {
856 var query = "?op=rpc&subop=publishSelected&ids=" +
857 param_escape(rows.toString()) + "&cmode=2";
859 new Ajax.Request("backend.php", {
861 onComplete: function(transport) {
862 handle_rpc_reply(transport);
868 exception_error("selectionToggleMarked", e);
872 function getSelectedArticleIds2() {
876 $$("#headlinesInnerContainer > div[id*=RROW][class*=Selected]").each(
878 rv.push(child.id.replace("RROW-", ""));
884 function getLoadedArticleIds() {
887 var children = $$("#headlinesInnerContainer > div[id*=RROW-]");
889 children.each(function(child) {
890 rv.push(child.id.replace("RROW-", ""));
897 // mode = all,none,unread,invert
898 function selectArticles(mode) {
901 var children = $$("#headlinesInnerContainer > div[id*=RROW]");
903 children.each(function(child) {
904 var id = child.id.replace("RROW-", "");
905 var cb = $("RCHK-" + id);
908 child.addClassName("Selected");
910 } else if (mode == "unread") {
911 if (child.hasClassName("Unread")) {
912 child.addClassName("Selected");
915 child.removeClassName("Selected");
918 } else if (mode == "invert") {
919 if (child.hasClassName("Selected")) {
920 child.removeClassName("Selected");
923 child.addClassName("Selected");
928 child.removeClassName("Selected");
934 exception_error("selectArticles", e);
938 function catchupPage() {
940 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
942 var str = __("Mark all visible articles in %s as read?");
944 str = str.replace("%s", fn);
946 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
950 selectArticles('all');
951 selectionToggleUnread(false, 'viewCurrentFeed()', true)
952 selectArticles('none');
955 function deleteSelection() {
959 var rows = getSelectedArticleIds2();
961 if (rows.length == 0) {
962 alert(__("No articles are selected."));
966 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
970 if (getActiveFeedId() != 0) {
971 str = __("Delete %d selected articles in %s?");
973 str = __("Delete %d selected articles?");
976 str = str.replace("%d", rows.length);
977 str = str.replace("%s", fn);
979 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
983 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
987 new Ajax.Request("backend.php", {
989 onComplete: function(transport) {
994 exception_error("deleteSelection", e);
998 function archiveSelection() {
1002 var rows = getSelectedArticleIds2();
1004 if (rows.length == 0) {
1005 alert(__("No articles are selected."));
1009 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1013 if (getActiveFeedId() != 0) {
1014 str = __("Archive %d selected articles in %s?");
1017 str = __("Move %d archived articles back?");
1021 str = str.replace("%d", rows.length);
1022 str = str.replace("%s", fn);
1024 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1028 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
1032 for (var i = 0; i < rows.length; i++) {
1033 cache_invalidate(rows[i]);
1036 new Ajax.Request("backend.php", {
1038 onComplete: function(transport) {
1043 exception_error("archiveSelection", e);
1047 function catchupSelection() {
1051 var rows = getSelectedArticleIds2();
1053 if (rows.length == 0) {
1054 alert(__("No articles are selected."));
1058 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1060 var str = __("Mark %d selected articles in %s as read?");
1062 str = str.replace("%d", rows.length);
1063 str = str.replace("%s", fn);
1065 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1069 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1072 exception_error("catchupSelection", e);
1076 function editArticleTags(id, feed_id, cdm_enabled) {
1077 displayDlg('editArticleTags', id,
1079 $("tags_str").focus();
1081 new Ajax.Autocompleter('tags_str', 'tags_choices',
1082 "backend.php?op=rpc&subop=completeTags",
1083 { tokens: ',', paramName: "search" });
1087 function editTagsSave() {
1089 notify_progress("Saving article tags...");
1091 var form = document.forms["tag_edit_form"];
1093 var query = Form.serialize("tag_edit_form");
1095 query = "?op=rpc&subop=setArticleTags&" + query;
1099 new Ajax.Request("backend.php", {
1101 onComplete: function(transport) {
1103 //console.log("tags saved...");
1108 if (transport.responseXML) {
1109 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1112 var id = tags_str.getAttribute("id");
1115 var tags = $("ATSTR-" + id);
1117 tags.innerHTML = tags_str.firstChild.nodeValue;
1120 cache_invalidate(id);
1126 exception_error("editTagsSave", e);
1131 function editTagsInsert() {
1134 var form = document.forms["tag_edit_form"];
1136 var found_tags = form.found_tags;
1137 var tags_str = form.tags_str;
1139 var tag = found_tags[found_tags.selectedIndex].value;
1141 if (tags_str.value.length > 0 &&
1142 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1144 tags_str.value = tags_str.value + ", ";
1147 tags_str.value = tags_str.value + tag + ", ";
1149 found_tags.selectedIndex = 0;
1152 exception_error("editTagsInsert", e);
1156 function cdmScrollToArticleId(id) {
1158 var ctr = $("headlines-frame");
1159 var e = $("RROW-" + id);
1161 if (!e || !ctr) return;
1163 ctr.scrollTop = e.offsetTop;
1166 exception_error("cdmScrollToArticleId", e);
1170 function cdmWatchdog() {
1174 var ctr = $("headlinesInnerContainer");
1178 var ids = new Array();
1180 var e = ctr.firstChild;
1183 if (e.className && e.hasClassName("Unread") && e.id &&
1184 e.id.match("RROW-")) {
1186 // article fits in viewport OR article is longer than viewport and
1187 // its bottom is visible
1189 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1190 ctr.scrollTop + ctr.offsetHeight) {
1192 // console.log(e.id + " is visible " + e.offsetTop + "." +
1193 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1194 // (ctr.scrollTop + ctr.offsetHeight));
1196 ids.push(e.id.replace("RROW-", ""));
1198 } else if (e.offsetHeight > ctr.offsetHeight &&
1199 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1200 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1202 ids.push(e.id.replace("RROW-", ""));
1206 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1208 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1209 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1211 ids.push(e.id.replace("RROW-", ""));
1220 console.log("cdmWatchdog, ids= " + ids.toString());
1222 if (ids.length > 0) {
1224 for (var i = 0; i < ids.length; i++) {
1225 var e = $("RROW-" + ids[i]);
1227 e.removeClassName("Unread");
1231 var query = "?op=rpc&subop=catchupSelected" +
1232 "&cmode=0" + "&ids=" + param_escape(ids.toString());
1234 new Ajax.Request("backend.php", {
1236 onComplete: function(transport) {
1237 handle_rpc_reply(transport);
1242 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
1245 exception_error("cdmWatchdog", e);
1251 function cache_inject(id, article, param) {
1254 if (!cache_check_param(id, param)) {
1255 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1257 var date = new Date();
1258 var ts = Math.round(date.getTime() / 1000);
1262 cache_obj["id"] = id;
1263 cache_obj["data"] = article;
1264 cache_obj["param"] = param;
1266 if (param) id = id + ":" + param;
1268 cache_added["TS:" + id] = ts;
1270 if (has_local_storage())
1271 localStorage.setItem(id, JSON.stringify(cache_obj));
1273 article_cache.push(cache_obj);
1276 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1279 exception_error("cache_inject", e);
1283 function cache_find(id) {
1285 if (has_local_storage()) {
1286 var cache_obj = localStorage.getItem(id);
1289 cache_obj = JSON.parse(cache_obj);
1292 return cache_obj['data'];
1296 for (var i = 0; i < article_cache.length; i++) {
1297 if (article_cache[i]["id"] == id) {
1298 return article_cache[i]["data"];
1305 function cache_find_param(id, param) {
1307 if (has_local_storage()) {
1309 if (param) id = id + ":" + param;
1311 var cache_obj = localStorage.getItem(id);
1314 cache_obj = JSON.parse(cache_obj);
1317 return cache_obj['data'];
1321 for (var i = 0; i < article_cache.length; i++) {
1322 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1323 return article_cache[i]["data"];
1331 function cache_check(id) {
1332 if (has_local_storage()) {
1333 if (localStorage.getItem(id))
1336 for (var i = 0; i < article_cache.length; i++) {
1337 if (article_cache[i]["id"] == id) {
1345 function cache_check_param(id, param) {
1346 if (has_local_storage()) {
1348 if (param) id = id + ":" + param;
1350 if (localStorage.getItem(id))
1354 for (var i = 0; i < article_cache.length; i++) {
1355 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1363 function cache_expire() {
1364 if (has_local_storage()) {
1366 var date = new Date();
1367 var timestamp = Math.round(date.getTime() / 1000);
1369 for (var i = 0; i < localStorage.length; i++) {
1371 var id = localStorage.key(i);
1373 if (timestamp - cache_added["TS:" + id] > 180) {
1374 localStorage.removeItem(id);
1379 while (article_cache.length > 25) {
1380 article_cache.shift();
1385 function cache_flush() {
1386 if (has_local_storage()) {
1387 localStorage.clear();
1389 article_cache = new Array();
1393 function cache_invalidate(id) {
1395 if (has_local_storage()) {
1399 for (var i = 0; i < localStorage.length; i++) {
1400 var key = localStorage.key(i);
1402 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1404 if (key == id || key.indexOf(id + ":") == 0) {
1405 localStorage.removeItem(key);
1416 while (i < article_cache.length) {
1417 if (article_cache[i]["id"] == id) {
1418 //console.log("cache_invalidate: removed id " + id);
1419 article_cache.splice(i, 1);
1426 //console.log("cache_invalidate: id not found: " + id);
1429 exception_error("cache_invalidate", e);
1433 function getActiveArticleId() {
1434 return active_post_id;
1437 function preloadBatchedArticles() {
1440 var query = "?op=rpc&subop=getArticles&ids=" +
1441 preload_id_batch.toString();
1443 new Ajax.Request("backend.php", {
1445 onComplete: function(transport) {
1447 preload_id_batch = [];
1449 var articles = transport.responseXML.getElementsByTagName("article");
1451 for (var i = 0; i < articles.length; i++) {
1452 var id = articles[i].getAttribute("id");
1453 if (!cache_check(id)) {
1454 cache_inject(id, articles[i].firstChild.nodeValue);
1455 console.log("preloaded article: " + id);
1461 exception_error("preloadBatchedArticles", e);
1465 function preloadArticleUnderPointer(id) {
1467 if (getInitParam("bw_limit") == "1") return;
1469 if (post_under_pointer == id && !cache_check(id)) {
1471 console.log("trying to preload article " + id);
1473 var neighbor_ids = getRelativePostIds(id, 1);
1475 /* only request uncached articles */
1477 if (preload_id_batch.indexOf(id) == -1) {
1478 for (var i = 0; i < neighbor_ids.length; i++) {
1479 if (!cache_check(neighbor_ids[i])) {
1480 preload_id_batch.push(neighbor_ids[i]);
1485 if (preload_id_batch.indexOf(id) == -1)
1486 preload_id_batch.push(id);
1488 //console.log("preload ids batch: " + preload_id_batch.toString());
1490 window.clearTimeout(preload_timeout_id);
1491 preload_batch_timeout_id = window.setTimeout('preloadBatchedArticles()', 1000);
1495 exception_error("preloadArticleUnderPointer", e);
1499 function postMouseIn(id) {
1501 if (post_under_pointer != id) {
1502 post_under_pointer = id;
1504 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1509 exception_error("postMouseIn", e);
1513 function postMouseOut(id) {
1515 post_under_pointer = false;
1517 exception_error("postMouseOut", e);
1521 function headlines_scroll_handler() {
1524 var e = $("headlinesInnerContainer");
1526 var toolbar_form = document.forms["main_toolbar_form"];
1528 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1529 // _infscroll_disable);
1531 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1532 if (!_infscroll_disable) {
1538 exception_error("headlines_scroll_handler", e);
1542 function catchupRelativeToArticle(below) {
1547 if (!getActiveArticleId()) {
1548 alert(__("No article is selected."));
1552 var visible_ids = getVisibleArticleIds();
1554 var ids_to_mark = new Array();
1557 for (var i = 0; i < visible_ids.length; i++) {
1558 if (visible_ids[i] != getActiveArticleId()) {
1559 var e = $("RROW-" + visible_ids[i]);
1561 if (e && e.hasClassName("Unread")) {
1562 ids_to_mark.push(visible_ids[i]);
1569 for (var i = visible_ids.length-1; i >= 0; i--) {
1570 if (visible_ids[i] != getActiveArticleId()) {
1571 var e = $("RROW-" + visible_ids[i]);
1573 if (e && e.hasClassName("Unread")) {
1574 ids_to_mark.push(visible_ids[i]);
1582 if (ids_to_mark.length == 0) {
1583 alert(__("No articles found to mark"));
1585 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1587 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1589 for (var i = 0; i < ids_to_mark.length; i++) {
1590 var e = $("RROW-" + ids_to_mark[i]);
1591 e.removeClassName("Unread");
1594 var query = "?op=rpc&subop=catchupSelected" +
1595 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1597 new Ajax.Request("backend.php", {
1599 onComplete: function(transport) {
1600 catchup_callback2(transport);
1607 exception_error("catchupRelativeToArticle", e);
1611 function cdmExpandArticle(id) {
1616 var elem = $("CICD-" + active_post_id);
1618 var upd_img_pic = $("FUPDPIC-" + id);
1620 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1621 upd_img_pic.src.match("fresh_sign.png"))) {
1623 upd_img_pic.src = "images/blank_icon.gif";
1626 if (id == active_post_id && Element.visible(elem))
1629 selectArticles("none");
1631 var old_offset = $("RROW-" + id).offsetTop;
1633 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1635 Element.show("CEXC-" + active_post_id);
1638 active_post_id = id;
1640 elem = $("CICD-" + id);
1642 if (!Element.visible(elem)) {
1644 Element.hide("CEXC-" + id);
1646 if ($("CWRAP-" + id).innerHTML == "") {
1648 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1650 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1651 __("Loading, please wait...") + "</div>";
1653 var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id);
1655 //console.log(query);
1657 new Ajax.Request("backend.php", {
1659 onComplete: function(transport) {
1660 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1662 if (transport.responseXML) {
1663 var article = transport.responseXML.getElementsByTagName("article")[0];
1664 var recv_id = article.getAttribute("id");
1667 $("CWRAP-" + id).innerHTML = article.firstChild.nodeValue;
1670 $("CWRAP-" + id).innerHTML = __("Unable to load article.");
1678 var new_offset = $("RROW-" + id).offsetTop;
1680 $("headlines-frame").scrollTop += (new_offset-old_offset);
1682 if ($("RROW-" + id).offsetTop != old_offset)
1683 $("headlines-frame").scrollTop = new_offset;
1685 toggleUnread(id, 0, true);
1689 exception_error("cdmExpandArticle", e);
1695 function fixHeadlinesOrder(ids) {
1697 for (var i = 0; i < ids.length; i++) {
1698 var e = $("RROW-" + ids[i]);
1702 e.removeClassName("even");
1703 e.addClassName("odd");
1705 e.removeClassName("odd");
1706 e.addClassName("even");
1711 exception_error("fixHeadlinesOrder", e);
1715 function getArticleUnderPointer() {
1716 return post_under_pointer;
1719 function zoomToArticle(event, id) {
1721 /* var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
1723 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0"); */
1725 var cached_article = cache_find(id);
1727 if (dijit.byId("ATAB-" + id))
1728 if (!event || !event.shiftKey)
1729 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1731 if (cached_article) {
1733 var article_pane = new dijit.layout.ContentPane({
1734 title: __("Loading...") , content: cached_article,
1735 style: 'padding : 0px;',
1739 dijit.byId("content-tabs").addChild(article_pane);
1741 if (!event || !event.shiftKey)
1742 dijit.byId("content-tabs").selectChild(article_pane);
1744 if ($("PTITLE-" + id))
1745 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1749 var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
1751 notify_progress("Loading, please wait...", true);
1753 new Ajax.Request("backend.php", {
1755 onComplete: function(transport) {
1758 if (transport.responseXML) {
1759 closeArticlePanel();
1761 var article = transport.responseXML.getElementsByTagName("article")[0];
1762 var content = article.firstChild.nodeValue;
1764 var article_pane = new dijit.layout.ContentPane({
1765 title: "article-" + id , content: content,
1766 style: 'padding : 0px;',
1770 dijit.byId("content-tabs").addChild(article_pane);
1772 if (!event || !event.shiftKey)
1773 dijit.byId("content-tabs").selectChild(article_pane);
1775 if ($("PTITLE-" + id))
1776 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1783 exception_error("zoomToArticle", e);
1787 function scrollArticle(offset) {
1790 var ci = $("content-insert");
1792 ci.scrollTop += offset;
1795 var hi = $("headlinesInnerContainer");
1797 hi.scrollTop += offset;
1802 exception_error("scrollArticle", e);
1806 function show_labels_in_headlines(transport) {
1808 if (transport.responseXML) {
1809 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
1811 var elems = info.getElementsByTagName("entry");
1813 for (var l = 0; l < elems.length; l++) {
1814 var e_id = elems[l].getAttribute("id");
1818 var ctr = $("HLLCTR-" + e_id);
1821 ctr.innerHTML = elems[l].firstChild.nodeValue;
1829 exception_error("show_labels_in_headlines", e);
1834 function toggleHeadlineActions() {
1836 var e = $("headlineActionsBody");
1837 var p = $("headlineActionsDrop");
1839 if (!Element.visible(e)) {
1846 e.style.left = (p.offsetLeft + 1) + "px";
1847 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1850 exception_error("toggleHeadlineActions", e);
1854 function publishWithNote(id, def_note) {
1856 if (!def_note) def_note = '';
1858 var note = prompt(__("Please enter a note for this article:"), def_note);
1860 if (note != undefined) {
1861 togglePub(id, false, false, note);
1865 exception_error("publishWithNote", e);
1869 function emailArticle(id) {
1872 var ids = getSelectedArticleIds2();
1874 if (ids.length == 0) {
1875 alert(__("No articles are selected."));
1879 id = ids.toString();
1882 displayDlg('emailArticle', id,
1884 document.forms['article_email_form'].destination.focus();
1886 new Ajax.Autocompleter('destination', 'destination_choices',
1887 "backend.php?op=rpc&subop=completeEmails",
1888 { tokens: '', paramName: "search" });
1893 exception_error("emailArticle", e);
1897 function emailArticleDo() {
1899 var f = document.forms['article_email_form'];
1901 if (f.destination.value == "") {
1902 alert("Please fill in the destination email.");
1906 if (f.subject.value == "") {
1907 alert("Please fill in the subject.");
1911 var query = Form.serialize("article_email_form");
1913 // console.log(query);
1915 new Ajax.Request("backend.php", {
1917 onComplete: function(transport) {
1920 var error = transport.responseXML.getElementsByTagName('error')[0];
1923 alert(__('Error sending email:') + ' ' + error.firstChild.nodeValue);
1925 notify_info('Your message has been sent.');
1930 exception_error("sendEmailDo", e);
1936 exception_error("emailArticleDo", e);
1940 function dismissArticle(id) {
1942 var elem = $("RROW-" + id);
1944 toggleUnread(id, 0, true);
1946 new Effect.Fade(elem, {duration : 0.5});
1948 active_post_id = false;
1951 exception_error("dismissArticle", e);
1955 function dismissSelectedArticles() {
1958 var ids = getVisibleArticleIds();
1962 for (var i = 0; i < ids.length; i++) {
1963 var elem = $("RROW-" + ids[i]);
1965 if (elem.className && elem.hasClassName("Selected") &&
1966 ids[i] != active_post_id) {
1967 new Effect.Fade(elem, {duration : 0.5});
1975 selectionToggleUnread(false);
1977 fixHeadlinesOrder(tmp);
1980 exception_error("dismissSelectedArticles", e);
1984 function dismissReadArticles() {
1987 var ids = getVisibleArticleIds();
1990 for (var i = 0; i < ids.length; i++) {
1991 var elem = $("RROW-" + ids[i]);
1993 if (elem.className && !elem.hasClassName("Unread") &&
1994 !elem.hasClassName("Selected")) {
1996 new Effect.Fade(elem, {duration : 0.5});
2002 fixHeadlinesOrder(tmp);
2005 exception_error("dismissSelectedArticles", e);
2009 function getVisibleArticleIds() {
2014 getLoadedArticleIds().each(function(id) {
2015 var elem = $("RROW-" + id);
2016 if (elem && Element.visible(elem))
2021 exception_error("getVisibleArticleIds", e);
2027 function cdmClicked(event, id) {
2029 var shift_key = event.shiftKey;
2033 if (!event.ctrlKey) {
2035 if (!getInitParam("cdm_expanded")) {
2036 return cdmExpandArticle(id);
2039 selectArticles("none");
2042 var elem = $("RROW-" + id);
2045 elem.removeClassName("Unread");
2047 var upd_img_pic = $("FUPDPIC-" + id);
2049 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
2050 upd_img_pic.src.match("fresh_sign.png"))) {
2052 upd_img_pic.src = "images/blank_icon.gif";
2055 active_post_id = id;
2057 var query = "?op=rpc&subop=catchupSelected" +
2058 "&cmode=0&ids=" + param_escape(id);
2060 new Ajax.Request("backend.php", {
2062 onComplete: function(transport) {
2063 handle_rpc_reply(transport);
2068 toggleSelected(id, true);
2069 toggleUnread(id, 0, false);
2070 zoomToArticle(event, id);
2074 exception_error("cdmClicked");
2080 function hlClicked(event, id) {
2083 if (!event.ctrlKey) {
2087 selectArticles('none');
2089 toggleUnread(id, 0, false);
2090 zoomToArticle(event, id);
2095 exception_error("hlClicked");
2101 function getFirstVisibleHeadlineId() {
2102 var rows = getVisibleArticleIds();
2107 function getLastVisibleHeadlineId() {
2108 var rows = getVisibleArticleIds();
2109 return rows[rows.length-1];
2112 function openArticleInNewWindow(id) {
2114 console.log("openArticleInNewWindow: " + id);
2116 var query = "?op=rpc&subop=getArticleLink&id=" + id;
2117 var wname = "ttrss_article_" + id;
2119 console.log(query + " " + wname);
2121 var w = window.open("", wname);
2123 if (!w) notify_error("Failed to open window for the article");
2125 new Ajax.Request("backend.php", {
2127 onComplete: function(transport) {
2129 var link = transport.responseXML.getElementsByTagName("link")[0];
2130 var id = transport.responseXML.getElementsByTagName("id")[0];
2132 console.log("open_article received link: " + link);
2136 var wname = "ttrss_article_" + id.firstChild.nodeValue;
2138 console.log("link url: " + link.firstChild.nodeValue + ", wname " + wname);
2140 var w = window.open(link.firstChild.nodeValue, wname);
2142 if (!w) { notify_error("Failed to load article in new window"); }
2145 id = id.firstChild.nodeValue;
2146 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
2149 notify_error("Can't open article: received invalid article link");
2154 exception_error("openArticleInNewWindow", e);
2158 function isCdmMode() {
2159 return getInitParam("combined_display_mode");
2162 function markHeadline(id) {
2163 var row = $("RROW-" + id);
2165 var check = $("RCHK-" + id);
2168 check.checked = true;
2171 row.addClassName("Selected");
2175 function getRelativePostIds(id, limit) {
2181 if (!limit) limit = 3;
2183 var ids = getVisibleArticleIds();
2185 for (var i = 0; i < ids.length; i++) {
2187 for (var k = 1; k <= limit; k++) {
2188 if (i > k-1) tmp.push(ids[i-k]);
2189 if (i < ids.length-k) tmp.push(ids[i+k]);
2196 exception_error("getRelativePostIds", e);
2202 function correctHeadlinesOffset(id) {
2206 var container = $("headlines-frame");
2207 var row = $("RROW-" + id);
2209 var viewport = container.offsetHeight;
2211 var rel_offset_top = row.offsetTop - container.scrollTop;
2212 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
2214 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2215 //console.log("Vport: " + viewport);
2217 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
2218 container.scrollTop = row.offsetTop;
2219 } else if (rel_offset_bottom > viewport) {
2221 /* doesn't properly work with Opera in some cases because
2222 Opera fucks up element scrolling */
2224 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
2228 exception_error("correctHeadlinesOffset", e);
2233 function headlineActionsChange(elem) {
2235 var op = elem[elem.selectedIndex].value;
2239 elem.selectedIndex = 0;
2242 exception_error("headlineActionsChange", e);
2246 function closeArticlePanel(id) {
2249 if (dijit.byId("ATAB-" + id))
2250 return dijit.byId("content-tabs").removeChild(dijit.byId("ATAB-" + id));
2252 if (dijit.byId("content-insert"))
2253 dijit.byId("headlines-wrap-inner").removeChild(
2254 dijit.byId("content-insert"));