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 = [];
17 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
19 function headlines_callback2(transport, offset, background, infscroll_req) {
21 handle_rpc_json(transport);
23 loading_set_progress(25);
25 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
33 reply = JSON.parse(transport.responseText);
40 is_cat = reply['headlines']['is_cat'];
41 feed_id = reply['headlines']['id'];
44 var content = reply['headlines']['content'];
46 if (getInitParam("cdm_auto_catchup") == 1) {
47 content = content + "<div id='headlines-spacer'></div>";
50 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
54 setActiveFeedId(feed_id, is_cat);
57 if (offset == 0 && infscroll_req == false) {
58 $("headlines-frame").scrollTop = 0;
62 var headlines_count = reply['headlines-info']['count'];
64 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
66 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
67 _infscroll_disable = 1;
69 _infscroll_disable = 0;
72 var counters = reply['counters'];
73 var articles = reply['articles'];
74 //var runtime_info = reply['runtime-info'];
76 if (offset == 0 && infscroll_req == false) {
77 dijit.byId("headlines-frame").attr('content',
78 reply['headlines']['content']);
80 dijit.byId("headlines-toolbar").attr('content',
81 reply['headlines']['toolbar']);
83 $$("#headlines-frame > div[id*=RROW]").each(function(row) {
84 if ($$("#headlines-frame DIV[id="+row.id+"]").length > 1) {
85 row.parentNode.removeChild(row);
89 if (getInitParam("cdm_auto_catchup") == 1) {
90 var hsp = $("headlines-spacer");
91 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
92 dijit.byId('headlines-frame').domNode.appendChild(hsp);
99 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
100 console.log("adding some more headlines: " + headlines_count);
102 var c = dijit.byId("headlines-frame");
103 var ids = getSelectedArticleIds2();
106 $("headlines-tmp").innerHTML = reply['headlines']['content'];
108 var hsp = $("headlines-spacer");
111 c.domNode.removeChild(hsp);
113 $$("#headlines-tmp > div").each(function(row) {
114 if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
115 row.style.display = 'none';
116 c.domNode.appendChild(row);
119 row.parentNode.removeChild(row);
123 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
125 fixHeadlinesOrder(getLoadedArticleIds());
127 if (getInitParam("cdm_auto_catchup") == 1) {
128 c.domNode.appendChild(hsp);
131 console.log("added " + num_added + " headlines");
133 console.log("restore selected ids: " + ids);
135 for (var i = 0; i < ids.length; i++) {
136 markHeadline(ids[i]);
141 $$("#headlines-frame > div[id*=RROW]").each(
143 if (!Element.visible(child))
144 new Effect.Appear(child, { duration : 0.5 });
148 console.log("no new headlines received");
150 var hsp = $("headlines-spacer");
152 if (hsp) hsp.innerHTML = "";
156 if (headlines_count > 0)
157 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
160 for (var i = 0; i < articles.length; i++) {
161 var a_id = articles[i]['id'];
162 cache_set("article:" + a_id, articles[i]['content']);
165 console.log("no cached articles received");
168 // do not precache stuff after fresh feed
170 precache_headlines();
173 parse_counters(counters);
178 console.error("Invalid object received: " + transport.responseText);
179 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
180 __('Could not update headlines (invalid object received - see error console for details)') +
184 _infscroll_request_sent = 0;
189 exception_error("headlines_callback2", e, transport);
193 function render_article(article) {
195 dijit.byId("headlines-wrap-inner").addChild(
196 dijit.byId("content-insert"));
198 var c = dijit.byId("content-insert");
201 c.domNode.scrollTop = 0;
204 c.attr('content', article);
206 correctHeadlinesOffset(getActiveArticleId());
213 exception_error("render_article", e);
217 function showArticleInHeadlines(id) {
221 selectArticles("none");
223 var crow = $("RROW-" + id);
227 var article_is_unread = crow.hasClassName("Unread");
229 crow.removeClassName("Unread");
231 selectArticles('none');
233 var upd_img_pic = $("FUPDPIC-" + id);
235 var view_mode = false;
238 view_mode = document.forms['main_toolbar_form'].view_mode;
239 view_mode = view_mode[view_mode.selectedIndex].value;
244 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
245 upd_img_pic.src.match("fresh_sign.png"))) {
247 upd_img_pic.src = "images/blank_icon.gif";
249 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
251 } else if (article_is_unread && view_mode == "all_articles") {
252 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
257 if (article_is_unread)
258 _force_scheduled_update = true;
261 exception_error("showArticleInHeadlines", e);
265 function article_callback2(transport, id) {
267 console.log("article_callback2 " + id);
269 handle_rpc_json(transport);
274 reply = JSON.parse(transport.responseText);
281 var upic = $('FUPDPIC-' + id);
283 if (upic) upic.src = 'images/blank_icon.gif';
285 reply.each(function(article) {
286 if (active_post_id == article['id']) {
287 render_article(article['content']);
289 cids_requested.remove(article['id']);
291 cache_set("article:" + article['id'], article['content']);
294 // if (id != last_requested_article) {
295 // console.log("requested article id is out of sequence, aborting");
300 console.error("Invalid object received: " + transport.responseText);
302 render_article("<div class='whiteBox'>" +
303 __('Could not display article (invalid object received - see error console for details)') + "</div>");
308 headlines_scroll_handler($("headlines-frame"));
311 if (!_infscroll_disable &&
312 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
322 exception_error("article_callback2", e, transport);
328 console.log("loading article: " + id);
330 var cached_article = cache_get("article:" + id);
332 console.log("cache check result: " + (cached_article != false));
336 var query = "?op=article&method=view&id=" + param_escape(id);
338 var neighbor_ids = getRelativePostIds(id);
340 /* only request uncached articles */
342 var cids_to_request = [];
344 for (var i = 0; i < neighbor_ids.length; i++) {
345 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
346 if (!cache_get("article:" + neighbor_ids[i])) {
347 cids_to_request.push(neighbor_ids[i]);
348 cids_requested.push(neighbor_ids[i]);
352 console.log("additional ids: " + cids_to_request.toString());
354 query = query + "&cids=" + cids_to_request.toString();
356 var crow = $("RROW-" + id);
357 var article_is_unread = crow.hasClassName("Unread");
360 showArticleInHeadlines(id);
362 precache_headlines();
364 if (!cached_article) {
366 var upic = $('FUPDPIC-' + id);
369 upic.src = getInitParam("sign_progress");
372 } else if (cached_article && article_is_unread) {
374 query = query + "&mode=prefetch";
376 render_article(cached_article);
378 } else if (cached_article) {
380 query = query + "&mode=prefetch_old";
381 render_article(cached_article);
383 // if we don't need to request any relative ids, we might as well skip
384 // the server roundtrip altogether
385 if (cids_to_request.length == 0) {
388 if (!_infscroll_disable &&
389 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
397 headlines_scroll_handler($("headlines-frame"));
403 last_requested_article = id;
407 if (article_is_unread) {
408 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
411 new Ajax.Request("backend.php", {
413 onComplete: function(transport) {
414 article_callback2(transport, id);
420 exception_error("view", e);
424 function toggleMark(id, client_only) {
426 var query = "?op=rpc&id=" + id + "&method=mark";
428 var img = $("FMPIC-" + id);
432 if (img.src.match("mark_unset")) {
433 img.src = img.src.replace("mark_unset", "mark_set");
434 img.alt = __("Unstar article");
435 query = query + "&mark=1";
438 img.src = img.src.replace("mark_set", "mark_unset");
439 img.alt = __("Star article");
440 query = query + "&mark=0";
443 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
446 new Ajax.Request("backend.php", {
448 onComplete: function(transport) {
449 handle_rpc_json(transport);
454 exception_error("toggleMark", e);
458 function togglePub(id, client_only, no_effects, note) {
460 var query = "?op=rpc&id=" + id + "&method=publ";
462 if (note != undefined) {
463 query = query + "¬e=" + param_escape(note);
465 query = query + "¬e=undefined";
468 var img = $("FPPIC-" + id);
472 if (img.src.match("pub_unset") || note != undefined) {
473 img.src = img.src.replace("pub_unset", "pub_set");
474 img.alt = __("Unpublish article");
475 query = query + "&pub=1";
478 img.src = img.src.replace("pub_set", "pub_unset");
479 img.alt = __("Publish article");
481 query = query + "&pub=0";
484 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
487 new Ajax.Request("backend.php", {
489 onComplete: function(transport) {
490 handle_rpc_json(transport);
495 exception_error("togglePub", e);
499 function moveToPost(mode) {
503 var rows = getVisibleArticleIds();
508 if (!$('RROW-' + active_post_id)) {
509 active_post_id = false;
512 if (active_post_id == false) {
514 prev_id = rows[rows.length-1]
516 for (var i = 0; i < rows.length; i++) {
517 if (rows[i] == active_post_id) {
519 // Account for adjacent identical article ids.
520 if (i > 0) prev_id = rows[i-1];
522 for (var j = i+1; j < rows.length; j++) {
523 if (rows[j] != active_post_id) {
533 if (mode == "next") {
537 cdmExpandArticle(next_id);
538 cdmScrollToArticleId(next_id);
541 correctHeadlinesOffset(next_id);
542 view(next_id, getActiveFeedId());
547 if (mode == "prev") {
550 cdmExpandArticle(prev_id);
551 cdmScrollToArticleId(prev_id);
553 correctHeadlinesOffset(prev_id);
554 view(prev_id, getActiveFeedId());
560 exception_error("moveToPost", e);
564 function toggleSelected(id, force_on) {
567 var cb = $("RCHK-" + id);
568 var row = $("RROW-" + id);
571 if (row.hasClassName('Selected') && !force_on) {
572 row.removeClassName('Selected');
573 if (cb) cb.checked = false;
575 row.addClassName('Selected');
576 if (cb) cb.checked = true;
580 exception_error("toggleSelected", e);
584 function toggleUnread_afh(effect) {
587 var elem = effect.element;
588 elem.style.backgroundColor = "";
591 exception_error("toggleUnread_afh", e);
595 function toggleUnread(id, cmode, effect) {
598 var row = $("RROW-" + id);
600 if (cmode == undefined || cmode == 2) {
601 if (row.hasClassName("Unread")) {
602 row.removeClassName("Unread");
605 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
606 afterFinish: toggleUnread_afh,
607 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
611 row.addClassName("Unread");
614 } else if (cmode == 0) {
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 } } );
624 } else if (cmode == 1) {
625 row.addClassName("Unread");
628 if (cmode == undefined) cmode = 2;
630 var query = "?op=rpc&method=catchupSelected" +
631 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
633 // notify_progress("Loading, please wait...");
635 new Ajax.Request("backend.php", {
637 onComplete: function(transport) {
638 handle_rpc_json(transport);
644 exception_error("toggleUnread", e);
648 function selectionRemoveLabel(id, ids) {
651 if (!ids) ids = getSelectedArticleIds2();
653 if (ids.length == 0) {
654 alert(__("No articles are selected."));
658 var query = "?op=rpc&method=removeFromLabel&ids=" +
659 param_escape(ids.toString()) + "&lid=" + param_escape(id);
663 new Ajax.Request("backend.php", {
665 onComplete: function(transport) {
666 handle_rpc_json(transport);
667 show_labels_in_headlines(transport);
671 exception_error("selectionAssignLabel", e);
676 function selectionAssignLabel(id, ids) {
679 if (!ids) ids = getSelectedArticleIds2();
681 if (ids.length == 0) {
682 alert(__("No articles are selected."));
686 var query = "?op=rpc&method=assignToLabel&ids=" +
687 param_escape(ids.toString()) + "&lid=" + param_escape(id);
691 new Ajax.Request("backend.php", {
693 onComplete: function(transport) {
694 handle_rpc_json(transport);
695 show_labels_in_headlines(transport);
699 exception_error("selectionAssignLabel", e);
704 function selectionToggleUnread(set_state, callback, no_error) {
706 var rows = getSelectedArticleIds2();
708 if (rows.length == 0 && !no_error) {
709 alert(__("No articles are selected."));
713 for (var i = 0; i < rows.length; i++) {
714 var row = $("RROW-" + rows[i]);
716 if (set_state == undefined) {
717 if (row.hasClassName("Unread")) {
718 row.removeClassName("Unread");
720 row.addClassName("Unread");
724 if (set_state == false) {
725 row.removeClassName("Unread");
728 if (set_state == true) {
729 row.addClassName("Unread");
734 if (rows.length > 0) {
738 if (set_state == undefined) {
740 } else if (set_state == true) {
742 } else if (set_state == false) {
746 var query = "?op=rpc&method=catchupSelected" +
747 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
749 notify_progress("Loading, please wait...");
751 new Ajax.Request("backend.php", {
753 onComplete: function(transport) {
754 handle_rpc_json(transport);
755 if (callback) callback(transport);
761 exception_error("selectionToggleUnread", e);
765 function selectionToggleMarked() {
768 var rows = getSelectedArticleIds2();
770 if (rows.length == 0) {
771 alert(__("No articles are selected."));
775 for (var i = 0; i < rows.length; i++) {
776 toggleMark(rows[i], true, true);
779 if (rows.length > 0) {
781 var query = "?op=rpc&method=markSelected&ids=" +
782 param_escape(rows.toString()) + "&cmode=2";
784 new Ajax.Request("backend.php", {
786 onComplete: function(transport) {
787 handle_rpc_json(transport);
793 exception_error("selectionToggleMarked", e);
797 function selectionTogglePublished() {
800 var rows = getSelectedArticleIds2();
802 if (rows.length == 0) {
803 alert(__("No articles are selected."));
807 for (var i = 0; i < rows.length; i++) {
808 togglePub(rows[i], true, true);
811 if (rows.length > 0) {
813 var query = "?op=rpc&method=publishSelected&ids=" +
814 param_escape(rows.toString()) + "&cmode=2";
816 new Ajax.Request("backend.php", {
818 onComplete: function(transport) {
819 handle_rpc_json(transport);
825 exception_error("selectionToggleMarked", e);
829 function getSelectedArticleIds2() {
833 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
835 rv.push(child.id.replace("RROW-", ""));
841 function getLoadedArticleIds() {
844 var children = $$("#headlines-frame > div[id*=RROW-]");
846 children.each(function(child) {
847 rv.push(child.id.replace("RROW-", ""));
854 // mode = all,none,unread,invert
855 function selectArticles(mode) {
858 var children = $$("#headlines-frame > div[id*=RROW]");
860 children.each(function(child) {
861 var id = child.id.replace("RROW-", "");
862 var cb = $("RCHK-" + id);
865 child.addClassName("Selected");
867 } else if (mode == "unread") {
868 if (child.hasClassName("Unread")) {
869 child.addClassName("Selected");
872 child.removeClassName("Selected");
875 } else if (mode == "invert") {
876 if (child.hasClassName("Selected")) {
877 child.removeClassName("Selected");
880 child.addClassName("Selected");
885 child.removeClassName("Selected");
891 exception_error("selectArticles", e);
895 function catchupPage() {
897 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
899 var str = __("Mark all visible articles in %s as read?");
901 str = str.replace("%s", fn);
903 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
907 selectArticles('all');
908 selectionToggleUnread(false, 'viewCurrentFeed()', true);
909 selectArticles('none');
912 function deleteSelection() {
916 var rows = getSelectedArticleIds2();
918 if (rows.length == 0) {
919 alert(__("No articles are selected."));
923 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
926 if (getActiveFeedId() != 0) {
927 str = __("Delete %d selected articles in %s?");
929 str = __("Delete %d selected articles?");
932 str = str.replace("%d", rows.length);
933 str = str.replace("%s", fn);
935 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
939 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
943 new Ajax.Request("backend.php", {
945 onComplete: function(transport) {
946 handle_rpc_json(transport);
951 exception_error("deleteSelection", e);
955 function archiveSelection() {
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 = __("Archive %d selected articles in %s?");
974 str = __("Move %d archived articles back?");
978 str = str.replace("%d", rows.length);
979 str = str.replace("%s", fn);
981 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
985 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
989 for (var i = 0; i < rows.length; i++) {
990 cache_delete("article:" + rows[i]);
993 new Ajax.Request("backend.php", {
995 onComplete: function(transport) {
996 handle_rpc_json(transport);
1001 exception_error("archiveSelection", e);
1005 function catchupSelection() {
1009 var rows = getSelectedArticleIds2();
1011 if (rows.length == 0) {
1012 alert(__("No articles are selected."));
1016 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1018 var str = __("Mark %d selected articles in %s as read?");
1020 str = str.replace("%d", rows.length);
1021 str = str.replace("%s", fn);
1023 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1027 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1030 exception_error("catchupSelection", e);
1034 function editArticleTags(id) {
1035 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1037 if (dijit.byId("editTagsDlg"))
1038 dijit.byId("editTagsDlg").destroyRecursive();
1040 dialog = new dijit.Dialog({
1042 title: __("Edit article Tags"),
1043 style: "width: 600px",
1044 execute: function() {
1045 if (this.validate()) {
1046 var query = dojo.objectToQuery(this.attr('value'));
1048 notify_progress("Saving article tags...", true);
1050 new Ajax.Request("backend.php", {
1052 onComplete: function(transport) {
1056 var data = JSON.parse(transport.responseText);
1059 var tags_str = article.tags;
1060 var id = tags_str.id;
1062 var tags = $("ATSTR-" + id);
1063 var tooltip = dijit.byId("ATSTRTIP-" + id);
1065 if (tags) tags.innerHTML = tags_str.content;
1066 if (tooltip) tooltip.attr('label', tags_str.content_full);
1068 cache_delete("article:" + id);
1077 var tmph = dojo.connect(dialog, 'onLoad', function() {
1078 dojo.disconnect(tmph);
1080 new Ajax.Autocompleter('tags_str', 'tags_choices',
1081 "backend.php?op=rpc&method=completeTags",
1082 { tokens: ',', paramName: "search" });
1089 function cdmScrollToArticleId(id) {
1091 var ctr = $("headlines-frame");
1092 var e = $("RROW-" + id);
1094 if (!e || !ctr) return;
1096 ctr.scrollTop = e.offsetTop;
1099 exception_error("cdmScrollToArticleId", e);
1103 function getActiveArticleId() {
1104 return active_post_id;
1107 function postMouseIn(id) {
1108 post_under_pointer = id;
1111 function postMouseOut(id) {
1112 post_under_pointer = false;
1115 function headlines_scroll_handler(e) {
1117 var hsp = $("headlines-spacer");
1119 if (!_infscroll_disable) {
1120 if ((hsp && e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1121 (e.scrollHeight != 0 &&
1122 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1125 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1126 __("Loading, please wait...");
1128 loadMoreHeadlines();
1133 if (hsp) hsp.innerHTML = "";
1136 if (getInitParam("cdm_auto_catchup") == 1) {
1138 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1140 if ($("headlines-frame").scrollTop >
1141 (child.offsetTop + child.offsetHeight/2)) {
1143 var id = child.id.replace("RROW-", "");
1145 if (catchup_id_batch.indexOf(id) == -1)
1146 catchup_id_batch.push(id);
1148 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1152 if (catchup_id_batch.length > 0) {
1153 window.clearTimeout(catchup_timeout_id);
1155 if (!_infscroll_request_sent) {
1156 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1163 console.warn("headlines_scroll_handler: " + e);
1167 function catchupBatchedArticles() {
1169 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1171 // make a copy of the array
1172 var batch = catchup_id_batch.slice();
1173 var query = "?op=rpc&method=catchupSelected" +
1174 "&cmode=0&ids=" + param_escape(batch.toString());
1178 new Ajax.Request("backend.php", {
1180 onComplete: function(transport) {
1181 handle_rpc_json(transport);
1183 batch.each(function(id) {
1184 var elem = $("RROW-" + id);
1185 if (elem) elem.removeClassName("Unread");
1186 catchup_id_batch.remove(id);
1193 exception_error("catchupBatchedArticles", e);
1197 function catchupRelativeToArticle(below, id) {
1201 if (!id) id = getActiveArticleId();
1204 alert(__("No article is selected."));
1208 var visible_ids = getVisibleArticleIds();
1210 var ids_to_mark = new Array();
1213 for (var i = 0; i < visible_ids.length; i++) {
1214 if (visible_ids[i] != id) {
1215 var e = $("RROW-" + visible_ids[i]);
1217 if (e && e.hasClassName("Unread")) {
1218 ids_to_mark.push(visible_ids[i]);
1225 for (var i = visible_ids.length-1; i >= 0; i--) {
1226 if (visible_ids[i] != id) {
1227 var e = $("RROW-" + visible_ids[i]);
1229 if (e && e.hasClassName("Unread")) {
1230 ids_to_mark.push(visible_ids[i]);
1238 if (ids_to_mark.length == 0) {
1239 alert(__("No articles found to mark"));
1241 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1243 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1245 for (var i = 0; i < ids_to_mark.length; i++) {
1246 var e = $("RROW-" + ids_to_mark[i]);
1247 e.removeClassName("Unread");
1250 var query = "?op=rpc&method=catchupSelected" +
1251 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1253 new Ajax.Request("backend.php", {
1255 onComplete: function(transport) {
1256 handle_rpc_json(transport);
1263 exception_error("catchupRelativeToArticle", e);
1267 function cdmExpandArticle(id) {
1272 var elem = $("CICD-" + active_post_id);
1274 var upd_img_pic = $("FUPDPIC-" + id);
1276 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1277 upd_img_pic.src.match("fresh_sign.png"))) {
1279 upd_img_pic.src = "images/blank_icon.gif";
1282 if (id == active_post_id && Element.visible(elem))
1285 selectArticles("none");
1287 var old_offset = $("RROW-" + id).offsetTop;
1289 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1291 Element.show("CEXC-" + active_post_id);
1294 active_post_id = id;
1296 elem = $("CICD-" + id);
1298 if (!Element.visible(elem)) {
1300 Element.hide("CEXC-" + id);
1302 if ($("CWRAP-" + id).innerHTML == "") {
1304 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1306 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1307 __("Loading, please wait...") + "</div>";
1309 var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
1311 var neighbor_ids = getRelativePostIds(id);
1313 /* only request uncached articles */
1314 var cids_to_request = [];
1316 for (var i = 0; i < neighbor_ids.length; i++) {
1317 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1318 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1319 cids_to_request.push(neighbor_ids[i]);
1320 cids_requested.push(neighbor_ids[i]);
1324 console.log("additional ids: " + cids_to_request.toString());
1326 query = query + "&cids=" + cids_to_request.toString();
1330 new Ajax.Request("backend.php", {
1332 onComplete: function(transport) {
1334 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1336 handle_rpc_json(transport);
1338 var reply = JSON.parse(transport.responseText);
1340 reply.each(function(article) {
1341 $("CWRAP-" + article['id']).innerHTML = article['content'];
1342 cids_requested.remove(article['id']);
1349 var new_offset = $("RROW-" + id).offsetTop;
1351 $("headlines-frame").scrollTop += (new_offset-old_offset);
1353 if ($("RROW-" + id).offsetTop != old_offset)
1354 $("headlines-frame").scrollTop = new_offset;
1356 toggleUnread(id, 0, true);
1360 exception_error("cdmExpandArticle", e);
1366 function fixHeadlinesOrder(ids) {
1368 for (var i = 0; i < ids.length; i++) {
1369 var e = $("RROW-" + ids[i]);
1373 e.removeClassName("even");
1374 e.addClassName("odd");
1376 e.removeClassName("odd");
1377 e.addClassName("even");
1382 exception_error("fixHeadlinesOrder", e);
1386 function getArticleUnderPointer() {
1387 return post_under_pointer;
1390 function zoomToArticle(event, id) {
1392 var cached_article = cache_get("article: " + id);
1394 if (dijit.byId("ATAB-" + id))
1395 if (!event || !event.shiftKey)
1396 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1398 if (dijit.byId("ATSTRTIP-" + id))
1399 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1401 if (cached_article) {
1402 //closeArticlePanel();
1404 var article_pane = new dijit.layout.ContentPane({
1405 title: __("Loading...") , content: cached_article,
1406 style: 'padding : 0px;',
1410 dijit.byId("content-tabs").addChild(article_pane);
1412 if (!event || !event.shiftKey)
1413 dijit.byId("content-tabs").selectChild(article_pane);
1415 if ($("PTITLE-" + id))
1416 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1420 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1422 notify_progress("Loading, please wait...", true);
1424 new Ajax.Request("backend.php", {
1426 onComplete: function(transport) {
1429 var reply = JSON.parse(transport.responseText);
1432 //closeArticlePanel();
1434 var content = reply[0]['content'];
1436 var article_pane = new dijit.layout.ContentPane({
1437 title: "article-" + id , content: content,
1438 style: 'padding : 0px;',
1442 dijit.byId("content-tabs").addChild(article_pane);
1444 if (!event || !event.shiftKey)
1445 dijit.byId("content-tabs").selectChild(article_pane);
1447 if ($("PTITLE-" + id))
1448 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1455 exception_error("zoomToArticle", e);
1459 function scrollArticle(offset) {
1462 var ci = $("content-insert");
1464 ci.scrollTop += offset;
1467 var hi = $("headlines-frame");
1469 hi.scrollTop += offset;
1474 exception_error("scrollArticle", e);
1478 function show_labels_in_headlines(transport) {
1480 var data = JSON.parse(transport.responseText);
1483 data['info-for-headlines'].each(function(elem) {
1484 var ctr = $("HLLCTR-" + elem.id);
1486 if (ctr) ctr.innerHTML = elem.labels;
1489 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1493 exception_error("show_labels_in_headlines", e);
1497 /* function toggleHeadlineActions() {
1499 var e = $("headlineActionsBody");
1500 var p = $("headlineActionsDrop");
1502 if (!Element.visible(e)) {
1509 e.style.left = (p.offsetLeft + 1) + "px";
1510 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1513 exception_error("toggleHeadlineActions", e);
1517 /* function publishWithNote(id, def_note) {
1519 if (!def_note) def_note = '';
1521 var note = prompt(__("Please enter a note for this article:"), def_note);
1523 if (note != undefined) {
1524 togglePub(id, false, false, note);
1528 exception_error("publishWithNote", e);
1532 function dismissArticle(id) {
1534 var elem = $("RROW-" + id);
1536 toggleUnread(id, 0, true);
1538 new Effect.Fade(elem, {duration : 0.5});
1540 active_post_id = false;
1543 exception_error("dismissArticle", e);
1547 function dismissSelectedArticles() {
1550 var ids = getVisibleArticleIds();
1554 for (var i = 0; i < ids.length; i++) {
1555 var elem = $("RROW-" + ids[i]);
1557 if (elem.className && elem.hasClassName("Selected") &&
1558 ids[i] != active_post_id) {
1559 new Effect.Fade(elem, {duration : 0.5});
1567 selectionToggleUnread(false);
1569 fixHeadlinesOrder(tmp);
1572 exception_error("dismissSelectedArticles", e);
1576 function dismissReadArticles() {
1579 var ids = getVisibleArticleIds();
1582 for (var i = 0; i < ids.length; i++) {
1583 var elem = $("RROW-" + ids[i]);
1585 if (elem.className && !elem.hasClassName("Unread") &&
1586 !elem.hasClassName("Selected")) {
1588 new Effect.Fade(elem, {duration : 0.5});
1594 fixHeadlinesOrder(tmp);
1597 exception_error("dismissSelectedArticles", e);
1601 function getVisibleArticleIds() {
1606 getLoadedArticleIds().each(function(id) {
1607 var elem = $("RROW-" + id);
1608 if (elem && Element.visible(elem))
1613 exception_error("getVisibleArticleIds", e);
1619 function cdmClicked(event, id) {
1621 //var shift_key = event.shiftKey;
1625 if (!event.ctrlKey) {
1627 if (!getInitParam("cdm_expanded")) {
1628 return cdmExpandArticle(id);
1631 selectArticles("none");
1634 var elem = $("RROW-" + id);
1635 var article_is_unread = elem.hasClassName("Unread");
1638 elem.removeClassName("Unread");
1640 var upd_img_pic = $("FUPDPIC-" + id);
1642 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1643 upd_img_pic.src.match("fresh_sign.png"))) {
1645 upd_img_pic.src = "images/blank_icon.gif";
1648 active_post_id = id;
1650 if (article_is_unread) {
1651 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1654 var query = "?op=rpc&method=catchupSelected" +
1655 "&cmode=0&ids=" + param_escape(id);
1657 new Ajax.Request("backend.php", {
1659 onComplete: function(transport) {
1660 handle_rpc_json(transport);
1667 toggleSelected(id, true);
1669 var elem = $("RROW-" + id);
1670 var article_is_unread = elem.hasClassName("Unread");
1672 if (article_is_unread) {
1673 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1676 toggleUnread(id, 0, false);
1677 zoomToArticle(event, id);
1681 exception_error("cdmClicked");
1687 function postClicked(event, id) {
1690 if (!event.ctrlKey) {
1693 postOpenInNewTab(event, id);
1698 exception_error("postClicked");
1702 function hlOpenInNewTab(event, id) {
1703 toggleUnread(id, 0, false);
1704 zoomToArticle(event, id);
1707 function postOpenInNewTab(event, id) {
1708 closeArticlePanel(id);
1709 zoomToArticle(event, id);
1712 function hlClicked(event, id) {
1714 if (event.which == 2) {
1717 } else if (event.altKey) {
1718 openArticleInNewWindow(id);
1719 } else if (!event.ctrlKey) {
1724 toggleUnread(id, 0, false);
1725 zoomToArticle(event, id);
1730 exception_error("hlClicked");
1734 function getFirstVisibleHeadlineId() {
1735 var rows = getVisibleArticleIds();
1740 function getLastVisibleHeadlineId() {
1741 var rows = getVisibleArticleIds();
1742 return rows[rows.length-1];
1745 function openArticleInNewWindow(id) {
1746 toggleUnread(id, 0, false);
1747 window.open("backend.php?op=article&method=redirect&id=" + id);
1750 function isCdmMode() {
1751 return getInitParam("combined_display_mode");
1754 function markHeadline(id) {
1755 var row = $("RROW-" + id);
1757 var check = $("RCHK-" + id);
1760 check.checked = true;
1763 row.addClassName("Selected");
1767 function getRelativePostIds(id, limit) {
1773 if (!limit) limit = 6; //3
1775 var ids = getVisibleArticleIds();
1777 for (var i = 0; i < ids.length; i++) {
1779 for (var k = 1; k <= limit; k++) {
1780 //if (i > k-1) tmp.push(ids[i-k]);
1781 if (i < ids.length-k) tmp.push(ids[i+k]);
1788 exception_error("getRelativePostIds", e);
1794 function correctHeadlinesOffset(id) {
1798 var container = $("headlines-frame");
1799 var row = $("RROW-" + id);
1801 if (!container || !row) return;
1803 var viewport = container.offsetHeight;
1805 var rel_offset_top = row.offsetTop - container.scrollTop;
1806 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1808 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1809 //console.log("Vport: " + viewport);
1811 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1812 container.scrollTop = row.offsetTop;
1813 } else if (rel_offset_bottom > viewport) {
1815 /* doesn't properly work with Opera in some cases because
1816 Opera fucks up element scrolling */
1818 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1822 exception_error("correctHeadlinesOffset", e);
1827 function headlineActionsChange(elem) {
1830 elem.attr('value', 'false');
1832 exception_error("headlineActionsChange", e);
1836 function closeArticlePanel() {
1838 var tabs = dijit.byId("content-tabs");
1839 var child = tabs.selectedChildWidget;
1841 if (child && tabs.getIndexOfChild(child) > 0) {
1842 tabs.removeChild(child);
1845 if (dijit.byId("content-insert"))
1846 dijit.byId("headlines-wrap-inner").removeChild(
1847 dijit.byId("content-insert"));
1851 function initHeadlinesMenu() {
1853 if (dijit.byId("headlinesMenu"))
1854 dijit.byId("headlinesMenu").destroyRecursive();
1859 nodes = $$("#headlines-frame > div[id*=RROW]");
1861 nodes = $$("#headlines-frame span[id*=RTITLE]");
1864 nodes.each(function(node) {
1868 var menu = new dijit.Menu({
1869 id: "headlinesMenu",
1873 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1874 var callerNode = event.target, match = null, tries = 0;
1876 while (match == null && callerNode && tries <= 3) {
1877 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1878 callerNode = callerNode.parentNode;
1882 if (match) this.callerRowId = parseInt(match[1]);
1886 /* if (!isCdmMode())
1887 menu.addChild(new dijit.MenuItem({
1888 label: __("View article"),
1889 onClick: function(event) {
1890 view(this.getParent().callerRowId);
1893 menu.addChild(new dijit.MenuItem({
1894 label: __("Open original article"),
1895 onClick: function(event) {
1896 openArticleInNewWindow(this.getParent().callerRowId);
1899 menu.addChild(new dijit.MenuItem({
1900 label: __("View in a tt-rss tab"),
1901 onClick: function(event) {
1902 hlOpenInNewTab(event, this.getParent().callerRowId);
1905 menu.addChild(new dijit.MenuSeparator());
1907 menu.addChild(new dijit.MenuItem({
1908 label: __("Mark above as read"),
1909 onClick: function(event) {
1910 catchupRelativeToArticle(0, this.getParent().callerRowId);
1913 menu.addChild(new dijit.MenuItem({
1914 label: __("Mark below as read"),
1915 onClick: function(event) {
1916 catchupRelativeToArticle(1, this.getParent().callerRowId);
1920 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1924 menu.addChild(new dijit.MenuSeparator());
1926 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1927 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1929 labels.each(function(label) {
1930 var id = label.id[0];
1931 var bare_id = id.substr(id.indexOf(":")+1);
1932 var name = label.name[0];
1934 bare_id = -11-bare_id;
1936 labelAddMenu.addChild(new dijit.MenuItem({
1939 onClick: function(event) {
1940 var ids = getSelectedArticleIds2();
1942 var id = this.getParent().ownerMenu.callerRowId + "";
1944 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1946 selectionAssignLabel(this.labelId, ids);
1949 labelDelMenu.addChild(new dijit.MenuItem({
1952 onClick: function(event) {
1953 var ids = getSelectedArticleIds2();
1955 var id = this.getParent().ownerMenu.callerRowId + "";
1957 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1959 selectionRemoveLabel(this.labelId, ids);
1964 menu.addChild(new dijit.PopupMenuItem({
1965 label: __("Assign label"),
1966 popup: labelAddMenu,
1969 menu.addChild(new dijit.PopupMenuItem({
1970 label: __("Remove label"),
1971 popup: labelDelMenu,
1979 exception_error("initHeadlinesMenu", e);
1984 function player(elem) {
1985 var aid = elem.getAttribute("audio-id");
1986 var status = elem.getAttribute("status");
1994 elem.innerHTML = __("Playing...");
1995 elem.title = __("Click to pause");
1996 elem.addClassName("playing");
2000 elem.innerHTML = __("Play");
2001 elem.title = __("Click to play");
2002 elem.removeClassName("playing");
2005 elem.setAttribute("status", status);
2007 alert("Your browser doesn't seem to support HTML5 audio.");
2011 function cache_set(id, obj) {
2012 //console.log("cache_set: " + id);
2015 sessionStorage[id] = obj;
2017 sessionStorage.clear();
2021 function cache_get(id) {
2023 return sessionStorage[id];
2026 function cache_clear() {
2028 sessionStorage.clear();
2031 function cache_delete(id) {
2033 sessionStorage.removeItem(id);
2036 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2037 if (toolbar_obj && content_obj) {
2038 cache_set("feed:" + feed + ":" + is_cat,
2039 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2042 obj = cache_get("feed:" + feed + ":" + is_cat);
2045 obj = JSON.parse(obj);
2047 if (toolbar_obj) obj.toolbar = toolbar_obj;
2048 if (content_obj) obj.content = content_obj;
2050 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2054 console.warn("cache_headlines failed: " + e);
2059 function render_local_headlines(feed, is_cat, obj) {
2062 dijit.byId("headlines-toolbar").attr('content',
2065 dijit.byId("headlines-frame").attr('content',
2068 dojo.parser.parse('headlines-toolbar');
2070 $("headlines-frame").scrollTop = 0;
2071 selectArticles('none');
2072 setActiveFeedId(feed, is_cat);
2073 initHeadlinesMenu();
2075 precache_headlines();
2078 exception_error("render_local_headlines", e);
2082 function precache_headlines_idle() {
2084 if (!feed_precache_timeout_id) {
2085 if (get_timestamp() - _viewfeed_last > 120) {
2087 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2090 feeds.each(function(item) {
2091 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2092 uncached.push(item);
2095 if (uncached.length > 0) {
2096 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2097 viewfeed(rf[0], '', rf[1], 0, true);
2101 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2104 exception_error("precache_headlines_idle", e);
2108 function precache_headlines() {
2111 if (!feed_precache_timeout_id) {
2112 feed_precache_timeout_id = window.setTimeout(function() {
2113 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2114 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2116 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2117 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2119 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2120 viewfeed(nf[0], '', nf[1], 0, true);
2122 window.setTimeout(function() {
2123 feed_precache_timeout_id = false;
2129 exception_error("precache_headlines", e);