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>");
309 if (!_infscroll_disable &&
310 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
320 exception_error("article_callback2", e, transport);
326 console.log("loading article: " + id);
328 var cached_article = cache_get("article:" + id);
330 console.log("cache check result: " + (cached_article != false));
334 var query = "?op=article&method=view&id=" + param_escape(id);
336 var neighbor_ids = getRelativePostIds(id);
338 /* only request uncached articles */
340 var cids_to_request = [];
342 for (var i = 0; i < neighbor_ids.length; i++) {
343 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
344 if (!cache_get("article:" + neighbor_ids[i])) {
345 cids_to_request.push(neighbor_ids[i]);
346 cids_requested.push(neighbor_ids[i]);
350 console.log("additional ids: " + cids_to_request.toString());
352 query = query + "&cids=" + cids_to_request.toString();
354 var crow = $("RROW-" + id);
355 var article_is_unread = crow.hasClassName("Unread");
358 showArticleInHeadlines(id);
360 precache_headlines();
362 if (!cached_article) {
364 var upic = $('FUPDPIC-' + id);
367 upic.src = getInitParam("sign_progress");
370 } else if (cached_article && article_is_unread) {
372 query = query + "&mode=prefetch";
374 render_article(cached_article);
376 } else if (cached_article) {
378 query = query + "&mode=prefetch_old";
379 render_article(cached_article);
381 // if we don't need to request any relative ids, we might as well skip
382 // the server roundtrip altogether
383 if (cids_to_request.length == 0) {
386 if (!_infscroll_disable &&
387 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
399 last_requested_article = id;
403 if (article_is_unread) {
404 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
407 new Ajax.Request("backend.php", {
409 onComplete: function(transport) {
410 article_callback2(transport, id);
416 exception_error("view", e);
420 function toggleMark(id, client_only) {
422 var query = "?op=rpc&id=" + id + "&method=mark";
424 var img = $("FMPIC-" + id);
428 if (img.src.match("mark_unset")) {
429 img.src = img.src.replace("mark_unset", "mark_set");
430 img.alt = __("Unstar article");
431 query = query + "&mark=1";
434 img.src = img.src.replace("mark_set", "mark_unset");
435 img.alt = __("Star article");
436 query = query + "&mark=0";
439 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
442 new Ajax.Request("backend.php", {
444 onComplete: function(transport) {
445 handle_rpc_json(transport);
450 exception_error("toggleMark", e);
454 function togglePub(id, client_only, no_effects, note) {
456 var query = "?op=rpc&id=" + id + "&method=publ";
458 if (note != undefined) {
459 query = query + "¬e=" + param_escape(note);
461 query = query + "¬e=undefined";
464 var img = $("FPPIC-" + id);
468 if (img.src.match("pub_unset") || note != undefined) {
469 img.src = img.src.replace("pub_unset", "pub_set");
470 img.alt = __("Unpublish article");
471 query = query + "&pub=1";
474 img.src = img.src.replace("pub_set", "pub_unset");
475 img.alt = __("Publish article");
477 query = query + "&pub=0";
480 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
483 new Ajax.Request("backend.php", {
485 onComplete: function(transport) {
486 handle_rpc_json(transport);
491 exception_error("togglePub", e);
495 function moveToPost(mode) {
499 var rows = getVisibleArticleIds();
504 if (!$('RROW-' + active_post_id)) {
505 active_post_id = false;
508 if (active_post_id == false) {
510 prev_id = rows[rows.length-1]
512 for (var i = 0; i < rows.length; i++) {
513 if (rows[i] == active_post_id) {
515 // Account for adjacent identical article ids.
516 if (i > 0) prev_id = rows[i-1];
518 for (var j = i+1; j < rows.length; j++) {
519 if (rows[j] != active_post_id) {
529 if (mode == "next") {
533 cdmExpandArticle(next_id);
534 cdmScrollToArticleId(next_id);
537 correctHeadlinesOffset(next_id);
538 view(next_id, getActiveFeedId());
543 if (mode == "prev") {
546 cdmExpandArticle(prev_id);
547 cdmScrollToArticleId(prev_id);
549 correctHeadlinesOffset(prev_id);
550 view(prev_id, getActiveFeedId());
556 exception_error("moveToPost", e);
560 function toggleSelected(id, force_on) {
563 var cb = $("RCHK-" + id);
564 var row = $("RROW-" + id);
567 if (row.hasClassName('Selected') && !force_on) {
568 row.removeClassName('Selected');
569 if (cb) cb.checked = false;
571 row.addClassName('Selected');
572 if (cb) cb.checked = true;
576 exception_error("toggleSelected", e);
580 function toggleUnread_afh(effect) {
583 var elem = effect.element;
584 elem.style.backgroundColor = "";
587 exception_error("toggleUnread_afh", e);
591 function toggleUnread(id, cmode, effect) {
594 var row = $("RROW-" + id);
596 if (cmode == undefined || cmode == 2) {
597 if (row.hasClassName("Unread")) {
598 row.removeClassName("Unread");
601 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
602 afterFinish: toggleUnread_afh,
603 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
607 row.addClassName("Unread");
610 } else if (cmode == 0) {
612 row.removeClassName("Unread");
615 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
616 afterFinish: toggleUnread_afh,
617 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
620 } else if (cmode == 1) {
621 row.addClassName("Unread");
624 if (cmode == undefined) cmode = 2;
626 var query = "?op=rpc&method=catchupSelected" +
627 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
629 // notify_progress("Loading, please wait...");
631 new Ajax.Request("backend.php", {
633 onComplete: function(transport) {
634 handle_rpc_json(transport);
640 exception_error("toggleUnread", e);
644 function selectionRemoveLabel(id, ids) {
647 if (!ids) ids = getSelectedArticleIds2();
649 if (ids.length == 0) {
650 alert(__("No articles are selected."));
654 var query = "?op=rpc&method=removeFromLabel&ids=" +
655 param_escape(ids.toString()) + "&lid=" + param_escape(id);
659 new Ajax.Request("backend.php", {
661 onComplete: function(transport) {
662 handle_rpc_json(transport);
663 show_labels_in_headlines(transport);
667 exception_error("selectionAssignLabel", e);
672 function selectionAssignLabel(id, ids) {
675 if (!ids) ids = getSelectedArticleIds2();
677 if (ids.length == 0) {
678 alert(__("No articles are selected."));
682 var query = "?op=rpc&method=assignToLabel&ids=" +
683 param_escape(ids.toString()) + "&lid=" + param_escape(id);
687 new Ajax.Request("backend.php", {
689 onComplete: function(transport) {
690 handle_rpc_json(transport);
691 show_labels_in_headlines(transport);
695 exception_error("selectionAssignLabel", e);
700 function selectionToggleUnread(set_state, callback, no_error) {
702 var rows = getSelectedArticleIds2();
704 if (rows.length == 0 && !no_error) {
705 alert(__("No articles are selected."));
709 for (var i = 0; i < rows.length; i++) {
710 var row = $("RROW-" + rows[i]);
712 if (set_state == undefined) {
713 if (row.hasClassName("Unread")) {
714 row.removeClassName("Unread");
716 row.addClassName("Unread");
720 if (set_state == false) {
721 row.removeClassName("Unread");
724 if (set_state == true) {
725 row.addClassName("Unread");
730 if (rows.length > 0) {
734 if (set_state == undefined) {
736 } else if (set_state == true) {
738 } else if (set_state == false) {
742 var query = "?op=rpc&method=catchupSelected" +
743 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
745 notify_progress("Loading, please wait...");
747 new Ajax.Request("backend.php", {
749 onComplete: function(transport) {
750 handle_rpc_json(transport);
751 if (callback) callback(transport);
757 exception_error("selectionToggleUnread", e);
761 function selectionToggleMarked() {
764 var rows = getSelectedArticleIds2();
766 if (rows.length == 0) {
767 alert(__("No articles are selected."));
771 for (var i = 0; i < rows.length; i++) {
772 toggleMark(rows[i], true, true);
775 if (rows.length > 0) {
777 var query = "?op=rpc&method=markSelected&ids=" +
778 param_escape(rows.toString()) + "&cmode=2";
780 new Ajax.Request("backend.php", {
782 onComplete: function(transport) {
783 handle_rpc_json(transport);
789 exception_error("selectionToggleMarked", e);
793 function selectionTogglePublished() {
796 var rows = getSelectedArticleIds2();
798 if (rows.length == 0) {
799 alert(__("No articles are selected."));
803 for (var i = 0; i < rows.length; i++) {
804 togglePub(rows[i], true, true);
807 if (rows.length > 0) {
809 var query = "?op=rpc&method=publishSelected&ids=" +
810 param_escape(rows.toString()) + "&cmode=2";
812 new Ajax.Request("backend.php", {
814 onComplete: function(transport) {
815 handle_rpc_json(transport);
821 exception_error("selectionToggleMarked", e);
825 function getSelectedArticleIds2() {
829 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
831 rv.push(child.id.replace("RROW-", ""));
837 function getLoadedArticleIds() {
840 var children = $$("#headlines-frame > div[id*=RROW-]");
842 children.each(function(child) {
843 rv.push(child.id.replace("RROW-", ""));
850 // mode = all,none,unread,invert
851 function selectArticles(mode) {
854 var children = $$("#headlines-frame > div[id*=RROW]");
856 children.each(function(child) {
857 var id = child.id.replace("RROW-", "");
858 var cb = $("RCHK-" + id);
861 child.addClassName("Selected");
863 } else if (mode == "unread") {
864 if (child.hasClassName("Unread")) {
865 child.addClassName("Selected");
868 child.removeClassName("Selected");
871 } else if (mode == "invert") {
872 if (child.hasClassName("Selected")) {
873 child.removeClassName("Selected");
876 child.addClassName("Selected");
881 child.removeClassName("Selected");
887 exception_error("selectArticles", e);
891 function catchupPage() {
893 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
895 var str = __("Mark all visible articles in %s as read?");
897 str = str.replace("%s", fn);
899 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
903 selectArticles('all');
904 selectionToggleUnread(false, 'viewCurrentFeed()', true);
905 selectArticles('none');
908 function deleteSelection() {
912 var rows = getSelectedArticleIds2();
914 if (rows.length == 0) {
915 alert(__("No articles are selected."));
919 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
922 if (getActiveFeedId() != 0) {
923 str = __("Delete %d selected articles in %s?");
925 str = __("Delete %d selected articles?");
928 str = str.replace("%d", rows.length);
929 str = str.replace("%s", fn);
931 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
935 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
939 new Ajax.Request("backend.php", {
941 onComplete: function(transport) {
942 handle_rpc_json(transport);
947 exception_error("deleteSelection", e);
951 function archiveSelection() {
955 var rows = getSelectedArticleIds2();
957 if (rows.length == 0) {
958 alert(__("No articles are selected."));
962 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
966 if (getActiveFeedId() != 0) {
967 str = __("Archive %d selected articles in %s?");
970 str = __("Move %d archived articles back?");
974 str = str.replace("%d", rows.length);
975 str = str.replace("%s", fn);
977 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
981 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
985 for (var i = 0; i < rows.length; i++) {
986 cache_delete("article:" + rows[i]);
989 new Ajax.Request("backend.php", {
991 onComplete: function(transport) {
992 handle_rpc_json(transport);
997 exception_error("archiveSelection", e);
1001 function catchupSelection() {
1005 var rows = getSelectedArticleIds2();
1007 if (rows.length == 0) {
1008 alert(__("No articles are selected."));
1012 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1014 var str = __("Mark %d selected articles in %s as read?");
1016 str = str.replace("%d", rows.length);
1017 str = str.replace("%s", fn);
1019 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1023 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1026 exception_error("catchupSelection", e);
1030 function editArticleTags(id) {
1031 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1033 if (dijit.byId("editTagsDlg"))
1034 dijit.byId("editTagsDlg").destroyRecursive();
1036 dialog = new dijit.Dialog({
1038 title: __("Edit article Tags"),
1039 style: "width: 600px",
1040 execute: function() {
1041 if (this.validate()) {
1042 var query = dojo.objectToQuery(this.attr('value'));
1044 notify_progress("Saving article tags...", true);
1046 new Ajax.Request("backend.php", {
1048 onComplete: function(transport) {
1052 var data = JSON.parse(transport.responseText);
1055 var tags_str = article.tags;
1056 var id = tags_str.id;
1058 var tags = $("ATSTR-" + id);
1059 var tooltip = dijit.byId("ATSTRTIP-" + id);
1061 if (tags) tags.innerHTML = tags_str.content;
1062 if (tooltip) tooltip.attr('label', tags_str.content_full);
1064 cache_delete("article:" + id);
1073 var tmph = dojo.connect(dialog, 'onLoad', function() {
1074 dojo.disconnect(tmph);
1076 new Ajax.Autocompleter('tags_str', 'tags_choices',
1077 "backend.php?op=rpc&method=completeTags",
1078 { tokens: ',', paramName: "search" });
1085 function cdmScrollToArticleId(id) {
1087 var ctr = $("headlines-frame");
1088 var e = $("RROW-" + id);
1090 if (!e || !ctr) return;
1092 ctr.scrollTop = e.offsetTop;
1095 exception_error("cdmScrollToArticleId", e);
1099 function getActiveArticleId() {
1100 return active_post_id;
1103 function postMouseIn(id) {
1104 post_under_pointer = id;
1107 function postMouseOut(id) {
1108 post_under_pointer = false;
1111 function headlines_scroll_handler(e) {
1113 var hsp = $("headlines-spacer");
1115 if (!_infscroll_disable) {
1116 if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1117 e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1120 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1121 __("Loading, please wait...");
1123 loadMoreHeadlines();
1128 if (hsp) hsp.innerHTML = "";
1131 if (getInitParam("cdm_auto_catchup") == 1) {
1133 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1135 if ($("headlines-frame").scrollTop >
1136 (child.offsetTop + child.offsetHeight/2)) {
1138 var id = child.id.replace("RROW-", "");
1140 if (catchup_id_batch.indexOf(id) == -1)
1141 catchup_id_batch.push(id);
1143 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1147 if (catchup_id_batch.length > 0) {
1148 window.clearTimeout(catchup_timeout_id);
1150 if (!_infscroll_request_sent) {
1151 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1158 console.warn("headlines_scroll_handler: " + e);
1162 function catchupBatchedArticles() {
1164 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1166 // make a copy of the array
1167 var batch = catchup_id_batch.slice();
1168 var query = "?op=rpc&method=catchupSelected" +
1169 "&cmode=0&ids=" + param_escape(batch.toString());
1173 new Ajax.Request("backend.php", {
1175 onComplete: function(transport) {
1176 handle_rpc_json(transport);
1178 batch.each(function(id) {
1179 var elem = $("RROW-" + id);
1180 if (elem) elem.removeClassName("Unread");
1181 catchup_id_batch.remove(id);
1188 exception_error("catchupBatchedArticles", e);
1192 function catchupRelativeToArticle(below, id) {
1196 if (!id) id = getActiveArticleId();
1199 alert(__("No article is selected."));
1203 var visible_ids = getVisibleArticleIds();
1205 var ids_to_mark = new Array();
1208 for (var i = 0; i < visible_ids.length; i++) {
1209 if (visible_ids[i] != id) {
1210 var e = $("RROW-" + visible_ids[i]);
1212 if (e && e.hasClassName("Unread")) {
1213 ids_to_mark.push(visible_ids[i]);
1220 for (var i = visible_ids.length-1; i >= 0; i--) {
1221 if (visible_ids[i] != id) {
1222 var e = $("RROW-" + visible_ids[i]);
1224 if (e && e.hasClassName("Unread")) {
1225 ids_to_mark.push(visible_ids[i]);
1233 if (ids_to_mark.length == 0) {
1234 alert(__("No articles found to mark"));
1236 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1238 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1240 for (var i = 0; i < ids_to_mark.length; i++) {
1241 var e = $("RROW-" + ids_to_mark[i]);
1242 e.removeClassName("Unread");
1245 var query = "?op=rpc&method=catchupSelected" +
1246 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1248 new Ajax.Request("backend.php", {
1250 onComplete: function(transport) {
1251 handle_rpc_json(transport);
1258 exception_error("catchupRelativeToArticle", e);
1262 function cdmExpandArticle(id) {
1267 var elem = $("CICD-" + active_post_id);
1269 var upd_img_pic = $("FUPDPIC-" + id);
1271 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1272 upd_img_pic.src.match("fresh_sign.png"))) {
1274 upd_img_pic.src = "images/blank_icon.gif";
1277 if (id == active_post_id && Element.visible(elem))
1280 selectArticles("none");
1282 var old_offset = $("RROW-" + id).offsetTop;
1284 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1286 Element.show("CEXC-" + active_post_id);
1289 active_post_id = id;
1291 elem = $("CICD-" + id);
1293 if (!Element.visible(elem)) {
1295 Element.hide("CEXC-" + id);
1297 if ($("CWRAP-" + id).innerHTML == "") {
1299 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1301 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1302 __("Loading, please wait...") + "</div>";
1304 var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
1306 var neighbor_ids = getRelativePostIds(id);
1308 /* only request uncached articles */
1309 var cids_to_request = [];
1311 for (var i = 0; i < neighbor_ids.length; i++) {
1312 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1313 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1314 cids_to_request.push(neighbor_ids[i]);
1315 cids_requested.push(neighbor_ids[i]);
1319 console.log("additional ids: " + cids_to_request.toString());
1321 query = query + "&cids=" + cids_to_request.toString();
1325 new Ajax.Request("backend.php", {
1327 onComplete: function(transport) {
1329 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1331 handle_rpc_json(transport);
1333 var reply = JSON.parse(transport.responseText);
1335 reply.each(function(article) {
1336 $("CWRAP-" + article['id']).innerHTML = article['content'];
1337 cids_requested.remove(article['id']);
1344 var new_offset = $("RROW-" + id).offsetTop;
1346 $("headlines-frame").scrollTop += (new_offset-old_offset);
1348 if ($("RROW-" + id).offsetTop != old_offset)
1349 $("headlines-frame").scrollTop = new_offset;
1351 toggleUnread(id, 0, true);
1355 exception_error("cdmExpandArticle", e);
1361 function fixHeadlinesOrder(ids) {
1363 for (var i = 0; i < ids.length; i++) {
1364 var e = $("RROW-" + ids[i]);
1368 e.removeClassName("even");
1369 e.addClassName("odd");
1371 e.removeClassName("odd");
1372 e.addClassName("even");
1377 exception_error("fixHeadlinesOrder", e);
1381 function getArticleUnderPointer() {
1382 return post_under_pointer;
1385 function zoomToArticle(event, id) {
1387 var cached_article = cache_get("article: " + id);
1389 if (dijit.byId("ATAB-" + id))
1390 if (!event || !event.shiftKey)
1391 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1393 if (dijit.byId("ATSTRTIP-" + id))
1394 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1396 if (cached_article) {
1397 //closeArticlePanel();
1399 var article_pane = new dijit.layout.ContentPane({
1400 title: __("Loading...") , content: cached_article,
1401 style: 'padding : 0px;',
1405 dijit.byId("content-tabs").addChild(article_pane);
1407 if (!event || !event.shiftKey)
1408 dijit.byId("content-tabs").selectChild(article_pane);
1410 if ($("PTITLE-" + id))
1411 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1415 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1417 notify_progress("Loading, please wait...", true);
1419 new Ajax.Request("backend.php", {
1421 onComplete: function(transport) {
1424 var reply = JSON.parse(transport.responseText);
1427 //closeArticlePanel();
1429 var content = reply[0]['content'];
1431 var article_pane = new dijit.layout.ContentPane({
1432 title: "article-" + id , content: content,
1433 style: 'padding : 0px;',
1437 dijit.byId("content-tabs").addChild(article_pane);
1439 if (!event || !event.shiftKey)
1440 dijit.byId("content-tabs").selectChild(article_pane);
1442 if ($("PTITLE-" + id))
1443 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1450 exception_error("zoomToArticle", e);
1454 function scrollArticle(offset) {
1457 var ci = $("content-insert");
1459 ci.scrollTop += offset;
1462 var hi = $("headlines-frame");
1464 hi.scrollTop += offset;
1469 exception_error("scrollArticle", e);
1473 function show_labels_in_headlines(transport) {
1475 var data = JSON.parse(transport.responseText);
1478 data['info-for-headlines'].each(function(elem) {
1479 var ctr = $("HLLCTR-" + elem.id);
1481 if (ctr) ctr.innerHTML = elem.labels;
1484 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1488 exception_error("show_labels_in_headlines", e);
1492 /* function toggleHeadlineActions() {
1494 var e = $("headlineActionsBody");
1495 var p = $("headlineActionsDrop");
1497 if (!Element.visible(e)) {
1504 e.style.left = (p.offsetLeft + 1) + "px";
1505 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1508 exception_error("toggleHeadlineActions", e);
1512 /* function publishWithNote(id, def_note) {
1514 if (!def_note) def_note = '';
1516 var note = prompt(__("Please enter a note for this article:"), def_note);
1518 if (note != undefined) {
1519 togglePub(id, false, false, note);
1523 exception_error("publishWithNote", e);
1527 function dismissArticle(id) {
1529 var elem = $("RROW-" + id);
1531 toggleUnread(id, 0, true);
1533 new Effect.Fade(elem, {duration : 0.5});
1535 active_post_id = false;
1538 exception_error("dismissArticle", e);
1542 function dismissSelectedArticles() {
1545 var ids = getVisibleArticleIds();
1549 for (var i = 0; i < ids.length; i++) {
1550 var elem = $("RROW-" + ids[i]);
1552 if (elem.className && elem.hasClassName("Selected") &&
1553 ids[i] != active_post_id) {
1554 new Effect.Fade(elem, {duration : 0.5});
1562 selectionToggleUnread(false);
1564 fixHeadlinesOrder(tmp);
1567 exception_error("dismissSelectedArticles", e);
1571 function dismissReadArticles() {
1574 var ids = getVisibleArticleIds();
1577 for (var i = 0; i < ids.length; i++) {
1578 var elem = $("RROW-" + ids[i]);
1580 if (elem.className && !elem.hasClassName("Unread") &&
1581 !elem.hasClassName("Selected")) {
1583 new Effect.Fade(elem, {duration : 0.5});
1589 fixHeadlinesOrder(tmp);
1592 exception_error("dismissSelectedArticles", e);
1596 function getVisibleArticleIds() {
1601 getLoadedArticleIds().each(function(id) {
1602 var elem = $("RROW-" + id);
1603 if (elem && Element.visible(elem))
1608 exception_error("getVisibleArticleIds", e);
1614 function cdmClicked(event, id) {
1616 //var shift_key = event.shiftKey;
1620 if (!event.ctrlKey) {
1622 if (!getInitParam("cdm_expanded")) {
1623 return cdmExpandArticle(id);
1626 selectArticles("none");
1629 var elem = $("RROW-" + id);
1630 var article_is_unread = elem.hasClassName("Unread");
1633 elem.removeClassName("Unread");
1635 var upd_img_pic = $("FUPDPIC-" + id);
1637 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1638 upd_img_pic.src.match("fresh_sign.png"))) {
1640 upd_img_pic.src = "images/blank_icon.gif";
1643 active_post_id = id;
1645 if (article_is_unread) {
1646 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1649 var query = "?op=rpc&method=catchupSelected" +
1650 "&cmode=0&ids=" + param_escape(id);
1652 new Ajax.Request("backend.php", {
1654 onComplete: function(transport) {
1655 handle_rpc_json(transport);
1662 toggleSelected(id, true);
1664 var elem = $("RROW-" + id);
1665 var article_is_unread = elem.hasClassName("Unread");
1667 if (article_is_unread) {
1668 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1671 toggleUnread(id, 0, false);
1672 zoomToArticle(event, id);
1676 exception_error("cdmClicked");
1682 function postClicked(event, id) {
1685 if (!event.ctrlKey) {
1688 postOpenInNewTab(event, id);
1693 exception_error("postClicked");
1697 function hlOpenInNewTab(event, id) {
1698 toggleUnread(id, 0, false);
1699 zoomToArticle(event, id);
1702 function postOpenInNewTab(event, id) {
1703 closeArticlePanel(id);
1704 zoomToArticle(event, id);
1707 function hlClicked(event, id) {
1709 if (event.which == 2) {
1712 } else if (event.altKey) {
1713 openArticleInNewWindow(id);
1714 } else if (!event.ctrlKey) {
1719 toggleUnread(id, 0, false);
1720 zoomToArticle(event, id);
1725 exception_error("hlClicked");
1729 function getFirstVisibleHeadlineId() {
1730 var rows = getVisibleArticleIds();
1735 function getLastVisibleHeadlineId() {
1736 var rows = getVisibleArticleIds();
1737 return rows[rows.length-1];
1740 function openArticleInNewWindow(id) {
1741 toggleUnread(id, 0, false);
1742 window.open("backend.php?op=article&method=redirect&id=" + id);
1745 function isCdmMode() {
1746 return getInitParam("combined_display_mode");
1749 function markHeadline(id) {
1750 var row = $("RROW-" + id);
1752 var check = $("RCHK-" + id);
1755 check.checked = true;
1758 row.addClassName("Selected");
1762 function getRelativePostIds(id, limit) {
1768 if (!limit) limit = 6; //3
1770 var ids = getVisibleArticleIds();
1772 for (var i = 0; i < ids.length; i++) {
1774 for (var k = 1; k <= limit; k++) {
1775 //if (i > k-1) tmp.push(ids[i-k]);
1776 if (i < ids.length-k) tmp.push(ids[i+k]);
1783 exception_error("getRelativePostIds", e);
1789 function correctHeadlinesOffset(id) {
1793 var container = $("headlines-frame");
1794 var row = $("RROW-" + id);
1796 if (!container || !row) return;
1798 var viewport = container.offsetHeight;
1800 var rel_offset_top = row.offsetTop - container.scrollTop;
1801 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1803 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1804 //console.log("Vport: " + viewport);
1806 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1807 container.scrollTop = row.offsetTop;
1808 } else if (rel_offset_bottom > viewport) {
1810 /* doesn't properly work with Opera in some cases because
1811 Opera fucks up element scrolling */
1813 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1817 exception_error("correctHeadlinesOffset", e);
1822 function headlineActionsChange(elem) {
1825 elem.attr('value', 'false');
1827 exception_error("headlineActionsChange", e);
1831 function closeArticlePanel() {
1833 var tabs = dijit.byId("content-tabs");
1834 var child = tabs.selectedChildWidget;
1836 if (child && tabs.getIndexOfChild(child) > 0) {
1837 tabs.removeChild(child);
1840 if (dijit.byId("content-insert"))
1841 dijit.byId("headlines-wrap-inner").removeChild(
1842 dijit.byId("content-insert"));
1846 function initHeadlinesMenu() {
1848 if (dijit.byId("headlinesMenu"))
1849 dijit.byId("headlinesMenu").destroyRecursive();
1854 nodes = $$("#headlines-frame > div[id*=RROW]");
1856 nodes = $$("#headlines-frame span[id*=RTITLE]");
1859 nodes.each(function(node) {
1863 var menu = new dijit.Menu({
1864 id: "headlinesMenu",
1868 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1869 var callerNode = event.target, match = null, tries = 0;
1871 while (match == null && callerNode && tries <= 3) {
1872 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1873 callerNode = callerNode.parentNode;
1877 if (match) this.callerRowId = parseInt(match[1]);
1881 /* if (!isCdmMode())
1882 menu.addChild(new dijit.MenuItem({
1883 label: __("View article"),
1884 onClick: function(event) {
1885 view(this.getParent().callerRowId);
1888 menu.addChild(new dijit.MenuItem({
1889 label: __("Open original article"),
1890 onClick: function(event) {
1891 openArticleInNewWindow(this.getParent().callerRowId);
1894 menu.addChild(new dijit.MenuItem({
1895 label: __("View in a tt-rss tab"),
1896 onClick: function(event) {
1897 hlOpenInNewTab(event, this.getParent().callerRowId);
1900 menu.addChild(new dijit.MenuSeparator());
1902 menu.addChild(new dijit.MenuItem({
1903 label: __("Mark above as read"),
1904 onClick: function(event) {
1905 catchupRelativeToArticle(0, this.getParent().callerRowId);
1908 menu.addChild(new dijit.MenuItem({
1909 label: __("Mark below as read"),
1910 onClick: function(event) {
1911 catchupRelativeToArticle(1, this.getParent().callerRowId);
1915 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1919 menu.addChild(new dijit.MenuSeparator());
1921 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1922 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1924 labels.each(function(label) {
1925 var id = label.id[0];
1926 var bare_id = id.substr(id.indexOf(":")+1);
1927 var name = label.name[0];
1929 bare_id = -11-bare_id;
1931 labelAddMenu.addChild(new dijit.MenuItem({
1934 onClick: function(event) {
1935 var ids = getSelectedArticleIds2();
1937 var id = this.getParent().ownerMenu.callerRowId + "";
1939 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1941 selectionAssignLabel(this.labelId, ids);
1944 labelDelMenu.addChild(new dijit.MenuItem({
1947 onClick: function(event) {
1948 var ids = getSelectedArticleIds2();
1950 var id = this.getParent().ownerMenu.callerRowId + "";
1952 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1954 selectionRemoveLabel(this.labelId, ids);
1959 menu.addChild(new dijit.PopupMenuItem({
1960 label: __("Assign label"),
1961 popup: labelAddMenu,
1964 menu.addChild(new dijit.PopupMenuItem({
1965 label: __("Remove label"),
1966 popup: labelDelMenu,
1974 exception_error("initHeadlinesMenu", e);
1979 function player(elem) {
1980 var aid = elem.getAttribute("audio-id");
1981 var status = elem.getAttribute("status");
1989 elem.innerHTML = __("Playing...");
1990 elem.title = __("Click to pause");
1991 elem.addClassName("playing");
1995 elem.innerHTML = __("Play");
1996 elem.title = __("Click to play");
1997 elem.removeClassName("playing");
2000 elem.setAttribute("status", status);
2002 alert("Your browser doesn't seem to support HTML5 audio.");
2006 function cache_set(id, obj) {
2007 //console.log("cache_set: " + id);
2010 sessionStorage[id] = obj;
2012 sessionStorage.clear();
2016 function cache_get(id) {
2018 return sessionStorage[id];
2021 function cache_clear() {
2023 sessionStorage.clear();
2026 function cache_delete(id) {
2028 sessionStorage.removeItem(id);
2031 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2032 if (toolbar_obj && content_obj) {
2033 cache_set("feed:" + feed + ":" + is_cat,
2034 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2037 obj = cache_get("feed:" + feed + ":" + is_cat);
2040 obj = JSON.parse(obj);
2042 if (toolbar_obj) obj.toolbar = toolbar_obj;
2043 if (content_obj) obj.content = content_obj;
2045 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2049 console.warn("cache_headlines failed: " + e);
2054 function render_local_headlines(feed, is_cat, obj) {
2057 dijit.byId("headlines-toolbar").attr('content',
2060 dijit.byId("headlines-frame").attr('content',
2063 dojo.parser.parse('headlines-toolbar');
2065 $("headlines-frame").scrollTop = 0;
2066 selectArticles('none');
2067 setActiveFeedId(feed, is_cat);
2068 initHeadlinesMenu();
2070 precache_headlines();
2073 exception_error("render_local_headlines", e);
2077 function precache_headlines_idle() {
2079 if (!feed_precache_timeout_id) {
2080 if (get_timestamp() - _viewfeed_last > 120) {
2082 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2085 feeds.each(function(item) {
2086 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2087 uncached.push(item);
2090 if (uncached.length > 0) {
2091 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2092 viewfeed(rf[0], '', rf[1], 0, true);
2096 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2099 exception_error("precache_headlines_idle", e);
2103 function precache_headlines() {
2106 if (!feed_precache_timeout_id) {
2107 feed_precache_timeout_id = window.setTimeout(function() {
2108 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2109 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2111 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2112 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2114 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2115 viewfeed(nf[0], '', nf[1], 0, true);
2117 window.setTimeout(function() {
2118 feed_precache_timeout_id = false;
2124 exception_error("precache_headlines", e);