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-"));
167 if (cb) cb.destroy();
169 dojo.parser.parse(child);
171 if (!Element.visible(child))
172 new Effect.Appear(child, { duration : 0.5 });
176 console.log("no new headlines received");
178 var hsp = $("headlines-spacer");
180 if (hsp) hsp.innerHTML = "";
184 if (headlines_count > 0)
185 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
188 for (var i = 0; i < articles.length; i++) {
189 var a_id = articles[i]['id'];
190 cache_set("article:" + a_id, articles[i]['content']);
193 console.log("no cached articles received");
196 // do not precache stuff after fresh feed
198 precache_headlines();
201 parse_counters(counters);
205 } else if (transport.responseText) {
206 console.error("Invalid object received: " + transport.responseText);
207 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
208 __('Could not update headlines (invalid object received - see error console for details)') +
211 notify_error("Error communicating with server.");
214 _infscroll_request_sent = 0;
219 exception_error("headlines_callback2", e, transport);
223 function render_article(article) {
225 dijit.byId("headlines-wrap-inner").addChild(
226 dijit.byId("content-insert"));
228 var c = dijit.byId("content-insert");
231 c.domNode.scrollTop = 0;
234 c.attr('content', article);
236 correctHeadlinesOffset(getActiveArticleId());
243 exception_error("render_article", e);
247 function showArticleInHeadlines(id) {
251 selectArticles("none");
253 var crow = $("RROW-" + id);
257 var article_is_unread = crow.hasClassName("Unread");
259 crow.removeClassName("Unread");
261 selectArticles('none');
263 var view_mode = false;
266 view_mode = document.forms['main_toolbar_form'].view_mode;
267 view_mode = view_mode[view_mode.selectedIndex].value;
272 if (article_is_unread && view_mode == "all_articles") {
273 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
278 if (article_is_unread)
279 _force_scheduled_update = true;
282 exception_error("showArticleInHeadlines", e);
286 function article_callback2(transport, id) {
288 console.log("article_callback2 " + id);
290 handle_rpc_json(transport);
295 reply = JSON.parse(transport.responseText);
302 reply.each(function(article) {
303 if (active_post_id == article['id']) {
304 render_article(article['content']);
306 cids_requested.remove(article['id']);
308 cache_set("article:" + article['id'], article['content']);
311 // if (id != last_requested_article) {
312 // console.log("requested article id is out of sequence, aborting");
317 console.error("Invalid object received: " + transport.responseText);
319 render_article("<div class='whiteBox'>" +
320 __('Could not display article (invalid object received - see error console for details)') + "</div>");
325 headlines_scroll_handler($("headlines-frame"));
328 if (!_infscroll_disable &&
329 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
339 exception_error("article_callback2", e, transport);
345 console.log("loading article: " + id);
347 var cached_article = cache_get("article:" + id);
349 console.log("cache check result: " + (cached_article != false));
353 var query = "?op=article&method=view&id=" + param_escape(id);
355 var neighbor_ids = getRelativePostIds(id);
357 /* only request uncached articles */
359 var cids_to_request = [];
361 for (var i = 0; i < neighbor_ids.length; i++) {
362 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
363 if (!cache_get("article:" + neighbor_ids[i])) {
364 cids_to_request.push(neighbor_ids[i]);
365 cids_requested.push(neighbor_ids[i]);
369 console.log("additional ids: " + cids_to_request.toString());
371 query = query + "&cids=" + cids_to_request.toString();
373 var crow = $("RROW-" + id);
374 var article_is_unread = crow.hasClassName("Unread");
377 showArticleInHeadlines(id);
379 precache_headlines();
381 if (cached_article && article_is_unread) {
383 query = query + "&mode=prefetch";
385 render_article(cached_article);
387 } else if (cached_article) {
389 query = query + "&mode=prefetch_old";
390 render_article(cached_article);
392 // if we don't need to request any relative ids, we might as well skip
393 // the server roundtrip altogether
394 if (cids_to_request.length == 0) {
397 if (!_infscroll_disable &&
398 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
406 headlines_scroll_handler($("headlines-frame"));
412 last_requested_article = id;
416 if (article_is_unread) {
417 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
420 new Ajax.Request("backend.php", {
422 onComplete: function(transport) {
423 article_callback2(transport, id);
429 exception_error("view", e);
433 function toggleMark(id, client_only) {
435 var query = "?op=rpc&id=" + id + "&method=mark";
437 var img = $("FMPIC-" + id);
441 if (img.src.match("mark_unset")) {
442 img.src = img.src.replace("mark_unset", "mark_set");
443 img.alt = __("Unstar article");
444 query = query + "&mark=1";
447 img.src = img.src.replace("mark_set", "mark_unset");
448 img.alt = __("Star article");
449 query = query + "&mark=0";
452 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
455 new Ajax.Request("backend.php", {
457 onComplete: function(transport) {
458 handle_rpc_json(transport);
463 exception_error("toggleMark", e);
467 function togglePub(id, client_only, no_effects, note) {
469 var query = "?op=rpc&id=" + id + "&method=publ";
471 if (note != undefined) {
472 query = query + "¬e=" + param_escape(note);
474 query = query + "¬e=undefined";
477 var img = $("FPPIC-" + id);
481 if (img.src.match("pub_unset") || note != undefined) {
482 img.src = img.src.replace("pub_unset", "pub_set");
483 img.alt = __("Unpublish article");
484 query = query + "&pub=1";
487 img.src = img.src.replace("pub_set", "pub_unset");
488 img.alt = __("Publish article");
490 query = query + "&pub=0";
493 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
496 new Ajax.Request("backend.php", {
498 onComplete: function(transport) {
499 handle_rpc_json(transport);
504 exception_error("togglePub", e);
508 function moveToPost(mode) {
512 var rows = getVisibleArticleIds();
517 if (!$('RROW-' + active_post_id)) {
518 active_post_id = false;
521 if (active_post_id == false) {
523 prev_id = rows[rows.length-1]
525 for (var i = 0; i < rows.length; i++) {
526 if (rows[i] == active_post_id) {
528 // Account for adjacent identical article ids.
529 if (i > 0) prev_id = rows[i-1];
531 for (var j = i+1; j < rows.length; j++) {
532 if (rows[j] != active_post_id) {
542 if (mode == "next") {
546 cdmExpandArticle(next_id);
547 cdmScrollToArticleId(next_id);
550 correctHeadlinesOffset(next_id);
551 view(next_id, getActiveFeedId());
556 if (mode == "prev") {
559 cdmExpandArticle(prev_id);
560 cdmScrollToArticleId(prev_id);
562 correctHeadlinesOffset(prev_id);
563 view(prev_id, getActiveFeedId());
569 exception_error("moveToPost", e);
573 function toggleSelected(id, force_on) {
576 var cb = dijit.byId("RCHK-" + id);
577 var row = $("RROW-" + id);
580 if (row.hasClassName('Selected') && !force_on) {
581 row.removeClassName('Selected');
582 if (cb) cb.attr("checked", false);
584 row.addClassName('Selected');
585 if (cb) cb.attr("checked", true);
589 exception_error("toggleSelected", e);
593 function toggleUnread_afh(effect) {
596 var elem = effect.element;
597 elem.style.backgroundColor = "";
600 exception_error("toggleUnread_afh", e);
604 function toggleUnread(id, cmode, effect) {
607 var row = $("RROW-" + id);
609 if (cmode == undefined || cmode == 2) {
610 if (row.hasClassName("Unread")) {
611 row.removeClassName("Unread");
614 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
615 afterFinish: toggleUnread_afh,
616 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
620 row.addClassName("Unread");
623 } else if (cmode == 0) {
625 row.removeClassName("Unread");
628 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
629 afterFinish: toggleUnread_afh,
630 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
633 } else if (cmode == 1) {
634 row.addClassName("Unread");
637 if (cmode == undefined) cmode = 2;
639 var query = "?op=rpc&method=catchupSelected" +
640 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
642 // notify_progress("Loading, please wait...");
644 new Ajax.Request("backend.php", {
646 onComplete: function(transport) {
647 handle_rpc_json(transport);
653 exception_error("toggleUnread", e);
657 function selectionRemoveLabel(id, ids) {
660 if (!ids) ids = getSelectedArticleIds2();
662 if (ids.length == 0) {
663 alert(__("No articles are selected."));
667 var query = "?op=rpc&method=removeFromLabel&ids=" +
668 param_escape(ids.toString()) + "&lid=" + param_escape(id);
672 new Ajax.Request("backend.php", {
674 onComplete: function(transport) {
675 handle_rpc_json(transport);
676 show_labels_in_headlines(transport);
680 exception_error("selectionAssignLabel", e);
685 function selectionAssignLabel(id, ids) {
688 if (!ids) ids = getSelectedArticleIds2();
690 if (ids.length == 0) {
691 alert(__("No articles are selected."));
695 var query = "?op=rpc&method=assignToLabel&ids=" +
696 param_escape(ids.toString()) + "&lid=" + param_escape(id);
700 new Ajax.Request("backend.php", {
702 onComplete: function(transport) {
703 handle_rpc_json(transport);
704 show_labels_in_headlines(transport);
708 exception_error("selectionAssignLabel", e);
713 function selectionToggleUnread(set_state, callback, no_error) {
715 var rows = getSelectedArticleIds2();
717 if (rows.length == 0 && !no_error) {
718 alert(__("No articles are selected."));
722 for (var i = 0; i < rows.length; i++) {
723 var row = $("RROW-" + rows[i]);
725 if (set_state == undefined) {
726 if (row.hasClassName("Unread")) {
727 row.removeClassName("Unread");
729 row.addClassName("Unread");
733 if (set_state == false) {
734 row.removeClassName("Unread");
737 if (set_state == true) {
738 row.addClassName("Unread");
743 if (rows.length > 0) {
747 if (set_state == undefined) {
749 } else if (set_state == true) {
751 } else if (set_state == false) {
755 var query = "?op=rpc&method=catchupSelected" +
756 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
758 notify_progress("Loading, please wait...");
760 new Ajax.Request("backend.php", {
762 onComplete: function(transport) {
763 handle_rpc_json(transport);
764 if (callback) callback(transport);
770 exception_error("selectionToggleUnread", e);
774 function selectionToggleMarked() {
777 var rows = getSelectedArticleIds2();
779 if (rows.length == 0) {
780 alert(__("No articles are selected."));
784 for (var i = 0; i < rows.length; i++) {
785 toggleMark(rows[i], true, true);
788 if (rows.length > 0) {
790 var query = "?op=rpc&method=markSelected&ids=" +
791 param_escape(rows.toString()) + "&cmode=2";
793 new Ajax.Request("backend.php", {
795 onComplete: function(transport) {
796 handle_rpc_json(transport);
802 exception_error("selectionToggleMarked", e);
806 function selectionTogglePublished() {
809 var rows = getSelectedArticleIds2();
811 if (rows.length == 0) {
812 alert(__("No articles are selected."));
816 for (var i = 0; i < rows.length; i++) {
817 togglePub(rows[i], true, true);
820 if (rows.length > 0) {
822 var query = "?op=rpc&method=publishSelected&ids=" +
823 param_escape(rows.toString()) + "&cmode=2";
825 new Ajax.Request("backend.php", {
827 onComplete: function(transport) {
828 handle_rpc_json(transport);
834 exception_error("selectionToggleMarked", e);
838 function getSelectedArticleIds2() {
842 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
844 rv.push(child.id.replace("RROW-", ""));
850 function getLoadedArticleIds() {
853 var children = $$("#headlines-frame > div[id*=RROW-]");
855 children.each(function(child) {
856 rv.push(child.id.replace("RROW-", ""));
863 // mode = all,none,unread,invert,marked,published
864 function selectArticles(mode) {
867 var children = $$("#headlines-frame > div[id*=RROW]");
869 children.each(function(child) {
870 var id = child.id.replace("RROW-", "");
871 var cb = dijit.byId("RCHK-" + id);
874 child.addClassName("Selected");
875 if (cb) cb.attr("checked", true);
876 } else if (mode == "unread") {
877 if (child.hasClassName("Unread")) {
878 child.addClassName("Selected");
879 if (cb) cb.attr("checked", true);
881 child.removeClassName("Selected");
882 if (cb) cb.attr("checked", false);
884 } else if (mode == "marked") {
885 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
887 if (img && img.src.match("mark_set")) {
888 child.addClassName("Selected");
889 if (cb) cb.attr("checked", true);
891 child.removeClassName("Selected");
892 if (cb) cb.attr("checked", false);
894 } else if (mode == "published") {
895 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
897 if (img && img.src.match("pub_set")) {
898 child.addClassName("Selected");
899 if (cb) cb.attr("checked", true);
901 child.removeClassName("Selected");
902 if (cb) cb.attr("checked", false);
905 } else if (mode == "invert") {
906 if (child.hasClassName("Selected")) {
907 child.removeClassName("Selected");
908 if (cb) cb.attr("checked", false);
910 child.addClassName("Selected");
911 if (cb) cb.attr("checked", true);
915 child.removeClassName("Selected");
916 if (cb) cb.attr("checked", false);
921 exception_error("selectArticles", e);
925 function catchupPage() {
927 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
929 var str = __("Mark all visible articles in %s as read?");
931 str = str.replace("%s", fn);
933 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
937 selectArticles('all');
938 selectionToggleUnread(false, 'viewCurrentFeed()', true);
939 selectArticles('none');
942 function deleteSelection() {
946 var rows = getSelectedArticleIds2();
948 if (rows.length == 0) {
949 alert(__("No articles are selected."));
953 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
956 if (getActiveFeedId() != 0) {
957 str = __("Delete %d selected articles in %s?");
959 str = __("Delete %d selected articles?");
962 str = str.replace("%d", rows.length);
963 str = str.replace("%s", fn);
965 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
969 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
973 new Ajax.Request("backend.php", {
975 onComplete: function(transport) {
976 handle_rpc_json(transport);
981 exception_error("deleteSelection", e);
985 function archiveSelection() {
989 var rows = getSelectedArticleIds2();
991 if (rows.length == 0) {
992 alert(__("No articles are selected."));
996 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1000 if (getActiveFeedId() != 0) {
1001 str = __("Archive %d selected articles in %s?");
1004 str = __("Move %d archived articles back?");
1008 str = str.replace("%d", rows.length);
1009 str = str.replace("%s", fn);
1011 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1015 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1019 for (var i = 0; i < rows.length; i++) {
1020 cache_delete("article:" + rows[i]);
1023 new Ajax.Request("backend.php", {
1025 onComplete: function(transport) {
1026 handle_rpc_json(transport);
1031 exception_error("archiveSelection", e);
1035 function catchupSelection() {
1039 var rows = getSelectedArticleIds2();
1041 if (rows.length == 0) {
1042 alert(__("No articles are selected."));
1046 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1048 var str = __("Mark %d selected articles in %s as read?");
1050 str = str.replace("%d", rows.length);
1051 str = str.replace("%s", fn);
1053 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1057 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1060 exception_error("catchupSelection", e);
1064 function editArticleTags(id) {
1065 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1067 if (dijit.byId("editTagsDlg"))
1068 dijit.byId("editTagsDlg").destroyRecursive();
1070 dialog = new dijit.Dialog({
1072 title: __("Edit article Tags"),
1073 style: "width: 600px",
1074 execute: function() {
1075 if (this.validate()) {
1076 var query = dojo.objectToQuery(this.attr('value'));
1078 notify_progress("Saving article tags...", true);
1080 new Ajax.Request("backend.php", {
1082 onComplete: function(transport) {
1086 var data = JSON.parse(transport.responseText);
1089 var tags_str = article.tags;
1090 var id = tags_str.id;
1092 var tags = $("ATSTR-" + id);
1093 var tooltip = dijit.byId("ATSTRTIP-" + id);
1095 if (tags) tags.innerHTML = tags_str.content;
1096 if (tooltip) tooltip.attr('label', tags_str.content_full);
1098 cache_delete("article:" + id);
1107 var tmph = dojo.connect(dialog, 'onLoad', function() {
1108 dojo.disconnect(tmph);
1110 new Ajax.Autocompleter('tags_str', 'tags_choices',
1111 "backend.php?op=rpc&method=completeTags",
1112 { tokens: ',', paramName: "search" });
1119 function cdmScrollToArticleId(id) {
1121 var ctr = $("headlines-frame");
1122 var e = $("RROW-" + id);
1124 if (!e || !ctr) return;
1126 ctr.scrollTop = e.offsetTop;
1129 exception_error("cdmScrollToArticleId", e);
1133 function getActiveArticleId() {
1134 return active_post_id;
1137 function postMouseIn(id) {
1138 post_under_pointer = id;
1141 function postMouseOut(id) {
1142 post_under_pointer = false;
1145 function headlines_scroll_handler(e) {
1147 var hsp = $("headlines-spacer");
1149 if (!_infscroll_disable) {
1150 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1151 (e.scrollHeight != 0 &&
1152 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1155 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1156 __("Loading, please wait...");
1158 loadMoreHeadlines();
1163 if (hsp) hsp.innerHTML = "";
1166 if (getInitParam("cdm_auto_catchup") == 1) {
1168 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1170 if ($("headlines-frame").scrollTop >
1171 (child.offsetTop + child.offsetHeight/2)) {
1173 var id = child.id.replace("RROW-", "");
1175 if (catchup_id_batch.indexOf(id) == -1)
1176 catchup_id_batch.push(id);
1178 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1182 if (catchup_id_batch.length > 0) {
1183 window.clearTimeout(catchup_timeout_id);
1185 if (!_infscroll_request_sent) {
1186 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1193 console.warn("headlines_scroll_handler: " + e);
1197 function catchupBatchedArticles() {
1199 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1201 // make a copy of the array
1202 var batch = catchup_id_batch.slice();
1203 var query = "?op=rpc&method=catchupSelected" +
1204 "&cmode=0&ids=" + param_escape(batch.toString());
1208 new Ajax.Request("backend.php", {
1210 onComplete: function(transport) {
1211 handle_rpc_json(transport);
1213 batch.each(function(id) {
1214 var elem = $("RROW-" + id);
1215 if (elem) elem.removeClassName("Unread");
1216 catchup_id_batch.remove(id);
1223 exception_error("catchupBatchedArticles", e);
1227 function catchupRelativeToArticle(below, id) {
1231 if (!id) id = getActiveArticleId();
1234 alert(__("No article is selected."));
1238 var visible_ids = getVisibleArticleIds();
1240 var ids_to_mark = new Array();
1243 for (var i = 0; i < visible_ids.length; i++) {
1244 if (visible_ids[i] != id) {
1245 var e = $("RROW-" + visible_ids[i]);
1247 if (e && e.hasClassName("Unread")) {
1248 ids_to_mark.push(visible_ids[i]);
1255 for (var i = visible_ids.length-1; i >= 0; i--) {
1256 if (visible_ids[i] != id) {
1257 var e = $("RROW-" + visible_ids[i]);
1259 if (e && e.hasClassName("Unread")) {
1260 ids_to_mark.push(visible_ids[i]);
1268 if (ids_to_mark.length == 0) {
1269 alert(__("No articles found to mark"));
1271 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1273 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1275 for (var i = 0; i < ids_to_mark.length; i++) {
1276 var e = $("RROW-" + ids_to_mark[i]);
1277 e.removeClassName("Unread");
1280 var query = "?op=rpc&method=catchupSelected" +
1281 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1283 new Ajax.Request("backend.php", {
1285 onComplete: function(transport) {
1286 handle_rpc_json(transport);
1293 exception_error("catchupRelativeToArticle", e);
1297 function cdmExpandArticle(id) {
1302 var elem = $("CICD-" + active_post_id);
1304 if (id == active_post_id && Element.visible(elem))
1307 selectArticles("none");
1309 var old_offset = $("RROW-" + id).offsetTop;
1311 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1313 Element.show("CEXC-" + active_post_id);
1316 active_post_id = id;
1318 elem = $("CICD-" + id);
1320 if (!Element.visible(elem)) {
1322 Element.hide("CEXC-" + id);
1325 var new_offset = $("RROW-" + id).offsetTop;
1327 $("headlines-frame").scrollTop += (new_offset-old_offset);
1329 if ($("RROW-" + id).offsetTop != old_offset)
1330 $("headlines-frame").scrollTop = new_offset;
1332 toggleUnread(id, 0, true);
1336 exception_error("cdmExpandArticle", e);
1342 function fixHeadlinesOrder(ids) {
1344 for (var i = 0; i < ids.length; i++) {
1345 var e = $("RROW-" + ids[i]);
1349 e.removeClassName("even");
1350 e.addClassName("odd");
1352 e.removeClassName("odd");
1353 e.addClassName("even");
1358 exception_error("fixHeadlinesOrder", e);
1362 function getArticleUnderPointer() {
1363 return post_under_pointer;
1366 function zoomToArticle(event, id) {
1368 var cached_article = cache_get("article: " + id);
1370 if (dijit.byId("ATAB-" + id))
1371 if (!event || !event.shiftKey)
1372 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1374 if (dijit.byId("ATSTRTIP-" + id))
1375 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1377 if (cached_article) {
1378 //closeArticlePanel();
1380 var article_pane = new dijit.layout.ContentPane({
1381 title: __("Loading...") , content: cached_article,
1382 style: 'padding : 0px;',
1386 dijit.byId("content-tabs").addChild(article_pane);
1388 if (!event || !event.shiftKey)
1389 dijit.byId("content-tabs").selectChild(article_pane);
1391 if ($("PTITLE-" + id))
1392 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1396 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1398 notify_progress("Loading, please wait...", true);
1400 new Ajax.Request("backend.php", {
1402 onComplete: function(transport) {
1405 var reply = JSON.parse(transport.responseText);
1408 //closeArticlePanel();
1410 var content = reply[0]['content'];
1412 var article_pane = new dijit.layout.ContentPane({
1413 title: "article-" + id , content: content,
1414 style: 'padding : 0px;',
1418 dijit.byId("content-tabs").addChild(article_pane);
1420 if (!event || !event.shiftKey)
1421 dijit.byId("content-tabs").selectChild(article_pane);
1423 if ($("PTITLE-" + id))
1424 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1431 exception_error("zoomToArticle", e);
1435 function scrollArticle(offset) {
1438 var ci = $("content-insert");
1440 ci.scrollTop += offset;
1443 var hi = $("headlines-frame");
1445 hi.scrollTop += offset;
1450 exception_error("scrollArticle", e);
1454 function show_labels_in_headlines(transport) {
1456 var data = JSON.parse(transport.responseText);
1459 data['info-for-headlines'].each(function(elem) {
1460 var ctr = $("HLLCTR-" + elem.id);
1462 if (ctr) ctr.innerHTML = elem.labels;
1465 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1469 exception_error("show_labels_in_headlines", e);
1473 /* function toggleHeadlineActions() {
1475 var e = $("headlineActionsBody");
1476 var p = $("headlineActionsDrop");
1478 if (!Element.visible(e)) {
1485 e.style.left = (p.offsetLeft + 1) + "px";
1486 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1489 exception_error("toggleHeadlineActions", e);
1493 /* function publishWithNote(id, def_note) {
1495 if (!def_note) def_note = '';
1497 var note = prompt(__("Please enter a note for this article:"), def_note);
1499 if (note != undefined) {
1500 togglePub(id, false, false, note);
1504 exception_error("publishWithNote", e);
1508 function dismissArticle(id) {
1510 var elem = $("RROW-" + id);
1512 toggleUnread(id, 0, true);
1514 new Effect.Fade(elem, {duration : 0.5});
1516 active_post_id = false;
1519 exception_error("dismissArticle", e);
1523 function dismissSelectedArticles() {
1526 var ids = getVisibleArticleIds();
1530 for (var i = 0; i < ids.length; i++) {
1531 var elem = $("RROW-" + ids[i]);
1533 if (elem.className && elem.hasClassName("Selected") &&
1534 ids[i] != active_post_id) {
1535 new Effect.Fade(elem, {duration : 0.5});
1543 selectionToggleUnread(false);
1545 fixHeadlinesOrder(tmp);
1548 exception_error("dismissSelectedArticles", e);
1552 function dismissReadArticles() {
1555 var ids = getVisibleArticleIds();
1558 for (var i = 0; i < ids.length; i++) {
1559 var elem = $("RROW-" + ids[i]);
1561 if (elem.className && !elem.hasClassName("Unread") &&
1562 !elem.hasClassName("Selected")) {
1564 new Effect.Fade(elem, {duration : 0.5});
1570 fixHeadlinesOrder(tmp);
1573 exception_error("dismissSelectedArticles", e);
1577 function getVisibleArticleIds() {
1582 getLoadedArticleIds().each(function(id) {
1583 var elem = $("RROW-" + id);
1584 if (elem && Element.visible(elem))
1589 exception_error("getVisibleArticleIds", e);
1595 function cdmClicked(event, id) {
1597 //var shift_key = event.shiftKey;
1601 if (!event.ctrlKey) {
1603 if (!getInitParam("cdm_expanded")) {
1604 return cdmExpandArticle(id);
1607 selectArticles("none");
1610 var elem = $("RROW-" + id);
1611 var article_is_unread = elem.hasClassName("Unread");
1614 elem.removeClassName("Unread");
1616 active_post_id = id;
1618 if (article_is_unread) {
1619 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1622 var query = "?op=rpc&method=catchupSelected" +
1623 "&cmode=0&ids=" + param_escape(id);
1625 new Ajax.Request("backend.php", {
1627 onComplete: function(transport) {
1628 handle_rpc_json(transport);
1635 toggleSelected(id, true);
1637 var elem = $("RROW-" + id);
1638 var article_is_unread = elem.hasClassName("Unread");
1640 if (article_is_unread) {
1641 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1644 toggleUnread(id, 0, false);
1645 zoomToArticle(event, id);
1649 exception_error("cdmClicked");
1655 function postClicked(event, id) {
1658 if (!event.ctrlKey) {
1661 postOpenInNewTab(event, id);
1666 exception_error("postClicked");
1670 function hlOpenInNewTab(event, id) {
1671 toggleUnread(id, 0, false);
1672 zoomToArticle(event, id);
1675 function postOpenInNewTab(event, id) {
1676 closeArticlePanel(id);
1677 zoomToArticle(event, id);
1680 function hlClicked(event, id) {
1682 if (event.which == 2) {
1685 } else if (event.altKey) {
1686 openArticleInNewWindow(id);
1687 } else if (!event.ctrlKey) {
1692 toggleUnread(id, 0, false);
1693 zoomToArticle(event, id);
1698 exception_error("hlClicked");
1702 function getFirstVisibleHeadlineId() {
1703 var rows = getVisibleArticleIds();
1708 function getLastVisibleHeadlineId() {
1709 var rows = getVisibleArticleIds();
1710 return rows[rows.length-1];
1713 function openArticleInNewWindow(id) {
1714 toggleUnread(id, 0, false);
1715 window.open("backend.php?op=article&method=redirect&id=" + id);
1718 function isCdmMode() {
1719 return getInitParam("combined_display_mode");
1722 function markHeadline(id) {
1723 var row = $("RROW-" + id);
1725 var check = dijit.byId("RCHK-" + id);
1728 check.attr("checked", true);
1731 row.addClassName("Selected");
1735 function getRelativePostIds(id, limit) {
1741 if (!limit) limit = 6; //3
1743 var ids = getVisibleArticleIds();
1745 for (var i = 0; i < ids.length; i++) {
1747 for (var k = 1; k <= limit; k++) {
1748 //if (i > k-1) tmp.push(ids[i-k]);
1749 if (i < ids.length-k) tmp.push(ids[i+k]);
1756 exception_error("getRelativePostIds", e);
1762 function correctHeadlinesOffset(id) {
1766 var container = $("headlines-frame");
1767 var row = $("RROW-" + id);
1769 if (!container || !row) return;
1771 var viewport = container.offsetHeight;
1773 var rel_offset_top = row.offsetTop - container.scrollTop;
1774 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1776 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1777 //console.log("Vport: " + viewport);
1779 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1780 container.scrollTop = row.offsetTop;
1781 } else if (rel_offset_bottom > viewport) {
1783 /* doesn't properly work with Opera in some cases because
1784 Opera fucks up element scrolling */
1786 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1790 exception_error("correctHeadlinesOffset", e);
1795 function headlineActionsChange(elem) {
1798 elem.attr('value', 'false');
1800 exception_error("headlineActionsChange", e);
1804 function closeArticlePanel() {
1806 var tabs = dijit.byId("content-tabs");
1807 var child = tabs.selectedChildWidget;
1809 if (child && tabs.getIndexOfChild(child) > 0) {
1810 tabs.removeChild(child);
1813 if (dijit.byId("content-insert"))
1814 dijit.byId("headlines-wrap-inner").removeChild(
1815 dijit.byId("content-insert"));
1819 function initHeadlinesMenu() {
1821 if (dijit.byId("headlinesMenu"))
1822 dijit.byId("headlinesMenu").destroyRecursive();
1827 nodes = $$("#headlines-frame > div[id*=RROW]");
1829 nodes = $$("#headlines-frame span[id*=RTITLE]");
1832 nodes.each(function(node) {
1836 var menu = new dijit.Menu({
1837 id: "headlinesMenu",
1841 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1842 var callerNode = event.target, match = null, tries = 0;
1844 while (match == null && callerNode && tries <= 3) {
1845 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1846 callerNode = callerNode.parentNode;
1850 if (match) this.callerRowId = parseInt(match[1]);
1854 /* if (!isCdmMode())
1855 menu.addChild(new dijit.MenuItem({
1856 label: __("View article"),
1857 onClick: function(event) {
1858 view(this.getParent().callerRowId);
1861 menu.addChild(new dijit.MenuItem({
1862 label: __("Open original article"),
1863 onClick: function(event) {
1864 openArticleInNewWindow(this.getParent().callerRowId);
1867 menu.addChild(new dijit.MenuItem({
1868 label: __("View in a tt-rss tab"),
1869 onClick: function(event) {
1870 hlOpenInNewTab(event, this.getParent().callerRowId);
1873 menu.addChild(new dijit.MenuSeparator());
1875 menu.addChild(new dijit.MenuItem({
1876 label: __("Mark above as read"),
1877 onClick: function(event) {
1878 catchupRelativeToArticle(0, this.getParent().callerRowId);
1881 menu.addChild(new dijit.MenuItem({
1882 label: __("Mark below as read"),
1883 onClick: function(event) {
1884 catchupRelativeToArticle(1, this.getParent().callerRowId);
1888 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1892 menu.addChild(new dijit.MenuSeparator());
1894 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1895 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1897 labels.each(function(label) {
1898 var id = label.id[0];
1899 var bare_id = id.substr(id.indexOf(":")+1);
1900 var name = label.name[0];
1902 bare_id = -11-bare_id;
1904 labelAddMenu.addChild(new dijit.MenuItem({
1907 onClick: function(event) {
1908 var ids = getSelectedArticleIds2();
1910 var id = this.getParent().ownerMenu.callerRowId + "";
1912 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1914 selectionAssignLabel(this.labelId, ids);
1917 labelDelMenu.addChild(new dijit.MenuItem({
1920 onClick: function(event) {
1921 var ids = getSelectedArticleIds2();
1923 var id = this.getParent().ownerMenu.callerRowId + "";
1925 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1927 selectionRemoveLabel(this.labelId, ids);
1932 menu.addChild(new dijit.PopupMenuItem({
1933 label: __("Assign label"),
1934 popup: labelAddMenu,
1937 menu.addChild(new dijit.PopupMenuItem({
1938 label: __("Remove label"),
1939 popup: labelDelMenu,
1947 exception_error("initHeadlinesMenu", e);
1952 function player(elem) {
1953 var aid = elem.getAttribute("audio-id");
1954 var status = elem.getAttribute("status");
1962 elem.innerHTML = __("Playing...");
1963 elem.title = __("Click to pause");
1964 elem.addClassName("playing");
1968 elem.innerHTML = __("Play");
1969 elem.title = __("Click to play");
1970 elem.removeClassName("playing");
1973 elem.setAttribute("status", status);
1975 alert("Your browser doesn't seem to support HTML5 audio.");
1979 function cache_set(id, obj) {
1980 //console.log("cache_set: " + id);
1983 sessionStorage[id] = obj;
1985 sessionStorage.clear();
1989 function cache_get(id) {
1991 return sessionStorage[id];
1994 function cache_clear() {
1996 sessionStorage.clear();
1999 function cache_delete(id) {
2001 sessionStorage.removeItem(id);
2004 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2005 if (toolbar_obj && content_obj) {
2006 cache_set("feed:" + feed + ":" + is_cat,
2007 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2010 obj = cache_get("feed:" + feed + ":" + is_cat);
2013 obj = JSON.parse(obj);
2015 if (toolbar_obj) obj.toolbar = toolbar_obj;
2016 if (content_obj) obj.content = content_obj;
2018 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2022 console.warn("cache_headlines failed: " + e);
2027 function render_local_headlines(feed, is_cat, obj) {
2030 dijit.byId("headlines-toolbar").attr('content',
2033 dijit.byId("headlines-frame").attr('content',
2036 dojo.parser.parse('headlines-toolbar');
2038 $("headlines-frame").scrollTop = 0;
2039 selectArticles('none');
2040 setActiveFeedId(feed, is_cat);
2041 initHeadlinesMenu();
2043 dijit.getEnclosingWidget(
2044 document.forms["main_toolbar_form"].update).attr('disabled',
2045 is_cat || feed <= 0);
2047 precache_headlines();
2050 exception_error("render_local_headlines", e);
2054 function precache_headlines_idle() {
2056 if (!feed_precache_timeout_id) {
2057 if (get_timestamp() - _viewfeed_last > 120) {
2059 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2062 feeds.each(function(item) {
2063 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2064 uncached.push(item);
2067 if (uncached.length > 0) {
2068 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2069 viewfeed(rf[0], '', rf[1], 0, true);
2073 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2076 exception_error("precache_headlines_idle", e);
2080 function precache_headlines() {
2083 if (!feed_precache_timeout_id) {
2084 feed_precache_timeout_id = window.setTimeout(function() {
2085 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2086 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2088 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2089 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2091 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2092 viewfeed(nf[0], '', nf[1], 0, true);
2094 window.setTimeout(function() {
2095 feed_precache_timeout_id = false;
2101 exception_error("precache_headlines", e);
2105 function cancelSearch() {
2110 exception_error("cancelSearch", e);
2114 function setSelectionScore() {
2116 var ids = getSelectedArticleIds2();
2118 if (ids.length > 0) {
2121 var score = prompt(__("Please enter new score for selected articles:"), score);
2123 if (score != undefined) {
2124 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2125 "&score=" + param_escape(score);
2127 new Ajax.Request("backend.php", {
2129 onComplete: function(transport) {
2130 var reply = JSON.parse(transport.responseText);
2134 ids.each(function(id) {
2135 var row = $("RROW-" + id);
2138 var pic = row.getElementsByClassName("hlScorePic")[0];
2141 pic.src = pic.src.replace(/score_.*?\.png/,
2142 reply["score_pic"]);
2143 pic.setAttribute("score", score);
2152 alert(__("No articles are selected."));
2155 exception_error("setSelectionScore", e);
2159 function changeScore(id, pic) {
2161 var score = pic.getAttribute("score");
2163 var new_score = prompt(__("Please enter new score for this article:"), score);
2165 if (new_score != undefined) {
2167 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2168 "&score=" + param_escape(new_score);
2170 new Ajax.Request("backend.php", {
2172 onComplete: function(transport) {
2173 var reply = JSON.parse(transport.responseText);
2176 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2177 pic.setAttribute("score", new_score);
2182 exception_error("changeScore", e);