1 var article_cache = new Array();
3 var _active_article_id = 0;
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;
13 var cids_requested = [];
14 var loaded_article_ids = [];
16 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
18 function headlines_callback2(transport, offset, background, infscroll_req) {
20 handle_rpc_json(transport);
22 loading_set_progress(25);
24 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
32 reply = JSON.parse(transport.responseText);
39 is_cat = reply['headlines']['is_cat'];
40 feed_id = reply['headlines']['id'];
43 var content = reply['headlines']['content'];
45 if (getInitParam("cdm_auto_catchup") == 1) {
46 content = content + "<div id='headlines-spacer'></div>";
51 setActiveFeedId(feed_id, is_cat);
53 dijit.getEnclosingWidget(
54 document.forms["main_toolbar_form"].update).attr('disabled',
55 is_cat || feed_id <= 0);
58 if (infscroll_req == false) {
59 $("headlines-frame").scrollTop = 0;
63 var headlines_count = reply['headlines-info']['count'];
65 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
67 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
68 _infscroll_disable = 1;
70 _infscroll_disable = 0;
73 var counters = reply['counters'];
74 var articles = reply['articles'];
75 //var runtime_info = reply['runtime-info'];
77 if (infscroll_req == false) {
78 loaded_article_ids = [];
80 dijit.byId("headlines-frame").attr('content',
81 reply['headlines']['content']);
83 dijit.byId("headlines-toolbar").attr('content',
84 reply['headlines']['toolbar']);
86 $$("#headlines-frame > div[id*=RROW]").each(function(row) {
87 if (loaded_article_ids.indexOf(row.id) != -1) {
88 row.parentNode.removeChild(row);
90 loaded_article_ids.push(row.id);
94 if (getInitParam("cdm_auto_catchup") == 1) {
95 var hsp = $("headlines-spacer");
96 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
97 dijit.byId('headlines-frame').domNode.appendChild(hsp);
103 $("feed_title").innerHTML += "<span id='cancel_search'>" +
104 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
110 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
111 console.log("adding some more headlines: " + headlines_count);
113 var c = dijit.byId("headlines-frame");
114 var ids = getSelectedArticleIds2();
117 $("headlines-tmp").innerHTML = reply['headlines']['content'];
119 var hsp = $("headlines-spacer");
122 c.domNode.removeChild(hsp);
124 $$("#headlines-tmp > div").each(function(row) {
125 if (row.className == 'cdmFeedTitle') {
126 row.style.display = 'none';
127 c.domNode.appendChild(row);
129 } else if (loaded_article_ids.indexOf(row.id) == -1) {
130 row.style.display = 'none';
131 c.domNode.appendChild(row);
133 loaded_article_ids.push(row.id);
135 row.parentNode.removeChild(row);
139 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
141 fixHeadlinesOrder(getLoadedArticleIds());
143 if (getInitParam("cdm_auto_catchup") == 1) {
144 c.domNode.appendChild(hsp);
147 console.log("added " + new_elems.size() + " headlines");
149 if (new_elems.size() == 0)
150 _infscroll_disable = true;
152 console.log("restore selected ids: " + ids);
154 for (var i = 0; i < ids.length; i++) {
155 markHeadline(ids[i]);
160 new_elems.each(function(child) {
161 var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
164 dojo.parser.parse(child);
166 if (!Element.visible(child))
167 new Effect.Appear(child, { duration : 0.5 });
169 c.domNode.removeChild(child);
174 console.log("no new headlines received");
176 var hsp = $("headlines-spacer");
178 if (hsp) hsp.innerHTML = "";
183 for (var i = 0; i < articles.length; i++) {
184 var a_id = articles[i]['id'];
185 cache_set("article:" + a_id, articles[i]['content']);
188 console.log("no cached articles received");
192 parse_counters(counters);
194 request_counters(true);
196 } else if (transport.responseText) {
197 console.error("Invalid object received: " + transport.responseText);
198 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
199 __('Could not update headlines (invalid object received - see error console for details)') +
202 //notify_error("Error communicating with server.");
203 Element.show(dijit.byId("net-alert").domNode);
206 _infscroll_request_sent = 0;
211 exception_error("headlines_callback2", e, transport);
215 function render_article(article) {
217 dijit.byId("headlines-wrap-inner").addChild(
218 dijit.byId("content-insert"));
220 var c = dijit.byId("content-insert");
223 c.domNode.scrollTop = 0;
226 c.attr('content', article);
228 correctHeadlinesOffset(getActiveArticleId());
235 exception_error("render_article", e);
239 function showArticleInHeadlines(id) {
243 selectArticles("none");
245 var crow = $("RROW-" + id);
249 var article_is_unread = crow.hasClassName("Unread");
251 crow.removeClassName("Unread");
253 selectArticles('none');
255 var view_mode = false;
258 view_mode = document.forms['main_toolbar_form'].view_mode;
259 view_mode = view_mode[view_mode.selectedIndex].value;
266 if (article_is_unread)
267 _force_scheduled_update = true;
270 exception_error("showArticleInHeadlines", e);
274 function article_callback2(transport, id) {
276 console.log("article_callback2 " + id);
278 handle_rpc_json(transport);
283 reply = JSON.parse(transport.responseText);
290 reply.each(function(article) {
291 if (getActiveArticleId() == article['id']) {
292 render_article(article['content']);
294 cids_requested.remove(article['id']);
296 cache_set("article:" + article['id'], article['content']);
299 // if (id != last_requested_article) {
300 // console.log("requested article id is out of sequence, aborting");
304 } else if (transport.responseText) {
305 console.error("Invalid object received: " + transport.responseText);
307 render_article("<div class='whiteBox'>" +
308 __('Could not display article (invalid object received - see error console for details)') + "</div>");
310 Element.show(dijit.byId("net-alert").domNode);
313 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
314 request_counters(unread_in_buffer == 0);
316 headlines_scroll_handler($("headlines-frame"));
319 if (!_infscroll_disable &&
320 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
330 exception_error("article_callback2", e, transport);
336 var crow = $("RROW-" + id);
340 console.log("loading article: " + id);
342 var cached_article = cache_get("article:" + id);
344 console.log("cache check result: " + (cached_article != false));
348 var query = "?op=article&method=view&id=" + param_escape(id);
350 var neighbor_ids = getRelativePostIds(id);
352 /* only request uncached articles */
354 var cids_to_request = [];
356 for (var i = 0; i < neighbor_ids.length; i++) {
357 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
358 if (!cache_get("article:" + neighbor_ids[i])) {
359 cids_to_request.push(neighbor_ids[i]);
360 cids_requested.push(neighbor_ids[i]);
364 console.log("additional ids: " + cids_to_request.toString());
366 query = query + "&cids=" + cids_to_request.toString();
368 var article_is_unread = crow.hasClassName("Unread");
370 setActiveArticleId(id);
371 showArticleInHeadlines(id);
373 if (cached_article && article_is_unread) {
375 query = query + "&mode=prefetch";
377 render_article(cached_article);
379 } else if (cached_article) {
381 query = query + "&mode=prefetch_old";
382 render_article(cached_article);
384 // if we don't need to request any relative ids, we might as well skip
385 // the server roundtrip altogether
386 if (cids_to_request.length == 0) {
389 if (!_infscroll_disable &&
390 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
398 headlines_scroll_handler($("headlines-frame"));
404 last_requested_article = id;
408 if (article_is_unread) {
409 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
412 new Ajax.Request("backend.php", {
414 onComplete: function(transport) {
415 article_callback2(transport, id);
421 exception_error("view", e);
425 function toggleMark(id, client_only) {
427 var query = "?op=rpc&id=" + id + "&method=mark";
429 var img = $("FMPIC-" + id);
433 if (img.src.match("mark_unset")) {
434 img.src = img.src.replace("mark_unset", "mark_set");
435 img.alt = __("Unstar article");
436 query = query + "&mark=1";
439 img.src = img.src.replace("mark_set", "mark_unset");
440 img.alt = __("Star article");
441 query = query + "&mark=0";
445 new Ajax.Request("backend.php", {
447 onComplete: function(transport) {
448 handle_rpc_json(transport);
453 exception_error("toggleMark", e);
457 function togglePub(id, client_only, no_effects, note) {
459 var query = "?op=rpc&id=" + id + "&method=publ";
461 if (note != undefined) {
462 query = query + "¬e=" + param_escape(note);
464 query = query + "¬e=undefined";
467 var img = $("FPPIC-" + id);
471 if (img.src.match("pub_unset") || note != undefined) {
472 img.src = img.src.replace("pub_unset", "pub_set");
473 img.alt = __("Unpublish article");
474 query = query + "&pub=1";
477 img.src = img.src.replace("pub_set", "pub_unset");
478 img.alt = __("Publish article");
480 query = query + "&pub=0";
484 new Ajax.Request("backend.php", {
486 onComplete: function(transport) {
487 handle_rpc_json(transport);
492 exception_error("togglePub", e);
496 function moveToPost(mode, noscroll) {
500 var rows = getVisibleArticleIds();
505 if (!$('RROW-' + getActiveArticleId())) {
506 setActiveArticleId(0);
509 if (!getActiveArticleId()) {
511 prev_id = rows[rows.length-1]
513 for (var i = 0; i < rows.length; i++) {
514 if (rows[i] == getActiveArticleId()) {
516 // Account for adjacent identical article ids.
517 if (i > 0) prev_id = rows[i-1];
519 for (var j = i+1; j < rows.length; j++) {
520 if (rows[j] != getActiveArticleId()) {
530 if (mode == "next") {
531 if (next_id || getActiveArticleId()) {
534 var article = $("RROW-" + getActiveArticleId());
535 var ctr = $("headlines-frame");
537 if (!noscroll && article && article.offsetTop + article.offsetHeight >
538 ctr.scrollTop + ctr.offsetHeight) {
540 scrollArticle(ctr.offsetHeight/2);
542 } else if (next_id) {
543 cdmExpandArticle(next_id);
544 cdmScrollToArticleId(next_id, noscroll);
547 } else if (next_id) {
548 correctHeadlinesOffset(next_id);
549 view(next_id, getActiveFeedId());
554 if (mode == "prev") {
555 if (prev_id || getActiveArticleId()) {
558 var article = $("RROW-" + getActiveArticleId());
559 var prev_article = $("RROW-" + prev_id);
560 var ctr = $("headlines-frame");
562 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
563 scrollArticle(-ctr.offsetHeight/3);
564 } else if (!noscroll && prev_article &&
565 prev_article.offsetTop < ctr.scrollTop) {
566 cdmExpandArticle(prev_id);
567 scrollArticle(-ctr.offsetHeight/3);
568 } else if (prev_id) {
569 cdmExpandArticle(prev_id);
570 cdmScrollToArticleId(prev_id, noscroll);
572 } else if (prev_id) {
573 correctHeadlinesOffset(prev_id);
574 view(prev_id, getActiveFeedId());
580 exception_error("moveToPost", e);
584 function toggleSelected(id, force_on) {
587 var cb = dijit.byId("RCHK-" + id);
588 var row = $("RROW-" + id);
591 if (row.hasClassName('Selected') && !force_on) {
592 row.removeClassName('Selected');
593 if (cb) cb.attr("checked", false);
595 row.addClassName('Selected');
596 if (cb) cb.attr("checked", true);
600 exception_error("toggleSelected", e);
604 function toggleUnread_afh(effect) {
607 var elem = effect.element;
608 elem.style.backgroundColor = "";
611 exception_error("toggleUnread_afh", e);
615 function toggleUnread(id, cmode, effect) {
618 var row = $("RROW-" + id);
620 if (cmode == undefined || cmode == 2) {
621 if (row.hasClassName("Unread")) {
622 row.removeClassName("Unread");
625 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
626 afterFinish: toggleUnread_afh,
627 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
631 row.addClassName("Unread");
634 } else if (cmode == 0) {
636 row.removeClassName("Unread");
639 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
640 afterFinish: toggleUnread_afh,
641 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
644 } else if (cmode == 1) {
645 row.addClassName("Unread");
648 if (cmode == undefined) cmode = 2;
650 var query = "?op=rpc&method=catchupSelected" +
651 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
653 // notify_progress("Loading, please wait...");
655 new Ajax.Request("backend.php", {
657 onComplete: function(transport) {
658 handle_rpc_json(transport);
664 exception_error("toggleUnread", e);
668 function selectionRemoveLabel(id, ids) {
671 if (!ids) ids = getSelectedArticleIds2();
673 if (ids.length == 0) {
674 alert(__("No articles are selected."));
678 var query = "?op=rpc&method=removeFromLabel&ids=" +
679 param_escape(ids.toString()) + "&lid=" + param_escape(id);
683 new Ajax.Request("backend.php", {
685 onComplete: function(transport) {
686 handle_rpc_json(transport);
687 show_labels_in_headlines(transport);
691 exception_error("selectionAssignLabel", e);
696 function selectionAssignLabel(id, ids) {
699 if (!ids) ids = getSelectedArticleIds2();
701 if (ids.length == 0) {
702 alert(__("No articles are selected."));
706 var query = "?op=rpc&method=assignToLabel&ids=" +
707 param_escape(ids.toString()) + "&lid=" + param_escape(id);
711 new Ajax.Request("backend.php", {
713 onComplete: function(transport) {
714 handle_rpc_json(transport);
715 show_labels_in_headlines(transport);
719 exception_error("selectionAssignLabel", e);
724 function selectionToggleUnread(set_state, callback, no_error) {
726 var rows = getSelectedArticleIds2();
728 if (rows.length == 0 && !no_error) {
729 alert(__("No articles are selected."));
733 for (var i = 0; i < rows.length; i++) {
734 var row = $("RROW-" + rows[i]);
736 if (set_state == undefined) {
737 if (row.hasClassName("Unread")) {
738 row.removeClassName("Unread");
740 row.addClassName("Unread");
744 if (set_state == false) {
745 row.removeClassName("Unread");
748 if (set_state == true) {
749 row.addClassName("Unread");
754 if (rows.length > 0) {
758 if (set_state == undefined) {
760 } else if (set_state == true) {
762 } else if (set_state == false) {
766 var query = "?op=rpc&method=catchupSelected" +
767 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
769 notify_progress("Loading, please wait...");
771 new Ajax.Request("backend.php", {
773 onComplete: function(transport) {
774 handle_rpc_json(transport);
775 if (callback) callback(transport);
781 exception_error("selectionToggleUnread", e);
785 function selectionToggleMarked() {
788 var rows = getSelectedArticleIds2();
790 if (rows.length == 0) {
791 alert(__("No articles are selected."));
795 for (var i = 0; i < rows.length; i++) {
796 toggleMark(rows[i], true, true);
799 if (rows.length > 0) {
801 var query = "?op=rpc&method=markSelected&ids=" +
802 param_escape(rows.toString()) + "&cmode=2";
804 new Ajax.Request("backend.php", {
806 onComplete: function(transport) {
807 handle_rpc_json(transport);
813 exception_error("selectionToggleMarked", e);
817 function selectionTogglePublished() {
820 var rows = getSelectedArticleIds2();
822 if (rows.length == 0) {
823 alert(__("No articles are selected."));
827 for (var i = 0; i < rows.length; i++) {
828 togglePub(rows[i], true, true);
831 if (rows.length > 0) {
833 var query = "?op=rpc&method=publishSelected&ids=" +
834 param_escape(rows.toString()) + "&cmode=2";
836 new Ajax.Request("backend.php", {
838 onComplete: function(transport) {
839 handle_rpc_json(transport);
845 exception_error("selectionToggleMarked", e);
849 function getSelectedArticleIds2() {
853 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
855 rv.push(child.id.replace("RROW-", ""));
861 function getLoadedArticleIds() {
864 var children = $$("#headlines-frame > div[id*=RROW-]");
866 children.each(function(child) {
867 rv.push(child.id.replace("RROW-", ""));
874 // mode = all,none,unread,invert,marked,published
875 function selectArticles(mode) {
878 var children = $$("#headlines-frame > div[id*=RROW]");
880 children.each(function(child) {
881 var id = child.id.replace("RROW-", "");
882 var cb = dijit.byId("RCHK-" + id);
885 child.addClassName("Selected");
886 if (cb) cb.attr("checked", true);
887 } else if (mode == "unread") {
888 if (child.hasClassName("Unread")) {
889 child.addClassName("Selected");
890 if (cb) cb.attr("checked", true);
892 child.removeClassName("Selected");
893 if (cb) cb.attr("checked", false);
895 } else if (mode == "marked") {
896 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
898 if (img && img.src.match("mark_set")) {
899 child.addClassName("Selected");
900 if (cb) cb.attr("checked", true);
902 child.removeClassName("Selected");
903 if (cb) cb.attr("checked", false);
905 } else if (mode == "published") {
906 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
908 if (img && img.src.match("pub_set")) {
909 child.addClassName("Selected");
910 if (cb) cb.attr("checked", true);
912 child.removeClassName("Selected");
913 if (cb) cb.attr("checked", false);
916 } else if (mode == "invert") {
917 if (child.hasClassName("Selected")) {
918 child.removeClassName("Selected");
919 if (cb) cb.attr("checked", false);
921 child.addClassName("Selected");
922 if (cb) cb.attr("checked", true);
926 child.removeClassName("Selected");
927 if (cb) cb.attr("checked", false);
932 exception_error("selectArticles", e);
936 function catchupPage() {
938 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
940 var str = __("Mark all visible articles in %s as read?");
942 str = str.replace("%s", fn);
944 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
948 selectArticles('all');
949 selectionToggleUnread(false, 'viewCurrentFeed()', true);
950 selectArticles('none');
953 function deleteSelection() {
957 var rows = getSelectedArticleIds2();
959 if (rows.length == 0) {
960 alert(__("No articles are selected."));
964 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
967 if (getActiveFeedId() != 0) {
968 str = __("Delete %d selected articles in %s?");
970 str = __("Delete %d selected articles?");
973 str = str.replace("%d", rows.length);
974 str = str.replace("%s", fn);
976 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
980 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
984 new Ajax.Request("backend.php", {
986 onComplete: function(transport) {
987 handle_rpc_json(transport);
992 exception_error("deleteSelection", e);
996 function archiveSelection() {
1000 var rows = getSelectedArticleIds2();
1002 if (rows.length == 0) {
1003 alert(__("No articles are selected."));
1007 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1011 if (getActiveFeedId() != 0) {
1012 str = __("Archive %d selected articles in %s?");
1015 str = __("Move %d archived articles back?");
1019 str = str.replace("%d", rows.length);
1020 str = str.replace("%s", fn);
1022 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1026 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1030 for (var i = 0; i < rows.length; i++) {
1031 cache_delete("article:" + rows[i]);
1034 new Ajax.Request("backend.php", {
1036 onComplete: function(transport) {
1037 handle_rpc_json(transport);
1042 exception_error("archiveSelection", e);
1046 function catchupSelection() {
1050 var rows = getSelectedArticleIds2();
1052 if (rows.length == 0) {
1053 alert(__("No articles are selected."));
1057 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1059 var str = __("Mark %d selected articles in %s as read?");
1061 str = str.replace("%d", rows.length);
1062 str = str.replace("%s", fn);
1064 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1068 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1071 exception_error("catchupSelection", e);
1075 function editArticleTags(id) {
1076 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1078 if (dijit.byId("editTagsDlg"))
1079 dijit.byId("editTagsDlg").destroyRecursive();
1081 dialog = new dijit.Dialog({
1083 title: __("Edit article Tags"),
1084 style: "width: 600px",
1085 execute: function() {
1086 if (this.validate()) {
1087 var query = dojo.objectToQuery(this.attr('value'));
1089 notify_progress("Saving article tags...", true);
1091 new Ajax.Request("backend.php", {
1093 onComplete: function(transport) {
1097 var data = JSON.parse(transport.responseText);
1100 var tags_str = article.tags;
1101 var id = tags_str.id;
1103 var tags = $("ATSTR-" + id);
1104 var tooltip = dijit.byId("ATSTRTIP-" + id);
1106 if (tags) tags.innerHTML = tags_str.content;
1107 if (tooltip) tooltip.attr('label', tags_str.content_full);
1109 cache_delete("article:" + id);
1118 var tmph = dojo.connect(dialog, 'onLoad', function() {
1119 dojo.disconnect(tmph);
1121 new Ajax.Autocompleter('tags_str', 'tags_choices',
1122 "backend.php?op=rpc&method=completeTags",
1123 { tokens: ',', paramName: "search" });
1130 function cdmScrollToArticleId(id, force) {
1132 var ctr = $("headlines-frame");
1133 var e = $("RROW-" + id);
1135 if (!e || !ctr) return;
1137 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1138 e.offsetTop < ctr.scrollTop) {
1139 ctr.scrollTop = e.offsetTop;
1143 exception_error("cdmScrollToArticleId", e);
1147 function setActiveArticleId(id) {
1148 _active_article_id = id;
1151 function getActiveArticleId() {
1152 return _active_article_id;
1155 function postMouseIn(id) {
1156 post_under_pointer = id;
1159 function postMouseOut(id) {
1160 post_under_pointer = false;
1163 function headlines_scroll_handler(e) {
1165 var hsp = $("headlines-spacer");
1167 if (!_infscroll_disable) {
1168 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1169 (e.scrollHeight != 0 &&
1170 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1173 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1174 __("Loading, please wait...");
1176 loadMoreHeadlines();
1181 if (hsp) hsp.innerHTML = "";
1184 if (getInitParam("cdm_auto_catchup") == 1) {
1186 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1188 if ($("headlines-frame").scrollTop >
1189 (child.offsetTop + child.offsetHeight/2)) {
1191 var id = child.id.replace("RROW-", "");
1193 if (catchup_id_batch.indexOf(id) == -1)
1194 catchup_id_batch.push(id);
1196 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1200 if (catchup_id_batch.length > 0) {
1201 window.clearTimeout(catchup_timeout_id);
1203 if (!_infscroll_request_sent) {
1204 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1211 console.warn("headlines_scroll_handler: " + e);
1215 function catchupBatchedArticles() {
1217 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1219 // make a copy of the array
1220 var batch = catchup_id_batch.slice();
1221 var query = "?op=rpc&method=catchupSelected" +
1222 "&cmode=0&ids=" + param_escape(batch.toString());
1226 new Ajax.Request("backend.php", {
1228 onComplete: function(transport) {
1229 handle_rpc_json(transport);
1231 batch.each(function(id) {
1232 var elem = $("RROW-" + id);
1233 if (elem) elem.removeClassName("Unread");
1234 catchup_id_batch.remove(id);
1241 exception_error("catchupBatchedArticles", e);
1245 function catchupRelativeToArticle(below, id) {
1249 if (!id) id = getActiveArticleId();
1252 alert(__("No article is selected."));
1256 var visible_ids = getVisibleArticleIds();
1258 var ids_to_mark = new Array();
1261 for (var i = 0; i < visible_ids.length; i++) {
1262 if (visible_ids[i] != id) {
1263 var e = $("RROW-" + visible_ids[i]);
1265 if (e && e.hasClassName("Unread")) {
1266 ids_to_mark.push(visible_ids[i]);
1273 for (var i = visible_ids.length-1; i >= 0; i--) {
1274 if (visible_ids[i] != id) {
1275 var e = $("RROW-" + visible_ids[i]);
1277 if (e && e.hasClassName("Unread")) {
1278 ids_to_mark.push(visible_ids[i]);
1286 if (ids_to_mark.length == 0) {
1287 alert(__("No articles found to mark"));
1289 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1291 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1293 for (var i = 0; i < ids_to_mark.length; i++) {
1294 var e = $("RROW-" + ids_to_mark[i]);
1295 e.removeClassName("Unread");
1298 var query = "?op=rpc&method=catchupSelected" +
1299 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1301 new Ajax.Request("backend.php", {
1303 onComplete: function(transport) {
1304 handle_rpc_json(transport);
1311 exception_error("catchupRelativeToArticle", e);
1315 function cdmCollapseArticle(event, id) {
1317 var row = $("RROW-" + id);
1318 var elem = $("CICD-" + id);
1321 var collapse = $$("div#RROW-" + id +
1322 " span[class='collapseBtn']")[0];
1325 Element.show("CEXC-" + id);
1326 Element.hide(collapse);
1328 markHeadline(id, false);
1330 if (id == getActiveArticleId()) {
1331 setActiveArticleId(0);
1334 if (event) Event.stop(event);
1338 exception_error("cdmCollapseArticle", e);
1342 function cdmExpandArticle(id) {
1345 console.log("cdmExpandArticle " + id);
1349 var elem = $("CICD-" + getActiveArticleId());
1351 if (id == getActiveArticleId() && Element.visible(elem))
1354 selectArticles("none");
1356 var old_offset = $("RROW-" + id).offsetTop;
1358 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1359 var collapse = $$("div#RROW-" + getActiveArticleId() +
1360 " span[class='collapseBtn']")[0];
1363 Element.show("CEXC-" + getActiveArticleId());
1364 Element.hide(collapse);
1367 setActiveArticleId(id);
1368 cdmScrollToArticleId(id, true);
1370 elem = $("CICD-" + id);
1372 var collapse = $$("div#RROW-" + id +
1373 " span[class='collapseBtn']")[0];
1375 var cencw = $("CENCW-" + id);
1377 if (!Element.visible(elem)) {
1379 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1380 cencw.setAttribute('id', '');
1384 Element.hide("CEXC-" + id);
1385 Element.show(collapse);
1388 /* var new_offset = $("RROW-" + id).offsetTop;
1390 $("headlines-frame").scrollTop += (new_offset-old_offset);
1392 if ($("RROW-" + id).offsetTop != old_offset)
1393 $("headlines-frame").scrollTop = new_offset; */
1395 toggleUnread(id, 0, true);
1399 exception_error("cdmExpandArticle", e);
1405 function fixHeadlinesOrder(ids) {
1407 for (var i = 0; i < ids.length; i++) {
1408 var e = $("RROW-" + ids[i]);
1412 e.removeClassName("even");
1413 e.addClassName("odd");
1415 e.removeClassName("odd");
1416 e.addClassName("even");
1421 exception_error("fixHeadlinesOrder", e);
1425 function getArticleUnderPointer() {
1426 return post_under_pointer;
1429 function scrollArticle(offset) {
1432 var ci = $("content-insert");
1434 ci.scrollTop += offset;
1437 var hi = $("headlines-frame");
1439 hi.scrollTop += offset;
1444 exception_error("scrollArticle", e);
1448 function show_labels_in_headlines(transport) {
1450 var data = JSON.parse(transport.responseText);
1453 data['info-for-headlines'].each(function(elem) {
1454 var ctr = $("HLLCTR-" + elem.id);
1456 if (ctr) ctr.innerHTML = elem.labels;
1460 exception_error("show_labels_in_headlines", e);
1464 function dismissArticle(id) {
1466 var elem = $("RROW-" + id);
1468 toggleUnread(id, 0, true);
1470 new Effect.Fade(elem, {duration : 0.5});
1472 if (id == getActiveArticleId()) {
1473 setActiveArticleId(0);
1477 exception_error("dismissArticle", e);
1481 function dismissSelectedArticles() {
1484 var ids = getVisibleArticleIds();
1488 for (var i = 0; i < ids.length; i++) {
1489 var elem = $("RROW-" + ids[i]);
1491 if (elem.className && elem.hasClassName("Selected") &&
1492 ids[i] != getActiveArticleId()) {
1493 new Effect.Fade(elem, {duration : 0.5});
1501 selectionToggleUnread(false);
1503 fixHeadlinesOrder(tmp);
1506 exception_error("dismissSelectedArticles", e);
1510 function dismissReadArticles() {
1513 var ids = getVisibleArticleIds();
1516 for (var i = 0; i < ids.length; i++) {
1517 var elem = $("RROW-" + ids[i]);
1519 if (elem.className && !elem.hasClassName("Unread") &&
1520 !elem.hasClassName("Selected")) {
1522 new Effect.Fade(elem, {duration : 0.5});
1528 fixHeadlinesOrder(tmp);
1531 exception_error("dismissSelectedArticles", e);
1535 function getVisibleArticleIds() {
1540 getLoadedArticleIds().each(function(id) {
1541 var elem = $("RROW-" + id);
1542 if (elem && Element.visible(elem))
1547 exception_error("getVisibleArticleIds", e);
1553 function cdmClicked(event, id) {
1555 //var shift_key = event.shiftKey;
1559 if (!event.ctrlKey) {
1561 if (!getInitParam("cdm_expanded")) {
1562 return cdmExpandArticle(id);
1565 selectArticles("none");
1568 var elem = $("RROW-" + id);
1569 var article_is_unread = elem.hasClassName("Unread");
1572 elem.removeClassName("Unread");
1574 setActiveArticleId(id);
1576 if (article_is_unread) {
1577 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1580 var query = "?op=rpc&method=catchupSelected" +
1581 "&cmode=0&ids=" + param_escape(id);
1583 new Ajax.Request("backend.php", {
1585 onComplete: function(transport) {
1586 handle_rpc_json(transport);
1589 return !event.shiftKey;
1593 toggleSelected(id, true);
1595 var elem = $("RROW-" + id);
1596 var article_is_unread = elem.hasClassName("Unread");
1598 if (article_is_unread) {
1599 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1602 toggleUnread(id, 0, false);
1604 openArticleInNewWindow(id);
1607 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1608 request_counters(unread_in_buffer == 0);
1611 exception_error("cdmClicked");
1617 function hlClicked(event, id) {
1619 if (event.which == 2) {
1622 } else if (event.ctrlKey) {
1623 toggleSelected(id, true);
1624 toggleUnread(id, 0, false);
1625 openArticleInNewWindow(id);
1633 exception_error("hlClicked");
1637 function getFirstVisibleHeadlineId() {
1638 var rows = getVisibleArticleIds();
1643 function getLastVisibleHeadlineId() {
1644 var rows = getVisibleArticleIds();
1645 return rows[rows.length-1];
1648 function openArticleInNewWindow(id) {
1649 toggleUnread(id, 0, false);
1650 window.open("backend.php?op=article&method=redirect&id=" + id);
1653 function isCdmMode() {
1654 return getInitParam("combined_display_mode");
1657 function markHeadline(id, marked) {
1658 if (marked == undefined) marked = true;
1660 var row = $("RROW-" + id);
1662 var check = dijit.byId("RCHK-" + id);
1665 check.attr("checked", marked);
1669 row.addClassName("Selected");
1671 row.removeClassName("Selected");
1675 function getRelativePostIds(id, limit) {
1681 if (!limit) limit = 6; //3
1683 var ids = getVisibleArticleIds();
1685 for (var i = 0; i < ids.length; i++) {
1687 for (var k = 1; k <= limit; k++) {
1688 //if (i > k-1) tmp.push(ids[i-k]);
1689 if (i < ids.length-k) tmp.push(ids[i+k]);
1696 exception_error("getRelativePostIds", e);
1702 function correctHeadlinesOffset(id) {
1706 var container = $("headlines-frame");
1707 var row = $("RROW-" + id);
1709 if (!container || !row) return;
1711 var viewport = container.offsetHeight;
1713 var rel_offset_top = row.offsetTop - container.scrollTop;
1714 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1716 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1717 //console.log("Vport: " + viewport);
1719 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1720 container.scrollTop = row.offsetTop;
1721 } else if (rel_offset_bottom > viewport) {
1723 /* doesn't properly work with Opera in some cases because
1724 Opera fucks up element scrolling */
1726 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1730 exception_error("correctHeadlinesOffset", e);
1735 function headlineActionsChange(elem) {
1738 elem.attr('value', 'false');
1740 exception_error("headlineActionsChange", e);
1744 function closeArticlePanel() {
1746 if (dijit.byId("content-insert"))
1747 dijit.byId("headlines-wrap-inner").removeChild(
1748 dijit.byId("content-insert"));
1751 function initHeadlinesMenu() {
1753 if (dijit.byId("headlinesMenu"))
1754 dijit.byId("headlinesMenu").destroyRecursive();
1759 nodes = $$("#headlines-frame > div[id*=RROW]");
1761 nodes = $$("#headlines-frame span[id*=RTITLE]");
1764 nodes.each(function(node) {
1768 var menu = new dijit.Menu({
1769 id: "headlinesMenu",
1773 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1774 var callerNode = event.target, match = null, tries = 0;
1776 while (match == null && callerNode && tries <= 3) {
1777 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1778 callerNode = callerNode.parentNode;
1782 if (match) this.callerRowId = parseInt(match[1]);
1786 /* if (!isCdmMode())
1787 menu.addChild(new dijit.MenuItem({
1788 label: __("View article"),
1789 onClick: function(event) {
1790 view(this.getParent().callerRowId);
1793 menu.addChild(new dijit.MenuItem({
1794 label: __("Open original article"),
1795 onClick: function(event) {
1796 openArticleInNewWindow(this.getParent().callerRowId);
1799 menu.addChild(new dijit.MenuSeparator());
1801 menu.addChild(new dijit.MenuItem({
1802 label: __("Mark above as read"),
1803 onClick: function(event) {
1804 catchupRelativeToArticle(0, this.getParent().callerRowId);
1807 menu.addChild(new dijit.MenuItem({
1808 label: __("Mark below as read"),
1809 onClick: function(event) {
1810 catchupRelativeToArticle(1, this.getParent().callerRowId);
1814 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1818 menu.addChild(new dijit.MenuSeparator());
1820 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1821 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1823 labels.each(function(label) {
1824 var id = label.id[0];
1825 var bare_id = id.substr(id.indexOf(":")+1);
1826 var name = label.name[0];
1828 bare_id = -11-bare_id;
1830 labelAddMenu.addChild(new dijit.MenuItem({
1833 onClick: function(event) {
1834 var ids = getSelectedArticleIds2();
1836 var id = this.getParent().ownerMenu.callerRowId + "";
1838 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1840 selectionAssignLabel(this.labelId, ids);
1843 labelDelMenu.addChild(new dijit.MenuItem({
1846 onClick: function(event) {
1847 var ids = getSelectedArticleIds2();
1849 var id = this.getParent().ownerMenu.callerRowId + "";
1851 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1853 selectionRemoveLabel(this.labelId, ids);
1858 menu.addChild(new dijit.PopupMenuItem({
1859 label: __("Assign label"),
1860 popup: labelAddMenu,
1863 menu.addChild(new dijit.PopupMenuItem({
1864 label: __("Remove label"),
1865 popup: labelDelMenu,
1873 exception_error("initHeadlinesMenu", e);
1878 function player(elem) {
1879 var aid = elem.getAttribute("audio-id");
1880 var status = elem.getAttribute("status");
1888 elem.innerHTML = __("Playing...");
1889 elem.title = __("Click to pause");
1890 elem.addClassName("playing");
1894 elem.innerHTML = __("Play");
1895 elem.title = __("Click to play");
1896 elem.removeClassName("playing");
1899 elem.setAttribute("status", status);
1901 alert("Your browser doesn't seem to support HTML5 audio.");
1905 function cache_set(id, obj) {
1906 //console.log("cache_set: " + id);
1909 sessionStorage[id] = obj;
1911 sessionStorage.clear();
1915 function cache_get(id) {
1917 return sessionStorage[id];
1920 function cache_clear() {
1922 sessionStorage.clear();
1925 function cache_delete(id) {
1927 sessionStorage.removeItem(id);
1930 function cancelSearch() {
1935 exception_error("cancelSearch", e);
1939 function setSelectionScore() {
1941 var ids = getSelectedArticleIds2();
1943 if (ids.length > 0) {
1946 var score = prompt(__("Please enter new score for selected articles:"), score);
1948 if (score != undefined) {
1949 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
1950 "&score=" + param_escape(score);
1952 new Ajax.Request("backend.php", {
1954 onComplete: function(transport) {
1955 var reply = JSON.parse(transport.responseText);
1959 ids.each(function(id) {
1960 var row = $("RROW-" + id);
1963 var pic = row.getElementsByClassName("hlScorePic")[0];
1966 pic.src = pic.src.replace(/score_.*?\.png/,
1967 reply["score_pic"]);
1968 pic.setAttribute("score", score);
1977 alert(__("No articles are selected."));
1980 exception_error("setSelectionScore", e);
1984 function changeScore(id, pic) {
1986 var score = pic.getAttribute("score");
1988 var new_score = prompt(__("Please enter new score for this article:"), score);
1990 if (new_score != undefined) {
1992 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
1993 "&score=" + param_escape(new_score);
1995 new Ajax.Request("backend.php", {
1997 onComplete: function(transport) {
1998 var reply = JSON.parse(transport.responseText);
2001 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2002 pic.setAttribute("score", new_score);
2007 exception_error("changeScore", e);