1 var active_post_id = false;
3 var article_cache = new Array();
5 var vgroup_last_feed = false;
6 var post_under_pointer = false;
8 var last_requested_article = false;
10 var catchup_id_batch = [];
11 var catchup_timeout_id = false;
12 var feed_precache_timeout_id = false;
13 var precache_idle_timeout_id = false;
15 var cids_requested = [];
16 var loaded_article_ids = [];
18 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
20 function headlines_callback2(transport, offset, background, infscroll_req) {
22 handle_rpc_json(transport);
24 loading_set_progress(25);
26 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
34 reply = JSON.parse(transport.responseText);
41 is_cat = reply['headlines']['is_cat'];
42 feed_id = reply['headlines']['id'];
45 var content = reply['headlines']['content'];
47 if (getInitParam("cdm_auto_catchup") == 1) {
48 content = content + "<div id='headlines-spacer'></div>";
51 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
55 setActiveFeedId(feed_id, is_cat);
57 dijit.getEnclosingWidget(
58 document.forms["main_toolbar_form"].update).attr('disabled',
59 is_cat || feed_id <= 0);
62 if (offset == 0 && infscroll_req == false) {
63 $("headlines-frame").scrollTop = 0;
67 var headlines_count = reply['headlines-info']['count'];
69 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
71 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
72 _infscroll_disable = 1;
74 _infscroll_disable = 0;
77 var counters = reply['counters'];
78 var articles = reply['articles'];
79 //var runtime_info = reply['runtime-info'];
81 if (offset == 0 && infscroll_req == false) {
82 loaded_article_ids = [];
84 dijit.byId("headlines-frame").attr('content',
85 reply['headlines']['content']);
87 dijit.byId("headlines-toolbar").attr('content',
88 reply['headlines']['toolbar']);
90 $$("#headlines-frame > div[id*=RROW]").each(function(row) {
91 if (loaded_article_ids.indexOf(row.id) != -1) {
92 row.parentNode.removeChild(row);
94 loaded_article_ids.push(row.id);
98 if (getInitParam("cdm_auto_catchup") == 1) {
99 var hsp = $("headlines-spacer");
100 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
101 dijit.byId('headlines-frame').domNode.appendChild(hsp);
107 $("feed_title").innerHTML += "<span id='cancel_search'>" +
108 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
114 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
115 console.log("adding some more headlines: " + headlines_count);
117 var c = dijit.byId("headlines-frame");
118 var ids = getSelectedArticleIds2();
121 $("headlines-tmp").innerHTML = reply['headlines']['content'];
123 var hsp = $("headlines-spacer");
126 c.domNode.removeChild(hsp);
128 $$("#headlines-tmp > div").each(function(row) {
129 if (row.className == 'cdmFeedTitle') {
130 row.style.display = 'none';
131 c.domNode.appendChild(row);
133 } else if (loaded_article_ids.indexOf(row.id) == -1) {
134 row.style.display = 'none';
135 c.domNode.appendChild(row);
137 loaded_article_ids.push(row.id);
139 row.parentNode.removeChild(row);
143 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
145 fixHeadlinesOrder(getLoadedArticleIds());
147 if (getInitParam("cdm_auto_catchup") == 1) {
148 c.domNode.appendChild(hsp);
151 console.log("added " + new_elems.size() + " headlines");
153 if (new_elems.size() == 0)
154 _infscroll_disable = true;
156 console.log("restore selected ids: " + ids);
158 for (var i = 0; i < ids.length; i++) {
159 markHeadline(ids[i]);
164 new_elems.each(function(child) {
165 if (!Element.visible(child))
166 new Effect.Appear(child, { duration : 0.5 });
170 console.log("no new headlines received");
172 var hsp = $("headlines-spacer");
174 if (hsp) hsp.innerHTML = "";
178 if (headlines_count > 0)
179 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
182 for (var i = 0; i < articles.length; i++) {
183 var a_id = articles[i]['id'];
184 cache_set("article:" + a_id, articles[i]['content']);
187 console.log("no cached articles received");
190 // do not precache stuff after fresh feed
192 precache_headlines();
195 parse_counters(counters);
200 console.error("Invalid object received: " + transport.responseText);
201 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
202 __('Could not update headlines (invalid object received - see error console for details)') +
206 _infscroll_request_sent = 0;
211 exception_error("headlines_callback2", e, transport);
215 function render_article(article) {
217 dijit.byId("headlines-wrap-inner").addChild(
218 dijit.byId("content-insert"));
220 var c = dijit.byId("content-insert");
223 c.domNode.scrollTop = 0;
226 c.attr('content', article);
228 correctHeadlinesOffset(getActiveArticleId());
235 exception_error("render_article", e);
239 function showArticleInHeadlines(id) {
243 selectArticles("none");
245 var crow = $("RROW-" + id);
249 var article_is_unread = crow.hasClassName("Unread");
251 crow.removeClassName("Unread");
253 selectArticles('none');
255 var upd_img_pic = $("FUPDPIC-" + id);
257 var view_mode = false;
260 view_mode = document.forms['main_toolbar_form'].view_mode;
261 view_mode = view_mode[view_mode.selectedIndex].value;
266 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
267 upd_img_pic.src.match("fresh_sign.png"))) {
269 upd_img_pic.src = "images/blank_icon.gif";
271 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
273 } else if (article_is_unread && view_mode == "all_articles") {
274 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
279 if (article_is_unread)
280 _force_scheduled_update = true;
283 exception_error("showArticleInHeadlines", e);
287 function article_callback2(transport, id) {
289 console.log("article_callback2 " + id);
291 handle_rpc_json(transport);
296 reply = JSON.parse(transport.responseText);
303 var upic = $('FUPDPIC-' + id);
305 if (upic) upic.src = 'images/blank_icon.gif';
307 reply.each(function(article) {
308 if (active_post_id == article['id']) {
309 render_article(article['content']);
311 cids_requested.remove(article['id']);
313 cache_set("article:" + article['id'], article['content']);
316 // if (id != last_requested_article) {
317 // console.log("requested article id is out of sequence, aborting");
322 console.error("Invalid object received: " + transport.responseText);
324 render_article("<div class='whiteBox'>" +
325 __('Could not display article (invalid object received - see error console for details)') + "</div>");
330 headlines_scroll_handler($("headlines-frame"));
333 if (!_infscroll_disable &&
334 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
344 exception_error("article_callback2", e, transport);
350 console.log("loading article: " + id);
352 var cached_article = cache_get("article:" + id);
354 console.log("cache check result: " + (cached_article != false));
358 var query = "?op=article&method=view&id=" + param_escape(id);
360 var neighbor_ids = getRelativePostIds(id);
362 /* only request uncached articles */
364 var cids_to_request = [];
366 for (var i = 0; i < neighbor_ids.length; i++) {
367 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
368 if (!cache_get("article:" + neighbor_ids[i])) {
369 cids_to_request.push(neighbor_ids[i]);
370 cids_requested.push(neighbor_ids[i]);
374 console.log("additional ids: " + cids_to_request.toString());
376 query = query + "&cids=" + cids_to_request.toString();
378 var crow = $("RROW-" + id);
379 var article_is_unread = crow.hasClassName("Unread");
382 showArticleInHeadlines(id);
384 precache_headlines();
386 if (!cached_article) {
388 var upic = $('FUPDPIC-' + id);
391 upic.src = getInitParam("sign_progress");
394 } else if (cached_article && article_is_unread) {
396 query = query + "&mode=prefetch";
398 render_article(cached_article);
400 } else if (cached_article) {
402 query = query + "&mode=prefetch_old";
403 render_article(cached_article);
405 // if we don't need to request any relative ids, we might as well skip
406 // the server roundtrip altogether
407 if (cids_to_request.length == 0) {
410 if (!_infscroll_disable &&
411 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
419 headlines_scroll_handler($("headlines-frame"));
425 last_requested_article = id;
429 if (article_is_unread) {
430 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
433 new Ajax.Request("backend.php", {
435 onComplete: function(transport) {
436 article_callback2(transport, id);
442 exception_error("view", e);
446 function toggleMark(id, client_only) {
448 var query = "?op=rpc&id=" + id + "&method=mark";
450 var img = $("FMPIC-" + id);
454 if (img.src.match("mark_unset")) {
455 img.src = img.src.replace("mark_unset", "mark_set");
456 img.alt = __("Unstar article");
457 query = query + "&mark=1";
460 img.src = img.src.replace("mark_set", "mark_unset");
461 img.alt = __("Star article");
462 query = query + "&mark=0";
465 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
468 new Ajax.Request("backend.php", {
470 onComplete: function(transport) {
471 handle_rpc_json(transport);
476 exception_error("toggleMark", e);
480 function togglePub(id, client_only, no_effects, note) {
482 var query = "?op=rpc&id=" + id + "&method=publ";
484 if (note != undefined) {
485 query = query + "¬e=" + param_escape(note);
487 query = query + "¬e=undefined";
490 var img = $("FPPIC-" + id);
494 if (img.src.match("pub_unset") || note != undefined) {
495 img.src = img.src.replace("pub_unset", "pub_set");
496 img.alt = __("Unpublish article");
497 query = query + "&pub=1";
500 img.src = img.src.replace("pub_set", "pub_unset");
501 img.alt = __("Publish article");
503 query = query + "&pub=0";
506 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
509 new Ajax.Request("backend.php", {
511 onComplete: function(transport) {
512 handle_rpc_json(transport);
517 exception_error("togglePub", e);
521 function moveToPost(mode) {
525 var rows = getVisibleArticleIds();
530 if (!$('RROW-' + active_post_id)) {
531 active_post_id = false;
534 if (active_post_id == false) {
536 prev_id = rows[rows.length-1]
538 for (var i = 0; i < rows.length; i++) {
539 if (rows[i] == active_post_id) {
541 // Account for adjacent identical article ids.
542 if (i > 0) prev_id = rows[i-1];
544 for (var j = i+1; j < rows.length; j++) {
545 if (rows[j] != active_post_id) {
555 if (mode == "next") {
559 cdmExpandArticle(next_id);
560 cdmScrollToArticleId(next_id);
563 correctHeadlinesOffset(next_id);
564 view(next_id, getActiveFeedId());
569 if (mode == "prev") {
572 cdmExpandArticle(prev_id);
573 cdmScrollToArticleId(prev_id);
575 correctHeadlinesOffset(prev_id);
576 view(prev_id, getActiveFeedId());
582 exception_error("moveToPost", e);
586 function toggleSelected(id, force_on) {
589 var cb = dijit.byId("RCHK-" + id);
590 var row = $("RROW-" + id);
593 if (row.hasClassName('Selected') && !force_on) {
594 row.removeClassName('Selected');
595 if (cb) cb.attr("checked", false);
597 row.addClassName('Selected');
598 if (cb) cb.attr("checked", true);
602 exception_error("toggleSelected", e);
606 function toggleUnread_afh(effect) {
609 var elem = effect.element;
610 elem.style.backgroundColor = "";
613 exception_error("toggleUnread_afh", e);
617 function toggleUnread(id, cmode, effect) {
620 var row = $("RROW-" + id);
622 if (cmode == undefined || cmode == 2) {
623 if (row.hasClassName("Unread")) {
624 row.removeClassName("Unread");
627 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
628 afterFinish: toggleUnread_afh,
629 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
633 row.addClassName("Unread");
636 } else if (cmode == 0) {
638 row.removeClassName("Unread");
641 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
642 afterFinish: toggleUnread_afh,
643 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
646 } else if (cmode == 1) {
647 row.addClassName("Unread");
650 if (cmode == undefined) cmode = 2;
652 var query = "?op=rpc&method=catchupSelected" +
653 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
655 // notify_progress("Loading, please wait...");
657 new Ajax.Request("backend.php", {
659 onComplete: function(transport) {
660 handle_rpc_json(transport);
666 exception_error("toggleUnread", e);
670 function selectionRemoveLabel(id, ids) {
673 if (!ids) ids = getSelectedArticleIds2();
675 if (ids.length == 0) {
676 alert(__("No articles are selected."));
680 var query = "?op=rpc&method=removeFromLabel&ids=" +
681 param_escape(ids.toString()) + "&lid=" + param_escape(id);
685 new Ajax.Request("backend.php", {
687 onComplete: function(transport) {
688 handle_rpc_json(transport);
689 show_labels_in_headlines(transport);
693 exception_error("selectionAssignLabel", e);
698 function selectionAssignLabel(id, ids) {
701 if (!ids) ids = getSelectedArticleIds2();
703 if (ids.length == 0) {
704 alert(__("No articles are selected."));
708 var query = "?op=rpc&method=assignToLabel&ids=" +
709 param_escape(ids.toString()) + "&lid=" + param_escape(id);
713 new Ajax.Request("backend.php", {
715 onComplete: function(transport) {
716 handle_rpc_json(transport);
717 show_labels_in_headlines(transport);
721 exception_error("selectionAssignLabel", e);
726 function selectionToggleUnread(set_state, callback, no_error) {
728 var rows = getSelectedArticleIds2();
730 if (rows.length == 0 && !no_error) {
731 alert(__("No articles are selected."));
735 for (var i = 0; i < rows.length; i++) {
736 var row = $("RROW-" + rows[i]);
738 if (set_state == undefined) {
739 if (row.hasClassName("Unread")) {
740 row.removeClassName("Unread");
742 row.addClassName("Unread");
746 if (set_state == false) {
747 row.removeClassName("Unread");
750 if (set_state == true) {
751 row.addClassName("Unread");
756 if (rows.length > 0) {
760 if (set_state == undefined) {
762 } else if (set_state == true) {
764 } else if (set_state == false) {
768 var query = "?op=rpc&method=catchupSelected" +
769 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
771 notify_progress("Loading, please wait...");
773 new Ajax.Request("backend.php", {
775 onComplete: function(transport) {
776 handle_rpc_json(transport);
777 if (callback) callback(transport);
783 exception_error("selectionToggleUnread", e);
787 function selectionToggleMarked() {
790 var rows = getSelectedArticleIds2();
792 if (rows.length == 0) {
793 alert(__("No articles are selected."));
797 for (var i = 0; i < rows.length; i++) {
798 toggleMark(rows[i], true, true);
801 if (rows.length > 0) {
803 var query = "?op=rpc&method=markSelected&ids=" +
804 param_escape(rows.toString()) + "&cmode=2";
806 new Ajax.Request("backend.php", {
808 onComplete: function(transport) {
809 handle_rpc_json(transport);
815 exception_error("selectionToggleMarked", e);
819 function selectionTogglePublished() {
822 var rows = getSelectedArticleIds2();
824 if (rows.length == 0) {
825 alert(__("No articles are selected."));
829 for (var i = 0; i < rows.length; i++) {
830 togglePub(rows[i], true, true);
833 if (rows.length > 0) {
835 var query = "?op=rpc&method=publishSelected&ids=" +
836 param_escape(rows.toString()) + "&cmode=2";
838 new Ajax.Request("backend.php", {
840 onComplete: function(transport) {
841 handle_rpc_json(transport);
847 exception_error("selectionToggleMarked", e);
851 function getSelectedArticleIds2() {
855 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
857 rv.push(child.id.replace("RROW-", ""));
863 function getLoadedArticleIds() {
866 var children = $$("#headlines-frame > div[id*=RROW-]");
868 children.each(function(child) {
869 rv.push(child.id.replace("RROW-", ""));
876 // mode = all,none,unread,invert,marked,published
877 function selectArticles(mode) {
880 var children = $$("#headlines-frame > div[id*=RROW]");
882 children.each(function(child) {
883 var id = child.id.replace("RROW-", "");
884 var cb = dijit.byId("RCHK-" + id);
887 child.addClassName("Selected");
888 cb.attr("checked", true);
889 } else if (mode == "unread") {
890 if (child.hasClassName("Unread")) {
891 child.addClassName("Selected");
892 cb.attr("checked", true);
894 child.removeClassName("Selected");
895 cb.attr("checked", false);
897 } else if (mode == "marked") {
898 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
900 if (img && img.src.match("mark_set")) {
901 child.addClassName("Selected");
902 cb.attr("checked", true);
904 child.removeClassName("Selected");
905 cb.attr("checked", false);
907 } else if (mode == "published") {
908 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
910 if (img && img.src.match("pub_set")) {
911 child.addClassName("Selected");
912 cb.attr("checked", true);
914 child.removeClassName("Selected");
915 cb.attr("checked", false);
918 } else if (mode == "invert") {
919 if (child.hasClassName("Selected")) {
920 child.removeClassName("Selected");
921 cb.attr("checked", false);
923 child.addClassName("Selected");
924 cb.attr("checked", true);
928 child.removeClassName("Selected");
929 cb.attr("checked", false);
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());
969 if (getActiveFeedId() != 0) {
970 str = __("Delete %d selected articles in %s?");
972 str = __("Delete %d selected articles?");
975 str = str.replace("%d", rows.length);
976 str = str.replace("%s", fn);
978 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
982 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
986 new Ajax.Request("backend.php", {
988 onComplete: function(transport) {
989 handle_rpc_json(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&method="+op+"&ids=" + param_escape(rows);
1032 for (var i = 0; i < rows.length; i++) {
1033 cache_delete("article:" + rows[i]);
1036 new Ajax.Request("backend.php", {
1038 onComplete: function(transport) {
1039 handle_rpc_json(transport);
1044 exception_error("archiveSelection", e);
1048 function catchupSelection() {
1052 var rows = getSelectedArticleIds2();
1054 if (rows.length == 0) {
1055 alert(__("No articles are selected."));
1059 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1061 var str = __("Mark %d selected articles in %s as read?");
1063 str = str.replace("%d", rows.length);
1064 str = str.replace("%s", fn);
1066 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1070 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1073 exception_error("catchupSelection", e);
1077 function editArticleTags(id) {
1078 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1080 if (dijit.byId("editTagsDlg"))
1081 dijit.byId("editTagsDlg").destroyRecursive();
1083 dialog = new dijit.Dialog({
1085 title: __("Edit article Tags"),
1086 style: "width: 600px",
1087 execute: function() {
1088 if (this.validate()) {
1089 var query = dojo.objectToQuery(this.attr('value'));
1091 notify_progress("Saving article tags...", true);
1093 new Ajax.Request("backend.php", {
1095 onComplete: function(transport) {
1099 var data = JSON.parse(transport.responseText);
1102 var tags_str = article.tags;
1103 var id = tags_str.id;
1105 var tags = $("ATSTR-" + id);
1106 var tooltip = dijit.byId("ATSTRTIP-" + id);
1108 if (tags) tags.innerHTML = tags_str.content;
1109 if (tooltip) tooltip.attr('label', tags_str.content_full);
1111 cache_delete("article:" + id);
1120 var tmph = dojo.connect(dialog, 'onLoad', function() {
1121 dojo.disconnect(tmph);
1123 new Ajax.Autocompleter('tags_str', 'tags_choices',
1124 "backend.php?op=rpc&method=completeTags",
1125 { tokens: ',', paramName: "search" });
1132 function cdmScrollToArticleId(id) {
1134 var ctr = $("headlines-frame");
1135 var e = $("RROW-" + id);
1137 if (!e || !ctr) return;
1139 ctr.scrollTop = e.offsetTop;
1142 exception_error("cdmScrollToArticleId", e);
1146 function getActiveArticleId() {
1147 return active_post_id;
1150 function postMouseIn(id) {
1151 post_under_pointer = id;
1154 function postMouseOut(id) {
1155 post_under_pointer = false;
1158 function headlines_scroll_handler(e) {
1160 var hsp = $("headlines-spacer");
1162 if (!_infscroll_disable) {
1163 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1164 (e.scrollHeight != 0 &&
1165 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1168 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1169 __("Loading, please wait...");
1171 loadMoreHeadlines();
1176 if (hsp) hsp.innerHTML = "";
1179 if (getInitParam("cdm_auto_catchup") == 1) {
1181 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1183 if ($("headlines-frame").scrollTop >
1184 (child.offsetTop + child.offsetHeight/2)) {
1186 var id = child.id.replace("RROW-", "");
1188 if (catchup_id_batch.indexOf(id) == -1)
1189 catchup_id_batch.push(id);
1191 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1195 if (catchup_id_batch.length > 0) {
1196 window.clearTimeout(catchup_timeout_id);
1198 if (!_infscroll_request_sent) {
1199 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1206 console.warn("headlines_scroll_handler: " + e);
1210 function catchupBatchedArticles() {
1212 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1214 // make a copy of the array
1215 var batch = catchup_id_batch.slice();
1216 var query = "?op=rpc&method=catchupSelected" +
1217 "&cmode=0&ids=" + param_escape(batch.toString());
1221 new Ajax.Request("backend.php", {
1223 onComplete: function(transport) {
1224 handle_rpc_json(transport);
1226 batch.each(function(id) {
1227 var elem = $("RROW-" + id);
1228 if (elem) elem.removeClassName("Unread");
1229 catchup_id_batch.remove(id);
1236 exception_error("catchupBatchedArticles", e);
1240 function catchupRelativeToArticle(below, id) {
1244 if (!id) id = getActiveArticleId();
1247 alert(__("No article is selected."));
1251 var visible_ids = getVisibleArticleIds();
1253 var ids_to_mark = new Array();
1256 for (var i = 0; i < visible_ids.length; i++) {
1257 if (visible_ids[i] != id) {
1258 var e = $("RROW-" + visible_ids[i]);
1260 if (e && e.hasClassName("Unread")) {
1261 ids_to_mark.push(visible_ids[i]);
1268 for (var i = visible_ids.length-1; i >= 0; i--) {
1269 if (visible_ids[i] != id) {
1270 var e = $("RROW-" + visible_ids[i]);
1272 if (e && e.hasClassName("Unread")) {
1273 ids_to_mark.push(visible_ids[i]);
1281 if (ids_to_mark.length == 0) {
1282 alert(__("No articles found to mark"));
1284 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1286 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1288 for (var i = 0; i < ids_to_mark.length; i++) {
1289 var e = $("RROW-" + ids_to_mark[i]);
1290 e.removeClassName("Unread");
1293 var query = "?op=rpc&method=catchupSelected" +
1294 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1296 new Ajax.Request("backend.php", {
1298 onComplete: function(transport) {
1299 handle_rpc_json(transport);
1306 exception_error("catchupRelativeToArticle", e);
1310 function cdmExpandArticle(id) {
1315 var elem = $("CICD-" + active_post_id);
1317 var upd_img_pic = $("FUPDPIC-" + id);
1319 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1320 upd_img_pic.src.match("fresh_sign.png"))) {
1322 upd_img_pic.src = "images/blank_icon.gif";
1325 if (id == active_post_id && Element.visible(elem))
1328 selectArticles("none");
1330 var old_offset = $("RROW-" + id).offsetTop;
1332 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1334 Element.show("CEXC-" + active_post_id);
1337 active_post_id = id;
1339 elem = $("CICD-" + id);
1341 if (!Element.visible(elem)) {
1343 Element.hide("CEXC-" + id);
1346 var new_offset = $("RROW-" + id).offsetTop;
1348 $("headlines-frame").scrollTop += (new_offset-old_offset);
1350 if ($("RROW-" + id).offsetTop != old_offset)
1351 $("headlines-frame").scrollTop = new_offset;
1353 toggleUnread(id, 0, true);
1357 exception_error("cdmExpandArticle", e);
1363 function fixHeadlinesOrder(ids) {
1365 for (var i = 0; i < ids.length; i++) {
1366 var e = $("RROW-" + ids[i]);
1370 e.removeClassName("even");
1371 e.addClassName("odd");
1373 e.removeClassName("odd");
1374 e.addClassName("even");
1379 exception_error("fixHeadlinesOrder", e);
1383 function getArticleUnderPointer() {
1384 return post_under_pointer;
1387 function zoomToArticle(event, id) {
1389 var cached_article = cache_get("article: " + id);
1391 if (dijit.byId("ATAB-" + id))
1392 if (!event || !event.shiftKey)
1393 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1395 if (dijit.byId("ATSTRTIP-" + id))
1396 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1398 if (cached_article) {
1399 //closeArticlePanel();
1401 var article_pane = new dijit.layout.ContentPane({
1402 title: __("Loading...") , content: cached_article,
1403 style: 'padding : 0px;',
1407 dijit.byId("content-tabs").addChild(article_pane);
1409 if (!event || !event.shiftKey)
1410 dijit.byId("content-tabs").selectChild(article_pane);
1412 if ($("PTITLE-" + id))
1413 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1417 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1419 notify_progress("Loading, please wait...", true);
1421 new Ajax.Request("backend.php", {
1423 onComplete: function(transport) {
1426 var reply = JSON.parse(transport.responseText);
1429 //closeArticlePanel();
1431 var content = reply[0]['content'];
1433 var article_pane = new dijit.layout.ContentPane({
1434 title: "article-" + id , content: content,
1435 style: 'padding : 0px;',
1439 dijit.byId("content-tabs").addChild(article_pane);
1441 if (!event || !event.shiftKey)
1442 dijit.byId("content-tabs").selectChild(article_pane);
1444 if ($("PTITLE-" + id))
1445 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1452 exception_error("zoomToArticle", e);
1456 function scrollArticle(offset) {
1459 var ci = $("content-insert");
1461 ci.scrollTop += offset;
1464 var hi = $("headlines-frame");
1466 hi.scrollTop += offset;
1471 exception_error("scrollArticle", e);
1475 function show_labels_in_headlines(transport) {
1477 var data = JSON.parse(transport.responseText);
1480 data['info-for-headlines'].each(function(elem) {
1481 var ctr = $("HLLCTR-" + elem.id);
1483 if (ctr) ctr.innerHTML = elem.labels;
1486 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1490 exception_error("show_labels_in_headlines", e);
1494 /* function toggleHeadlineActions() {
1496 var e = $("headlineActionsBody");
1497 var p = $("headlineActionsDrop");
1499 if (!Element.visible(e)) {
1506 e.style.left = (p.offsetLeft + 1) + "px";
1507 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1510 exception_error("toggleHeadlineActions", e);
1514 /* function publishWithNote(id, def_note) {
1516 if (!def_note) def_note = '';
1518 var note = prompt(__("Please enter a note for this article:"), def_note);
1520 if (note != undefined) {
1521 togglePub(id, false, false, note);
1525 exception_error("publishWithNote", e);
1529 function dismissArticle(id) {
1531 var elem = $("RROW-" + id);
1533 toggleUnread(id, 0, true);
1535 new Effect.Fade(elem, {duration : 0.5});
1537 active_post_id = false;
1540 exception_error("dismissArticle", e);
1544 function dismissSelectedArticles() {
1547 var ids = getVisibleArticleIds();
1551 for (var i = 0; i < ids.length; i++) {
1552 var elem = $("RROW-" + ids[i]);
1554 if (elem.className && elem.hasClassName("Selected") &&
1555 ids[i] != active_post_id) {
1556 new Effect.Fade(elem, {duration : 0.5});
1564 selectionToggleUnread(false);
1566 fixHeadlinesOrder(tmp);
1569 exception_error("dismissSelectedArticles", e);
1573 function dismissReadArticles() {
1576 var ids = getVisibleArticleIds();
1579 for (var i = 0; i < ids.length; i++) {
1580 var elem = $("RROW-" + ids[i]);
1582 if (elem.className && !elem.hasClassName("Unread") &&
1583 !elem.hasClassName("Selected")) {
1585 new Effect.Fade(elem, {duration : 0.5});
1591 fixHeadlinesOrder(tmp);
1594 exception_error("dismissSelectedArticles", e);
1598 function getVisibleArticleIds() {
1603 getLoadedArticleIds().each(function(id) {
1604 var elem = $("RROW-" + id);
1605 if (elem && Element.visible(elem))
1610 exception_error("getVisibleArticleIds", e);
1616 function cdmClicked(event, id) {
1618 //var shift_key = event.shiftKey;
1622 if (!event.ctrlKey) {
1624 if (!getInitParam("cdm_expanded")) {
1625 return cdmExpandArticle(id);
1628 selectArticles("none");
1631 var elem = $("RROW-" + id);
1632 var article_is_unread = elem.hasClassName("Unread");
1635 elem.removeClassName("Unread");
1637 var upd_img_pic = $("FUPDPIC-" + id);
1639 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1640 upd_img_pic.src.match("fresh_sign.png"))) {
1642 upd_img_pic.src = "images/blank_icon.gif";
1645 active_post_id = id;
1647 if (article_is_unread) {
1648 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1651 var query = "?op=rpc&method=catchupSelected" +
1652 "&cmode=0&ids=" + param_escape(id);
1654 new Ajax.Request("backend.php", {
1656 onComplete: function(transport) {
1657 handle_rpc_json(transport);
1664 toggleSelected(id, true);
1666 var elem = $("RROW-" + id);
1667 var article_is_unread = elem.hasClassName("Unread");
1669 if (article_is_unread) {
1670 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1673 toggleUnread(id, 0, false);
1674 zoomToArticle(event, id);
1678 exception_error("cdmClicked");
1684 function postClicked(event, id) {
1687 if (!event.ctrlKey) {
1690 postOpenInNewTab(event, id);
1695 exception_error("postClicked");
1699 function hlOpenInNewTab(event, id) {
1700 toggleUnread(id, 0, false);
1701 zoomToArticle(event, id);
1704 function postOpenInNewTab(event, id) {
1705 closeArticlePanel(id);
1706 zoomToArticle(event, id);
1709 function hlClicked(event, id) {
1711 if (event.which == 2) {
1714 } else if (event.altKey) {
1715 openArticleInNewWindow(id);
1716 } else if (!event.ctrlKey) {
1721 toggleUnread(id, 0, false);
1722 zoomToArticle(event, id);
1727 exception_error("hlClicked");
1731 function getFirstVisibleHeadlineId() {
1732 var rows = getVisibleArticleIds();
1737 function getLastVisibleHeadlineId() {
1738 var rows = getVisibleArticleIds();
1739 return rows[rows.length-1];
1742 function openArticleInNewWindow(id) {
1743 toggleUnread(id, 0, false);
1744 window.open("backend.php?op=article&method=redirect&id=" + id);
1747 function isCdmMode() {
1748 return getInitParam("combined_display_mode");
1751 function markHeadline(id) {
1752 var row = $("RROW-" + id);
1754 var check = dijit.byId("RCHK-" + id);
1757 check.attr("checked", true);
1760 row.addClassName("Selected");
1764 function getRelativePostIds(id, limit) {
1770 if (!limit) limit = 6; //3
1772 var ids = getVisibleArticleIds();
1774 for (var i = 0; i < ids.length; i++) {
1776 for (var k = 1; k <= limit; k++) {
1777 //if (i > k-1) tmp.push(ids[i-k]);
1778 if (i < ids.length-k) tmp.push(ids[i+k]);
1785 exception_error("getRelativePostIds", e);
1791 function correctHeadlinesOffset(id) {
1795 var container = $("headlines-frame");
1796 var row = $("RROW-" + id);
1798 if (!container || !row) return;
1800 var viewport = container.offsetHeight;
1802 var rel_offset_top = row.offsetTop - container.scrollTop;
1803 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1805 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1806 //console.log("Vport: " + viewport);
1808 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1809 container.scrollTop = row.offsetTop;
1810 } else if (rel_offset_bottom > viewport) {
1812 /* doesn't properly work with Opera in some cases because
1813 Opera fucks up element scrolling */
1815 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1819 exception_error("correctHeadlinesOffset", e);
1824 function headlineActionsChange(elem) {
1827 elem.attr('value', 'false');
1829 exception_error("headlineActionsChange", e);
1833 function closeArticlePanel() {
1835 var tabs = dijit.byId("content-tabs");
1836 var child = tabs.selectedChildWidget;
1838 if (child && tabs.getIndexOfChild(child) > 0) {
1839 tabs.removeChild(child);
1842 if (dijit.byId("content-insert"))
1843 dijit.byId("headlines-wrap-inner").removeChild(
1844 dijit.byId("content-insert"));
1848 function initHeadlinesMenu() {
1850 if (dijit.byId("headlinesMenu"))
1851 dijit.byId("headlinesMenu").destroyRecursive();
1856 nodes = $$("#headlines-frame > div[id*=RROW]");
1858 nodes = $$("#headlines-frame span[id*=RTITLE]");
1861 nodes.each(function(node) {
1865 var menu = new dijit.Menu({
1866 id: "headlinesMenu",
1870 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1871 var callerNode = event.target, match = null, tries = 0;
1873 while (match == null && callerNode && tries <= 3) {
1874 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1875 callerNode = callerNode.parentNode;
1879 if (match) this.callerRowId = parseInt(match[1]);
1883 /* if (!isCdmMode())
1884 menu.addChild(new dijit.MenuItem({
1885 label: __("View article"),
1886 onClick: function(event) {
1887 view(this.getParent().callerRowId);
1890 menu.addChild(new dijit.MenuItem({
1891 label: __("Open original article"),
1892 onClick: function(event) {
1893 openArticleInNewWindow(this.getParent().callerRowId);
1896 menu.addChild(new dijit.MenuItem({
1897 label: __("View in a tt-rss tab"),
1898 onClick: function(event) {
1899 hlOpenInNewTab(event, this.getParent().callerRowId);
1902 menu.addChild(new dijit.MenuSeparator());
1904 menu.addChild(new dijit.MenuItem({
1905 label: __("Mark above as read"),
1906 onClick: function(event) {
1907 catchupRelativeToArticle(0, this.getParent().callerRowId);
1910 menu.addChild(new dijit.MenuItem({
1911 label: __("Mark below as read"),
1912 onClick: function(event) {
1913 catchupRelativeToArticle(1, this.getParent().callerRowId);
1917 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1921 menu.addChild(new dijit.MenuSeparator());
1923 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1924 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1926 labels.each(function(label) {
1927 var id = label.id[0];
1928 var bare_id = id.substr(id.indexOf(":")+1);
1929 var name = label.name[0];
1931 bare_id = -11-bare_id;
1933 labelAddMenu.addChild(new dijit.MenuItem({
1936 onClick: function(event) {
1937 var ids = getSelectedArticleIds2();
1939 var id = this.getParent().ownerMenu.callerRowId + "";
1941 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1943 selectionAssignLabel(this.labelId, ids);
1946 labelDelMenu.addChild(new dijit.MenuItem({
1949 onClick: function(event) {
1950 var ids = getSelectedArticleIds2();
1952 var id = this.getParent().ownerMenu.callerRowId + "";
1954 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1956 selectionRemoveLabel(this.labelId, ids);
1961 menu.addChild(new dijit.PopupMenuItem({
1962 label: __("Assign label"),
1963 popup: labelAddMenu,
1966 menu.addChild(new dijit.PopupMenuItem({
1967 label: __("Remove label"),
1968 popup: labelDelMenu,
1976 exception_error("initHeadlinesMenu", e);
1981 function player(elem) {
1982 var aid = elem.getAttribute("audio-id");
1983 var status = elem.getAttribute("status");
1991 elem.innerHTML = __("Playing...");
1992 elem.title = __("Click to pause");
1993 elem.addClassName("playing");
1997 elem.innerHTML = __("Play");
1998 elem.title = __("Click to play");
1999 elem.removeClassName("playing");
2002 elem.setAttribute("status", status);
2004 alert("Your browser doesn't seem to support HTML5 audio.");
2008 function cache_set(id, obj) {
2009 //console.log("cache_set: " + id);
2012 sessionStorage[id] = obj;
2014 sessionStorage.clear();
2018 function cache_get(id) {
2020 return sessionStorage[id];
2023 function cache_clear() {
2025 sessionStorage.clear();
2028 function cache_delete(id) {
2030 sessionStorage.removeItem(id);
2033 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2034 if (toolbar_obj && content_obj) {
2035 cache_set("feed:" + feed + ":" + is_cat,
2036 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2039 obj = cache_get("feed:" + feed + ":" + is_cat);
2042 obj = JSON.parse(obj);
2044 if (toolbar_obj) obj.toolbar = toolbar_obj;
2045 if (content_obj) obj.content = content_obj;
2047 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2051 console.warn("cache_headlines failed: " + e);
2056 function render_local_headlines(feed, is_cat, obj) {
2059 dijit.byId("headlines-toolbar").attr('content',
2062 dijit.byId("headlines-frame").attr('content',
2065 dojo.parser.parse('headlines-toolbar');
2067 $("headlines-frame").scrollTop = 0;
2068 selectArticles('none');
2069 setActiveFeedId(feed, is_cat);
2070 initHeadlinesMenu();
2072 dijit.getEnclosingWidget(
2073 document.forms["main_toolbar_form"].update).attr('disabled',
2074 is_cat || feed <= 0);
2076 precache_headlines();
2079 exception_error("render_local_headlines", e);
2083 function precache_headlines_idle() {
2085 if (!feed_precache_timeout_id) {
2086 if (get_timestamp() - _viewfeed_last > 120) {
2088 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2091 feeds.each(function(item) {
2092 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2093 uncached.push(item);
2096 if (uncached.length > 0) {
2097 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2098 viewfeed(rf[0], '', rf[1], 0, true);
2102 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2105 exception_error("precache_headlines_idle", e);
2109 function precache_headlines() {
2112 if (!feed_precache_timeout_id) {
2113 feed_precache_timeout_id = window.setTimeout(function() {
2114 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2115 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2117 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2118 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2120 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2121 viewfeed(nf[0], '', nf[1], 0, true);
2123 window.setTimeout(function() {
2124 feed_precache_timeout_id = false;
2130 exception_error("precache_headlines", e);
2134 function cancelSearch() {
2139 exception_error("cancelSearch", e);
2143 function setSelectionScore() {
2145 var ids = getSelectedArticleIds2();
2147 if (ids.length > 0) {
2150 var score = prompt(__("Please enter new score for selected articles:"), score);
2152 if (score != undefined) {
2153 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2154 "&score=" + param_escape(score);
2156 new Ajax.Request("backend.php", {
2158 onComplete: function(transport) {
2159 var reply = JSON.parse(transport.responseText);
2163 ids.each(function(id) {
2164 var row = $("RROW-" + id);
2167 var pic = row.getElementsByClassName("hlScorePic")[0];
2170 pic.src = pic.src.replace(/score_.*?\.png/,
2171 reply["score_pic"]);
2172 pic.setAttribute("score", score);
2181 alert(__("No articles are selected."));
2184 exception_error("setSelectionScore", e);
2188 function changeScore(id, pic) {
2190 var score = pic.getAttribute("score");
2192 var new_score = prompt(__("Please enter new score for this article:"), score);
2194 if (new_score != undefined) {
2196 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2197 "&score=" + param_escape(new_score);
2199 new Ajax.Request("backend.php", {
2201 onComplete: function(transport) {
2202 var reply = JSON.parse(transport.responseText);
2205 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2206 pic.setAttribute("score", new_score);
2211 exception_error("changeScore", e);