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']);
84 if (getInitParam("cdm_auto_catchup") == 1) {
85 var hsp = $("headlines-spacer");
86 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
87 dijit.byId('headlines-frame').domNode.appendChild(hsp);
94 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
95 console.log("adding some more headlines...");
97 var c = dijit.byId("headlines-frame");
98 var ids = getSelectedArticleIds2();
100 $("headlines-tmp").innerHTML = reply['headlines']['content'];
102 var hsp = $("headlines-spacer");
105 c.domNode.removeChild(hsp);
107 $$("#headlines-tmp > div").each(function(row) {
108 if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
109 row.style.display = 'none';
110 c.domNode.appendChild(row);
112 row.parentNode.removeChild(row);
116 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
118 fixHeadlinesOrder(getLoadedArticleIds());
120 if (getInitParam("cdm_auto_catchup") == 1) {
121 c.domNode.appendChild(hsp);
124 console.log("restore selected ids: " + ids);
126 for (var i = 0; i < ids.length; i++) {
127 markHeadline(ids[i]);
132 $$("#headlines-frame > div[id*=RROW]").each(
134 if (!Element.visible(child))
135 new Effect.Appear(child, { duration : 0.5 });
139 console.log("no new headlines received");
141 var hsp = $("headlines-spacer");
143 if (hsp) hsp.innerHTML = "";
147 if (headlines_count > 0)
148 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
151 for (var i = 0; i < articles.length; i++) {
152 var a_id = articles[i]['id'];
153 cache_set("article:" + a_id, articles[i]['content']);
156 console.log("no cached articles received");
159 // do not precache stuff after fresh feed
161 precache_headlines();
164 parse_counters(counters);
169 console.error("Invalid object received: " + transport.responseText);
170 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
171 __('Could not update headlines (invalid object received - see error console for details)') +
175 _infscroll_request_sent = 0;
180 exception_error("headlines_callback2", e, transport);
184 function render_article(article) {
186 dijit.byId("headlines-wrap-inner").addChild(
187 dijit.byId("content-insert"));
189 var c = dijit.byId("content-insert");
192 c.domNode.scrollTop = 0;
195 c.attr('content', article);
197 correctHeadlinesOffset(getActiveArticleId());
204 exception_error("render_article", e);
208 function showArticleInHeadlines(id) {
212 selectArticles("none");
214 var crow = $("RROW-" + id);
218 var article_is_unread = crow.hasClassName("Unread");
220 crow.removeClassName("Unread");
222 selectArticles('none');
224 var upd_img_pic = $("FUPDPIC-" + id);
226 var view_mode = false;
229 view_mode = document.forms['main_toolbar_form'].view_mode;
230 view_mode = view_mode[view_mode.selectedIndex].value;
235 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
236 upd_img_pic.src.match("fresh_sign.png"))) {
238 upd_img_pic.src = "images/blank_icon.gif";
240 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
242 } else if (article_is_unread && view_mode == "all_articles") {
243 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
248 if (article_is_unread)
249 _force_scheduled_update = true;
252 exception_error("showArticleInHeadlines", e);
256 function article_callback2(transport, id) {
258 console.log("article_callback2 " + id);
260 handle_rpc_json(transport);
265 reply = JSON.parse(transport.responseText);
272 var upic = $('FUPDPIC-' + id);
274 if (upic) upic.src = 'images/blank_icon.gif';
276 reply.each(function(article) {
277 if (active_post_id == article['id']) {
278 render_article(article['content']);
280 cids_requested.remove(article['id']);
282 cache_set("article:" + article['id'], article['content']);
285 // if (id != last_requested_article) {
286 // console.log("requested article id is out of sequence, aborting");
291 console.error("Invalid object received: " + transport.responseText);
293 render_article("<div class='whiteBox'>" +
294 __('Could not display article (invalid object received - see error console for details)') + "</div>");
300 if (!_infscroll_disable &&
301 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
311 exception_error("article_callback2", e, transport);
317 console.log("loading article: " + id);
319 var cached_article = cache_get("article:" + id);
321 console.log("cache check result: " + (cached_article != false));
325 var query = "?op=article&method=view&id=" + param_escape(id);
327 var neighbor_ids = getRelativePostIds(id);
329 /* only request uncached articles */
331 var cids_to_request = [];
333 for (var i = 0; i < neighbor_ids.length; i++) {
334 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
335 if (!cache_get("article:" + neighbor_ids[i])) {
336 cids_to_request.push(neighbor_ids[i]);
337 cids_requested.push(neighbor_ids[i]);
341 console.log("additional ids: " + cids_to_request.toString());
343 query = query + "&cids=" + cids_to_request.toString();
345 var crow = $("RROW-" + id);
346 var article_is_unread = crow.hasClassName("Unread");
349 showArticleInHeadlines(id);
351 precache_headlines();
353 if (!cached_article) {
355 var upic = $('FUPDPIC-' + id);
358 upic.src = getInitParam("sign_progress");
361 } else if (cached_article && article_is_unread) {
363 query = query + "&mode=prefetch";
365 render_article(cached_article);
367 } else if (cached_article) {
369 query = query + "&mode=prefetch_old";
370 render_article(cached_article);
372 // if we don't need to request any relative ids, we might as well skip
373 // the server roundtrip altogether
374 if (cids_to_request.length == 0) {
377 if (!_infscroll_disable &&
378 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
390 last_requested_article = id;
394 if (article_is_unread) {
395 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
398 new Ajax.Request("backend.php", {
400 onComplete: function(transport) {
401 article_callback2(transport, id);
407 exception_error("view", e);
411 function toggleMark(id, client_only) {
413 var query = "?op=rpc&id=" + id + "&method=mark";
415 var img = $("FMPIC-" + id);
419 if (img.src.match("mark_unset")) {
420 img.src = img.src.replace("mark_unset", "mark_set");
421 img.alt = __("Unstar article");
422 query = query + "&mark=1";
425 img.src = img.src.replace("mark_set", "mark_unset");
426 img.alt = __("Star article");
427 query = query + "&mark=0";
430 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
433 new Ajax.Request("backend.php", {
435 onComplete: function(transport) {
436 handle_rpc_json(transport);
441 exception_error("toggleMark", e);
445 function togglePub(id, client_only, no_effects, note) {
447 var query = "?op=rpc&id=" + id + "&method=publ";
449 if (note != undefined) {
450 query = query + "¬e=" + param_escape(note);
452 query = query + "¬e=undefined";
455 var img = $("FPPIC-" + id);
459 if (img.src.match("pub_unset") || note != undefined) {
460 img.src = img.src.replace("pub_unset", "pub_set");
461 img.alt = __("Unpublish article");
462 query = query + "&pub=1";
465 img.src = img.src.replace("pub_set", "pub_unset");
466 img.alt = __("Publish article");
468 query = query + "&pub=0";
471 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
474 new Ajax.Request("backend.php", {
476 onComplete: function(transport) {
477 handle_rpc_json(transport);
482 exception_error("togglePub", e);
486 function moveToPost(mode) {
490 var rows = getVisibleArticleIds();
495 if (!$('RROW-' + active_post_id)) {
496 active_post_id = false;
499 if (active_post_id == false) {
501 prev_id = rows[rows.length-1]
503 for (var i = 0; i < rows.length; i++) {
504 if (rows[i] == active_post_id) {
506 // Account for adjacent identical article ids.
507 if (i > 0) prev_id = rows[i-1];
509 for (var j = i+1; j < rows.length; j++) {
510 if (rows[j] != active_post_id) {
520 if (mode == "next") {
524 cdmExpandArticle(next_id);
525 cdmScrollToArticleId(next_id);
528 correctHeadlinesOffset(next_id);
529 view(next_id, getActiveFeedId());
534 if (mode == "prev") {
537 cdmExpandArticle(prev_id);
538 cdmScrollToArticleId(prev_id);
540 correctHeadlinesOffset(prev_id);
541 view(prev_id, getActiveFeedId());
547 exception_error("moveToPost", e);
551 function toggleSelected(id, force_on) {
554 var cb = $("RCHK-" + id);
555 var row = $("RROW-" + id);
558 if (row.hasClassName('Selected') && !force_on) {
559 row.removeClassName('Selected');
560 if (cb) cb.checked = false;
562 row.addClassName('Selected');
563 if (cb) cb.checked = true;
567 exception_error("toggleSelected", e);
571 function toggleUnread_afh(effect) {
574 var elem = effect.element;
575 elem.style.backgroundColor = "";
578 exception_error("toggleUnread_afh", e);
582 function toggleUnread(id, cmode, effect) {
585 var row = $("RROW-" + id);
587 if (cmode == undefined || cmode == 2) {
588 if (row.hasClassName("Unread")) {
589 row.removeClassName("Unread");
592 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
593 afterFinish: toggleUnread_afh,
594 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
598 row.addClassName("Unread");
601 } else if (cmode == 0) {
603 row.removeClassName("Unread");
606 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
607 afterFinish: toggleUnread_afh,
608 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
611 } else if (cmode == 1) {
612 row.addClassName("Unread");
615 if (cmode == undefined) cmode = 2;
617 var query = "?op=rpc&method=catchupSelected" +
618 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
620 // notify_progress("Loading, please wait...");
622 new Ajax.Request("backend.php", {
624 onComplete: function(transport) {
625 handle_rpc_json(transport);
631 exception_error("toggleUnread", e);
635 function selectionRemoveLabel(id, ids) {
638 if (!ids) ids = getSelectedArticleIds2();
640 if (ids.length == 0) {
641 alert(__("No articles are selected."));
645 var query = "?op=rpc&method=removeFromLabel&ids=" +
646 param_escape(ids.toString()) + "&lid=" + param_escape(id);
650 new Ajax.Request("backend.php", {
652 onComplete: function(transport) {
653 handle_rpc_json(transport);
654 show_labels_in_headlines(transport);
658 exception_error("selectionAssignLabel", e);
663 function selectionAssignLabel(id, ids) {
666 if (!ids) ids = getSelectedArticleIds2();
668 if (ids.length == 0) {
669 alert(__("No articles are selected."));
673 var query = "?op=rpc&method=assignToLabel&ids=" +
674 param_escape(ids.toString()) + "&lid=" + param_escape(id);
678 new Ajax.Request("backend.php", {
680 onComplete: function(transport) {
681 handle_rpc_json(transport);
682 show_labels_in_headlines(transport);
686 exception_error("selectionAssignLabel", e);
691 function selectionToggleUnread(set_state, callback, no_error) {
693 var rows = getSelectedArticleIds2();
695 if (rows.length == 0 && !no_error) {
696 alert(__("No articles are selected."));
700 for (var i = 0; i < rows.length; i++) {
701 var row = $("RROW-" + rows[i]);
703 if (set_state == undefined) {
704 if (row.hasClassName("Unread")) {
705 row.removeClassName("Unread");
707 row.addClassName("Unread");
711 if (set_state == false) {
712 row.removeClassName("Unread");
715 if (set_state == true) {
716 row.addClassName("Unread");
721 if (rows.length > 0) {
725 if (set_state == undefined) {
727 } else if (set_state == true) {
729 } else if (set_state == false) {
733 var query = "?op=rpc&method=catchupSelected" +
734 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
736 notify_progress("Loading, please wait...");
738 new Ajax.Request("backend.php", {
740 onComplete: function(transport) {
741 handle_rpc_json(transport);
742 if (callback) callback(transport);
748 exception_error("selectionToggleUnread", e);
752 function selectionToggleMarked() {
755 var rows = getSelectedArticleIds2();
757 if (rows.length == 0) {
758 alert(__("No articles are selected."));
762 for (var i = 0; i < rows.length; i++) {
763 toggleMark(rows[i], true, true);
766 if (rows.length > 0) {
768 var query = "?op=rpc&method=markSelected&ids=" +
769 param_escape(rows.toString()) + "&cmode=2";
771 new Ajax.Request("backend.php", {
773 onComplete: function(transport) {
774 handle_rpc_json(transport);
780 exception_error("selectionToggleMarked", e);
784 function selectionTogglePublished() {
787 var rows = getSelectedArticleIds2();
789 if (rows.length == 0) {
790 alert(__("No articles are selected."));
794 for (var i = 0; i < rows.length; i++) {
795 togglePub(rows[i], true, true);
798 if (rows.length > 0) {
800 var query = "?op=rpc&method=publishSelected&ids=" +
801 param_escape(rows.toString()) + "&cmode=2";
803 new Ajax.Request("backend.php", {
805 onComplete: function(transport) {
806 handle_rpc_json(transport);
812 exception_error("selectionToggleMarked", e);
816 function getSelectedArticleIds2() {
820 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
822 rv.push(child.id.replace("RROW-", ""));
828 function getLoadedArticleIds() {
831 var children = $$("#headlines-frame > div[id*=RROW-]");
833 children.each(function(child) {
834 rv.push(child.id.replace("RROW-", ""));
841 // mode = all,none,unread,invert
842 function selectArticles(mode) {
845 var children = $$("#headlines-frame > div[id*=RROW]");
847 children.each(function(child) {
848 var id = child.id.replace("RROW-", "");
849 var cb = $("RCHK-" + id);
852 child.addClassName("Selected");
854 } else if (mode == "unread") {
855 if (child.hasClassName("Unread")) {
856 child.addClassName("Selected");
859 child.removeClassName("Selected");
862 } else if (mode == "invert") {
863 if (child.hasClassName("Selected")) {
864 child.removeClassName("Selected");
867 child.addClassName("Selected");
872 child.removeClassName("Selected");
878 exception_error("selectArticles", e);
882 function catchupPage() {
884 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
886 var str = __("Mark all visible articles in %s as read?");
888 str = str.replace("%s", fn);
890 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
894 selectArticles('all');
895 selectionToggleUnread(false, 'viewCurrentFeed()', true);
896 selectArticles('none');
899 function deleteSelection() {
903 var rows = getSelectedArticleIds2();
905 if (rows.length == 0) {
906 alert(__("No articles are selected."));
910 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
913 if (getActiveFeedId() != 0) {
914 str = __("Delete %d selected articles in %s?");
916 str = __("Delete %d selected articles?");
919 str = str.replace("%d", rows.length);
920 str = str.replace("%s", fn);
922 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
926 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
930 new Ajax.Request("backend.php", {
932 onComplete: function(transport) {
933 handle_rpc_json(transport);
938 exception_error("deleteSelection", e);
942 function archiveSelection() {
946 var rows = getSelectedArticleIds2();
948 if (rows.length == 0) {
949 alert(__("No articles are selected."));
953 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
957 if (getActiveFeedId() != 0) {
958 str = __("Archive %d selected articles in %s?");
961 str = __("Move %d archived articles back?");
965 str = str.replace("%d", rows.length);
966 str = str.replace("%s", fn);
968 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
972 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
976 for (var i = 0; i < rows.length; i++) {
977 cache_delete("article:" + rows[i]);
980 new Ajax.Request("backend.php", {
982 onComplete: function(transport) {
983 handle_rpc_json(transport);
988 exception_error("archiveSelection", e);
992 function catchupSelection() {
996 var rows = getSelectedArticleIds2();
998 if (rows.length == 0) {
999 alert(__("No articles are selected."));
1003 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1005 var str = __("Mark %d selected articles in %s as read?");
1007 str = str.replace("%d", rows.length);
1008 str = str.replace("%s", fn);
1010 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1014 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1017 exception_error("catchupSelection", e);
1021 function editArticleTags(id) {
1022 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1024 if (dijit.byId("editTagsDlg"))
1025 dijit.byId("editTagsDlg").destroyRecursive();
1027 dialog = new dijit.Dialog({
1029 title: __("Edit article Tags"),
1030 style: "width: 600px",
1031 execute: function() {
1032 if (this.validate()) {
1033 var query = dojo.objectToQuery(this.attr('value'));
1035 notify_progress("Saving article tags...", true);
1037 new Ajax.Request("backend.php", {
1039 onComplete: function(transport) {
1043 var data = JSON.parse(transport.responseText);
1046 var tags_str = article.tags;
1047 var id = tags_str.id;
1049 var tags = $("ATSTR-" + id);
1050 var tooltip = dijit.byId("ATSTRTIP-" + id);
1052 if (tags) tags.innerHTML = tags_str.content;
1053 if (tooltip) tooltip.attr('label', tags_str.content_full);
1055 cache_delete("article:" + id);
1064 var tmph = dojo.connect(dialog, 'onLoad', function() {
1065 dojo.disconnect(tmph);
1067 new Ajax.Autocompleter('tags_str', 'tags_choices',
1068 "backend.php?op=rpc&method=completeTags",
1069 { tokens: ',', paramName: "search" });
1076 function cdmScrollToArticleId(id) {
1078 var ctr = $("headlines-frame");
1079 var e = $("RROW-" + id);
1081 if (!e || !ctr) return;
1083 ctr.scrollTop = e.offsetTop;
1086 exception_error("cdmScrollToArticleId", e);
1090 function getActiveArticleId() {
1091 return active_post_id;
1094 function postMouseIn(id) {
1095 post_under_pointer = id;
1098 function postMouseOut(id) {
1099 post_under_pointer = false;
1102 function headlines_scroll_handler(e) {
1104 var hsp = $("headlines-spacer");
1106 if (!_infscroll_disable) {
1107 if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
1108 e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
1111 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1112 __("Loading, please wait...");
1114 loadMoreHeadlines();
1119 if (hsp) hsp.innerHTML = "";
1122 if (getInitParam("cdm_auto_catchup") == 1) {
1124 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1126 if ($("headlines-frame").scrollTop >
1127 (child.offsetTop + child.offsetHeight/2)) {
1129 var id = child.id.replace("RROW-", "");
1131 if (catchup_id_batch.indexOf(id) == -1)
1132 catchup_id_batch.push(id);
1134 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1138 if (catchup_id_batch.length > 0) {
1139 window.clearTimeout(catchup_timeout_id);
1141 if (!_infscroll_request_sent) {
1142 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1149 console.warn("headlines_scroll_handler: " + e);
1153 function catchupBatchedArticles() {
1155 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1157 var query = "?op=rpc&method=catchupSelected" +
1158 "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
1160 new Ajax.Request("backend.php", {
1162 onComplete: function(transport) {
1163 handle_rpc_json(transport);
1165 catchup_id_batch.each(function(id) {
1166 var elem = $("RROW-" + id);
1167 if (elem) elem.removeClassName("Unread");
1170 catchup_id_batch = [];
1175 exception_error("catchupBatchedArticles", e);
1179 function catchupRelativeToArticle(below, id) {
1183 if (!id) id = getActiveArticleId();
1186 alert(__("No article is selected."));
1190 var visible_ids = getVisibleArticleIds();
1192 var ids_to_mark = new Array();
1195 for (var i = 0; i < visible_ids.length; i++) {
1196 if (visible_ids[i] != id) {
1197 var e = $("RROW-" + visible_ids[i]);
1199 if (e && e.hasClassName("Unread")) {
1200 ids_to_mark.push(visible_ids[i]);
1207 for (var i = visible_ids.length-1; i >= 0; i--) {
1208 if (visible_ids[i] != id) {
1209 var e = $("RROW-" + visible_ids[i]);
1211 if (e && e.hasClassName("Unread")) {
1212 ids_to_mark.push(visible_ids[i]);
1220 if (ids_to_mark.length == 0) {
1221 alert(__("No articles found to mark"));
1223 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1225 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1227 for (var i = 0; i < ids_to_mark.length; i++) {
1228 var e = $("RROW-" + ids_to_mark[i]);
1229 e.removeClassName("Unread");
1232 var query = "?op=rpc&method=catchupSelected" +
1233 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1235 new Ajax.Request("backend.php", {
1237 onComplete: function(transport) {
1238 handle_rpc_json(transport);
1245 exception_error("catchupRelativeToArticle", e);
1249 function cdmExpandArticle(id) {
1254 var elem = $("CICD-" + active_post_id);
1256 var upd_img_pic = $("FUPDPIC-" + id);
1258 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1259 upd_img_pic.src.match("fresh_sign.png"))) {
1261 upd_img_pic.src = "images/blank_icon.gif";
1264 if (id == active_post_id && Element.visible(elem))
1267 selectArticles("none");
1269 var old_offset = $("RROW-" + id).offsetTop;
1271 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1273 Element.show("CEXC-" + active_post_id);
1276 active_post_id = id;
1278 elem = $("CICD-" + id);
1280 if (!Element.visible(elem)) {
1282 Element.hide("CEXC-" + id);
1284 if ($("CWRAP-" + id).innerHTML == "") {
1286 $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
1288 $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
1289 __("Loading, please wait...") + "</div>";
1291 var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
1293 var neighbor_ids = getRelativePostIds(id);
1295 /* only request uncached articles */
1296 var cids_to_request = [];
1298 for (var i = 0; i < neighbor_ids.length; i++) {
1299 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
1300 if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
1301 cids_to_request.push(neighbor_ids[i]);
1302 cids_requested.push(neighbor_ids[i]);
1306 console.log("additional ids: " + cids_to_request.toString());
1308 query = query + "&cids=" + cids_to_request.toString();
1312 new Ajax.Request("backend.php", {
1314 onComplete: function(transport) {
1316 $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
1318 handle_rpc_json(transport);
1320 var reply = JSON.parse(transport.responseText);
1322 reply.each(function(article) {
1323 $("CWRAP-" + article['id']).innerHTML = article['content'];
1324 cids_requested.remove(article['id']);
1331 var new_offset = $("RROW-" + id).offsetTop;
1333 $("headlines-frame").scrollTop += (new_offset-old_offset);
1335 if ($("RROW-" + id).offsetTop != old_offset)
1336 $("headlines-frame").scrollTop = new_offset;
1338 toggleUnread(id, 0, true);
1342 exception_error("cdmExpandArticle", e);
1348 function fixHeadlinesOrder(ids) {
1350 for (var i = 0; i < ids.length; i++) {
1351 var e = $("RROW-" + ids[i]);
1355 e.removeClassName("even");
1356 e.addClassName("odd");
1358 e.removeClassName("odd");
1359 e.addClassName("even");
1364 exception_error("fixHeadlinesOrder", e);
1368 function getArticleUnderPointer() {
1369 return post_under_pointer;
1372 function zoomToArticle(event, id) {
1374 var cached_article = cache_get("article: " + id);
1376 if (dijit.byId("ATAB-" + id))
1377 if (!event || !event.shiftKey)
1378 return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
1380 if (dijit.byId("ATSTRTIP-" + id))
1381 dijit.byId("ATSTRTIP-" + id).destroyRecursive();
1383 if (cached_article) {
1384 //closeArticlePanel();
1386 var article_pane = new dijit.layout.ContentPane({
1387 title: __("Loading...") , content: cached_article,
1388 style: 'padding : 0px;',
1392 dijit.byId("content-tabs").addChild(article_pane);
1394 if (!event || !event.shiftKey)
1395 dijit.byId("content-tabs").selectChild(article_pane);
1397 if ($("PTITLE-" + id))
1398 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1402 var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
1404 notify_progress("Loading, please wait...", true);
1406 new Ajax.Request("backend.php", {
1408 onComplete: function(transport) {
1411 var reply = JSON.parse(transport.responseText);
1414 //closeArticlePanel();
1416 var content = reply[0]['content'];
1418 var article_pane = new dijit.layout.ContentPane({
1419 title: "article-" + id , content: content,
1420 style: 'padding : 0px;',
1424 dijit.byId("content-tabs").addChild(article_pane);
1426 if (!event || !event.shiftKey)
1427 dijit.byId("content-tabs").selectChild(article_pane);
1429 if ($("PTITLE-" + id))
1430 article_pane.attr('title', $("PTITLE-" + id).innerHTML);
1437 exception_error("zoomToArticle", e);
1441 function scrollArticle(offset) {
1444 var ci = $("content-insert");
1446 ci.scrollTop += offset;
1449 var hi = $("headlines-frame");
1451 hi.scrollTop += offset;
1456 exception_error("scrollArticle", e);
1460 function show_labels_in_headlines(transport) {
1462 var data = JSON.parse(transport.responseText);
1465 data['info-for-headlines'].each(function(elem) {
1466 var ctr = $("HLLCTR-" + elem.id);
1468 if (ctr) ctr.innerHTML = elem.labels;
1471 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1475 exception_error("show_labels_in_headlines", e);
1479 /* function toggleHeadlineActions() {
1481 var e = $("headlineActionsBody");
1482 var p = $("headlineActionsDrop");
1484 if (!Element.visible(e)) {
1491 e.style.left = (p.offsetLeft + 1) + "px";
1492 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1495 exception_error("toggleHeadlineActions", e);
1499 /* function publishWithNote(id, def_note) {
1501 if (!def_note) def_note = '';
1503 var note = prompt(__("Please enter a note for this article:"), def_note);
1505 if (note != undefined) {
1506 togglePub(id, false, false, note);
1510 exception_error("publishWithNote", e);
1514 function dismissArticle(id) {
1516 var elem = $("RROW-" + id);
1518 toggleUnread(id, 0, true);
1520 new Effect.Fade(elem, {duration : 0.5});
1522 active_post_id = false;
1525 exception_error("dismissArticle", e);
1529 function dismissSelectedArticles() {
1532 var ids = getVisibleArticleIds();
1536 for (var i = 0; i < ids.length; i++) {
1537 var elem = $("RROW-" + ids[i]);
1539 if (elem.className && elem.hasClassName("Selected") &&
1540 ids[i] != active_post_id) {
1541 new Effect.Fade(elem, {duration : 0.5});
1549 selectionToggleUnread(false);
1551 fixHeadlinesOrder(tmp);
1554 exception_error("dismissSelectedArticles", e);
1558 function dismissReadArticles() {
1561 var ids = getVisibleArticleIds();
1564 for (var i = 0; i < ids.length; i++) {
1565 var elem = $("RROW-" + ids[i]);
1567 if (elem.className && !elem.hasClassName("Unread") &&
1568 !elem.hasClassName("Selected")) {
1570 new Effect.Fade(elem, {duration : 0.5});
1576 fixHeadlinesOrder(tmp);
1579 exception_error("dismissSelectedArticles", e);
1583 function getVisibleArticleIds() {
1588 getLoadedArticleIds().each(function(id) {
1589 var elem = $("RROW-" + id);
1590 if (elem && Element.visible(elem))
1595 exception_error("getVisibleArticleIds", e);
1601 function cdmClicked(event, id) {
1603 //var shift_key = event.shiftKey;
1607 if (!event.ctrlKey) {
1609 if (!getInitParam("cdm_expanded")) {
1610 return cdmExpandArticle(id);
1613 selectArticles("none");
1616 var elem = $("RROW-" + id);
1617 var article_is_unread = elem.hasClassName("Unread");
1620 elem.removeClassName("Unread");
1622 var upd_img_pic = $("FUPDPIC-" + id);
1624 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
1625 upd_img_pic.src.match("fresh_sign.png"))) {
1627 upd_img_pic.src = "images/blank_icon.gif";
1630 active_post_id = id;
1632 if (article_is_unread) {
1633 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1636 var query = "?op=rpc&method=catchupSelected" +
1637 "&cmode=0&ids=" + param_escape(id);
1639 new Ajax.Request("backend.php", {
1641 onComplete: function(transport) {
1642 handle_rpc_json(transport);
1649 toggleSelected(id, true);
1651 var elem = $("RROW-" + id);
1652 var article_is_unread = elem.hasClassName("Unread");
1654 if (article_is_unread) {
1655 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1658 toggleUnread(id, 0, false);
1659 zoomToArticle(event, id);
1663 exception_error("cdmClicked");
1669 function postClicked(event, id) {
1672 if (!event.ctrlKey) {
1675 postOpenInNewTab(event, id);
1680 exception_error("postClicked");
1684 function hlOpenInNewTab(event, id) {
1685 toggleUnread(id, 0, false);
1686 zoomToArticle(event, id);
1689 function postOpenInNewTab(event, id) {
1690 closeArticlePanel(id);
1691 zoomToArticle(event, id);
1694 function hlClicked(event, id) {
1696 if (event.which == 2) {
1699 } else if (event.altKey) {
1700 openArticleInNewWindow(id);
1701 } else if (!event.ctrlKey) {
1706 toggleUnread(id, 0, false);
1707 zoomToArticle(event, id);
1712 exception_error("hlClicked");
1716 function getFirstVisibleHeadlineId() {
1717 var rows = getVisibleArticleIds();
1722 function getLastVisibleHeadlineId() {
1723 var rows = getVisibleArticleIds();
1724 return rows[rows.length-1];
1727 function openArticleInNewWindow(id) {
1728 toggleUnread(id, 0, false);
1729 window.open("backend.php?op=article&method=redirect&id=" + id);
1732 function isCdmMode() {
1733 return getInitParam("combined_display_mode");
1736 function markHeadline(id) {
1737 var row = $("RROW-" + id);
1739 var check = $("RCHK-" + id);
1742 check.checked = true;
1745 row.addClassName("Selected");
1749 function getRelativePostIds(id, limit) {
1755 if (!limit) limit = 6; //3
1757 var ids = getVisibleArticleIds();
1759 for (var i = 0; i < ids.length; i++) {
1761 for (var k = 1; k <= limit; k++) {
1762 //if (i > k-1) tmp.push(ids[i-k]);
1763 if (i < ids.length-k) tmp.push(ids[i+k]);
1770 exception_error("getRelativePostIds", e);
1776 function correctHeadlinesOffset(id) {
1780 var container = $("headlines-frame");
1781 var row = $("RROW-" + id);
1783 var viewport = container.offsetHeight;
1785 var rel_offset_top = row.offsetTop - container.scrollTop;
1786 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1788 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1789 //console.log("Vport: " + viewport);
1791 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1792 container.scrollTop = row.offsetTop;
1793 } else if (rel_offset_bottom > viewport) {
1795 /* doesn't properly work with Opera in some cases because
1796 Opera fucks up element scrolling */
1798 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1802 exception_error("correctHeadlinesOffset", e);
1807 function headlineActionsChange(elem) {
1810 elem.attr('value', 'false');
1812 exception_error("headlineActionsChange", e);
1816 function closeArticlePanel() {
1818 var tabs = dijit.byId("content-tabs");
1819 var child = tabs.selectedChildWidget;
1821 if (child && tabs.getIndexOfChild(child) > 0) {
1822 tabs.removeChild(child);
1825 if (dijit.byId("content-insert"))
1826 dijit.byId("headlines-wrap-inner").removeChild(
1827 dijit.byId("content-insert"));
1831 function initHeadlinesMenu() {
1833 if (dijit.byId("headlinesMenu"))
1834 dijit.byId("headlinesMenu").destroyRecursive();
1839 nodes = $$("#headlines-frame > div[id*=RROW]");
1841 nodes = $$("#headlines-frame span[id*=RTITLE]");
1844 nodes.each(function(node) {
1848 var menu = new dijit.Menu({
1849 id: "headlinesMenu",
1853 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1854 var callerNode = event.target, match = null, tries = 0;
1856 while (match == null && callerNode && tries <= 3) {
1857 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1858 callerNode = callerNode.parentNode;
1862 if (match) this.callerRowId = parseInt(match[1]);
1866 /* if (!isCdmMode())
1867 menu.addChild(new dijit.MenuItem({
1868 label: __("View article"),
1869 onClick: function(event) {
1870 view(this.getParent().callerRowId);
1873 menu.addChild(new dijit.MenuItem({
1874 label: __("Open original article"),
1875 onClick: function(event) {
1876 openArticleInNewWindow(this.getParent().callerRowId);
1879 menu.addChild(new dijit.MenuItem({
1880 label: __("View in a tt-rss tab"),
1881 onClick: function(event) {
1882 hlOpenInNewTab(event, this.getParent().callerRowId);
1885 menu.addChild(new dijit.MenuSeparator());
1887 menu.addChild(new dijit.MenuItem({
1888 label: __("Mark above as read"),
1889 onClick: function(event) {
1890 catchupRelativeToArticle(0, this.getParent().callerRowId);
1893 menu.addChild(new dijit.MenuItem({
1894 label: __("Mark below as read"),
1895 onClick: function(event) {
1896 catchupRelativeToArticle(1, this.getParent().callerRowId);
1900 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1904 menu.addChild(new dijit.MenuSeparator());
1906 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1907 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1909 labels.each(function(label) {
1910 var id = label.id[0];
1911 var bare_id = id.substr(id.indexOf(":")+1);
1912 var name = label.name[0];
1914 bare_id = -11-bare_id;
1916 labelAddMenu.addChild(new dijit.MenuItem({
1919 onClick: function(event) {
1920 selectionAssignLabel(this.labelId,
1921 [this.getParent().ownerMenu.callerRowId]);
1924 labelDelMenu.addChild(new dijit.MenuItem({
1927 onClick: function(event) {
1928 selectionRemoveLabel(this.labelId,
1929 [this.getParent().ownerMenu.callerRowId]);
1934 menu.addChild(new dijit.PopupMenuItem({
1935 label: __("Assign label"),
1936 popup: labelAddMenu,
1939 menu.addChild(new dijit.PopupMenuItem({
1940 label: __("Remove label"),
1941 popup: labelDelMenu,
1949 exception_error("initHeadlinesMenu", e);
1954 function player(elem) {
1955 var aid = elem.getAttribute("audio-id");
1956 var status = elem.getAttribute("status");
1964 elem.innerHTML = __("Playing...");
1965 elem.title = __("Click to pause");
1966 elem.addClassName("playing");
1970 elem.innerHTML = __("Play");
1971 elem.title = __("Click to play");
1972 elem.removeClassName("playing");
1975 elem.setAttribute("status", status);
1977 alert("Your browser doesn't seem to support HTML5 audio.");
1981 function cache_set(id, obj) {
1982 //console.log("cache_set: " + id);
1985 sessionStorage[id] = obj;
1987 sessionStorage.clear();
1991 function cache_get(id) {
1993 return sessionStorage[id];
1996 function cache_clear() {
1998 sessionStorage.clear();
2001 function cache_delete(id) {
2003 sessionStorage.removeItem(id);
2006 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
2007 if (toolbar_obj && content_obj) {
2008 cache_set("feed:" + feed + ":" + is_cat,
2009 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
2012 obj = cache_get("feed:" + feed + ":" + is_cat);
2015 obj = JSON.parse(obj);
2017 if (toolbar_obj) obj.toolbar = toolbar_obj;
2018 if (content_obj) obj.content = content_obj;
2020 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
2024 console.warn("cache_headlines failed: " + e);
2029 function render_local_headlines(feed, is_cat, obj) {
2032 dijit.byId("headlines-toolbar").attr('content',
2035 dijit.byId("headlines-frame").attr('content',
2038 dojo.parser.parse('headlines-toolbar');
2040 $("headlines-frame").scrollTop = 0;
2041 selectArticles('none');
2042 setActiveFeedId(feed, is_cat);
2043 initHeadlinesMenu();
2045 precache_headlines();
2048 exception_error("render_local_headlines", e);
2052 function precache_headlines_idle() {
2054 if (!feed_precache_timeout_id) {
2055 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
2058 feeds.each(function(item) {
2059 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
2060 uncached.push(item);
2063 if (uncached.length > 0) {
2064 var rf = uncached[Math.floor(Math.random()*uncached.length)];
2065 viewfeed(rf[0], '', rf[1], 0, true);
2068 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
2071 exception_error("precache_headlines_idle", e);
2075 function precache_headlines() {
2078 if (!feed_precache_timeout_id) {
2079 feed_precache_timeout_id = window.setTimeout(function() {
2080 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2081 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2083 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
2084 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
2086 if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
2087 viewfeed(nf[0], '', nf[1], 0, true);
2089 window.setTimeout(function() {
2090 feed_precache_timeout_id = false;
2096 exception_error("precache_headlines", e);