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 var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
168 dojo.parser.parse(child);
170 if (!Element.visible(child))
171 new Effect.Appear(child, { duration : 0.5 });
173 c.domNode.removeChild(child);
178 console.log("no new headlines received");
180 var hsp = $("headlines-spacer");
182 if (hsp) hsp.innerHTML = "";
186 if (headlines_count > 0)
187 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
190 for (var i = 0; i < articles.length; i++) {
191 var a_id = articles[i]['id'];
192 cache_set("article:" + a_id, articles[i]['content']);
195 console.log("no cached articles received");
198 // do not precache stuff after fresh feed
200 precache_headlines();
203 parse_counters(counters);
207 } else if (transport.responseText) {
208 console.error("Invalid object received: " + transport.responseText);
209 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
210 __('Could not update headlines (invalid object received - see error console for details)') +
213 //notify_error("Error communicating with server.");
214 Element.show("net-alert");
217 _infscroll_request_sent = 0;
222 exception_error("headlines_callback2", e, transport);
226 function render_article(article) {
228 dijit.byId("headlines-wrap-inner").addChild(
229 dijit.byId("content-insert"));
231 var c = dijit.byId("content-insert");
234 c.domNode.scrollTop = 0;
237 c.attr('content', article);
239 correctHeadlinesOffset(getActiveArticleId());
246 exception_error("render_article", e);
250 function showArticleInHeadlines(id) {
254 selectArticles("none");
256 var crow = $("RROW-" + id);
260 var article_is_unread = crow.hasClassName("Unread");
262 crow.removeClassName("Unread");
264 selectArticles('none');
266 var view_mode = false;
269 view_mode = document.forms['main_toolbar_form'].view_mode;
270 view_mode = view_mode[view_mode.selectedIndex].value;
275 if (article_is_unread && view_mode == "all_articles") {
276 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
281 if (article_is_unread)
282 _force_scheduled_update = true;
285 exception_error("showArticleInHeadlines", e);
289 function article_callback2(transport, id) {
291 console.log("article_callback2 " + id);
293 handle_rpc_json(transport);
298 reply = JSON.parse(transport.responseText);
305 reply.each(function(article) {
306 if (active_post_id == article['id']) {
307 render_article(article['content']);
309 cids_requested.remove(article['id']);
311 cache_set("article:" + article['id'], article['content']);
314 // if (id != last_requested_article) {
315 // console.log("requested article id is out of sequence, aborting");
319 } else if (transport.responseText) {
320 console.error("Invalid object received: " + transport.responseText);
322 render_article("<div class='whiteBox'>" +
323 __('Could not display article (invalid object received - see error console for details)') + "</div>");
325 Element.show("net-alert");
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 && article_is_unread) {
388 query = query + "&mode=prefetch";
390 render_article(cached_article);
392 } else if (cached_article) {
394 query = query + "&mode=prefetch_old";
395 render_article(cached_article);
397 // if we don't need to request any relative ids, we might as well skip
398 // the server roundtrip altogether
399 if (cids_to_request.length == 0) {
402 if (!_infscroll_disable &&
403 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
411 headlines_scroll_handler($("headlines-frame"));
417 last_requested_article = id;
421 if (article_is_unread) {
422 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
425 new Ajax.Request("backend.php", {
427 onComplete: function(transport) {
428 article_callback2(transport, id);
434 exception_error("view", e);
438 function toggleMark(id, client_only) {
440 var query = "?op=rpc&id=" + id + "&method=mark";
442 var img = $("FMPIC-" + id);
446 if (img.src.match("mark_unset")) {
447 img.src = img.src.replace("mark_unset", "mark_set");
448 img.alt = __("Unstar article");
449 query = query + "&mark=1";
452 img.src = img.src.replace("mark_set", "mark_unset");
453 img.alt = __("Star article");
454 query = query + "&mark=0";
457 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
460 new Ajax.Request("backend.php", {
462 onComplete: function(transport) {
463 handle_rpc_json(transport);
468 exception_error("toggleMark", e);
472 function togglePub(id, client_only, no_effects, note) {
474 var query = "?op=rpc&id=" + id + "&method=publ";
476 if (note != undefined) {
477 query = query + "¬e=" + param_escape(note);
479 query = query + "¬e=undefined";
482 var img = $("FPPIC-" + id);
486 if (img.src.match("pub_unset") || note != undefined) {
487 img.src = img.src.replace("pub_unset", "pub_set");
488 img.alt = __("Unpublish article");
489 query = query + "&pub=1";
492 img.src = img.src.replace("pub_set", "pub_unset");
493 img.alt = __("Publish article");
495 query = query + "&pub=0";
498 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
501 new Ajax.Request("backend.php", {
503 onComplete: function(transport) {
504 handle_rpc_json(transport);
509 exception_error("togglePub", e);
513 function moveToPost(mode) {
517 var rows = getVisibleArticleIds();
522 if (!$('RROW-' + active_post_id)) {
523 active_post_id = false;
526 if (active_post_id == false) {
528 prev_id = rows[rows.length-1]
530 for (var i = 0; i < rows.length; i++) {
531 if (rows[i] == active_post_id) {
533 // Account for adjacent identical article ids.
534 if (i > 0) prev_id = rows[i-1];
536 for (var j = i+1; j < rows.length; j++) {
537 if (rows[j] != active_post_id) {
547 if (mode == "next") {
551 cdmExpandArticle(next_id);
552 cdmScrollToArticleId(next_id);
555 correctHeadlinesOffset(next_id);
556 view(next_id, getActiveFeedId());
561 if (mode == "prev") {
564 cdmExpandArticle(prev_id);
565 cdmScrollToArticleId(prev_id);
567 correctHeadlinesOffset(prev_id);
568 view(prev_id, getActiveFeedId());
574 exception_error("moveToPost", e);
578 function toggleSelected(id, force_on) {
581 var cb = dijit.byId("RCHK-" + id);
582 var row = $("RROW-" + id);
585 if (row.hasClassName('Selected') && !force_on) {
586 row.removeClassName('Selected');
587 if (cb) cb.attr("checked", false);
589 row.addClassName('Selected');
590 if (cb) cb.attr("checked", true);
594 exception_error("toggleSelected", e);
598 function toggleUnread_afh(effect) {
601 var elem = effect.element;
602 elem.style.backgroundColor = "";
605 exception_error("toggleUnread_afh", e);
609 function toggleUnread(id, cmode, effect) {
612 var row = $("RROW-" + id);
614 if (cmode == undefined || cmode == 2) {
615 if (row.hasClassName("Unread")) {
616 row.removeClassName("Unread");
619 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
620 afterFinish: toggleUnread_afh,
621 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
625 row.addClassName("Unread");
628 } else if (cmode == 0) {
630 row.removeClassName("Unread");
633 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
634 afterFinish: toggleUnread_afh,
635 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
638 } else if (cmode == 1) {
639 row.addClassName("Unread");
642 if (cmode == undefined) cmode = 2;
644 var query = "?op=rpc&method=catchupSelected" +
645 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
647 // notify_progress("Loading, please wait...");
649 new Ajax.Request("backend.php", {
651 onComplete: function(transport) {
652 handle_rpc_json(transport);
658 exception_error("toggleUnread", e);
662 function selectionRemoveLabel(id, ids) {
665 if (!ids) ids = getSelectedArticleIds2();
667 if (ids.length == 0) {
668 alert(__("No articles are selected."));
672 var query = "?op=rpc&method=removeFromLabel&ids=" +
673 param_escape(ids.toString()) + "&lid=" + param_escape(id);
677 new Ajax.Request("backend.php", {
679 onComplete: function(transport) {
680 handle_rpc_json(transport);
681 show_labels_in_headlines(transport);
685 exception_error("selectionAssignLabel", e);
690 function selectionAssignLabel(id, ids) {
693 if (!ids) ids = getSelectedArticleIds2();
695 if (ids.length == 0) {
696 alert(__("No articles are selected."));
700 var query = "?op=rpc&method=assignToLabel&ids=" +
701 param_escape(ids.toString()) + "&lid=" + param_escape(id);
705 new Ajax.Request("backend.php", {
707 onComplete: function(transport) {
708 handle_rpc_json(transport);
709 show_labels_in_headlines(transport);
713 exception_error("selectionAssignLabel", e);
718 function selectionToggleUnread(set_state, callback, no_error) {
720 var rows = getSelectedArticleIds2();
722 if (rows.length == 0 && !no_error) {
723 alert(__("No articles are selected."));
727 for (var i = 0; i < rows.length; i++) {
728 var row = $("RROW-" + rows[i]);
730 if (set_state == undefined) {
731 if (row.hasClassName("Unread")) {
732 row.removeClassName("Unread");
734 row.addClassName("Unread");
738 if (set_state == false) {
739 row.removeClassName("Unread");
742 if (set_state == true) {
743 row.addClassName("Unread");
748 if (rows.length > 0) {
752 if (set_state == undefined) {
754 } else if (set_state == true) {
756 } else if (set_state == false) {
760 var query = "?op=rpc&method=catchupSelected" +
761 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
763 notify_progress("Loading, please wait...");
765 new Ajax.Request("backend.php", {
767 onComplete: function(transport) {
768 handle_rpc_json(transport);
769 if (callback) callback(transport);
775 exception_error("selectionToggleUnread", e);
779 function selectionToggleMarked() {
782 var rows = getSelectedArticleIds2();
784 if (rows.length == 0) {
785 alert(__("No articles are selected."));
789 for (var i = 0; i < rows.length; i++) {
790 toggleMark(rows[i], true, true);
793 if (rows.length > 0) {
795 var query = "?op=rpc&method=markSelected&ids=" +
796 param_escape(rows.toString()) + "&cmode=2";
798 new Ajax.Request("backend.php", {
800 onComplete: function(transport) {
801 handle_rpc_json(transport);
807 exception_error("selectionToggleMarked", e);
811 function selectionTogglePublished() {
814 var rows = getSelectedArticleIds2();
816 if (rows.length == 0) {
817 alert(__("No articles are selected."));
821 for (var i = 0; i < rows.length; i++) {
822 togglePub(rows[i], true, true);
825 if (rows.length > 0) {
827 var query = "?op=rpc&method=publishSelected&ids=" +
828 param_escape(rows.toString()) + "&cmode=2";
830 new Ajax.Request("backend.php", {
832 onComplete: function(transport) {
833 handle_rpc_json(transport);
839 exception_error("selectionToggleMarked", e);
843 function getSelectedArticleIds2() {
847 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
849 rv.push(child.id.replace("RROW-", ""));
855 function getLoadedArticleIds() {
858 var children = $$("#headlines-frame > div[id*=RROW-]");
860 children.each(function(child) {
861 rv.push(child.id.replace("RROW-", ""));
868 // mode = all,none,unread,invert,marked,published
869 function selectArticles(mode) {
872 var children = $$("#headlines-frame > div[id*=RROW]");
874 children.each(function(child) {
875 var id = child.id.replace("RROW-", "");
876 var cb = dijit.byId("RCHK-" + id);
879 child.addClassName("Selected");
880 if (cb) cb.attr("checked", true);
881 } else if (mode == "unread") {
882 if (child.hasClassName("Unread")) {
883 child.addClassName("Selected");
884 if (cb) cb.attr("checked", true);
886 child.removeClassName("Selected");
887 if (cb) cb.attr("checked", false);
889 } else if (mode == "marked") {
890 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
892 if (img && img.src.match("mark_set")) {
893 child.addClassName("Selected");
894 if (cb) cb.attr("checked", true);
896 child.removeClassName("Selected");
897 if (cb) cb.attr("checked", false);
899 } else if (mode == "published") {
900 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
902 if (img && img.src.match("pub_set")) {
903 child.addClassName("Selected");
904 if (cb) cb.attr("checked", true);
906 child.removeClassName("Selected");
907 if (cb) cb.attr("checked", false);
910 } else if (mode == "invert") {
911 if (child.hasClassName("Selected")) {
912 child.removeClassName("Selected");
913 if (cb) cb.attr("checked", false);
915 child.addClassName("Selected");
916 if (cb) cb.attr("checked", true);
920 child.removeClassName("Selected");
921 if (cb) cb.attr("checked", false);
926 exception_error("selectArticles", e);
930 function catchupPage() {
932 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
934 var str = __("Mark all visible articles in %s as read?");
936 str = str.replace("%s", fn);
938 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
942 selectArticles('all');
943 selectionToggleUnread(false, 'viewCurrentFeed()', true);
944 selectArticles('none');
947 function deleteSelection() {
951 var rows = getSelectedArticleIds2();
953 if (rows.length == 0) {
954 alert(__("No articles are selected."));
958 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
961 if (getActiveFeedId() != 0) {
962 str = __("Delete %d selected articles in %s?");
964 str = __("Delete %d selected articles?");
967 str = str.replace("%d", rows.length);
968 str = str.replace("%s", fn);
970 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
974 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
978 new Ajax.Request("backend.php", {
980 onComplete: function(transport) {
981 handle_rpc_json(transport);
986 exception_error("deleteSelection", e);
990 function archiveSelection() {
994 var rows = getSelectedArticleIds2();
996 if (rows.length == 0) {
997 alert(__("No articles are selected."));
1001 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1005 if (getActiveFeedId() != 0) {
1006 str = __("Archive %d selected articles in %s?");
1009 str = __("Move %d archived articles back?");
1013 str = str.replace("%d", rows.length);
1014 str = str.replace("%s", fn);
1016 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1020 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1024 for (var i = 0; i < rows.length; i++) {
1025 cache_delete("article:" + rows[i]);
1028 new Ajax.Request("backend.php", {
1030 onComplete: function(transport) {
1031 handle_rpc_json(transport);
1036 exception_error("archiveSelection", e);
1040 function catchupSelection() {
1044 var rows = getSelectedArticleIds2();
1046 if (rows.length == 0) {
1047 alert(__("No articles are selected."));
1051 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1053 var str = __("Mark %d selected articles in %s as read?");
1055 str = str.replace("%d", rows.length);
1056 str = str.replace("%s", fn);
1058 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1062 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1065 exception_error("catchupSelection", e);
1069 function editArticleTags(id) {
1070 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1072 if (dijit.byId("editTagsDlg"))
1073 dijit.byId("editTagsDlg").destroyRecursive();
1075 dialog = new dijit.Dialog({
1077 title: __("Edit article Tags"),
1078 style: "width: 600px",
1079 execute: function() {
1080 if (this.validate()) {
1081 var query = dojo.objectToQuery(this.attr('value'));
1083 notify_progress("Saving article tags...", true);
1085 new Ajax.Request("backend.php", {
1087 onComplete: function(transport) {
1091 var data = JSON.parse(transport.responseText);
1094 var tags_str = article.tags;
1095 var id = tags_str.id;
1097 var tags = $("ATSTR-" + id);
1098 var tooltip = dijit.byId("ATSTRTIP-" + id);
1100 if (tags) tags.innerHTML = tags_str.content;
1101 if (tooltip) tooltip.attr('label', tags_str.content_full);
1103 cache_delete("article:" + id);
1112 var tmph = dojo.connect(dialog, 'onLoad', function() {
1113 dojo.disconnect(tmph);
1115 new Ajax.Autocompleter('tags_str', 'tags_choices',
1116 "backend.php?op=rpc&method=completeTags",
1117 { tokens: ',', paramName: "search" });
1124 function cdmScrollToArticleId(id) {
1126 var ctr = $("headlines-frame");
1127 var e = $("RROW-" + id);
1129 if (!e || !ctr) return;
1131 ctr.scrollTop = e.offsetTop;
1134 exception_error("cdmScrollToArticleId", e);
1138 function getActiveArticleId() {
1139 return active_post_id;
1142 function postMouseIn(id) {
1143 post_under_pointer = id;
1146 function postMouseOut(id) {
1147 post_under_pointer = false;
1150 function headlines_scroll_handler(e) {
1152 var hsp = $("headlines-spacer");
1154 if (!_infscroll_disable) {
1155 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1156 (e.scrollHeight != 0 &&
1157 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1160 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1161 __("Loading, please wait...");
1163 loadMoreHeadlines();
1168 if (hsp) hsp.innerHTML = "";
1171 if (getInitParam("cdm_auto_catchup") == 1) {
1173 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1175 if ($("headlines-frame").scrollTop >
1176 (child.offsetTop + child.offsetHeight/2)) {
1178 var id = child.id.replace("RROW-", "");
1180 if (catchup_id_batch.indexOf(id) == -1)
1181 catchup_id_batch.push(id);
1183 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1187 if (catchup_id_batch.length > 0) {
1188 window.clearTimeout(catchup_timeout_id);
1190 if (!_infscroll_request_sent) {
1191 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1198 console.warn("headlines_scroll_handler: " + e);
1202 function catchupBatchedArticles() {
1204 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1206 // make a copy of the array
1207 var batch = catchup_id_batch.slice();
1208 var query = "?op=rpc&method=catchupSelected" +
1209 "&cmode=0&ids=" + param_escape(batch.toString());
1213 new Ajax.Request("backend.php", {
1215 onComplete: function(transport) {
1216 handle_rpc_json(transport);
1218 batch.each(function(id) {
1219 var elem = $("RROW-" + id);
1220 if (elem) elem.removeClassName("Unread");
1221 catchup_id_batch.remove(id);
1228 exception_error("catchupBatchedArticles", e);
1232 function catchupRelativeToArticle(below, id) {
1236 if (!id) id = getActiveArticleId();
1239 alert(__("No article is selected."));
1243 var visible_ids = getVisibleArticleIds();
1245 var ids_to_mark = new Array();
1248 for (var i = 0; i < visible_ids.length; i++) {
1249 if (visible_ids[i] != id) {
1250 var e = $("RROW-" + visible_ids[i]);
1252 if (e && e.hasClassName("Unread")) {
1253 ids_to_mark.push(visible_ids[i]);
1260 for (var i = visible_ids.length-1; i >= 0; i--) {
1261 if (visible_ids[i] != id) {
1262 var e = $("RROW-" + visible_ids[i]);
1264 if (e && e.hasClassName("Unread")) {
1265 ids_to_mark.push(visible_ids[i]);
1273 if (ids_to_mark.length == 0) {
1274 alert(__("No articles found to mark"));
1276 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1278 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1280 for (var i = 0; i < ids_to_mark.length; i++) {
1281 var e = $("RROW-" + ids_to_mark[i]);
1282 e.removeClassName("Unread");
1285 var query = "?op=rpc&method=catchupSelected" +
1286 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1288 new Ajax.Request("backend.php", {
1290 onComplete: function(transport) {
1291 handle_rpc_json(transport);
1298 exception_error("catchupRelativeToArticle", e);
1302 function cdmExpandArticle(id) {
1307 var elem = $("CICD-" + active_post_id);
1309 if (id == active_post_id && Element.visible(elem))
1312 selectArticles("none");
1314 var old_offset = $("RROW-" + id).offsetTop;
1316 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1318 Element.show("CEXC-" + active_post_id);
1321 active_post_id = id;
1323 elem = $("CICD-" + id);
1325 if (!Element.visible(elem)) {
1327 Element.hide("CEXC-" + id);
1330 var new_offset = $("RROW-" + id).offsetTop;
1332 $("headlines-frame").scrollTop += (new_offset-old_offset);
1334 if ($("RROW-" + id).offsetTop != old_offset)
1335 $("headlines-frame").scrollTop = new_offset;
1337 toggleUnread(id, 0, true);
1341 exception_error("cdmExpandArticle", e);
1347 function fixHeadlinesOrder(ids) {
1349 for (var i = 0; i < ids.length; i++) {
1350 var e = $("RROW-" + ids[i]);
1354 e.removeClassName("even");
1355 e.addClassName("odd");
1357 e.removeClassName("odd");
1358 e.addClassName("even");
1363 exception_error("fixHeadlinesOrder", e);
1367 function getArticleUnderPointer() {
1368 return post_under_pointer;
1371 function zoomToArticle(event, id) {
1373 var cached_article = cache_get("article: " + id);
1375 if (dijit.byId("ATAB-" + id))
1376 if (!event || !event.shiftKey)
1377 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1379 if (dijit.byId("ATSTRTIP-" + id))
1380 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1382 if (cached_article) {
1383 //closeArticlePanel();
1385 var article_pane = new dijit.layout.ContentPane({
1386 title: __("Loading...") , content: cached_article,
1387 style: 'padding : 0px;',
1391 dijit.byId("content-tabs").addChild(article_pane);
1393 if (!event || !event.shiftKey)
1394 dijit.byId("content-tabs").selectChild(article_pane);
1396 if ($("PTITLE-" + id))
1397 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1401 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1403 notify_progress("Loading, please wait...", true);
1405 new Ajax.Request("backend.php", {
1407 onComplete: function(transport) {
1410 var reply = JSON.parse(transport.responseText);
1413 //closeArticlePanel();
1415 var content = reply[0]['content'];
1417 var article_pane = new dijit.layout.ContentPane({
1418 title: "article-" + id , content: content,
1419 style: 'padding : 0px;',
1423 dijit.byId("content-tabs").addChild(article_pane);
1425 if (!event || !event.shiftKey)
1426 dijit.byId("content-tabs").selectChild(article_pane);
1428 if ($("PTITLE-" + id))
1429 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1436 exception_error("zoomToArticle", e);
1440 function scrollArticle(offset) {
1443 var ci = $("content-insert");
1445 ci.scrollTop += offset;
1448 var hi = $("headlines-frame");
1450 hi.scrollTop += offset;
1455 exception_error("scrollArticle", e);
1459 function show_labels_in_headlines(transport) {
1461 var data = JSON.parse(transport.responseText);
1464 data['info-for-headlines'].each(function(elem) {
1465 var ctr = $("HLLCTR-" + elem.id);
1467 if (ctr) ctr.innerHTML = elem.labels;
1470 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1474 exception_error("show_labels_in_headlines", e);
1478 /* function toggleHeadlineActions() {
1480 var e = $("headlineActionsBody");
1481 var p = $("headlineActionsDrop");
1483 if (!Element.visible(e)) {
1490 e.style.left = (p.offsetLeft + 1) + "px";
1491 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1494 exception_error("toggleHeadlineActions", e);
1498 /* function publishWithNote(id, def_note) {
1500 if (!def_note) def_note = '';
1502 var note = prompt(__("Please enter a note for this article:"), def_note);
1504 if (note != undefined) {
1505 togglePub(id, false, false, note);
1509 exception_error("publishWithNote", e);
1513 function dismissArticle(id) {
1515 var elem = $("RROW-" + id);
1517 toggleUnread(id, 0, true);
1519 new Effect.Fade(elem, {duration : 0.5});
1521 active_post_id = false;
1524 exception_error("dismissArticle", e);
1528 function dismissSelectedArticles() {
1531 var ids = getVisibleArticleIds();
1535 for (var i = 0; i < ids.length; i++) {
1536 var elem = $("RROW-" + ids[i]);
1538 if (elem.className && elem.hasClassName("Selected") &&
1539 ids[i] != active_post_id) {
1540 new Effect.Fade(elem, {duration : 0.5});
1548 selectionToggleUnread(false);
1550 fixHeadlinesOrder(tmp);
1553 exception_error("dismissSelectedArticles", e);
1557 function dismissReadArticles() {
1560 var ids = getVisibleArticleIds();
1563 for (var i = 0; i < ids.length; i++) {
1564 var elem = $("RROW-" + ids[i]);
1566 if (elem.className && !elem.hasClassName("Unread") &&
1567 !elem.hasClassName("Selected")) {
1569 new Effect.Fade(elem, {duration : 0.5});
1575 fixHeadlinesOrder(tmp);
1578 exception_error("dismissSelectedArticles", e);
1582 function getVisibleArticleIds() {
1587 getLoadedArticleIds().each(function(id) {
1588 var elem = $("RROW-" + id);
1589 if (elem && Element.visible(elem))
1594 exception_error("getVisibleArticleIds", e);
1600 function cdmClicked(event, id) {
1602 //var shift_key = event.shiftKey;
1606 if (!event.ctrlKey) {
1608 if (!getInitParam("cdm_expanded")) {
1609 return cdmExpandArticle(id);
1612 selectArticles("none");
1615 var elem = $("RROW-" + id);
1616 var article_is_unread = elem.hasClassName("Unread");
1619 elem.removeClassName("Unread");
1621 active_post_id = id;
1623 if (article_is_unread) {
1624 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1627 var query = "?op=rpc&method=catchupSelected" +
1628 "&cmode=0&ids=" + param_escape(id);
1630 new Ajax.Request("backend.php", {
1632 onComplete: function(transport) {
1633 handle_rpc_json(transport);
1640 toggleSelected(id, true);
1642 var elem = $("RROW-" + id);
1643 var article_is_unread = elem.hasClassName("Unread");
1645 if (article_is_unread) {
1646 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1649 toggleUnread(id, 0, false);
1650 zoomToArticle(event, id);
1654 exception_error("cdmClicked");
1660 function postClicked(event, id) {
1663 if (!event.ctrlKey) {
1666 postOpenInNewTab(event, id);
1671 exception_error("postClicked");
1675 function hlOpenInNewTab(event, id) {
1676 toggleUnread(id, 0, false);
1677 zoomToArticle(event, id);
1680 function postOpenInNewTab(event, id) {
1681 closeArticlePanel(id);
1682 zoomToArticle(event, id);
1685 function hlClicked(event, id) {
1687 if (event.which == 2) {
1690 } else if (event.altKey) {
1691 openArticleInNewWindow(id);
1692 } else if (!event.ctrlKey) {
1697 toggleUnread(id, 0, false);
1698 zoomToArticle(event, id);
1703 exception_error("hlClicked");
1707 function getFirstVisibleHeadlineId() {
1708 var rows = getVisibleArticleIds();
1713 function getLastVisibleHeadlineId() {
1714 var rows = getVisibleArticleIds();
1715 return rows[rows.length-1];
1718 function openArticleInNewWindow(id) {
1719 toggleUnread(id, 0, false);
1720 window.open("backend.php?op=article&method=redirect&id=" + id);
1723 function isCdmMode() {
1724 return getInitParam("combined_display_mode");
1727 function markHeadline(id) {
1728 var row = $("RROW-" + id);
1730 var check = dijit.byId("RCHK-" + id);
1733 check.attr("checked", true);
1736 row.addClassName("Selected");
1740 function getRelativePostIds(id, limit) {
1746 if (!limit) limit = 6; //3
1748 var ids = getVisibleArticleIds();
1750 for (var i = 0; i < ids.length; i++) {
1752 for (var k = 1; k <= limit; k++) {
1753 //if (i > k-1) tmp.push(ids[i-k]);
1754 if (i < ids.length-k) tmp.push(ids[i+k]);
1761 exception_error("getRelativePostIds", e);
1767 function correctHeadlinesOffset(id) {
1771 var container = $("headlines-frame");
1772 var row = $("RROW-" + id);
1774 if (!container || !row) return;
1776 var viewport = container.offsetHeight;
1778 var rel_offset_top = row.offsetTop - container.scrollTop;
1779 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1781 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1782 //console.log("Vport: " + viewport);
1784 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1785 container.scrollTop = row.offsetTop;
1786 } else if (rel_offset_bottom > viewport) {
1788 /* doesn't properly work with Opera in some cases because
1789 Opera fucks up element scrolling */
1791 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1795 exception_error("correctHeadlinesOffset", e);
1800 function headlineActionsChange(elem) {
1803 elem.attr('value', 'false');
1805 exception_error("headlineActionsChange", e);
1809 function closeArticlePanel() {
1811 var tabs = dijit.byId("content-tabs");
1812 var child = tabs.selectedChildWidget;
1814 if (child && tabs.getIndexOfChild(child) > 0) {
1815 tabs.removeChild(child);
1818 if (dijit.byId("content-insert"))
1819 dijit.byId("headlines-wrap-inner").removeChild(
1820 dijit.byId("content-insert"));
1824 function initHeadlinesMenu() {
1826 if (dijit.byId("headlinesMenu"))
1827 dijit.byId("headlinesMenu").destroyRecursive();
1832 nodes = $$("#headlines-frame > div[id*=RROW]");
1834 nodes = $$("#headlines-frame span[id*=RTITLE]");
1837 nodes.each(function(node) {
1841 var menu = new dijit.Menu({
1842 id: "headlinesMenu",
1846 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1847 var callerNode = event.target, match = null, tries = 0;
1849 while (match == null && callerNode && tries <= 3) {
1850 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1851 callerNode = callerNode.parentNode;
1855 if (match) this.callerRowId = parseInt(match[1]);
1859 /* if (!isCdmMode())
1860 menu.addChild(new dijit.MenuItem({
1861 label: __("View article"),
1862 onClick: function(event) {
1863 view(this.getParent().callerRowId);
1866 menu.addChild(new dijit.MenuItem({
1867 label: __("Open original article"),
1868 onClick: function(event) {
1869 openArticleInNewWindow(this.getParent().callerRowId);
1872 menu.addChild(new dijit.MenuItem({
1873 label: __("View in a tt-rss tab"),
1874 onClick: function(event) {
1875 hlOpenInNewTab(event, this.getParent().callerRowId);
1878 menu.addChild(new dijit.MenuSeparator());
1880 menu.addChild(new dijit.MenuItem({
1881 label: __("Mark above as read"),
1882 onClick: function(event) {
1883 catchupRelativeToArticle(0, this.getParent().callerRowId);
1886 menu.addChild(new dijit.MenuItem({
1887 label: __("Mark below as read"),
1888 onClick: function(event) {
1889 catchupRelativeToArticle(1, this.getParent().callerRowId);
1893 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1897 menu.addChild(new dijit.MenuSeparator());
1899 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1900 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1902 labels.each(function(label) {
1903 var id = label.id[0];
1904 var bare_id = id.substr(id.indexOf(":")+1);
1905 var name = label.name[0];
1907 bare_id = -11-bare_id;
1909 labelAddMenu.addChild(new dijit.MenuItem({
1912 onClick: function(event) {
1913 var ids = getSelectedArticleIds2();
1915 var id = this.getParent().ownerMenu.callerRowId + "";
1917 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1919 selectionAssignLabel(this.labelId, ids);
1922 labelDelMenu.addChild(new dijit.MenuItem({
1925 onClick: function(event) {
1926 var ids = getSelectedArticleIds2();
1928 var id = this.getParent().ownerMenu.callerRowId + "";
1930 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1932 selectionRemoveLabel(this.labelId, ids);
1937 menu.addChild(new dijit.PopupMenuItem({
1938 label: __("Assign label"),
1939 popup: labelAddMenu,
1942 menu.addChild(new dijit.PopupMenuItem({
1943 label: __("Remove label"),
1944 popup: labelDelMenu,
1952 exception_error("initHeadlinesMenu", e);
1957 function player(elem) {
1958 var aid = elem.getAttribute("audio-id");
1959 var status = elem.getAttribute("status");
1967 elem.innerHTML = __("Playing...");
1968 elem.title = __("Click to pause");
1969 elem.addClassName("playing");
1973 elem.innerHTML = __("Play");
1974 elem.title = __("Click to play");
1975 elem.removeClassName("playing");
1978 elem.setAttribute("status", status);
1980 alert("Your browser doesn't seem to support HTML5 audio.");
1984 function cache_set(id, obj) {
1985 //console.log("cache_set: " + id);
1988 sessionStorage[id] = obj;
1990 sessionStorage.clear();
1994 function cache_get(id) {
1996 return sessionStorage[id];
1999 function cache_clear() {
2001 sessionStorage.clear();
2004 function cache_delete(id) {
2006 sessionStorage.removeItem(id);
2009 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2010 if (toolbar_obj && content_obj) {
2011 cache_set("feed:" + feed + ":" + is_cat,
2012 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2015 obj = cache_get("feed:" + feed + ":" + is_cat);
2018 obj = JSON.parse(obj);
2020 if (toolbar_obj) obj.toolbar = toolbar_obj;
2021 if (content_obj) obj.content = content_obj;
2023 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2027 console.warn("cache_headlines failed: " + e);
2032 function render_local_headlines(feed, is_cat, obj) {
2035 dijit.byId("headlines-toolbar").attr('content',
2038 dijit.byId("headlines-frame").attr('content',
2041 dojo.parser.parse('headlines-toolbar');
2043 $("headlines-frame").scrollTop = 0;
2044 selectArticles('none');
2045 setActiveFeedId(feed, is_cat);
2046 initHeadlinesMenu();
2048 dijit.getEnclosingWidget(
2049 document.forms["main_toolbar_form"].update).attr('disabled',
2050 is_cat || feed <= 0);
2052 precache_headlines();
2055 exception_error("render_local_headlines", e);
2059 function precache_headlines_idle() {
2061 if (!feed_precache_timeout_id) {
2062 if (get_timestamp() - _viewfeed_last > 120) {
2064 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2067 feeds.each(function(item) {
2068 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2069 uncached.push(item);
2072 if (uncached.length > 0) {
2073 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2074 viewfeed(rf[0], '', rf[1], 0, true);
2078 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2081 exception_error("precache_headlines_idle", e);
2085 function precache_headlines() {
2088 if (!feed_precache_timeout_id) {
2089 feed_precache_timeout_id = window.setTimeout(function() {
2090 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2091 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2093 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2094 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2096 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2097 viewfeed(nf[0], '', nf[1], 0, true);
2099 window.setTimeout(function() {
2100 feed_precache_timeout_id = false;
2106 exception_error("precache_headlines", e);
2110 function cancelSearch() {
2115 exception_error("cancelSearch", e);
2119 function setSelectionScore() {
2121 var ids = getSelectedArticleIds2();
2123 if (ids.length > 0) {
2126 var score = prompt(__("Please enter new score for selected articles:"), score);
2128 if (score != undefined) {
2129 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2130 "&score=" + param_escape(score);
2132 new Ajax.Request("backend.php", {
2134 onComplete: function(transport) {
2135 var reply = JSON.parse(transport.responseText);
2139 ids.each(function(id) {
2140 var row = $("RROW-" + id);
2143 var pic = row.getElementsByClassName("hlScorePic")[0];
2146 pic.src = pic.src.replace(/score_.*?\.png/,
2147 reply["score_pic"]);
2148 pic.setAttribute("score", score);
2157 alert(__("No articles are selected."));
2160 exception_error("setSelectionScore", e);
2164 function changeScore(id, pic) {
2166 var score = pic.getAttribute("score");
2168 var new_score = prompt(__("Please enter new score for this article:"), score);
2170 if (new_score != undefined) {
2172 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2173 "&score=" + param_escape(new_score);
2175 new Ajax.Request("backend.php", {
2177 onComplete: function(transport) {
2178 var reply = JSON.parse(transport.responseText);
2181 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2182 pic.setAttribute("score", new_score);
2187 exception_error("changeScore", e);