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");
134 _infscroll_disable = true;
136 console.log("restore selected ids: " + ids);
138 for (var i = 0; i < ids.length; i++) {
139 markHeadline(ids[i]);
144 $$("#headlines-frame > div[id*=RROW]").each(
146 if (!Element.visible(child))
147 new Effect.Appear(child, { duration : 0.5 });
151 console.log("no new headlines received");
153 var hsp = $("headlines-spacer");
155 if (hsp) hsp.innerHTML = "";
159 if (headlines_count > 0)
160 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
163 for (var i = 0; i < articles.length; i++) {
164 var a_id = articles[i]['id'];
165 cache_set("article:" + a_id, articles[i]['content']);
168 console.log("no cached articles received");
171 // do not precache stuff after fresh feed
173 precache_headlines();
176 parse_counters(counters);
181 console.error("Invalid object received: " + transport.responseText);
182 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
183 __('Could not update headlines (invalid object received - see error console for details)') +
187 _infscroll_request_sent = 0;
192 exception_error("headlines_callback2", e, transport);
196 function render_article(article) {
198 dijit.byId("headlines-wrap-inner").addChild(
199 dijit.byId("content-insert"));
201 var c = dijit.byId("content-insert");
204 c.domNode.scrollTop = 0;
207 c.attr('content', article);
209 correctHeadlinesOffset(getActiveArticleId());
216 exception_error("render_article", e);
220 function showArticleInHeadlines(id) {
224 selectArticles("none");
226 var crow = $("RROW-" + id);
230 var article_is_unread = crow.hasClassName("Unread");
232 crow.removeClassName("Unread");
234 selectArticles('none');
236 var upd_img_pic = $("FUPDPIC-" + id);
238 var view_mode = false;
241 view_mode = document.forms['main_toolbar_form'].view_mode;
242 view_mode = view_mode[view_mode.selectedIndex].value;
247 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
248 upd_img_pic.src.match("fresh_sign.png"))) {
250 upd_img_pic.src = "images/blank_icon.gif";
252 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
254 } else if (article_is_unread && view_mode == "all_articles") {
255 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
260 if (article_is_unread)
261 _force_scheduled_update = true;
264 exception_error("showArticleInHeadlines", e);
268 function article_callback2(transport, id) {
270 console.log("article_callback2 " + id);
272 handle_rpc_json(transport);
277 reply = JSON.parse(transport.responseText);
284 var upic = $('FUPDPIC-' + id);
286 if (upic) upic.src = 'images/blank_icon.gif';
288 reply.each(function(article) {
289 if (active_post_id == article['id']) {
290 render_article(article['content']);
292 cids_requested.remove(article['id']);
294 cache_set("article:" + article['id'], article['content']);
297 // if (id != last_requested_article) {
298 // console.log("requested article id is out of sequence, aborting");
303 console.error("Invalid object received: " + transport.responseText);
305 render_article("<div class='whiteBox'>" +
306 __('Could not display article (invalid object received - see error console for details)') + "</div>");
311 headlines_scroll_handler($("headlines-frame"));
314 if (!_infscroll_disable &&
315 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
325 exception_error("article_callback2", e, transport);
331 console.log("loading article: " + id);
333 var cached_article = cache_get("article:" + id);
335 console.log("cache check result: " + (cached_article != false));
339 var query = "?op=article&method=view&id=" + param_escape(id);
341 var neighbor_ids = getRelativePostIds(id);
343 /* only request uncached articles */
345 var cids_to_request = [];
347 for (var i = 0; i < neighbor_ids.length; i++) {
348 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
349 if (!cache_get("article:" + neighbor_ids[i])) {
350 cids_to_request.push(neighbor_ids[i]);
351 cids_requested.push(neighbor_ids[i]);
355 console.log("additional ids: " + cids_to_request.toString());
357 query = query + "&cids=" + cids_to_request.toString();
359 var crow = $("RROW-" + id);
360 var article_is_unread = crow.hasClassName("Unread");
363 showArticleInHeadlines(id);
365 precache_headlines();
367 if (!cached_article) {
369 var upic = $('FUPDPIC-' + id);
372 upic.src = getInitParam("sign_progress");
375 } else if (cached_article && article_is_unread) {
377 query = query + "&mode=prefetch";
379 render_article(cached_article);
381 } else if (cached_article) {
383 query = query + "&mode=prefetch_old";
384 render_article(cached_article);
386 // if we don't need to request any relative ids, we might as well skip
387 // the server roundtrip altogether
388 if (cids_to_request.length == 0) {
391 if (!_infscroll_disable &&
392 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
400 headlines_scroll_handler($("headlines-frame"));
406 last_requested_article = id;
410 if (article_is_unread) {
411 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
414 new Ajax.Request("backend.php", {
416 onComplete: function(transport) {
417 article_callback2(transport, id);
423 exception_error("view", e);
427 function toggleMark(id, client_only) {
429 var query = "?op=rpc&id=" + id + "&method=mark";
431 var img = $("FMPIC-" + id);
435 if (img.src.match("mark_unset")) {
436 img.src = img.src.replace("mark_unset", "mark_set");
437 img.alt = __("Unstar article");
438 query = query + "&mark=1";
441 img.src = img.src.replace("mark_set", "mark_unset");
442 img.alt = __("Star article");
443 query = query + "&mark=0";
446 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
449 new Ajax.Request("backend.php", {
451 onComplete: function(transport) {
452 handle_rpc_json(transport);
457 exception_error("toggleMark", e);
461 function togglePub(id, client_only, no_effects, note) {
463 var query = "?op=rpc&id=" + id + "&method=publ";
465 if (note != undefined) {
466 query = query + "¬e=" + param_escape(note);
468 query = query + "¬e=undefined";
471 var img = $("FPPIC-" + id);
475 if (img.src.match("pub_unset") || note != undefined) {
476 img.src = img.src.replace("pub_unset", "pub_set");
477 img.alt = __("Unpublish article");
478 query = query + "&pub=1";
481 img.src = img.src.replace("pub_set", "pub_unset");
482 img.alt = __("Publish article");
484 query = query + "&pub=0";
487 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
490 new Ajax.Request("backend.php", {
492 onComplete: function(transport) {
493 handle_rpc_json(transport);
498 exception_error("togglePub", e);
502 function moveToPost(mode) {
506 var rows = getVisibleArticleIds();
511 if (!$('RROW-' + active_post_id)) {
512 active_post_id = false;
515 if (active_post_id == false) {
517 prev_id = rows[rows.length-1]
519 for (var i = 0; i < rows.length; i++) {
520 if (rows[i] == active_post_id) {
522 // Account for adjacent identical article ids.
523 if (i > 0) prev_id = rows[i-1];
525 for (var j = i+1; j < rows.length; j++) {
526 if (rows[j] != active_post_id) {
536 if (mode == "next") {
540 cdmExpandArticle(next_id);
541 cdmScrollToArticleId(next_id);
544 correctHeadlinesOffset(next_id);
545 view(next_id, getActiveFeedId());
550 if (mode == "prev") {
553 cdmExpandArticle(prev_id);
554 cdmScrollToArticleId(prev_id);
556 correctHeadlinesOffset(prev_id);
557 view(prev_id, getActiveFeedId());
563 exception_error("moveToPost", e);
567 function toggleSelected(id, force_on) {
570 var cb = $("RCHK-" + id);
571 var row = $("RROW-" + id);
574 if (row.hasClassName('Selected') && !force_on) {
575 row.removeClassName('Selected');
576 if (cb) cb.checked = false;
578 row.addClassName('Selected');
579 if (cb) cb.checked = true;
583 exception_error("toggleSelected", e);
587 function toggleUnread_afh(effect) {
590 var elem = effect.element;
591 elem.style.backgroundColor = "";
594 exception_error("toggleUnread_afh", e);
598 function toggleUnread(id, cmode, effect) {
601 var row = $("RROW-" + id);
603 if (cmode == undefined || cmode == 2) {
604 if (row.hasClassName("Unread")) {
605 row.removeClassName("Unread");
608 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
609 afterFinish: toggleUnread_afh,
610 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
614 row.addClassName("Unread");
617 } else if (cmode == 0) {
619 row.removeClassName("Unread");
622 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
623 afterFinish: toggleUnread_afh,
624 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
627 } else if (cmode == 1) {
628 row.addClassName("Unread");
631 if (cmode == undefined) cmode = 2;
633 var query = "?op=rpc&method=catchupSelected" +
634 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
636 // notify_progress("Loading, please wait...");
638 new Ajax.Request("backend.php", {
640 onComplete: function(transport) {
641 handle_rpc_json(transport);
647 exception_error("toggleUnread", e);
651 function selectionRemoveLabel(id, ids) {
654 if (!ids) ids = getSelectedArticleIds2();
656 if (ids.length == 0) {
657 alert(__("No articles are selected."));
661 var query = "?op=rpc&method=removeFromLabel&ids=" +
662 param_escape(ids.toString()) + "&lid=" + param_escape(id);
666 new Ajax.Request("backend.php", {
668 onComplete: function(transport) {
669 handle_rpc_json(transport);
670 show_labels_in_headlines(transport);
674 exception_error("selectionAssignLabel", e);
679 function selectionAssignLabel(id, ids) {
682 if (!ids) ids = getSelectedArticleIds2();
684 if (ids.length == 0) {
685 alert(__("No articles are selected."));
689 var query = "?op=rpc&method=assignToLabel&ids=" +
690 param_escape(ids.toString()) + "&lid=" + param_escape(id);
694 new Ajax.Request("backend.php", {
696 onComplete: function(transport) {
697 handle_rpc_json(transport);
698 show_labels_in_headlines(transport);
702 exception_error("selectionAssignLabel", e);
707 function selectionToggleUnread(set_state, callback, no_error) {
709 var rows = getSelectedArticleIds2();
711 if (rows.length == 0 && !no_error) {
712 alert(__("No articles are selected."));
716 for (var i = 0; i < rows.length; i++) {
717 var row = $("RROW-" + rows[i]);
719 if (set_state == undefined) {
720 if (row.hasClassName("Unread")) {
721 row.removeClassName("Unread");
723 row.addClassName("Unread");
727 if (set_state == false) {
728 row.removeClassName("Unread");
731 if (set_state == true) {
732 row.addClassName("Unread");
737 if (rows.length > 0) {
741 if (set_state == undefined) {
743 } else if (set_state == true) {
745 } else if (set_state == false) {
749 var query = "?op=rpc&method=catchupSelected" +
750 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
752 notify_progress("Loading, please wait...");
754 new Ajax.Request("backend.php", {
756 onComplete: function(transport) {
757 handle_rpc_json(transport);
758 if (callback) callback(transport);
764 exception_error("selectionToggleUnread", e);
768 function selectionToggleMarked() {
771 var rows = getSelectedArticleIds2();
773 if (rows.length == 0) {
774 alert(__("No articles are selected."));
778 for (var i = 0; i < rows.length; i++) {
779 toggleMark(rows[i], true, true);
782 if (rows.length > 0) {
784 var query = "?op=rpc&method=markSelected&ids=" +
785 param_escape(rows.toString()) + "&cmode=2";
787 new Ajax.Request("backend.php", {
789 onComplete: function(transport) {
790 handle_rpc_json(transport);
796 exception_error("selectionToggleMarked", e);
800 function selectionTogglePublished() {
803 var rows = getSelectedArticleIds2();
805 if (rows.length == 0) {
806 alert(__("No articles are selected."));
810 for (var i = 0; i < rows.length; i++) {
811 togglePub(rows[i], true, true);
814 if (rows.length > 0) {
816 var query = "?op=rpc&method=publishSelected&ids=" +
817 param_escape(rows.toString()) + "&cmode=2";
819 new Ajax.Request("backend.php", {
821 onComplete: function(transport) {
822 handle_rpc_json(transport);
828 exception_error("selectionToggleMarked", e);
832 function getSelectedArticleIds2() {
836 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
838 rv.push(child.id.replace("RROW-", ""));
844 function getLoadedArticleIds() {
847 var children = $$("#headlines-frame > div[id*=RROW-]");
849 children.each(function(child) {
850 rv.push(child.id.replace("RROW-", ""));
857 // mode = all,none,unread,invert,marked,published
858 function selectArticles(mode) {
861 var children = $$("#headlines-frame > div[id*=RROW]");
863 children.each(function(child) {
864 var id = child.id.replace("RROW-", "");
865 var cb = $("RCHK-" + id);
868 child.addClassName("Selected");
870 } else if (mode == "unread") {
871 if (child.hasClassName("Unread")) {
872 child.addClassName("Selected");
875 child.removeClassName("Selected");
878 } else if (mode == "marked") {
879 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
881 if (img && img.src.match("mark_set")) {
882 child.addClassName("Selected");
885 child.removeClassName("Selected");
888 } else if (mode == "published") {
889 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
891 if (img && img.src.match("pub_set")) {
892 child.addClassName("Selected");
895 child.removeClassName("Selected");
899 } else if (mode == "invert") {
900 if (child.hasClassName("Selected")) {
901 child.removeClassName("Selected");
904 child.addClassName("Selected");
909 child.removeClassName("Selected");
915 exception_error("selectArticles", e);
919 function catchupPage() {
921 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
923 var str = __("Mark all visible articles in %s as read?");
925 str = str.replace("%s", fn);
927 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
931 selectArticles('all');
932 selectionToggleUnread(false, 'viewCurrentFeed()', true);
933 selectArticles('none');
936 function deleteSelection() {
940 var rows = getSelectedArticleIds2();
942 if (rows.length == 0) {
943 alert(__("No articles are selected."));
947 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
950 if (getActiveFeedId() != 0) {
951 str = __("Delete %d selected articles in %s?");
953 str = __("Delete %d selected articles?");
956 str = str.replace("%d", rows.length);
957 str = str.replace("%s", fn);
959 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
963 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
967 new Ajax.Request("backend.php", {
969 onComplete: function(transport) {
970 handle_rpc_json(transport);
975 exception_error("deleteSelection", e);
979 function archiveSelection() {
983 var rows = getSelectedArticleIds2();
985 if (rows.length == 0) {
986 alert(__("No articles are selected."));
990 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
994 if (getActiveFeedId() != 0) {
995 str = __("Archive %d selected articles in %s?");
998 str = __("Move %d archived articles back?");
1002 str = str.replace("%d", rows.length);
1003 str = str.replace("%s", fn);
1005 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1009 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1013 for (var i = 0; i < rows.length; i++) {
1014 cache_delete("article:" + rows[i]);
1017 new Ajax.Request("backend.php", {
1019 onComplete: function(transport) {
1020 handle_rpc_json(transport);
1025 exception_error("archiveSelection", e);
1029 function catchupSelection() {
1033 var rows = getSelectedArticleIds2();
1035 if (rows.length == 0) {
1036 alert(__("No articles are selected."));
1040 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1042 var str = __("Mark %d selected articles in %s as read?");
1044 str = str.replace("%d", rows.length);
1045 str = str.replace("%s", fn);
1047 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1051 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1054 exception_error("catchupSelection", e);
1058 function editArticleTags(id) {
1059 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1061 if (dijit.byId("editTagsDlg"))
1062 dijit.byId("editTagsDlg").destroyRecursive();
1064 dialog = new dijit.Dialog({
1066 title: __("Edit article Tags"),
1067 style: "width: 600px",
1068 execute: function() {
1069 if (this.validate()) {
1070 var query = dojo.objectToQuery(this.attr('value'));
1072 notify_progress("Saving article tags...", true);
1074 new Ajax.Request("backend.php", {
1076 onComplete: function(transport) {
1080 var data = JSON.parse(transport.responseText);
1083 var tags_str = article.tags;
1084 var id = tags_str.id;
1086 var tags = $("ATSTR-" + id);
1087 var tooltip = dijit.byId("ATSTRTIP-" + id);
1089 if (tags) tags.innerHTML = tags_str.content;
1090 if (tooltip) tooltip.attr('label', tags_str.content_full);
1092 cache_delete("article:" + id);
1101 var tmph = dojo.connect(dialog, 'onLoad', function() {
1102 dojo.disconnect(tmph);
1104 new Ajax.Autocompleter('tags_str', 'tags_choices',
1105 "backend.php?op=rpc&method=completeTags",
1106 { tokens: ',', paramName: "search" });
1113 function cdmScrollToArticleId(id) {
1115 var ctr = $("headlines-frame");
1116 var e = $("RROW-" + id);
1118 if (!e || !ctr) return;
1120 ctr.scrollTop = e.offsetTop;
1123 exception_error("cdmScrollToArticleId", e);
1127 function getActiveArticleId() {
1128 return active_post_id;
1131 function postMouseIn(id) {
1132 post_under_pointer = id;
1135 function postMouseOut(id) {
1136 post_under_pointer = false;
1139 function headlines_scroll_handler(e) {
1141 var hsp = $("headlines-spacer");
1143 if (!_infscroll_disable) {
1144 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1145 (e.scrollHeight != 0 &&
1146 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1149 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1150 __("Loading, please wait...");
1152 loadMoreHeadlines();
1157 if (hsp) hsp.innerHTML = "";
1160 if (getInitParam("cdm_auto_catchup") == 1) {
1162 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1164 if ($("headlines-frame").scrollTop >
1165 (child.offsetTop + child.offsetHeight/2)) {
1167 var id = child.id.replace("RROW-", "");
1169 if (catchup_id_batch.indexOf(id) == -1)
1170 catchup_id_batch.push(id);
1172 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1176 if (catchup_id_batch.length > 0) {
1177 window.clearTimeout(catchup_timeout_id);
1179 if (!_infscroll_request_sent) {
1180 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1187 console.warn("headlines_scroll_handler: " + e);
1191 function catchupBatchedArticles() {
1193 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1195 // make a copy of the array
1196 var batch = catchup_id_batch.slice();
1197 var query = "?op=rpc&method=catchupSelected" +
1198 "&cmode=0&ids=" + param_escape(batch.toString());
1202 new Ajax.Request("backend.php", {
1204 onComplete: function(transport) {
1205 handle_rpc_json(transport);
1207 batch.each(function(id) {
1208 var elem = $("RROW-" + id);
1209 if (elem) elem.removeClassName("Unread");
1210 catchup_id_batch.remove(id);
1217 exception_error("catchupBatchedArticles", e);
1221 function catchupRelativeToArticle(below, id) {
1225 if (!id) id = getActiveArticleId();
1228 alert(__("No article is selected."));
1232 var visible_ids = getVisibleArticleIds();
1234 var ids_to_mark = new Array();
1237 for (var i = 0; i < visible_ids.length; i++) {
1238 if (visible_ids[i] != id) {
1239 var e = $("RROW-" + visible_ids[i]);
1241 if (e && e.hasClassName("Unread")) {
1242 ids_to_mark.push(visible_ids[i]);
1249 for (var i = visible_ids.length-1; i >= 0; i--) {
1250 if (visible_ids[i] != id) {
1251 var e = $("RROW-" + visible_ids[i]);
1253 if (e && e.hasClassName("Unread")) {
1254 ids_to_mark.push(visible_ids[i]);
1262 if (ids_to_mark.length == 0) {
1263 alert(__("No articles found to mark"));
1265 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1267 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1269 for (var i = 0; i < ids_to_mark.length; i++) {
1270 var e = $("RROW-" + ids_to_mark[i]);
1271 e.removeClassName("Unread");
1274 var query = "?op=rpc&method=catchupSelected" +
1275 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1277 new Ajax.Request("backend.php", {
1279 onComplete: function(transport) {
1280 handle_rpc_json(transport);
1287 exception_error("catchupRelativeToArticle", e);
1291 function cdmExpandArticle(id) {
1296 var elem = $("CICD-" + active_post_id);
1298 var upd_img_pic = $("FUPDPIC-" + id);
1300 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1301 upd_img_pic.src.match("fresh_sign.png"))) {
1303 upd_img_pic.src = "images/blank_icon.gif";
1306 if (id == active_post_id && Element.visible(elem))
1309 selectArticles("none");
1311 var old_offset = $("RROW-" + id).offsetTop;
1313 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1315 Element.show("CEXC-" + active_post_id);
1318 active_post_id = id;
1320 elem = $("CICD-" + id);
1322 if (!Element.visible(elem)) {
1324 Element.hide("CEXC-" + id);
1326 if ($("CWRAP-" + id).innerHTML == "") {
1328 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1330 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1331 __("Loading, please wait...") + "</div>";
1333 var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
1335 var neighbor_ids = getRelativePostIds(id);
1337 /* only request uncached articles */
1338 var cids_to_request = [];
1340 for (var i = 0; i < neighbor_ids.length; i++) {
1341 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1342 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1343 cids_to_request.push(neighbor_ids[i]);
1344 cids_requested.push(neighbor_ids[i]);
1348 console.log("additional ids: " + cids_to_request.toString());
1350 query = query + "&cids=" + cids_to_request.toString();
1354 new Ajax.Request("backend.php", {
1356 onComplete: function(transport) {
1358 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1360 handle_rpc_json(transport);
1362 var reply = JSON.parse(transport.responseText);
1364 reply.each(function(article) {
1365 $("CWRAP-" + article['id']).innerHTML = article['content'];
1366 cids_requested.remove(article['id']);
1373 var new_offset = $("RROW-" + id).offsetTop;
1375 $("headlines-frame").scrollTop += (new_offset-old_offset);
1377 if ($("RROW-" + id).offsetTop != old_offset)
1378 $("headlines-frame").scrollTop = new_offset;
1380 toggleUnread(id, 0, true);
1384 exception_error("cdmExpandArticle", e);
1390 function fixHeadlinesOrder(ids) {
1392 for (var i = 0; i < ids.length; i++) {
1393 var e = $("RROW-" + ids[i]);
1397 e.removeClassName("even");
1398 e.addClassName("odd");
1400 e.removeClassName("odd");
1401 e.addClassName("even");
1406 exception_error("fixHeadlinesOrder", e);
1410 function getArticleUnderPointer() {
1411 return post_under_pointer;
1414 function zoomToArticle(event, id) {
1416 var cached_article = cache_get("article: " + id);
1418 if (dijit.byId("ATAB-" + id))
1419 if (!event || !event.shiftKey)
1420 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1422 if (dijit.byId("ATSTRTIP-" + id))
1423 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1425 if (cached_article) {
1426 //closeArticlePanel();
1428 var article_pane = new dijit.layout.ContentPane({
1429 title: __("Loading...") , content: cached_article,
1430 style: 'padding : 0px;',
1434 dijit.byId("content-tabs").addChild(article_pane);
1436 if (!event || !event.shiftKey)
1437 dijit.byId("content-tabs").selectChild(article_pane);
1439 if ($("PTITLE-" + id))
1440 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1444 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1446 notify_progress("Loading, please wait...", true);
1448 new Ajax.Request("backend.php", {
1450 onComplete: function(transport) {
1453 var reply = JSON.parse(transport.responseText);
1456 //closeArticlePanel();
1458 var content = reply[0]['content'];
1460 var article_pane = new dijit.layout.ContentPane({
1461 title: "article-" + id , content: content,
1462 style: 'padding : 0px;',
1466 dijit.byId("content-tabs").addChild(article_pane);
1468 if (!event || !event.shiftKey)
1469 dijit.byId("content-tabs").selectChild(article_pane);
1471 if ($("PTITLE-" + id))
1472 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1479 exception_error("zoomToArticle", e);
1483 function scrollArticle(offset) {
1486 var ci = $("content-insert");
1488 ci.scrollTop += offset;
1491 var hi = $("headlines-frame");
1493 hi.scrollTop += offset;
1498 exception_error("scrollArticle", e);
1502 function show_labels_in_headlines(transport) {
1504 var data = JSON.parse(transport.responseText);
1507 data['info-for-headlines'].each(function(elem) {
1508 var ctr = $("HLLCTR-" + elem.id);
1510 if (ctr) ctr.innerHTML = elem.labels;
1513 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1517 exception_error("show_labels_in_headlines", e);
1521 /* function toggleHeadlineActions() {
1523 var e = $("headlineActionsBody");
1524 var p = $("headlineActionsDrop");
1526 if (!Element.visible(e)) {
1533 e.style.left = (p.offsetLeft + 1) + "px";
1534 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1537 exception_error("toggleHeadlineActions", e);
1541 /* function publishWithNote(id, def_note) {
1543 if (!def_note) def_note = '';
1545 var note = prompt(__("Please enter a note for this article:"), def_note);
1547 if (note != undefined) {
1548 togglePub(id, false, false, note);
1552 exception_error("publishWithNote", e);
1556 function dismissArticle(id) {
1558 var elem = $("RROW-" + id);
1560 toggleUnread(id, 0, true);
1562 new Effect.Fade(elem, {duration : 0.5});
1564 active_post_id = false;
1567 exception_error("dismissArticle", e);
1571 function dismissSelectedArticles() {
1574 var ids = getVisibleArticleIds();
1578 for (var i = 0; i < ids.length; i++) {
1579 var elem = $("RROW-" + ids[i]);
1581 if (elem.className && elem.hasClassName("Selected") &&
1582 ids[i] != active_post_id) {
1583 new Effect.Fade(elem, {duration : 0.5});
1591 selectionToggleUnread(false);
1593 fixHeadlinesOrder(tmp);
1596 exception_error("dismissSelectedArticles", e);
1600 function dismissReadArticles() {
1603 var ids = getVisibleArticleIds();
1606 for (var i = 0; i < ids.length; i++) {
1607 var elem = $("RROW-" + ids[i]);
1609 if (elem.className && !elem.hasClassName("Unread") &&
1610 !elem.hasClassName("Selected")) {
1612 new Effect.Fade(elem, {duration : 0.5});
1618 fixHeadlinesOrder(tmp);
1621 exception_error("dismissSelectedArticles", e);
1625 function getVisibleArticleIds() {
1630 getLoadedArticleIds().each(function(id) {
1631 var elem = $("RROW-" + id);
1632 if (elem && Element.visible(elem))
1637 exception_error("getVisibleArticleIds", e);
1643 function cdmClicked(event, id) {
1645 //var shift_key = event.shiftKey;
1649 if (!event.ctrlKey) {
1651 if (!getInitParam("cdm_expanded")) {
1652 return cdmExpandArticle(id);
1655 selectArticles("none");
1658 var elem = $("RROW-" + id);
1659 var article_is_unread = elem.hasClassName("Unread");
1662 elem.removeClassName("Unread");
1664 var upd_img_pic = $("FUPDPIC-" + id);
1666 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1667 upd_img_pic.src.match("fresh_sign.png"))) {
1669 upd_img_pic.src = "images/blank_icon.gif";
1672 active_post_id = id;
1674 if (article_is_unread) {
1675 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1678 var query = "?op=rpc&method=catchupSelected" +
1679 "&cmode=0&ids=" + param_escape(id);
1681 new Ajax.Request("backend.php", {
1683 onComplete: function(transport) {
1684 handle_rpc_json(transport);
1691 toggleSelected(id, true);
1693 var elem = $("RROW-" + id);
1694 var article_is_unread = elem.hasClassName("Unread");
1696 if (article_is_unread) {
1697 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1700 toggleUnread(id, 0, false);
1701 zoomToArticle(event, id);
1705 exception_error("cdmClicked");
1711 function postClicked(event, id) {
1714 if (!event.ctrlKey) {
1717 postOpenInNewTab(event, id);
1722 exception_error("postClicked");
1726 function hlOpenInNewTab(event, id) {
1727 toggleUnread(id, 0, false);
1728 zoomToArticle(event, id);
1731 function postOpenInNewTab(event, id) {
1732 closeArticlePanel(id);
1733 zoomToArticle(event, id);
1736 function hlClicked(event, id) {
1738 if (event.which == 2) {
1741 } else if (event.altKey) {
1742 openArticleInNewWindow(id);
1743 } else if (!event.ctrlKey) {
1748 toggleUnread(id, 0, false);
1749 zoomToArticle(event, id);
1754 exception_error("hlClicked");
1758 function getFirstVisibleHeadlineId() {
1759 var rows = getVisibleArticleIds();
1764 function getLastVisibleHeadlineId() {
1765 var rows = getVisibleArticleIds();
1766 return rows[rows.length-1];
1769 function openArticleInNewWindow(id) {
1770 toggleUnread(id, 0, false);
1771 window.open("backend.php?op=article&method=redirect&id=" + id);
1774 function isCdmMode() {
1775 return getInitParam("combined_display_mode");
1778 function markHeadline(id) {
1779 var row = $("RROW-" + id);
1781 var check = $("RCHK-" + id);
1784 check.checked = true;
1787 row.addClassName("Selected");
1791 function getRelativePostIds(id, limit) {
1797 if (!limit) limit = 6; //3
1799 var ids = getVisibleArticleIds();
1801 for (var i = 0; i < ids.length; i++) {
1803 for (var k = 1; k <= limit; k++) {
1804 //if (i > k-1) tmp.push(ids[i-k]);
1805 if (i < ids.length-k) tmp.push(ids[i+k]);
1812 exception_error("getRelativePostIds", e);
1818 function correctHeadlinesOffset(id) {
1822 var container = $("headlines-frame");
1823 var row = $("RROW-" + id);
1825 if (!container || !row) return;
1827 var viewport = container.offsetHeight;
1829 var rel_offset_top = row.offsetTop - container.scrollTop;
1830 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1832 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1833 //console.log("Vport: " + viewport);
1835 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1836 container.scrollTop = row.offsetTop;
1837 } else if (rel_offset_bottom > viewport) {
1839 /* doesn't properly work with Opera in some cases because
1840 Opera fucks up element scrolling */
1842 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1846 exception_error("correctHeadlinesOffset", e);
1851 function headlineActionsChange(elem) {
1854 elem.attr('value', 'false');
1856 exception_error("headlineActionsChange", e);
1860 function closeArticlePanel() {
1862 var tabs = dijit.byId("content-tabs");
1863 var child = tabs.selectedChildWidget;
1865 if (child && tabs.getIndexOfChild(child) > 0) {
1866 tabs.removeChild(child);
1869 if (dijit.byId("content-insert"))
1870 dijit.byId("headlines-wrap-inner").removeChild(
1871 dijit.byId("content-insert"));
1875 function initHeadlinesMenu() {
1877 if (dijit.byId("headlinesMenu"))
1878 dijit.byId("headlinesMenu").destroyRecursive();
1883 nodes = $$("#headlines-frame > div[id*=RROW]");
1885 nodes = $$("#headlines-frame span[id*=RTITLE]");
1888 nodes.each(function(node) {
1892 var menu = new dijit.Menu({
1893 id: "headlinesMenu",
1897 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1898 var callerNode = event.target, match = null, tries = 0;
1900 while (match == null && callerNode && tries <= 3) {
1901 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1902 callerNode = callerNode.parentNode;
1906 if (match) this.callerRowId = parseInt(match[1]);
1910 /* if (!isCdmMode())
1911 menu.addChild(new dijit.MenuItem({
1912 label: __("View article"),
1913 onClick: function(event) {
1914 view(this.getParent().callerRowId);
1917 menu.addChild(new dijit.MenuItem({
1918 label: __("Open original article"),
1919 onClick: function(event) {
1920 openArticleInNewWindow(this.getParent().callerRowId);
1923 menu.addChild(new dijit.MenuItem({
1924 label: __("View in a tt-rss tab"),
1925 onClick: function(event) {
1926 hlOpenInNewTab(event, this.getParent().callerRowId);
1929 menu.addChild(new dijit.MenuSeparator());
1931 menu.addChild(new dijit.MenuItem({
1932 label: __("Mark above as read"),
1933 onClick: function(event) {
1934 catchupRelativeToArticle(0, this.getParent().callerRowId);
1937 menu.addChild(new dijit.MenuItem({
1938 label: __("Mark below as read"),
1939 onClick: function(event) {
1940 catchupRelativeToArticle(1, this.getParent().callerRowId);
1944 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1948 menu.addChild(new dijit.MenuSeparator());
1950 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1951 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1953 labels.each(function(label) {
1954 var id = label.id[0];
1955 var bare_id = id.substr(id.indexOf(":")+1);
1956 var name = label.name[0];
1958 bare_id = -11-bare_id;
1960 labelAddMenu.addChild(new dijit.MenuItem({
1963 onClick: function(event) {
1964 var ids = getSelectedArticleIds2();
1966 var id = this.getParent().ownerMenu.callerRowId + "";
1968 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1970 selectionAssignLabel(this.labelId, ids);
1973 labelDelMenu.addChild(new dijit.MenuItem({
1976 onClick: function(event) {
1977 var ids = getSelectedArticleIds2();
1979 var id = this.getParent().ownerMenu.callerRowId + "";
1981 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1983 selectionRemoveLabel(this.labelId, ids);
1988 menu.addChild(new dijit.PopupMenuItem({
1989 label: __("Assign label"),
1990 popup: labelAddMenu,
1993 menu.addChild(new dijit.PopupMenuItem({
1994 label: __("Remove label"),
1995 popup: labelDelMenu,
2003 exception_error("initHeadlinesMenu", e);
2008 function player(elem) {
2009 var aid = elem.getAttribute("audio-id");
2010 var status = elem.getAttribute("status");
2018 elem.innerHTML = __("Playing...");
2019 elem.title = __("Click to pause");
2020 elem.addClassName("playing");
2024 elem.innerHTML = __("Play");
2025 elem.title = __("Click to play");
2026 elem.removeClassName("playing");
2029 elem.setAttribute("status", status);
2031 alert("Your browser doesn't seem to support HTML5 audio.");
2035 function cache_set(id, obj) {
2036 //console.log("cache_set: " + id);
2039 sessionStorage[id] = obj;
2041 sessionStorage.clear();
2045 function cache_get(id) {
2047 return sessionStorage[id];
2050 function cache_clear() {
2052 sessionStorage.clear();
2055 function cache_delete(id) {
2057 sessionStorage.removeItem(id);
2060 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2061 if (toolbar_obj && content_obj) {
2062 cache_set("feed:" + feed + ":" + is_cat,
2063 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2066 obj = cache_get("feed:" + feed + ":" + is_cat);
2069 obj = JSON.parse(obj);
2071 if (toolbar_obj) obj.toolbar = toolbar_obj;
2072 if (content_obj) obj.content = content_obj;
2074 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2078 console.warn("cache_headlines failed: " + e);
2083 function render_local_headlines(feed, is_cat, obj) {
2086 dijit.byId("headlines-toolbar").attr('content',
2089 dijit.byId("headlines-frame").attr('content',
2092 dojo.parser.parse('headlines-toolbar');
2094 $("headlines-frame").scrollTop = 0;
2095 selectArticles('none');
2096 setActiveFeedId(feed, is_cat);
2097 initHeadlinesMenu();
2099 precache_headlines();
2102 exception_error("render_local_headlines", e);
2106 function precache_headlines_idle() {
2108 if (!feed_precache_timeout_id) {
2109 if (get_timestamp() - _viewfeed_last > 120) {
2111 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2114 feeds.each(function(item) {
2115 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2116 uncached.push(item);
2119 if (uncached.length > 0) {
2120 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2121 viewfeed(rf[0], '', rf[1], 0, true);
2125 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2128 exception_error("precache_headlines_idle", e);
2132 function precache_headlines() {
2135 if (!feed_precache_timeout_id) {
2136 feed_precache_timeout_id = window.setTimeout(function() {
2137 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2138 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2140 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2141 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2143 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2144 viewfeed(nf[0], '', nf[1], 0, true);
2146 window.setTimeout(function() {
2147 feed_precache_timeout_id = false;
2153 exception_error("precache_headlines", e);