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 dojo.parser.parse('headlines-tmp');
125 var hsp = $("headlines-spacer");
128 c.domNode.removeChild(hsp);
130 $$("#headlines-tmp > div").each(function(row) {
131 if (row.className == 'cdmFeedTitle') {
132 row.style.display = 'none';
133 c.domNode.appendChild(row);
135 } else if (loaded_article_ids.indexOf(row.id) == -1) {
136 row.style.display = 'none';
137 c.domNode.appendChild(row);
139 loaded_article_ids.push(row.id);
141 row.parentNode.removeChild(row);
145 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
147 fixHeadlinesOrder(getLoadedArticleIds());
149 if (getInitParam("cdm_auto_catchup") == 1) {
150 c.domNode.appendChild(hsp);
153 console.log("added " + new_elems.size() + " headlines");
155 if (new_elems.size() == 0)
156 _infscroll_disable = true;
158 console.log("restore selected ids: " + ids);
160 for (var i = 0; i < ids.length; i++) {
161 markHeadline(ids[i]);
166 new_elems.each(function(child) {
167 if (!Element.visible(child))
168 new Effect.Appear(child, { duration : 0.5 });
172 console.log("no new headlines received");
174 var hsp = $("headlines-spacer");
176 if (hsp) hsp.innerHTML = "";
180 if (headlines_count > 0)
181 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
184 for (var i = 0; i < articles.length; i++) {
185 var a_id = articles[i]['id'];
186 cache_set("article:" + a_id, articles[i]['content']);
189 console.log("no cached articles received");
192 // do not precache stuff after fresh feed
194 precache_headlines();
197 parse_counters(counters);
202 console.error("Invalid object received: " + transport.responseText);
203 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
204 __('Could not update headlines (invalid object received - see error console for details)') +
208 _infscroll_request_sent = 0;
213 exception_error("headlines_callback2", e, transport);
217 function render_article(article) {
219 dijit.byId("headlines-wrap-inner").addChild(
220 dijit.byId("content-insert"));
222 var c = dijit.byId("content-insert");
225 c.domNode.scrollTop = 0;
228 c.attr('content', article);
230 correctHeadlinesOffset(getActiveArticleId());
237 exception_error("render_article", e);
241 function showArticleInHeadlines(id) {
245 selectArticles("none");
247 var crow = $("RROW-" + id);
251 var article_is_unread = crow.hasClassName("Unread");
253 crow.removeClassName("Unread");
255 selectArticles('none');
257 var upd_img_pic = $("FUPDPIC-" + id);
259 var view_mode = false;
262 view_mode = document.forms['main_toolbar_form'].view_mode;
263 view_mode = view_mode[view_mode.selectedIndex].value;
268 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
269 upd_img_pic.src.match("fresh_sign.png"))) {
271 upd_img_pic.src = "images/blank_icon.gif";
273 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
275 } else if (article_is_unread && view_mode == "all_articles") {
276 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
281 if (article_is_unread)
282 _force_scheduled_update = true;
285 exception_error("showArticleInHeadlines", e);
289 function article_callback2(transport, id) {
291 console.log("article_callback2 " + id);
293 handle_rpc_json(transport);
298 reply = JSON.parse(transport.responseText);
305 var upic = $('FUPDPIC-' + id);
307 if (upic) upic.src = 'images/blank_icon.gif';
309 reply.each(function(article) {
310 if (active_post_id == article['id']) {
311 render_article(article['content']);
313 cids_requested.remove(article['id']);
315 cache_set("article:" + article['id'], article['content']);
318 // if (id != last_requested_article) {
319 // console.log("requested article id is out of sequence, aborting");
324 console.error("Invalid object received: " + transport.responseText);
326 render_article("<div class='whiteBox'>" +
327 __('Could not display article (invalid object received - see error console for details)') + "</div>");
332 headlines_scroll_handler($("headlines-frame"));
335 if (!_infscroll_disable &&
336 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
346 exception_error("article_callback2", e, transport);
352 console.log("loading article: " + id);
354 var cached_article = cache_get("article:" + id);
356 console.log("cache check result: " + (cached_article != false));
360 var query = "?op=article&method=view&id=" + param_escape(id);
362 var neighbor_ids = getRelativePostIds(id);
364 /* only request uncached articles */
366 var cids_to_request = [];
368 for (var i = 0; i < neighbor_ids.length; i++) {
369 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
370 if (!cache_get("article:" + neighbor_ids[i])) {
371 cids_to_request.push(neighbor_ids[i]);
372 cids_requested.push(neighbor_ids[i]);
376 console.log("additional ids: " + cids_to_request.toString());
378 query = query + "&cids=" + cids_to_request.toString();
380 var crow = $("RROW-" + id);
381 var article_is_unread = crow.hasClassName("Unread");
384 showArticleInHeadlines(id);
386 precache_headlines();
388 if (!cached_article) {
390 var upic = $('FUPDPIC-' + id);
393 upic.src = getInitParam("sign_progress");
396 } else if (cached_article && article_is_unread) {
398 query = query + "&mode=prefetch";
400 render_article(cached_article);
402 } else if (cached_article) {
404 query = query + "&mode=prefetch_old";
405 render_article(cached_article);
407 // if we don't need to request any relative ids, we might as well skip
408 // the server roundtrip altogether
409 if (cids_to_request.length == 0) {
412 if (!_infscroll_disable &&
413 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
421 headlines_scroll_handler($("headlines-frame"));
427 last_requested_article = id;
431 if (article_is_unread) {
432 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
435 new Ajax.Request("backend.php", {
437 onComplete: function(transport) {
438 article_callback2(transport, id);
444 exception_error("view", e);
448 function toggleMark(id, client_only) {
450 var query = "?op=rpc&id=" + id + "&method=mark";
452 var img = $("FMPIC-" + id);
456 if (img.src.match("mark_unset")) {
457 img.src = img.src.replace("mark_unset", "mark_set");
458 img.alt = __("Unstar article");
459 query = query + "&mark=1";
462 img.src = img.src.replace("mark_set", "mark_unset");
463 img.alt = __("Star article");
464 query = query + "&mark=0";
467 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
470 new Ajax.Request("backend.php", {
472 onComplete: function(transport) {
473 handle_rpc_json(transport);
478 exception_error("toggleMark", e);
482 function togglePub(id, client_only, no_effects, note) {
484 var query = "?op=rpc&id=" + id + "&method=publ";
486 if (note != undefined) {
487 query = query + "¬e=" + param_escape(note);
489 query = query + "¬e=undefined";
492 var img = $("FPPIC-" + id);
496 if (img.src.match("pub_unset") || note != undefined) {
497 img.src = img.src.replace("pub_unset", "pub_set");
498 img.alt = __("Unpublish article");
499 query = query + "&pub=1";
502 img.src = img.src.replace("pub_set", "pub_unset");
503 img.alt = __("Publish article");
505 query = query + "&pub=0";
508 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
511 new Ajax.Request("backend.php", {
513 onComplete: function(transport) {
514 handle_rpc_json(transport);
519 exception_error("togglePub", e);
523 function moveToPost(mode) {
527 var rows = getVisibleArticleIds();
532 if (!$('RROW-' + active_post_id)) {
533 active_post_id = false;
536 if (active_post_id == false) {
538 prev_id = rows[rows.length-1]
540 for (var i = 0; i < rows.length; i++) {
541 if (rows[i] == active_post_id) {
543 // Account for adjacent identical article ids.
544 if (i > 0) prev_id = rows[i-1];
546 for (var j = i+1; j < rows.length; j++) {
547 if (rows[j] != active_post_id) {
557 if (mode == "next") {
561 cdmExpandArticle(next_id);
562 cdmScrollToArticleId(next_id);
565 correctHeadlinesOffset(next_id);
566 view(next_id, getActiveFeedId());
571 if (mode == "prev") {
574 cdmExpandArticle(prev_id);
575 cdmScrollToArticleId(prev_id);
577 correctHeadlinesOffset(prev_id);
578 view(prev_id, getActiveFeedId());
584 exception_error("moveToPost", e);
588 function toggleSelected(id, force_on) {
591 var cb = dijit.byId("RCHK-" + id);
592 var row = $("RROW-" + id);
595 if (row.hasClassName('Selected') && !force_on) {
596 row.removeClassName('Selected');
597 if (cb) cb.attr("checked", false);
599 row.addClassName('Selected');
600 if (cb) cb.attr("checked", true);
604 exception_error("toggleSelected", e);
608 function toggleUnread_afh(effect) {
611 var elem = effect.element;
612 elem.style.backgroundColor = "";
615 exception_error("toggleUnread_afh", e);
619 function toggleUnread(id, cmode, effect) {
622 var row = $("RROW-" + id);
624 if (cmode == undefined || cmode == 2) {
625 if (row.hasClassName("Unread")) {
626 row.removeClassName("Unread");
629 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
630 afterFinish: toggleUnread_afh,
631 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
635 row.addClassName("Unread");
638 } else if (cmode == 0) {
640 row.removeClassName("Unread");
643 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
644 afterFinish: toggleUnread_afh,
645 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
648 } else if (cmode == 1) {
649 row.addClassName("Unread");
652 if (cmode == undefined) cmode = 2;
654 var query = "?op=rpc&method=catchupSelected" +
655 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
657 // notify_progress("Loading, please wait...");
659 new Ajax.Request("backend.php", {
661 onComplete: function(transport) {
662 handle_rpc_json(transport);
668 exception_error("toggleUnread", e);
672 function selectionRemoveLabel(id, ids) {
675 if (!ids) ids = getSelectedArticleIds2();
677 if (ids.length == 0) {
678 alert(__("No articles are selected."));
682 var query = "?op=rpc&method=removeFromLabel&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 selectionAssignLabel(id, ids) {
703 if (!ids) ids = getSelectedArticleIds2();
705 if (ids.length == 0) {
706 alert(__("No articles are selected."));
710 var query = "?op=rpc&method=assignToLabel&ids=" +
711 param_escape(ids.toString()) + "&lid=" + param_escape(id);
715 new Ajax.Request("backend.php", {
717 onComplete: function(transport) {
718 handle_rpc_json(transport);
719 show_labels_in_headlines(transport);
723 exception_error("selectionAssignLabel", e);
728 function selectionToggleUnread(set_state, callback, no_error) {
730 var rows = getSelectedArticleIds2();
732 if (rows.length == 0 && !no_error) {
733 alert(__("No articles are selected."));
737 for (var i = 0; i < rows.length; i++) {
738 var row = $("RROW-" + rows[i]);
740 if (set_state == undefined) {
741 if (row.hasClassName("Unread")) {
742 row.removeClassName("Unread");
744 row.addClassName("Unread");
748 if (set_state == false) {
749 row.removeClassName("Unread");
752 if (set_state == true) {
753 row.addClassName("Unread");
758 if (rows.length > 0) {
762 if (set_state == undefined) {
764 } else if (set_state == true) {
766 } else if (set_state == false) {
770 var query = "?op=rpc&method=catchupSelected" +
771 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
773 notify_progress("Loading, please wait...");
775 new Ajax.Request("backend.php", {
777 onComplete: function(transport) {
778 handle_rpc_json(transport);
779 if (callback) callback(transport);
785 exception_error("selectionToggleUnread", e);
789 function selectionToggleMarked() {
792 var rows = getSelectedArticleIds2();
794 if (rows.length == 0) {
795 alert(__("No articles are selected."));
799 for (var i = 0; i < rows.length; i++) {
800 toggleMark(rows[i], true, true);
803 if (rows.length > 0) {
805 var query = "?op=rpc&method=markSelected&ids=" +
806 param_escape(rows.toString()) + "&cmode=2";
808 new Ajax.Request("backend.php", {
810 onComplete: function(transport) {
811 handle_rpc_json(transport);
817 exception_error("selectionToggleMarked", e);
821 function selectionTogglePublished() {
824 var rows = getSelectedArticleIds2();
826 if (rows.length == 0) {
827 alert(__("No articles are selected."));
831 for (var i = 0; i < rows.length; i++) {
832 togglePub(rows[i], true, true);
835 if (rows.length > 0) {
837 var query = "?op=rpc&method=publishSelected&ids=" +
838 param_escape(rows.toString()) + "&cmode=2";
840 new Ajax.Request("backend.php", {
842 onComplete: function(transport) {
843 handle_rpc_json(transport);
849 exception_error("selectionToggleMarked", e);
853 function getSelectedArticleIds2() {
857 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
859 rv.push(child.id.replace("RROW-", ""));
865 function getLoadedArticleIds() {
868 var children = $$("#headlines-frame > div[id*=RROW-]");
870 children.each(function(child) {
871 rv.push(child.id.replace("RROW-", ""));
878 // mode = all,none,unread,invert,marked,published
879 function selectArticles(mode) {
882 var children = $$("#headlines-frame > div[id*=RROW]");
884 children.each(function(child) {
885 var id = child.id.replace("RROW-", "");
886 var cb = dijit.byId("RCHK-" + id);
889 child.addClassName("Selected");
890 cb.attr("checked", true);
891 } else if (mode == "unread") {
892 if (child.hasClassName("Unread")) {
893 child.addClassName("Selected");
894 cb.attr("checked", true);
896 child.removeClassName("Selected");
897 cb.attr("checked", false);
899 } else if (mode == "marked") {
900 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
902 if (img && img.src.match("mark_set")) {
903 child.addClassName("Selected");
904 cb.attr("checked", true);
906 child.removeClassName("Selected");
907 cb.attr("checked", false);
909 } else if (mode == "published") {
910 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
912 if (img && img.src.match("pub_set")) {
913 child.addClassName("Selected");
914 cb.attr("checked", true);
916 child.removeClassName("Selected");
917 cb.attr("checked", false);
920 } else if (mode == "invert") {
921 if (child.hasClassName("Selected")) {
922 child.removeClassName("Selected");
923 cb.attr("checked", false);
925 child.addClassName("Selected");
926 cb.attr("checked", true);
930 child.removeClassName("Selected");
931 cb.attr("checked", false);
936 exception_error("selectArticles", e);
940 function catchupPage() {
942 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
944 var str = __("Mark all visible articles in %s as read?");
946 str = str.replace("%s", fn);
948 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
952 selectArticles('all');
953 selectionToggleUnread(false, 'viewCurrentFeed()', true);
954 selectArticles('none');
957 function deleteSelection() {
961 var rows = getSelectedArticleIds2();
963 if (rows.length == 0) {
964 alert(__("No articles are selected."));
968 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
971 if (getActiveFeedId() != 0) {
972 str = __("Delete %d selected articles in %s?");
974 str = __("Delete %d selected articles?");
977 str = str.replace("%d", rows.length);
978 str = str.replace("%s", fn);
980 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
984 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
988 new Ajax.Request("backend.php", {
990 onComplete: function(transport) {
991 handle_rpc_json(transport);
996 exception_error("deleteSelection", e);
1000 function archiveSelection() {
1004 var rows = getSelectedArticleIds2();
1006 if (rows.length == 0) {
1007 alert(__("No articles are selected."));
1011 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1015 if (getActiveFeedId() != 0) {
1016 str = __("Archive %d selected articles in %s?");
1019 str = __("Move %d archived articles back?");
1023 str = str.replace("%d", rows.length);
1024 str = str.replace("%s", fn);
1026 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1030 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1034 for (var i = 0; i < rows.length; i++) {
1035 cache_delete("article:" + rows[i]);
1038 new Ajax.Request("backend.php", {
1040 onComplete: function(transport) {
1041 handle_rpc_json(transport);
1046 exception_error("archiveSelection", e);
1050 function catchupSelection() {
1054 var rows = getSelectedArticleIds2();
1056 if (rows.length == 0) {
1057 alert(__("No articles are selected."));
1061 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1063 var str = __("Mark %d selected articles in %s as read?");
1065 str = str.replace("%d", rows.length);
1066 str = str.replace("%s", fn);
1068 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1072 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1075 exception_error("catchupSelection", e);
1079 function editArticleTags(id) {
1080 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1082 if (dijit.byId("editTagsDlg"))
1083 dijit.byId("editTagsDlg").destroyRecursive();
1085 dialog = new dijit.Dialog({
1087 title: __("Edit article Tags"),
1088 style: "width: 600px",
1089 execute: function() {
1090 if (this.validate()) {
1091 var query = dojo.objectToQuery(this.attr('value'));
1093 notify_progress("Saving article tags...", true);
1095 new Ajax.Request("backend.php", {
1097 onComplete: function(transport) {
1101 var data = JSON.parse(transport.responseText);
1104 var tags_str = article.tags;
1105 var id = tags_str.id;
1107 var tags = $("ATSTR-" + id);
1108 var tooltip = dijit.byId("ATSTRTIP-" + id);
1110 if (tags) tags.innerHTML = tags_str.content;
1111 if (tooltip) tooltip.attr('label', tags_str.content_full);
1113 cache_delete("article:" + id);
1122 var tmph = dojo.connect(dialog, 'onLoad', function() {
1123 dojo.disconnect(tmph);
1125 new Ajax.Autocompleter('tags_str', 'tags_choices',
1126 "backend.php?op=rpc&method=completeTags",
1127 { tokens: ',', paramName: "search" });
1134 function cdmScrollToArticleId(id) {
1136 var ctr = $("headlines-frame");
1137 var e = $("RROW-" + id);
1139 if (!e || !ctr) return;
1141 ctr.scrollTop = e.offsetTop;
1144 exception_error("cdmScrollToArticleId", e);
1148 function getActiveArticleId() {
1149 return active_post_id;
1152 function postMouseIn(id) {
1153 post_under_pointer = id;
1156 function postMouseOut(id) {
1157 post_under_pointer = false;
1160 function headlines_scroll_handler(e) {
1162 var hsp = $("headlines-spacer");
1164 if (!_infscroll_disable) {
1165 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1166 (e.scrollHeight != 0 &&
1167 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1170 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1171 __("Loading, please wait...");
1173 loadMoreHeadlines();
1178 if (hsp) hsp.innerHTML = "";
1181 if (getInitParam("cdm_auto_catchup") == 1) {
1183 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1185 if ($("headlines-frame").scrollTop >
1186 (child.offsetTop + child.offsetHeight/2)) {
1188 var id = child.id.replace("RROW-", "");
1190 if (catchup_id_batch.indexOf(id) == -1)
1191 catchup_id_batch.push(id);
1193 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1197 if (catchup_id_batch.length > 0) {
1198 window.clearTimeout(catchup_timeout_id);
1200 if (!_infscroll_request_sent) {
1201 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1208 console.warn("headlines_scroll_handler: " + e);
1212 function catchupBatchedArticles() {
1214 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1216 // make a copy of the array
1217 var batch = catchup_id_batch.slice();
1218 var query = "?op=rpc&method=catchupSelected" +
1219 "&cmode=0&ids=" + param_escape(batch.toString());
1223 new Ajax.Request("backend.php", {
1225 onComplete: function(transport) {
1226 handle_rpc_json(transport);
1228 batch.each(function(id) {
1229 var elem = $("RROW-" + id);
1230 if (elem) elem.removeClassName("Unread");
1231 catchup_id_batch.remove(id);
1238 exception_error("catchupBatchedArticles", e);
1242 function catchupRelativeToArticle(below, id) {
1246 if (!id) id = getActiveArticleId();
1249 alert(__("No article is selected."));
1253 var visible_ids = getVisibleArticleIds();
1255 var ids_to_mark = new Array();
1258 for (var i = 0; i < visible_ids.length; i++) {
1259 if (visible_ids[i] != id) {
1260 var e = $("RROW-" + visible_ids[i]);
1262 if (e && e.hasClassName("Unread")) {
1263 ids_to_mark.push(visible_ids[i]);
1270 for (var i = visible_ids.length-1; i >= 0; i--) {
1271 if (visible_ids[i] != id) {
1272 var e = $("RROW-" + visible_ids[i]);
1274 if (e && e.hasClassName("Unread")) {
1275 ids_to_mark.push(visible_ids[i]);
1283 if (ids_to_mark.length == 0) {
1284 alert(__("No articles found to mark"));
1286 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1288 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1290 for (var i = 0; i < ids_to_mark.length; i++) {
1291 var e = $("RROW-" + ids_to_mark[i]);
1292 e.removeClassName("Unread");
1295 var query = "?op=rpc&method=catchupSelected" +
1296 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1298 new Ajax.Request("backend.php", {
1300 onComplete: function(transport) {
1301 handle_rpc_json(transport);
1308 exception_error("catchupRelativeToArticle", e);
1312 function cdmExpandArticle(id) {
1317 var elem = $("CICD-" + active_post_id);
1319 var upd_img_pic = $("FUPDPIC-" + id);
1321 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1322 upd_img_pic.src.match("fresh_sign.png"))) {
1324 upd_img_pic.src = "images/blank_icon.gif";
1327 if (id == active_post_id && Element.visible(elem))
1330 selectArticles("none");
1332 var old_offset = $("RROW-" + id).offsetTop;
1334 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1336 Element.show("CEXC-" + active_post_id);
1339 active_post_id = id;
1341 elem = $("CICD-" + id);
1343 if (!Element.visible(elem)) {
1345 Element.hide("CEXC-" + id);
1348 var new_offset = $("RROW-" + id).offsetTop;
1350 $("headlines-frame").scrollTop += (new_offset-old_offset);
1352 if ($("RROW-" + id).offsetTop != old_offset)
1353 $("headlines-frame").scrollTop = new_offset;
1355 toggleUnread(id, 0, true);
1359 exception_error("cdmExpandArticle", e);
1365 function fixHeadlinesOrder(ids) {
1367 for (var i = 0; i < ids.length; i++) {
1368 var e = $("RROW-" + ids[i]);
1372 e.removeClassName("even");
1373 e.addClassName("odd");
1375 e.removeClassName("odd");
1376 e.addClassName("even");
1381 exception_error("fixHeadlinesOrder", e);
1385 function getArticleUnderPointer() {
1386 return post_under_pointer;
1389 function zoomToArticle(event, id) {
1391 var cached_article = cache_get("article: " + id);
1393 if (dijit.byId("ATAB-" + id))
1394 if (!event || !event.shiftKey)
1395 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1397 if (dijit.byId("ATSTRTIP-" + id))
1398 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1400 if (cached_article) {
1401 //closeArticlePanel();
1403 var article_pane = new dijit.layout.ContentPane({
1404 title: __("Loading...") , content: cached_article,
1405 style: 'padding : 0px;',
1409 dijit.byId("content-tabs").addChild(article_pane);
1411 if (!event || !event.shiftKey)
1412 dijit.byId("content-tabs").selectChild(article_pane);
1414 if ($("PTITLE-" + id))
1415 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1419 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1421 notify_progress("Loading, please wait...", true);
1423 new Ajax.Request("backend.php", {
1425 onComplete: function(transport) {
1428 var reply = JSON.parse(transport.responseText);
1431 //closeArticlePanel();
1433 var content = reply[0]['content'];
1435 var article_pane = new dijit.layout.ContentPane({
1436 title: "article-" + id , content: content,
1437 style: 'padding : 0px;',
1441 dijit.byId("content-tabs").addChild(article_pane);
1443 if (!event || !event.shiftKey)
1444 dijit.byId("content-tabs").selectChild(article_pane);
1446 if ($("PTITLE-" + id))
1447 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1454 exception_error("zoomToArticle", e);
1458 function scrollArticle(offset) {
1461 var ci = $("content-insert");
1463 ci.scrollTop += offset;
1466 var hi = $("headlines-frame");
1468 hi.scrollTop += offset;
1473 exception_error("scrollArticle", e);
1477 function show_labels_in_headlines(transport) {
1479 var data = JSON.parse(transport.responseText);
1482 data['info-for-headlines'].each(function(elem) {
1483 var ctr = $("HLLCTR-" + elem.id);
1485 if (ctr) ctr.innerHTML = elem.labels;
1488 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1492 exception_error("show_labels_in_headlines", e);
1496 /* function toggleHeadlineActions() {
1498 var e = $("headlineActionsBody");
1499 var p = $("headlineActionsDrop");
1501 if (!Element.visible(e)) {
1508 e.style.left = (p.offsetLeft + 1) + "px";
1509 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1512 exception_error("toggleHeadlineActions", e);
1516 /* function publishWithNote(id, def_note) {
1518 if (!def_note) def_note = '';
1520 var note = prompt(__("Please enter a note for this article:"), def_note);
1522 if (note != undefined) {
1523 togglePub(id, false, false, note);
1527 exception_error("publishWithNote", e);
1531 function dismissArticle(id) {
1533 var elem = $("RROW-" + id);
1535 toggleUnread(id, 0, true);
1537 new Effect.Fade(elem, {duration : 0.5});
1539 active_post_id = false;
1542 exception_error("dismissArticle", e);
1546 function dismissSelectedArticles() {
1549 var ids = getVisibleArticleIds();
1553 for (var i = 0; i < ids.length; i++) {
1554 var elem = $("RROW-" + ids[i]);
1556 if (elem.className && elem.hasClassName("Selected") &&
1557 ids[i] != active_post_id) {
1558 new Effect.Fade(elem, {duration : 0.5});
1566 selectionToggleUnread(false);
1568 fixHeadlinesOrder(tmp);
1571 exception_error("dismissSelectedArticles", e);
1575 function dismissReadArticles() {
1578 var ids = getVisibleArticleIds();
1581 for (var i = 0; i < ids.length; i++) {
1582 var elem = $("RROW-" + ids[i]);
1584 if (elem.className && !elem.hasClassName("Unread") &&
1585 !elem.hasClassName("Selected")) {
1587 new Effect.Fade(elem, {duration : 0.5});
1593 fixHeadlinesOrder(tmp);
1596 exception_error("dismissSelectedArticles", e);
1600 function getVisibleArticleIds() {
1605 getLoadedArticleIds().each(function(id) {
1606 var elem = $("RROW-" + id);
1607 if (elem && Element.visible(elem))
1612 exception_error("getVisibleArticleIds", e);
1618 function cdmClicked(event, id) {
1620 //var shift_key = event.shiftKey;
1624 if (!event.ctrlKey) {
1626 if (!getInitParam("cdm_expanded")) {
1627 return cdmExpandArticle(id);
1630 selectArticles("none");
1633 var elem = $("RROW-" + id);
1634 var article_is_unread = elem.hasClassName("Unread");
1637 elem.removeClassName("Unread");
1639 var upd_img_pic = $("FUPDPIC-" + id);
1641 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1642 upd_img_pic.src.match("fresh_sign.png"))) {
1644 upd_img_pic.src = "images/blank_icon.gif";
1647 active_post_id = id;
1649 if (article_is_unread) {
1650 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1653 var query = "?op=rpc&method=catchupSelected" +
1654 "&cmode=0&ids=" + param_escape(id);
1656 new Ajax.Request("backend.php", {
1658 onComplete: function(transport) {
1659 handle_rpc_json(transport);
1666 toggleSelected(id, true);
1668 var elem = $("RROW-" + id);
1669 var article_is_unread = elem.hasClassName("Unread");
1671 if (article_is_unread) {
1672 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1675 toggleUnread(id, 0, false);
1676 zoomToArticle(event, id);
1680 exception_error("cdmClicked");
1686 function postClicked(event, id) {
1689 if (!event.ctrlKey) {
1692 postOpenInNewTab(event, id);
1697 exception_error("postClicked");
1701 function hlOpenInNewTab(event, id) {
1702 toggleUnread(id, 0, false);
1703 zoomToArticle(event, id);
1706 function postOpenInNewTab(event, id) {
1707 closeArticlePanel(id);
1708 zoomToArticle(event, id);
1711 function hlClicked(event, id) {
1713 if (event.which == 2) {
1716 } else if (event.altKey) {
1717 openArticleInNewWindow(id);
1718 } else if (!event.ctrlKey) {
1723 toggleUnread(id, 0, false);
1724 zoomToArticle(event, id);
1729 exception_error("hlClicked");
1733 function getFirstVisibleHeadlineId() {
1734 var rows = getVisibleArticleIds();
1739 function getLastVisibleHeadlineId() {
1740 var rows = getVisibleArticleIds();
1741 return rows[rows.length-1];
1744 function openArticleInNewWindow(id) {
1745 toggleUnread(id, 0, false);
1746 window.open("backend.php?op=article&method=redirect&id=" + id);
1749 function isCdmMode() {
1750 return getInitParam("combined_display_mode");
1753 function markHeadline(id) {
1754 var row = $("RROW-" + id);
1756 var check = dijit.byId("RCHK-" + id);
1759 check.attr("checked", true);
1762 row.addClassName("Selected");
1766 function getRelativePostIds(id, limit) {
1772 if (!limit) limit = 6; //3
1774 var ids = getVisibleArticleIds();
1776 for (var i = 0; i < ids.length; i++) {
1778 for (var k = 1; k <= limit; k++) {
1779 //if (i > k-1) tmp.push(ids[i-k]);
1780 if (i < ids.length-k) tmp.push(ids[i+k]);
1787 exception_error("getRelativePostIds", e);
1793 function correctHeadlinesOffset(id) {
1797 var container = $("headlines-frame");
1798 var row = $("RROW-" + id);
1800 if (!container || !row) return;
1802 var viewport = container.offsetHeight;
1804 var rel_offset_top = row.offsetTop - container.scrollTop;
1805 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1807 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1808 //console.log("Vport: " + viewport);
1810 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1811 container.scrollTop = row.offsetTop;
1812 } else if (rel_offset_bottom > viewport) {
1814 /* doesn't properly work with Opera in some cases because
1815 Opera fucks up element scrolling */
1817 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1821 exception_error("correctHeadlinesOffset", e);
1826 function headlineActionsChange(elem) {
1829 elem.attr('value', 'false');
1831 exception_error("headlineActionsChange", e);
1835 function closeArticlePanel() {
1837 var tabs = dijit.byId("content-tabs");
1838 var child = tabs.selectedChildWidget;
1840 if (child && tabs.getIndexOfChild(child) > 0) {
1841 tabs.removeChild(child);
1844 if (dijit.byId("content-insert"))
1845 dijit.byId("headlines-wrap-inner").removeChild(
1846 dijit.byId("content-insert"));
1850 function initHeadlinesMenu() {
1852 if (dijit.byId("headlinesMenu"))
1853 dijit.byId("headlinesMenu").destroyRecursive();
1858 nodes = $$("#headlines-frame > div[id*=RROW]");
1860 nodes = $$("#headlines-frame span[id*=RTITLE]");
1863 nodes.each(function(node) {
1867 var menu = new dijit.Menu({
1868 id: "headlinesMenu",
1872 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1873 var callerNode = event.target, match = null, tries = 0;
1875 while (match == null && callerNode && tries <= 3) {
1876 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1877 callerNode = callerNode.parentNode;
1881 if (match) this.callerRowId = parseInt(match[1]);
1885 /* if (!isCdmMode())
1886 menu.addChild(new dijit.MenuItem({
1887 label: __("View article"),
1888 onClick: function(event) {
1889 view(this.getParent().callerRowId);
1892 menu.addChild(new dijit.MenuItem({
1893 label: __("Open original article"),
1894 onClick: function(event) {
1895 openArticleInNewWindow(this.getParent().callerRowId);
1898 menu.addChild(new dijit.MenuItem({
1899 label: __("View in a tt-rss tab"),
1900 onClick: function(event) {
1901 hlOpenInNewTab(event, this.getParent().callerRowId);
1904 menu.addChild(new dijit.MenuSeparator());
1906 menu.addChild(new dijit.MenuItem({
1907 label: __("Mark above as read"),
1908 onClick: function(event) {
1909 catchupRelativeToArticle(0, this.getParent().callerRowId);
1912 menu.addChild(new dijit.MenuItem({
1913 label: __("Mark below as read"),
1914 onClick: function(event) {
1915 catchupRelativeToArticle(1, this.getParent().callerRowId);
1919 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1923 menu.addChild(new dijit.MenuSeparator());
1925 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1926 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1928 labels.each(function(label) {
1929 var id = label.id[0];
1930 var bare_id = id.substr(id.indexOf(":")+1);
1931 var name = label.name[0];
1933 bare_id = -11-bare_id;
1935 labelAddMenu.addChild(new dijit.MenuItem({
1938 onClick: function(event) {
1939 var ids = getSelectedArticleIds2();
1941 var id = this.getParent().ownerMenu.callerRowId + "";
1943 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1945 selectionAssignLabel(this.labelId, ids);
1948 labelDelMenu.addChild(new dijit.MenuItem({
1951 onClick: function(event) {
1952 var ids = getSelectedArticleIds2();
1954 var id = this.getParent().ownerMenu.callerRowId + "";
1956 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1958 selectionRemoveLabel(this.labelId, ids);
1963 menu.addChild(new dijit.PopupMenuItem({
1964 label: __("Assign label"),
1965 popup: labelAddMenu,
1968 menu.addChild(new dijit.PopupMenuItem({
1969 label: __("Remove label"),
1970 popup: labelDelMenu,
1978 exception_error("initHeadlinesMenu", e);
1983 function player(elem) {
1984 var aid = elem.getAttribute("audio-id");
1985 var status = elem.getAttribute("status");
1993 elem.innerHTML = __("Playing...");
1994 elem.title = __("Click to pause");
1995 elem.addClassName("playing");
1999 elem.innerHTML = __("Play");
2000 elem.title = __("Click to play");
2001 elem.removeClassName("playing");
2004 elem.setAttribute("status", status);
2006 alert("Your browser doesn't seem to support HTML5 audio.");
2010 function cache_set(id, obj) {
2011 //console.log("cache_set: " + id);
2014 sessionStorage[id] = obj;
2016 sessionStorage.clear();
2020 function cache_get(id) {
2022 return sessionStorage[id];
2025 function cache_clear() {
2027 sessionStorage.clear();
2030 function cache_delete(id) {
2032 sessionStorage.removeItem(id);
2035 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2036 if (toolbar_obj && content_obj) {
2037 cache_set("feed:" + feed + ":" + is_cat,
2038 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2041 obj = cache_get("feed:" + feed + ":" + is_cat);
2044 obj = JSON.parse(obj);
2046 if (toolbar_obj) obj.toolbar = toolbar_obj;
2047 if (content_obj) obj.content = content_obj;
2049 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2053 console.warn("cache_headlines failed: " + e);
2058 function render_local_headlines(feed, is_cat, obj) {
2061 dijit.byId("headlines-toolbar").attr('content',
2064 dijit.byId("headlines-frame").attr('content',
2067 dojo.parser.parse('headlines-toolbar');
2069 $("headlines-frame").scrollTop = 0;
2070 selectArticles('none');
2071 setActiveFeedId(feed, is_cat);
2072 initHeadlinesMenu();
2074 dijit.getEnclosingWidget(
2075 document.forms["main_toolbar_form"].update).attr('disabled',
2076 is_cat || feed <= 0);
2078 precache_headlines();
2081 exception_error("render_local_headlines", e);
2085 function precache_headlines_idle() {
2087 if (!feed_precache_timeout_id) {
2088 if (get_timestamp() - _viewfeed_last > 120) {
2090 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2093 feeds.each(function(item) {
2094 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2095 uncached.push(item);
2098 if (uncached.length > 0) {
2099 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2100 viewfeed(rf[0], '', rf[1], 0, true);
2104 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2107 exception_error("precache_headlines_idle", e);
2111 function precache_headlines() {
2114 if (!feed_precache_timeout_id) {
2115 feed_precache_timeout_id = window.setTimeout(function() {
2116 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2117 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2119 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2120 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2122 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2123 viewfeed(nf[0], '', nf[1], 0, true);
2125 window.setTimeout(function() {
2126 feed_precache_timeout_id = false;
2132 exception_error("precache_headlines", e);
2136 function cancelSearch() {
2141 exception_error("cancelSearch", e);
2145 function setSelectionScore() {
2147 var ids = getSelectedArticleIds2();
2149 if (ids.length > 0) {
2152 var score = prompt(__("Please enter new score for selected articles:"), score);
2154 if (score != undefined) {
2155 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2156 "&score=" + param_escape(score);
2158 new Ajax.Request("backend.php", {
2160 onComplete: function(transport) {
2161 var reply = JSON.parse(transport.responseText);
2165 ids.each(function(id) {
2166 var row = $("RROW-" + id);
2169 var pic = row.getElementsByClassName("hlScorePic")[0];
2172 pic.src = pic.src.replace(/score_.*?\.png/,
2173 reply["score_pic"]);
2174 pic.setAttribute("score", score);
2183 alert(__("No articles are selected."));
2186 exception_error("setSelectionScore", e);
2190 function changeScore(id, pic) {
2192 var score = pic.getAttribute("score");
2194 var new_score = prompt(__("Please enter new score for this article:"), score);
2196 if (new_score != undefined) {
2198 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2199 "&score=" + param_escape(new_score);
2201 new Ajax.Request("backend.php", {
2203 onComplete: function(transport) {
2204 var reply = JSON.parse(transport.responseText);
2207 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2208 pic.setAttribute("score", new_score);
2213 exception_error("changeScore", e);