1 var active_post_id = false;
3 var article_cache = new Array();
5 var vgroup_last_feed = false;
6 var post_under_pointer = false;
8 var last_requested_article = false;
10 var catchup_id_batch = [];
11 var catchup_timeout_id = false;
12 var feed_precache_timeout_id = false;
13 var precache_idle_timeout_id = false;
15 var cids_requested = [];
16 var loaded_article_ids = [];
18 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
20 function headlines_callback2(transport, offset, background, infscroll_req) {
22 handle_rpc_json(transport);
24 loading_set_progress(25);
26 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
34 reply = JSON.parse(transport.responseText);
41 is_cat = reply['headlines']['is_cat'];
42 feed_id = reply['headlines']['id'];
45 var content = reply['headlines']['content'];
47 if (getInitParam("cdm_auto_catchup") == 1) {
48 content = content + "<div id='headlines-spacer'></div>";
51 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
55 setActiveFeedId(feed_id, is_cat);
57 dijit.getEnclosingWidget(
58 document.forms["main_toolbar_form"].update).attr('disabled',
59 is_cat || feed_id <= 0);
62 if (offset == 0 && infscroll_req == false) {
63 $("headlines-frame").scrollTop = 0;
67 var headlines_count = reply['headlines-info']['count'];
69 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
71 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
72 _infscroll_disable = 1;
74 _infscroll_disable = 0;
77 var counters = reply['counters'];
78 var articles = reply['articles'];
79 //var runtime_info = reply['runtime-info'];
81 if (offset == 0 && infscroll_req == false) {
82 loaded_article_ids = [];
84 dijit.byId("headlines-frame").attr('content',
85 reply['headlines']['content']);
87 dijit.byId("headlines-toolbar").attr('content',
88 reply['headlines']['toolbar']);
90 $$("#headlines-frame > div[id*=RROW]").each(function(row) {
91 if (loaded_article_ids.indexOf(row.id) != -1) {
92 row.parentNode.removeChild(row);
94 loaded_article_ids.push(row.id);
98 if (getInitParam("cdm_auto_catchup") == 1) {
99 var hsp = $("headlines-spacer");
100 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
101 dijit.byId('headlines-frame').domNode.appendChild(hsp);
107 $("feed_title").innerHTML += "<span id='cancel_search'>" +
108 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
114 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
115 console.log("adding some more headlines: " + headlines_count);
117 var c = dijit.byId("headlines-frame");
118 var ids = getSelectedArticleIds2();
121 $("headlines-tmp").innerHTML = reply['headlines']['content'];
123 var hsp = $("headlines-spacer");
126 c.domNode.removeChild(hsp);
128 $$("#headlines-tmp > div").each(function(row) {
129 if (row.className == 'cdmFeedTitle') {
130 row.style.display = 'none';
131 c.domNode.appendChild(row);
133 } else if (loaded_article_ids.indexOf(row.id) == -1) {
134 row.style.display = 'none';
135 c.domNode.appendChild(row);
137 loaded_article_ids.push(row.id);
139 row.parentNode.removeChild(row);
143 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
145 fixHeadlinesOrder(getLoadedArticleIds());
147 if (getInitParam("cdm_auto_catchup") == 1) {
148 c.domNode.appendChild(hsp);
151 console.log("added " + new_elems.size() + " headlines");
153 if (new_elems.size() == 0)
154 _infscroll_disable = true;
156 console.log("restore selected ids: " + ids);
158 for (var i = 0; i < ids.length; i++) {
159 markHeadline(ids[i]);
164 new_elems.each(function(child) {
165 var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
168 dojo.parser.parse(child);
170 if (!Element.visible(child))
171 new Effect.Appear(child, { duration : 0.5 });
173 c.domNode.removeChild(child);
178 console.log("no new headlines received");
180 var hsp = $("headlines-spacer");
182 if (hsp) hsp.innerHTML = "";
186 if (headlines_count > 0)
187 cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
190 for (var i = 0; i < articles.length; i++) {
191 var a_id = articles[i]['id'];
192 cache_set("article:" + a_id, articles[i]['content']);
195 console.log("no cached articles received");
198 // do not precache stuff after fresh feed
200 precache_headlines();
203 parse_counters(counters);
205 request_counters(true);
207 } else if (transport.responseText) {
208 console.error("Invalid object received: " + transport.responseText);
209 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
210 __('Could not update headlines (invalid object received - see error console for details)') +
213 //notify_error("Error communicating with server.");
214 Element.show(dijit.byId("net-alert").domNode);
217 _infscroll_request_sent = 0;
222 exception_error("headlines_callback2", e, transport);
226 function render_article(article) {
228 dijit.byId("headlines-wrap-inner").addChild(
229 dijit.byId("content-insert"));
231 var c = dijit.byId("content-insert");
234 c.domNode.scrollTop = 0;
237 c.attr('content', article);
239 correctHeadlinesOffset(getActiveArticleId());
246 exception_error("render_article", e);
250 function showArticleInHeadlines(id) {
254 selectArticles("none");
256 var crow = $("RROW-" + id);
260 var article_is_unread = crow.hasClassName("Unread");
262 crow.removeClassName("Unread");
264 selectArticles('none');
266 var view_mode = false;
269 view_mode = document.forms['main_toolbar_form'].view_mode;
270 view_mode = view_mode[view_mode.selectedIndex].value;
275 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 reply.each(function(article) {
306 if (active_post_id == article['id']) {
307 render_article(article['content']);
309 cids_requested.remove(article['id']);
311 cache_set("article:" + article['id'], article['content']);
314 // if (id != last_requested_article) {
315 // console.log("requested article id is out of sequence, aborting");
319 } else if (transport.responseText) {
320 console.error("Invalid object received: " + transport.responseText);
322 render_article("<div class='whiteBox'>" +
323 __('Could not display article (invalid object received - see error console for details)') + "</div>");
325 Element.show(dijit.byId("net-alert").domNode);
330 headlines_scroll_handler($("headlines-frame"));
333 if (!_infscroll_disable &&
334 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
344 exception_error("article_callback2", e, transport);
350 var crow = $("RROW-" + id);
354 console.log("loading article: " + id);
356 var cached_article = cache_get("article:" + id);
358 console.log("cache check result: " + (cached_article != false));
362 var query = "?op=article&method=view&id=" + param_escape(id);
364 var neighbor_ids = getRelativePostIds(id);
366 /* only request uncached articles */
368 var cids_to_request = [];
370 for (var i = 0; i < neighbor_ids.length; i++) {
371 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
372 if (!cache_get("article:" + neighbor_ids[i])) {
373 cids_to_request.push(neighbor_ids[i]);
374 cids_requested.push(neighbor_ids[i]);
378 console.log("additional ids: " + cids_to_request.toString());
380 query = query + "&cids=" + cids_to_request.toString();
382 var article_is_unread = crow.hasClassName("Unread");
385 showArticleInHeadlines(id);
387 precache_headlines();
389 if (cached_article && article_is_unread) {
391 query = query + "&mode=prefetch";
393 render_article(cached_article);
395 } else if (cached_article) {
397 query = query + "&mode=prefetch_old";
398 render_article(cached_article);
400 // if we don't need to request any relative ids, we might as well skip
401 // the server roundtrip altogether
402 if (cids_to_request.length == 0) {
405 if (!_infscroll_disable &&
406 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
414 headlines_scroll_handler($("headlines-frame"));
420 last_requested_article = id;
424 if (article_is_unread) {
425 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
428 new Ajax.Request("backend.php", {
430 onComplete: function(transport) {
431 article_callback2(transport, id);
437 exception_error("view", e);
441 function toggleMark(id, client_only) {
443 var query = "?op=rpc&id=" + id + "&method=mark";
445 var img = $("FMPIC-" + id);
449 if (img.src.match("mark_unset")) {
450 img.src = img.src.replace("mark_unset", "mark_set");
451 img.alt = __("Unstar article");
452 query = query + "&mark=1";
455 img.src = img.src.replace("mark_set", "mark_unset");
456 img.alt = __("Star article");
457 query = query + "&mark=0";
460 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
463 new Ajax.Request("backend.php", {
465 onComplete: function(transport) {
466 handle_rpc_json(transport);
471 exception_error("toggleMark", e);
475 function togglePub(id, client_only, no_effects, note) {
477 var query = "?op=rpc&id=" + id + "&method=publ";
479 if (note != undefined) {
480 query = query + "¬e=" + param_escape(note);
482 query = query + "¬e=undefined";
485 var img = $("FPPIC-" + id);
489 if (img.src.match("pub_unset") || note != undefined) {
490 img.src = img.src.replace("pub_unset", "pub_set");
491 img.alt = __("Unpublish article");
492 query = query + "&pub=1";
495 img.src = img.src.replace("pub_set", "pub_unset");
496 img.alt = __("Publish article");
498 query = query + "&pub=0";
501 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
504 new Ajax.Request("backend.php", {
506 onComplete: function(transport) {
507 handle_rpc_json(transport);
512 exception_error("togglePub", e);
516 function moveToPost(mode) {
520 var rows = getVisibleArticleIds();
525 if (!$('RROW-' + active_post_id)) {
526 active_post_id = false;
529 if (active_post_id == false) {
531 prev_id = rows[rows.length-1]
533 for (var i = 0; i < rows.length; i++) {
534 if (rows[i] == active_post_id) {
536 // Account for adjacent identical article ids.
537 if (i > 0) prev_id = rows[i-1];
539 for (var j = i+1; j < rows.length; j++) {
540 if (rows[j] != active_post_id) {
550 if (mode == "next") {
554 cdmExpandArticle(next_id);
555 cdmScrollToArticleId(next_id);
558 correctHeadlinesOffset(next_id);
559 view(next_id, getActiveFeedId());
564 if (mode == "prev") {
567 cdmExpandArticle(prev_id);
568 cdmScrollToArticleId(prev_id);
570 correctHeadlinesOffset(prev_id);
571 view(prev_id, getActiveFeedId());
577 exception_error("moveToPost", e);
581 function toggleSelected(id, force_on) {
584 var cb = dijit.byId("RCHK-" + id);
585 var row = $("RROW-" + id);
588 if (row.hasClassName('Selected') && !force_on) {
589 row.removeClassName('Selected');
590 if (cb) cb.attr("checked", false);
592 row.addClassName('Selected');
593 if (cb) cb.attr("checked", true);
597 exception_error("toggleSelected", e);
601 function toggleUnread_afh(effect) {
604 var elem = effect.element;
605 elem.style.backgroundColor = "";
608 exception_error("toggleUnread_afh", e);
612 function toggleUnread(id, cmode, effect) {
615 var row = $("RROW-" + id);
617 if (cmode == undefined || cmode == 2) {
618 if (row.hasClassName("Unread")) {
619 row.removeClassName("Unread");
622 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
623 afterFinish: toggleUnread_afh,
624 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
628 row.addClassName("Unread");
631 } else if (cmode == 0) {
633 row.removeClassName("Unread");
636 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
637 afterFinish: toggleUnread_afh,
638 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
641 } else if (cmode == 1) {
642 row.addClassName("Unread");
645 if (cmode == undefined) cmode = 2;
647 var query = "?op=rpc&method=catchupSelected" +
648 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
650 // notify_progress("Loading, please wait...");
652 new Ajax.Request("backend.php", {
654 onComplete: function(transport) {
655 handle_rpc_json(transport);
661 exception_error("toggleUnread", e);
665 function selectionRemoveLabel(id, ids) {
668 if (!ids) ids = getSelectedArticleIds2();
670 if (ids.length == 0) {
671 alert(__("No articles are selected."));
675 var query = "?op=rpc&method=removeFromLabel&ids=" +
676 param_escape(ids.toString()) + "&lid=" + param_escape(id);
680 new Ajax.Request("backend.php", {
682 onComplete: function(transport) {
683 handle_rpc_json(transport);
684 show_labels_in_headlines(transport);
688 exception_error("selectionAssignLabel", e);
693 function selectionAssignLabel(id, ids) {
696 if (!ids) ids = getSelectedArticleIds2();
698 if (ids.length == 0) {
699 alert(__("No articles are selected."));
703 var query = "?op=rpc&method=assignToLabel&ids=" +
704 param_escape(ids.toString()) + "&lid=" + param_escape(id);
708 new Ajax.Request("backend.php", {
710 onComplete: function(transport) {
711 handle_rpc_json(transport);
712 show_labels_in_headlines(transport);
716 exception_error("selectionAssignLabel", e);
721 function selectionToggleUnread(set_state, callback, no_error) {
723 var rows = getSelectedArticleIds2();
725 if (rows.length == 0 && !no_error) {
726 alert(__("No articles are selected."));
730 for (var i = 0; i < rows.length; i++) {
731 var row = $("RROW-" + rows[i]);
733 if (set_state == undefined) {
734 if (row.hasClassName("Unread")) {
735 row.removeClassName("Unread");
737 row.addClassName("Unread");
741 if (set_state == false) {
742 row.removeClassName("Unread");
745 if (set_state == true) {
746 row.addClassName("Unread");
751 if (rows.length > 0) {
755 if (set_state == undefined) {
757 } else if (set_state == true) {
759 } else if (set_state == false) {
763 var query = "?op=rpc&method=catchupSelected" +
764 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
766 notify_progress("Loading, please wait...");
768 new Ajax.Request("backend.php", {
770 onComplete: function(transport) {
771 handle_rpc_json(transport);
772 if (callback) callback(transport);
778 exception_error("selectionToggleUnread", e);
782 function selectionToggleMarked() {
785 var rows = getSelectedArticleIds2();
787 if (rows.length == 0) {
788 alert(__("No articles are selected."));
792 for (var i = 0; i < rows.length; i++) {
793 toggleMark(rows[i], true, true);
796 if (rows.length > 0) {
798 var query = "?op=rpc&method=markSelected&ids=" +
799 param_escape(rows.toString()) + "&cmode=2";
801 new Ajax.Request("backend.php", {
803 onComplete: function(transport) {
804 handle_rpc_json(transport);
810 exception_error("selectionToggleMarked", e);
814 function selectionTogglePublished() {
817 var rows = getSelectedArticleIds2();
819 if (rows.length == 0) {
820 alert(__("No articles are selected."));
824 for (var i = 0; i < rows.length; i++) {
825 togglePub(rows[i], true, true);
828 if (rows.length > 0) {
830 var query = "?op=rpc&method=publishSelected&ids=" +
831 param_escape(rows.toString()) + "&cmode=2";
833 new Ajax.Request("backend.php", {
835 onComplete: function(transport) {
836 handle_rpc_json(transport);
842 exception_error("selectionToggleMarked", e);
846 function getSelectedArticleIds2() {
850 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
852 rv.push(child.id.replace("RROW-", ""));
858 function getLoadedArticleIds() {
861 var children = $$("#headlines-frame > div[id*=RROW-]");
863 children.each(function(child) {
864 rv.push(child.id.replace("RROW-", ""));
871 // mode = all,none,unread,invert,marked,published
872 function selectArticles(mode) {
875 var children = $$("#headlines-frame > div[id*=RROW]");
877 children.each(function(child) {
878 var id = child.id.replace("RROW-", "");
879 var cb = dijit.byId("RCHK-" + id);
882 child.addClassName("Selected");
883 if (cb) cb.attr("checked", true);
884 } else if (mode == "unread") {
885 if (child.hasClassName("Unread")) {
886 child.addClassName("Selected");
887 if (cb) cb.attr("checked", true);
889 child.removeClassName("Selected");
890 if (cb) cb.attr("checked", false);
892 } else if (mode == "marked") {
893 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
895 if (img && img.src.match("mark_set")) {
896 child.addClassName("Selected");
897 if (cb) cb.attr("checked", true);
899 child.removeClassName("Selected");
900 if (cb) cb.attr("checked", false);
902 } else if (mode == "published") {
903 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
905 if (img && img.src.match("pub_set")) {
906 child.addClassName("Selected");
907 if (cb) cb.attr("checked", true);
909 child.removeClassName("Selected");
910 if (cb) cb.attr("checked", false);
913 } else if (mode == "invert") {
914 if (child.hasClassName("Selected")) {
915 child.removeClassName("Selected");
916 if (cb) cb.attr("checked", false);
918 child.addClassName("Selected");
919 if (cb) cb.attr("checked", true);
923 child.removeClassName("Selected");
924 if (cb) cb.attr("checked", false);
929 exception_error("selectArticles", e);
933 function catchupPage() {
935 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
937 var str = __("Mark all visible articles in %s as read?");
939 str = str.replace("%s", fn);
941 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
945 selectArticles('all');
946 selectionToggleUnread(false, 'viewCurrentFeed()', true);
947 selectArticles('none');
950 function deleteSelection() {
954 var rows = getSelectedArticleIds2();
956 if (rows.length == 0) {
957 alert(__("No articles are selected."));
961 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
964 if (getActiveFeedId() != 0) {
965 str = __("Delete %d selected articles in %s?");
967 str = __("Delete %d selected articles?");
970 str = str.replace("%d", rows.length);
971 str = str.replace("%s", fn);
973 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
977 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
981 new Ajax.Request("backend.php", {
983 onComplete: function(transport) {
984 handle_rpc_json(transport);
989 exception_error("deleteSelection", e);
993 function archiveSelection() {
997 var rows = getSelectedArticleIds2();
999 if (rows.length == 0) {
1000 alert(__("No articles are selected."));
1004 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1008 if (getActiveFeedId() != 0) {
1009 str = __("Archive %d selected articles in %s?");
1012 str = __("Move %d archived articles back?");
1016 str = str.replace("%d", rows.length);
1017 str = str.replace("%s", fn);
1019 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1023 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1027 for (var i = 0; i < rows.length; i++) {
1028 cache_delete("article:" + rows[i]);
1031 new Ajax.Request("backend.php", {
1033 onComplete: function(transport) {
1034 handle_rpc_json(transport);
1039 exception_error("archiveSelection", e);
1043 function catchupSelection() {
1047 var rows = getSelectedArticleIds2();
1049 if (rows.length == 0) {
1050 alert(__("No articles are selected."));
1054 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1056 var str = __("Mark %d selected articles in %s as read?");
1058 str = str.replace("%d", rows.length);
1059 str = str.replace("%s", fn);
1061 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1065 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1068 exception_error("catchupSelection", e);
1072 function editArticleTags(id) {
1073 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1075 if (dijit.byId("editTagsDlg"))
1076 dijit.byId("editTagsDlg").destroyRecursive();
1078 dialog = new dijit.Dialog({
1080 title: __("Edit article Tags"),
1081 style: "width: 600px",
1082 execute: function() {
1083 if (this.validate()) {
1084 var query = dojo.objectToQuery(this.attr('value'));
1086 notify_progress("Saving article tags...", true);
1088 new Ajax.Request("backend.php", {
1090 onComplete: function(transport) {
1094 var data = JSON.parse(transport.responseText);
1097 var tags_str = article.tags;
1098 var id = tags_str.id;
1100 var tags = $("ATSTR-" + id);
1101 var tooltip = dijit.byId("ATSTRTIP-" + id);
1103 if (tags) tags.innerHTML = tags_str.content;
1104 if (tooltip) tooltip.attr('label', tags_str.content_full);
1106 cache_delete("article:" + id);
1115 var tmph = dojo.connect(dialog, 'onLoad', function() {
1116 dojo.disconnect(tmph);
1118 new Ajax.Autocompleter('tags_str', 'tags_choices',
1119 "backend.php?op=rpc&method=completeTags",
1120 { tokens: ',', paramName: "search" });
1127 function cdmScrollToArticleId(id) {
1129 var ctr = $("headlines-frame");
1130 var e = $("RROW-" + id);
1132 if (!e || !ctr) return;
1134 ctr.scrollTop = e.offsetTop;
1137 exception_error("cdmScrollToArticleId", e);
1141 function getActiveArticleId() {
1142 return active_post_id;
1145 function postMouseIn(id) {
1146 post_under_pointer = id;
1149 function postMouseOut(id) {
1150 post_under_pointer = false;
1153 function headlines_scroll_handler(e) {
1155 var hsp = $("headlines-spacer");
1157 if (!_infscroll_disable) {
1158 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1159 (e.scrollHeight != 0 &&
1160 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1163 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1164 __("Loading, please wait...");
1166 loadMoreHeadlines();
1171 if (hsp) hsp.innerHTML = "";
1174 if (getInitParam("cdm_auto_catchup") == 1) {
1176 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1178 if ($("headlines-frame").scrollTop >
1179 (child.offsetTop + child.offsetHeight/2)) {
1181 var id = child.id.replace("RROW-", "");
1183 if (catchup_id_batch.indexOf(id) == -1)
1184 catchup_id_batch.push(id);
1186 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1190 if (catchup_id_batch.length > 0) {
1191 window.clearTimeout(catchup_timeout_id);
1193 if (!_infscroll_request_sent) {
1194 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1201 console.warn("headlines_scroll_handler: " + e);
1205 function catchupBatchedArticles() {
1207 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1209 // make a copy of the array
1210 var batch = catchup_id_batch.slice();
1211 var query = "?op=rpc&method=catchupSelected" +
1212 "&cmode=0&ids=" + param_escape(batch.toString());
1216 new Ajax.Request("backend.php", {
1218 onComplete: function(transport) {
1219 handle_rpc_json(transport);
1221 batch.each(function(id) {
1222 var elem = $("RROW-" + id);
1223 if (elem) elem.removeClassName("Unread");
1224 catchup_id_batch.remove(id);
1231 exception_error("catchupBatchedArticles", e);
1235 function catchupRelativeToArticle(below, id) {
1239 if (!id) id = getActiveArticleId();
1242 alert(__("No article is selected."));
1246 var visible_ids = getVisibleArticleIds();
1248 var ids_to_mark = new Array();
1251 for (var i = 0; i < visible_ids.length; i++) {
1252 if (visible_ids[i] != id) {
1253 var e = $("RROW-" + visible_ids[i]);
1255 if (e && e.hasClassName("Unread")) {
1256 ids_to_mark.push(visible_ids[i]);
1263 for (var i = visible_ids.length-1; i >= 0; i--) {
1264 if (visible_ids[i] != id) {
1265 var e = $("RROW-" + visible_ids[i]);
1267 if (e && e.hasClassName("Unread")) {
1268 ids_to_mark.push(visible_ids[i]);
1276 if (ids_to_mark.length == 0) {
1277 alert(__("No articles found to mark"));
1279 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1281 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1283 for (var i = 0; i < ids_to_mark.length; i++) {
1284 var e = $("RROW-" + ids_to_mark[i]);
1285 e.removeClassName("Unread");
1288 var query = "?op=rpc&method=catchupSelected" +
1289 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1291 new Ajax.Request("backend.php", {
1293 onComplete: function(transport) {
1294 handle_rpc_json(transport);
1301 exception_error("catchupRelativeToArticle", e);
1305 function cdmExpandArticle(id) {
1310 var elem = $("CICD-" + active_post_id);
1312 if (id == active_post_id && Element.visible(elem))
1315 selectArticles("none");
1317 var old_offset = $("RROW-" + id).offsetTop;
1319 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1321 Element.show("CEXC-" + active_post_id);
1324 active_post_id = id;
1326 elem = $("CICD-" + id);
1328 if (!Element.visible(elem)) {
1330 Element.hide("CEXC-" + id);
1333 var new_offset = $("RROW-" + id).offsetTop;
1335 $("headlines-frame").scrollTop += (new_offset-old_offset);
1337 if ($("RROW-" + id).offsetTop != old_offset)
1338 $("headlines-frame").scrollTop = new_offset;
1340 toggleUnread(id, 0, true);
1344 exception_error("cdmExpandArticle", e);
1350 function fixHeadlinesOrder(ids) {
1352 for (var i = 0; i < ids.length; i++) {
1353 var e = $("RROW-" + ids[i]);
1357 e.removeClassName("even");
1358 e.addClassName("odd");
1360 e.removeClassName("odd");
1361 e.addClassName("even");
1366 exception_error("fixHeadlinesOrder", e);
1370 function getArticleUnderPointer() {
1371 return post_under_pointer;
1374 function scrollArticle(offset) {
1377 var ci = $("content-insert");
1379 ci.scrollTop += offset;
1382 var hi = $("headlines-frame");
1384 hi.scrollTop += offset;
1389 exception_error("scrollArticle", e);
1393 function show_labels_in_headlines(transport) {
1395 var data = JSON.parse(transport.responseText);
1398 data['info-for-headlines'].each(function(elem) {
1399 var ctr = $("HLLCTR-" + elem.id);
1401 if (ctr) ctr.innerHTML = elem.labels;
1404 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1408 exception_error("show_labels_in_headlines", e);
1412 function dismissArticle(id) {
1414 var elem = $("RROW-" + id);
1416 toggleUnread(id, 0, true);
1418 new Effect.Fade(elem, {duration : 0.5});
1420 active_post_id = false;
1423 exception_error("dismissArticle", e);
1427 function dismissSelectedArticles() {
1430 var ids = getVisibleArticleIds();
1434 for (var i = 0; i < ids.length; i++) {
1435 var elem = $("RROW-" + ids[i]);
1437 if (elem.className && elem.hasClassName("Selected") &&
1438 ids[i] != active_post_id) {
1439 new Effect.Fade(elem, {duration : 0.5});
1447 selectionToggleUnread(false);
1449 fixHeadlinesOrder(tmp);
1452 exception_error("dismissSelectedArticles", e);
1456 function dismissReadArticles() {
1459 var ids = getVisibleArticleIds();
1462 for (var i = 0; i < ids.length; i++) {
1463 var elem = $("RROW-" + ids[i]);
1465 if (elem.className && !elem.hasClassName("Unread") &&
1466 !elem.hasClassName("Selected")) {
1468 new Effect.Fade(elem, {duration : 0.5});
1474 fixHeadlinesOrder(tmp);
1477 exception_error("dismissSelectedArticles", e);
1481 function getVisibleArticleIds() {
1486 getLoadedArticleIds().each(function(id) {
1487 var elem = $("RROW-" + id);
1488 if (elem && Element.visible(elem))
1493 exception_error("getVisibleArticleIds", e);
1499 function cdmClicked(event, id) {
1501 //var shift_key = event.shiftKey;
1505 if (!event.ctrlKey) {
1507 if (!getInitParam("cdm_expanded")) {
1508 return cdmExpandArticle(id);
1511 selectArticles("none");
1514 var elem = $("RROW-" + id);
1515 var article_is_unread = elem.hasClassName("Unread");
1518 elem.removeClassName("Unread");
1520 active_post_id = id;
1522 if (article_is_unread) {
1523 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1526 var query = "?op=rpc&method=catchupSelected" +
1527 "&cmode=0&ids=" + param_escape(id);
1529 new Ajax.Request("backend.php", {
1531 onComplete: function(transport) {
1532 handle_rpc_json(transport);
1539 toggleSelected(id, true);
1541 var elem = $("RROW-" + id);
1542 var article_is_unread = elem.hasClassName("Unread");
1544 if (article_is_unread) {
1545 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1548 toggleUnread(id, 0, false);
1550 openArticleInNewWindow(id);
1556 exception_error("cdmClicked");
1562 function hlClicked(event, id) {
1564 if (event.which == 2) {
1567 } else if (event.ctrlKey) {
1568 toggleSelected(id, true);
1569 toggleUnread(id, 0, false);
1570 openArticleInNewWindow(id);
1578 exception_error("hlClicked");
1582 function getFirstVisibleHeadlineId() {
1583 var rows = getVisibleArticleIds();
1588 function getLastVisibleHeadlineId() {
1589 var rows = getVisibleArticleIds();
1590 return rows[rows.length-1];
1593 function openArticleInNewWindow(id) {
1594 toggleUnread(id, 0, false);
1595 window.open("backend.php?op=article&method=redirect&id=" + id);
1598 function isCdmMode() {
1599 return getInitParam("combined_display_mode");
1602 function markHeadline(id) {
1603 var row = $("RROW-" + id);
1605 var check = dijit.byId("RCHK-" + id);
1608 check.attr("checked", true);
1611 row.addClassName("Selected");
1615 function getRelativePostIds(id, limit) {
1621 if (!limit) limit = 6; //3
1623 var ids = getVisibleArticleIds();
1625 for (var i = 0; i < ids.length; i++) {
1627 for (var k = 1; k <= limit; k++) {
1628 //if (i > k-1) tmp.push(ids[i-k]);
1629 if (i < ids.length-k) tmp.push(ids[i+k]);
1636 exception_error("getRelativePostIds", e);
1642 function correctHeadlinesOffset(id) {
1646 var container = $("headlines-frame");
1647 var row = $("RROW-" + id);
1649 if (!container || !row) return;
1651 var viewport = container.offsetHeight;
1653 var rel_offset_top = row.offsetTop - container.scrollTop;
1654 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1656 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1657 //console.log("Vport: " + viewport);
1659 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1660 container.scrollTop = row.offsetTop;
1661 } else if (rel_offset_bottom > viewport) {
1663 /* doesn't properly work with Opera in some cases because
1664 Opera fucks up element scrolling */
1666 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1670 exception_error("correctHeadlinesOffset", e);
1675 function headlineActionsChange(elem) {
1678 elem.attr('value', 'false');
1680 exception_error("headlineActionsChange", e);
1684 function closeArticlePanel() {
1686 if (dijit.byId("content-insert"))
1687 dijit.byId("headlines-wrap-inner").removeChild(
1688 dijit.byId("content-insert"));
1691 function initHeadlinesMenu() {
1693 if (dijit.byId("headlinesMenu"))
1694 dijit.byId("headlinesMenu").destroyRecursive();
1699 nodes = $$("#headlines-frame > div[id*=RROW]");
1701 nodes = $$("#headlines-frame span[id*=RTITLE]");
1704 nodes.each(function(node) {
1708 var menu = new dijit.Menu({
1709 id: "headlinesMenu",
1713 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1714 var callerNode = event.target, match = null, tries = 0;
1716 while (match == null && callerNode && tries <= 3) {
1717 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1718 callerNode = callerNode.parentNode;
1722 if (match) this.callerRowId = parseInt(match[1]);
1726 /* if (!isCdmMode())
1727 menu.addChild(new dijit.MenuItem({
1728 label: __("View article"),
1729 onClick: function(event) {
1730 view(this.getParent().callerRowId);
1733 menu.addChild(new dijit.MenuItem({
1734 label: __("Open original article"),
1735 onClick: function(event) {
1736 openArticleInNewWindow(this.getParent().callerRowId);
1739 menu.addChild(new dijit.MenuSeparator());
1741 menu.addChild(new dijit.MenuItem({
1742 label: __("Mark above as read"),
1743 onClick: function(event) {
1744 catchupRelativeToArticle(0, this.getParent().callerRowId);
1747 menu.addChild(new dijit.MenuItem({
1748 label: __("Mark below as read"),
1749 onClick: function(event) {
1750 catchupRelativeToArticle(1, this.getParent().callerRowId);
1754 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1758 menu.addChild(new dijit.MenuSeparator());
1760 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1761 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1763 labels.each(function(label) {
1764 var id = label.id[0];
1765 var bare_id = id.substr(id.indexOf(":")+1);
1766 var name = label.name[0];
1768 bare_id = -11-bare_id;
1770 labelAddMenu.addChild(new dijit.MenuItem({
1773 onClick: function(event) {
1774 var ids = getSelectedArticleIds2();
1776 var id = this.getParent().ownerMenu.callerRowId + "";
1778 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1780 selectionAssignLabel(this.labelId, ids);
1783 labelDelMenu.addChild(new dijit.MenuItem({
1786 onClick: function(event) {
1787 var ids = getSelectedArticleIds2();
1789 var id = this.getParent().ownerMenu.callerRowId + "";
1791 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1793 selectionRemoveLabel(this.labelId, ids);
1798 menu.addChild(new dijit.PopupMenuItem({
1799 label: __("Assign label"),
1800 popup: labelAddMenu,
1803 menu.addChild(new dijit.PopupMenuItem({
1804 label: __("Remove label"),
1805 popup: labelDelMenu,
1813 exception_error("initHeadlinesMenu", e);
1818 function player(elem) {
1819 var aid = elem.getAttribute("audio-id");
1820 var status = elem.getAttribute("status");
1828 elem.innerHTML = __("Playing...");
1829 elem.title = __("Click to pause");
1830 elem.addClassName("playing");
1834 elem.innerHTML = __("Play");
1835 elem.title = __("Click to play");
1836 elem.removeClassName("playing");
1839 elem.setAttribute("status", status);
1841 alert("Your browser doesn't seem to support HTML5 audio.");
1845 function cache_set(id, obj) {
1846 //console.log("cache_set: " + id);
1849 sessionStorage[id] = obj;
1851 sessionStorage.clear();
1855 function cache_get(id) {
1857 return sessionStorage[id];
1860 function cache_clear() {
1862 sessionStorage.clear();
1865 function cache_delete(id) {
1867 sessionStorage.removeItem(id);
1870 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
1871 if (toolbar_obj && content_obj) {
1872 cache_set("feed:" + feed + ":" + is_cat,
1873 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
1876 obj = cache_get("feed:" + feed + ":" + is_cat);
1879 obj = JSON.parse(obj);
1881 if (toolbar_obj) obj.toolbar = toolbar_obj;
1882 if (content_obj) obj.content = content_obj;
1884 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
1888 console.warn("cache_headlines failed: " + e);
1893 function render_local_headlines(feed, is_cat, obj) {
1896 dijit.byId("headlines-toolbar").attr('content',
1899 dijit.byId("headlines-frame").attr('content',
1902 dojo.parser.parse('headlines-toolbar');
1904 $("headlines-frame").scrollTop = 0;
1905 selectArticles('none');
1906 setActiveFeedId(feed, is_cat);
1907 initHeadlinesMenu();
1909 dijit.getEnclosingWidget(
1910 document.forms["main_toolbar_form"].update).attr('disabled',
1911 is_cat || feed <= 0);
1913 precache_headlines();
1916 exception_error("render_local_headlines", e);
1920 function precache_headlines_idle() {
1922 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
1923 if (get_timestamp() - _viewfeed_last > 120) {
1925 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
1928 feeds.each(function(item) {
1929 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
1930 uncached.push(item);
1933 if (uncached.length > 0) {
1934 var rf = uncached[Math.floor(Math.random()*uncached.length)];
1935 viewfeed(rf[0], '', rf[1], 0, true);
1939 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
1942 exception_error("precache_headlines_idle", e);
1946 function precache_headlines() {
1948 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
1950 feed_precache_timeout_id = window.setTimeout(function() {
1951 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
1952 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
1954 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
1955 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
1957 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
1958 viewfeed(nf[0], '', nf[1], 0, true);
1960 window.setTimeout(function() {
1961 feed_precache_timeout_id = false;
1967 exception_error("precache_headlines", e);
1971 function cancelSearch() {
1976 exception_error("cancelSearch", e);
1980 function setSelectionScore() {
1982 var ids = getSelectedArticleIds2();
1984 if (ids.length > 0) {
1987 var score = prompt(__("Please enter new score for selected articles:"), score);
1989 if (score != undefined) {
1990 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
1991 "&score=" + param_escape(score);
1993 new Ajax.Request("backend.php", {
1995 onComplete: function(transport) {
1996 var reply = JSON.parse(transport.responseText);
2000 ids.each(function(id) {
2001 var row = $("RROW-" + id);
2004 var pic = row.getElementsByClassName("hlScorePic")[0];
2007 pic.src = pic.src.replace(/score_.*?\.png/,
2008 reply["score_pic"]);
2009 pic.setAttribute("score", score);
2018 alert(__("No articles are selected."));
2021 exception_error("setSelectionScore", e);
2025 function changeScore(id, pic) {
2027 var score = pic.getAttribute("score");
2029 var new_score = prompt(__("Please enter new score for this article:"), score);
2031 if (new_score != undefined) {
2033 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2034 "&score=" + param_escape(new_score);
2036 new Ajax.Request("backend.php", {
2038 onComplete: function(transport) {
2039 var reply = JSON.parse(transport.responseText);
2042 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2043 pic.setAttribute("score", new_score);
2048 exception_error("changeScore", e);