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 _post_preview_timeout = false;
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>";
53 setActiveFeedId(feed_id, is_cat);
55 dijit.getEnclosingWidget(
56 document.forms["main_toolbar_form"].update).attr('disabled',
57 is_cat || feed_id <= 0);
60 if (infscroll_req == false) {
61 $("headlines-frame").scrollTop = 0;
65 var headlines_count = reply['headlines-info']['count'];
67 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
69 if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
70 _infscroll_disable = 1;
72 _infscroll_disable = 0;
75 var counters = reply['counters'];
76 var articles = reply['articles'];
77 //var runtime_info = reply['runtime-info'];
79 if (infscroll_req == false) {
80 loaded_article_ids = [];
82 dijit.byId("headlines-frame").attr('content',
83 reply['headlines']['content']);
85 dijit.byId("headlines-toolbar").attr('content',
86 reply['headlines']['toolbar']);
88 $$("#headlines-frame > div[id*=RROW]").each(function(row) {
89 if (loaded_article_ids.indexOf(row.id) != -1) {
90 row.parentNode.removeChild(row);
92 loaded_article_ids.push(row.id);
96 if (getInitParam("cdm_auto_catchup") == 1) {
97 var hsp = $("headlines-spacer");
98 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
99 dijit.byId('headlines-frame').domNode.appendChild(hsp);
105 $("feed_title").innerHTML += "<span id='cancel_search'>" +
106 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
112 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
113 console.log("adding some more headlines: " + headlines_count);
115 var c = dijit.byId("headlines-frame");
116 var ids = getSelectedArticleIds2();
119 $("headlines-tmp").innerHTML = reply['headlines']['content'];
121 var hsp = $("headlines-spacer");
124 c.domNode.removeChild(hsp);
126 $$("#headlines-tmp > div").each(function(row) {
127 if (row.className == 'cdmFeedTitle') {
128 row.style.display = 'none';
129 c.domNode.appendChild(row);
131 } else if (loaded_article_ids.indexOf(row.id) == -1) {
132 row.style.display = 'none';
133 c.domNode.appendChild(row);
135 loaded_article_ids.push(row.id);
137 row.parentNode.removeChild(row);
141 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
143 fixHeadlinesOrder(getLoadedArticleIds());
145 if (getInitParam("cdm_auto_catchup") == 1) {
146 c.domNode.appendChild(hsp);
149 console.log("added " + new_elems.size() + " headlines");
151 if (new_elems.size() == 0)
152 _infscroll_disable = true;
154 console.log("restore selected ids: " + ids);
156 for (var i = 0; i < ids.length; i++) {
157 markHeadline(ids[i]);
162 new_elems.each(function(child) {
163 var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
166 dojo.parser.parse(child);
168 if (!Element.visible(child))
169 new Effect.Appear(child, { duration : 0.5 });
171 c.domNode.removeChild(child);
176 console.log("no new headlines received");
178 var hsp = $("headlines-spacer");
180 if (hsp) hsp.innerHTML = "";
185 for (var i = 0; i < articles.length; i++) {
186 var a_id = articles[i]['id'];
187 cache_set("article:" + a_id, articles[i]['content']);
190 console.log("no cached articles received");
194 parse_counters(counters);
196 request_counters(true);
198 } else if (transport.responseText) {
199 console.error("Invalid object received: " + transport.responseText);
200 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
201 __('Could not update headlines (invalid object received - see error console for details)') +
204 //notify_error("Error communicating with server.");
205 Element.show(dijit.byId("net-alert").domNode);
208 _infscroll_request_sent = 0;
210 unpackVisibleHeadlines();
215 exception_error("headlines_callback2", e, transport);
219 function render_article(article) {
221 dijit.byId("headlines-wrap-inner").addChild(
222 dijit.byId("content-insert"));
224 var c = dijit.byId("content-insert");
227 c.domNode.scrollTop = 0;
230 c.attr('content', article);
232 correctHeadlinesOffset(getActiveArticleId());
239 exception_error("render_article", e);
243 function showArticleInHeadlines(id) {
247 selectArticles("none");
249 var crow = $("RROW-" + id);
253 var article_is_unread = crow.hasClassName("Unread");
255 crow.removeClassName("Unread");
257 selectArticles('none');
259 var view_mode = false;
262 view_mode = document.forms['main_toolbar_form'].view_mode;
263 view_mode = view_mode[view_mode.selectedIndex].value;
270 if (article_is_unread)
271 _force_scheduled_update = true;
274 exception_error("showArticleInHeadlines", e);
278 function article_callback2(transport, id) {
280 console.log("article_callback2 " + id);
282 handle_rpc_json(transport);
287 reply = JSON.parse(transport.responseText);
294 reply.each(function(article) {
295 if (getActiveArticleId() == article['id']) {
296 render_article(article['content']);
298 cids_requested.remove(article['id']);
300 cache_set("article:" + article['id'], article['content']);
303 // if (id != last_requested_article) {
304 // console.log("requested article id is out of sequence, aborting");
308 } else if (transport.responseText) {
309 console.error("Invalid object received: " + transport.responseText);
311 render_article("<div class='whiteBox'>" +
312 __('Could not display article (invalid object received - see error console for details)') + "</div>");
314 Element.show(dijit.byId("net-alert").domNode);
317 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
318 request_counters(unread_in_buffer == 0);
320 //headlines_scroll_handler($("headlines-frame"));
323 if (!_infscroll_disable &&
324 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
334 exception_error("article_callback2", e, transport);
340 var crow = $("RROW-" + id);
344 console.log("loading article: " + id);
346 var cached_article = cache_get("article:" + id);
348 console.log("cache check result: " + (cached_article != false));
352 var query = "?op=article&method=view&id=" + param_escape(id);
354 var neighbor_ids = getRelativePostIds(id);
356 /* only request uncached articles */
358 var cids_to_request = [];
360 for (var i = 0; i < neighbor_ids.length; i++) {
361 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
362 if (!cache_get("article:" + neighbor_ids[i])) {
363 cids_to_request.push(neighbor_ids[i]);
364 cids_requested.push(neighbor_ids[i]);
368 console.log("additional ids: " + cids_to_request.toString());
370 query = query + "&cids=" + cids_to_request.toString();
372 var article_is_unread = crow.hasClassName("Unread");
374 setActiveArticleId(id);
375 showArticleInHeadlines(id);
377 if (cached_article && article_is_unread) {
379 query = query + "&mode=prefetch";
381 render_article(cached_article);
383 } else if (cached_article) {
385 query = query + "&mode=prefetch_old";
386 render_article(cached_article);
388 // if we don't need to request any relative ids, we might as well skip
389 // the server roundtrip altogether
390 if (cids_to_request.length == 0) {
393 if (!_infscroll_disable &&
394 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
402 //headlines_scroll_handler($("headlines-frame"));
408 last_requested_article = id;
412 if (article_is_unread) {
413 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
416 new Ajax.Request("backend.php", {
418 onComplete: function(transport) {
419 article_callback2(transport, id);
425 exception_error("view", e);
429 function toggleMark(id, client_only) {
431 var query = "?op=rpc&id=" + id + "&method=mark";
433 var img = $("FMPIC-" + id);
437 if (img.src.match("mark_unset")) {
438 img.src = img.src.replace("mark_unset", "mark_set");
439 img.alt = __("Unstar article");
440 query = query + "&mark=1";
443 img.src = img.src.replace("mark_set", "mark_unset");
444 img.alt = __("Star article");
445 query = query + "&mark=0";
449 new Ajax.Request("backend.php", {
451 onComplete: function(transport) {
452 handle_rpc_json(transport);
457 exception_error("toggleMark", e);
461 function togglePub(id, client_only, no_effects, note) {
463 var query = "?op=rpc&id=" + id + "&method=publ";
465 if (note != undefined) {
466 query = query + "¬e=" + param_escape(note);
468 query = query + "¬e=undefined";
471 var img = $("FPPIC-" + id);
475 if (img.src.match("pub_unset") || note != undefined) {
476 img.src = img.src.replace("pub_unset", "pub_set");
477 img.alt = __("Unpublish article");
478 query = query + "&pub=1";
481 img.src = img.src.replace("pub_set", "pub_unset");
482 img.alt = __("Publish article");
484 query = query + "&pub=0";
488 new Ajax.Request("backend.php", {
490 onComplete: function(transport) {
491 handle_rpc_json(transport);
496 exception_error("togglePub", e);
500 function moveToPost(mode, noscroll) {
504 var rows = getVisibleArticleIds();
509 if (!$('RROW-' + getActiveArticleId())) {
510 setActiveArticleId(0);
513 if (!getActiveArticleId()) {
515 prev_id = rows[rows.length-1]
517 for (var i = 0; i < rows.length; i++) {
518 if (rows[i] == getActiveArticleId()) {
520 // Account for adjacent identical article ids.
521 if (i > 0) prev_id = rows[i-1];
523 for (var j = i+1; j < rows.length; j++) {
524 if (rows[j] != getActiveArticleId()) {
534 if (mode == "next") {
535 if (next_id || getActiveArticleId()) {
538 var article = $("RROW-" + getActiveArticleId());
539 var ctr = $("headlines-frame");
541 if (!noscroll && article && article.offsetTop + article.offsetHeight >
542 ctr.scrollTop + ctr.offsetHeight) {
544 scrollArticle(ctr.offsetHeight/2);
546 } else if (next_id) {
547 cdmExpandArticle(next_id);
548 cdmScrollToArticleId(next_id, true);
551 } else if (next_id) {
552 correctHeadlinesOffset(next_id);
553 view(next_id, getActiveFeedId());
558 if (mode == "prev") {
559 if (prev_id || getActiveArticleId()) {
562 var article = $("RROW-" + getActiveArticleId());
563 var prev_article = $("RROW-" + prev_id);
564 var ctr = $("headlines-frame");
566 if (!getInitParam("cdm_expanded")) {
568 if (!noscroll && article.offsetTop < ctr.scrollTop) {
569 scrollArticle(-ctr.offsetHeight/3);
571 cdmExpandArticle(prev_id);
572 cdmScrollToArticleId(prev_id, true);
576 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
577 scrollArticle(-ctr.offsetHeight/3);
578 } else if (!noscroll && prev_article &&
579 prev_article.offsetTop < ctr.scrollTop) {
580 cdmExpandArticle(prev_id);
581 scrollArticle(-ctr.offsetHeight/3);
582 } else if (prev_id) {
583 cdmExpandArticle(prev_id);
584 cdmScrollToArticleId(prev_id, noscroll);
588 } else if (prev_id) {
589 correctHeadlinesOffset(prev_id);
590 view(prev_id, getActiveFeedId());
596 exception_error("moveToPost", e);
600 function toggleSelected(id, force_on) {
603 var cb = dijit.byId("RCHK-" + id);
604 var row = $("RROW-" + id);
607 if (row.hasClassName('Selected') && !force_on) {
608 row.removeClassName('Selected');
609 if (cb) cb.attr("checked", false);
611 row.addClassName('Selected');
612 if (cb) cb.attr("checked", true);
616 exception_error("toggleSelected", e);
620 function toggleUnread_afh(effect) {
623 var elem = effect.element;
624 elem.style.backgroundColor = "";
627 exception_error("toggleUnread_afh", e);
631 function toggleUnread(id, cmode, effect) {
634 var row = $("RROW-" + id);
636 if (cmode == undefined || cmode == 2) {
637 if (row.hasClassName("Unread")) {
638 row.removeClassName("Unread");
641 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
642 afterFinish: toggleUnread_afh,
643 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
647 row.addClassName("Unread");
650 } else if (cmode == 0) {
652 row.removeClassName("Unread");
655 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
656 afterFinish: toggleUnread_afh,
657 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
660 } else if (cmode == 1) {
661 row.addClassName("Unread");
664 if (cmode == undefined) cmode = 2;
666 var query = "?op=rpc&method=catchupSelected" +
667 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
669 // notify_progress("Loading, please wait...");
671 new Ajax.Request("backend.php", {
673 onComplete: function(transport) {
674 handle_rpc_json(transport);
680 exception_error("toggleUnread", e);
684 function selectionRemoveLabel(id, ids) {
687 if (!ids) ids = getSelectedArticleIds2();
689 if (ids.length == 0) {
690 alert(__("No articles are selected."));
694 var query = "?op=rpc&method=removeFromLabel&ids=" +
695 param_escape(ids.toString()) + "&lid=" + param_escape(id);
699 new Ajax.Request("backend.php", {
701 onComplete: function(transport) {
702 handle_rpc_json(transport);
703 show_labels_in_headlines(transport);
707 exception_error("selectionAssignLabel", e);
712 function selectionAssignLabel(id, ids) {
715 if (!ids) ids = getSelectedArticleIds2();
717 if (ids.length == 0) {
718 alert(__("No articles are selected."));
722 var query = "?op=rpc&method=assignToLabel&ids=" +
723 param_escape(ids.toString()) + "&lid=" + param_escape(id);
727 new Ajax.Request("backend.php", {
729 onComplete: function(transport) {
730 handle_rpc_json(transport);
731 show_labels_in_headlines(transport);
735 exception_error("selectionAssignLabel", e);
740 function selectionToggleUnread(set_state, callback, no_error) {
742 var rows = getSelectedArticleIds2();
744 if (rows.length == 0 && !no_error) {
745 alert(__("No articles are selected."));
749 for (var i = 0; i < rows.length; i++) {
750 var row = $("RROW-" + rows[i]);
752 if (set_state == undefined) {
753 if (row.hasClassName("Unread")) {
754 row.removeClassName("Unread");
756 row.addClassName("Unread");
760 if (set_state == false) {
761 row.removeClassName("Unread");
764 if (set_state == true) {
765 row.addClassName("Unread");
770 if (rows.length > 0) {
774 if (set_state == undefined) {
776 } else if (set_state == true) {
778 } else if (set_state == false) {
782 var query = "?op=rpc&method=catchupSelected" +
783 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
785 notify_progress("Loading, please wait...");
787 new Ajax.Request("backend.php", {
789 onComplete: function(transport) {
790 handle_rpc_json(transport);
791 if (callback) callback(transport);
797 exception_error("selectionToggleUnread", e);
801 function selectionToggleMarked() {
804 var rows = getSelectedArticleIds2();
806 if (rows.length == 0) {
807 alert(__("No articles are selected."));
811 for (var i = 0; i < rows.length; i++) {
812 toggleMark(rows[i], true, true);
815 if (rows.length > 0) {
817 var query = "?op=rpc&method=markSelected&ids=" +
818 param_escape(rows.toString()) + "&cmode=2";
820 new Ajax.Request("backend.php", {
822 onComplete: function(transport) {
823 handle_rpc_json(transport);
829 exception_error("selectionToggleMarked", e);
833 function selectionTogglePublished() {
836 var rows = getSelectedArticleIds2();
838 if (rows.length == 0) {
839 alert(__("No articles are selected."));
843 for (var i = 0; i < rows.length; i++) {
844 togglePub(rows[i], true, true);
847 if (rows.length > 0) {
849 var query = "?op=rpc&method=publishSelected&ids=" +
850 param_escape(rows.toString()) + "&cmode=2";
852 new Ajax.Request("backend.php", {
854 onComplete: function(transport) {
855 handle_rpc_json(transport);
861 exception_error("selectionToggleMarked", e);
865 function getSelectedArticleIds2() {
869 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
871 rv.push(child.id.replace("RROW-", ""));
877 function getLoadedArticleIds() {
880 var children = $$("#headlines-frame > div[id*=RROW-]");
882 children.each(function(child) {
883 rv.push(child.id.replace("RROW-", ""));
890 // mode = all,none,unread,invert,marked,published
891 function selectArticles(mode) {
894 var children = $$("#headlines-frame > div[id*=RROW]");
896 children.each(function(child) {
897 var id = child.id.replace("RROW-", "");
898 var cb = dijit.byId("RCHK-" + id);
901 child.addClassName("Selected");
902 if (cb) cb.attr("checked", true);
903 } else if (mode == "unread") {
904 if (child.hasClassName("Unread")) {
905 child.addClassName("Selected");
906 if (cb) cb.attr("checked", true);
908 child.removeClassName("Selected");
909 if (cb) cb.attr("checked", false);
911 } else if (mode == "marked") {
912 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
914 if (img && img.src.match("mark_set")) {
915 child.addClassName("Selected");
916 if (cb) cb.attr("checked", true);
918 child.removeClassName("Selected");
919 if (cb) cb.attr("checked", false);
921 } else if (mode == "published") {
922 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
924 if (img && img.src.match("pub_set")) {
925 child.addClassName("Selected");
926 if (cb) cb.attr("checked", true);
928 child.removeClassName("Selected");
929 if (cb) cb.attr("checked", false);
932 } else if (mode == "invert") {
933 if (child.hasClassName("Selected")) {
934 child.removeClassName("Selected");
935 if (cb) cb.attr("checked", false);
937 child.addClassName("Selected");
938 if (cb) cb.attr("checked", true);
942 child.removeClassName("Selected");
943 if (cb) cb.attr("checked", false);
948 exception_error("selectArticles", e);
952 function catchupPage() {
954 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
956 var str = __("Mark all visible articles in %s as read?");
958 str = str.replace("%s", fn);
960 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
964 selectArticles('all');
965 selectionToggleUnread(false, 'viewCurrentFeed()', true);
966 selectArticles('none');
969 function deleteSelection() {
973 var rows = getSelectedArticleIds2();
975 if (rows.length == 0) {
976 alert(__("No articles are selected."));
980 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
983 if (getActiveFeedId() != 0) {
984 str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows.length);
986 str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
989 str = str.replace("%d", rows.length);
990 str = str.replace("%s", fn);
992 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
996 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
1000 new Ajax.Request("backend.php", {
1002 onComplete: function(transport) {
1003 handle_rpc_json(transport);
1008 exception_error("deleteSelection", e);
1012 function archiveSelection() {
1016 var rows = getSelectedArticleIds2();
1018 if (rows.length == 0) {
1019 alert(__("No articles are selected."));
1023 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1027 if (getActiveFeedId() != 0) {
1028 str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
1031 str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
1035 str = str.replace("%d", rows.length);
1036 str = str.replace("%s", fn);
1038 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1042 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1046 for (var i = 0; i < rows.length; i++) {
1047 cache_delete("article:" + rows[i]);
1050 new Ajax.Request("backend.php", {
1052 onComplete: function(transport) {
1053 handle_rpc_json(transport);
1058 exception_error("archiveSelection", e);
1062 function catchupSelection() {
1066 var rows = getSelectedArticleIds2();
1068 if (rows.length == 0) {
1069 alert(__("No articles are selected."));
1073 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1075 var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
1077 str = str.replace("%d", rows.length);
1078 str = str.replace("%s", fn);
1080 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1084 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1087 exception_error("catchupSelection", e);
1091 function editArticleTags(id) {
1092 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1094 if (dijit.byId("editTagsDlg"))
1095 dijit.byId("editTagsDlg").destroyRecursive();
1097 dialog = new dijit.Dialog({
1099 title: __("Edit article Tags"),
1100 style: "width: 600px",
1101 execute: function() {
1102 if (this.validate()) {
1103 var query = dojo.objectToQuery(this.attr('value'));
1105 notify_progress("Saving article tags...", true);
1107 new Ajax.Request("backend.php", {
1109 onComplete: function(transport) {
1113 var data = JSON.parse(transport.responseText);
1116 var tags_str = article.tags;
1117 var id = tags_str.id;
1119 var tags = $("ATSTR-" + id);
1120 var tooltip = dijit.byId("ATSTRTIP-" + id);
1122 if (tags) tags.innerHTML = tags_str.content;
1123 if (tooltip) tooltip.attr('label', tags_str.content_full);
1125 cache_delete("article:" + id);
1134 var tmph = dojo.connect(dialog, 'onLoad', function() {
1135 dojo.disconnect(tmph);
1137 new Ajax.Autocompleter('tags_str', 'tags_choices',
1138 "backend.php?op=rpc&method=completeTags",
1139 { tokens: ',', paramName: "search" });
1146 function cdmScrollToArticleId(id, force) {
1148 var ctr = $("headlines-frame");
1149 var e = $("RROW-" + id);
1151 if (!e || !ctr) return;
1153 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1154 e.offsetTop < ctr.scrollTop) {
1155 ctr.scrollTop = e.offsetTop;
1159 exception_error("cdmScrollToArticleId", e);
1163 function setActiveArticleId(id) {
1164 _active_article_id = id;
1167 function getActiveArticleId() {
1168 return _active_article_id;
1171 function postMouseIn(e, id) {
1172 post_under_pointer = id;
1174 if (_post_preview_timeout) window.clearTimeout(_post_preview_timeout);
1176 if (!isCdmMode() || !getInitParam("cdm_expanded")) {
1177 _post_preview_timeout = window.setTimeout(function() {
1178 displaySmallArticlePreview(e, id);
1183 function displaySmallArticlePreview(e, id) {
1185 var query = "?op=rpc&method=cdmarticlepreview&id=" + id;
1187 new Ajax.Request("backend.php", {
1189 onComplete: function(transport) {
1190 cexc = $("CEXC-" + id);
1191 preview = $("small_article_preview");
1192 row = $("RROW-" + id);
1194 if (id != getActiveArticleId() && (!isCdmMode() || (cexc && Element.visible(cexc))) && row && preview) {
1195 preview.innerHTML = transport.responseText;
1196 new Effect.Appear(preview, {duration:0.2});
1199 left: (e.clientX + 20) + 'px',
1200 top: (Element.cumulativeOffset(row)[1] + row.offsetHeight + 10) + 'px' });
1208 exception_error("displaySmallArticlePreview", e);
1212 function postMouseOut(id) {
1213 post_under_pointer = false;
1215 if (_post_preview_timeout) window.clearTimeout(_post_preview_timeout);
1217 if (Element.visible("small_article_preview"))
1218 Element.hide("small_article_preview");
1221 function unpackVisibleHeadlines() {
1224 if (!isCdmMode()) return;
1226 $$("#headlines-frame > div[id*=RROW]").each(
1228 if (child.offsetTop <= $("headlines-frame").scrollTop +
1229 $("headlines-frame").offsetHeight) {
1231 var cencw = $("CENCW-" + child.id.replace("RROW-", ""));
1234 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1235 cencw.setAttribute('id', '');
1236 Element.show(cencw);
1244 exception_error("unpackVisibleHeadlines", e);
1248 function headlines_scroll_handler(e) {
1250 var hsp = $("headlines-spacer");
1252 unpackVisibleHeadlines();
1254 if (!_infscroll_disable) {
1255 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1256 (e.scrollHeight != 0 &&
1257 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1260 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1261 __("Loading, please wait...");
1263 loadMoreHeadlines();
1268 if (hsp) hsp.innerHTML = "";
1271 if (getInitParam("cdm_auto_catchup") == 1) {
1273 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1275 if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
1276 (child.offsetTop + child.offsetHeight/2)) {
1278 var id = child.id.replace("RROW-", "");
1280 if (catchup_id_batch.indexOf(id) == -1)
1281 catchup_id_batch.push(id);
1283 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1287 if (catchup_id_batch.length > 0) {
1288 window.clearTimeout(catchup_timeout_id);
1290 if (!_infscroll_request_sent) {
1291 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1298 console.warn("headlines_scroll_handler: " + e);
1302 function catchupBatchedArticles() {
1304 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1306 // make a copy of the array
1307 var batch = catchup_id_batch.slice();
1308 var query = "?op=rpc&method=catchupSelected" +
1309 "&cmode=0&ids=" + param_escape(batch.toString());
1313 new Ajax.Request("backend.php", {
1315 onComplete: function(transport) {
1316 handle_rpc_json(transport);
1318 batch.each(function(id) {
1319 var elem = $("RROW-" + id);
1320 if (elem) elem.removeClassName("Unread");
1321 catchup_id_batch.remove(id);
1328 exception_error("catchupBatchedArticles", e);
1332 function catchupRelativeToArticle(below, id) {
1336 if (!id) id = getActiveArticleId();
1339 alert(__("No article is selected."));
1343 var visible_ids = getVisibleArticleIds();
1345 var ids_to_mark = new Array();
1348 for (var i = 0; i < visible_ids.length; i++) {
1349 if (visible_ids[i] != id) {
1350 var e = $("RROW-" + visible_ids[i]);
1352 if (e && e.hasClassName("Unread")) {
1353 ids_to_mark.push(visible_ids[i]);
1360 for (var i = visible_ids.length-1; i >= 0; i--) {
1361 if (visible_ids[i] != id) {
1362 var e = $("RROW-" + visible_ids[i]);
1364 if (e && e.hasClassName("Unread")) {
1365 ids_to_mark.push(visible_ids[i]);
1373 if (ids_to_mark.length == 0) {
1374 alert(__("No articles found to mark"));
1376 var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
1378 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1380 for (var i = 0; i < ids_to_mark.length; i++) {
1381 var e = $("RROW-" + ids_to_mark[i]);
1382 e.removeClassName("Unread");
1385 var query = "?op=rpc&method=catchupSelected" +
1386 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1388 new Ajax.Request("backend.php", {
1390 onComplete: function(transport) {
1391 handle_rpc_json(transport);
1398 exception_error("catchupRelativeToArticle", e);
1402 function cdmCollapseArticle(event, id) {
1404 var row = $("RROW-" + id);
1405 var elem = $("CICD-" + id);
1408 var collapse = $$("div#RROW-" + id +
1409 " span[class='collapseBtn']")[0];
1412 Element.show("CEXC-" + id);
1413 Element.hide(collapse);
1415 markHeadline(id, false);
1417 if (id == getActiveArticleId()) {
1418 setActiveArticleId(0);
1421 if (event) Event.stop(event);
1425 exception_error("cdmCollapseArticle", e);
1429 function cdmExpandArticle(id) {
1431 console.log("cdmExpandArticle " + id);
1433 if (!$("RROW-" + id)) return false;
1437 var elem = $("CICD-" + getActiveArticleId());
1439 if (id == getActiveArticleId() && Element.visible(elem))
1442 selectArticles("none");
1444 var old_offset = $("RROW-" + id).offsetTop;
1446 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1447 var collapse = $$("div#RROW-" + getActiveArticleId() +
1448 " span[class='collapseBtn']")[0];
1451 Element.show("CEXC-" + getActiveArticleId());
1452 Element.hide(collapse);
1453 $("RROW-" + getActiveArticleId()).removeClassName("active");
1456 setActiveArticleId(id);
1458 elem = $("CICD-" + id);
1460 var collapse = $$("div#RROW-" + id +
1461 " span[class='collapseBtn']")[0];
1463 var cencw = $("CENCW-" + id);
1465 if (!Element.visible(elem)) {
1467 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1468 cencw.setAttribute('id', '');
1469 Element.show(cencw);
1473 Element.hide("CEXC-" + id);
1474 Element.show(collapse);
1475 $("RROW-" + id).addClassName("active");
1478 var new_offset = $("RROW-" + id).offsetTop;
1480 if (old_offset > new_offset)
1481 $("headlines-frame").scrollTop -= (old_offset-new_offset);
1483 toggleUnread(id, 0, true);
1487 exception_error("cdmExpandArticle", e);
1493 function fixHeadlinesOrder(ids) {
1495 for (var i = 0; i < ids.length; i++) {
1496 var e = $("RROW-" + ids[i]);
1500 e.removeClassName("even");
1501 e.addClassName("odd");
1503 e.removeClassName("odd");
1504 e.addClassName("even");
1509 exception_error("fixHeadlinesOrder", e);
1513 function getArticleUnderPointer() {
1514 return post_under_pointer;
1517 function scrollArticle(offset) {
1520 var ci = $("content-insert");
1522 ci.scrollTop += offset;
1525 var hi = $("headlines-frame");
1527 hi.scrollTop += offset;
1532 exception_error("scrollArticle", e);
1536 function show_labels_in_headlines(transport) {
1538 var data = JSON.parse(transport.responseText);
1541 data['info-for-headlines'].each(function(elem) {
1542 var ctr = $("HLLCTR-" + elem.id);
1544 if (ctr) ctr.innerHTML = elem.labels;
1548 exception_error("show_labels_in_headlines", e);
1552 function dismissArticle(id) {
1554 var elem = $("RROW-" + id);
1556 toggleUnread(id, 0, true);
1558 new Effect.Fade(elem, {duration : 0.5});
1560 if (id == getActiveArticleId()) {
1561 setActiveArticleId(0);
1565 exception_error("dismissArticle", e);
1569 function dismissSelectedArticles() {
1572 var ids = getVisibleArticleIds();
1576 for (var i = 0; i < ids.length; i++) {
1577 var elem = $("RROW-" + ids[i]);
1579 if (elem.className && elem.hasClassName("Selected") &&
1580 ids[i] != getActiveArticleId()) {
1581 new Effect.Fade(elem, {duration : 0.5});
1589 selectionToggleUnread(false);
1591 fixHeadlinesOrder(tmp);
1594 exception_error("dismissSelectedArticles", e);
1598 function dismissReadArticles() {
1601 var ids = getVisibleArticleIds();
1604 for (var i = 0; i < ids.length; i++) {
1605 var elem = $("RROW-" + ids[i]);
1607 if (elem.className && !elem.hasClassName("Unread") &&
1608 !elem.hasClassName("Selected")) {
1610 new Effect.Fade(elem, {duration : 0.5});
1616 fixHeadlinesOrder(tmp);
1619 exception_error("dismissSelectedArticles", e);
1623 function getVisibleArticleIds() {
1628 getLoadedArticleIds().each(function(id) {
1629 var elem = $("RROW-" + id);
1630 if (elem && Element.visible(elem))
1635 exception_error("getVisibleArticleIds", e);
1641 function cdmClicked(event, id) {
1643 //var shift_key = event.shiftKey;
1647 if (!event.ctrlKey) {
1649 if (!getInitParam("cdm_expanded")) {
1650 return cdmExpandArticle(id);
1653 selectArticles("none");
1656 var elem = $("RROW-" + id);
1657 var article_is_unread = elem.hasClassName("Unread");
1660 elem.removeClassName("Unread");
1662 setActiveArticleId(id);
1664 if (article_is_unread) {
1665 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1668 var query = "?op=rpc&method=catchupSelected" +
1669 "&cmode=0&ids=" + param_escape(id);
1671 new Ajax.Request("backend.php", {
1673 onComplete: function(transport) {
1674 handle_rpc_json(transport);
1677 return !event.shiftKey;
1681 toggleSelected(id, true);
1683 var elem = $("RROW-" + id);
1684 var article_is_unread = elem.hasClassName("Unread");
1686 if (article_is_unread) {
1687 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1690 toggleUnread(id, 0, false);
1692 openArticleInNewWindow(id);
1695 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1696 request_counters(unread_in_buffer == 0);
1699 exception_error("cdmClicked");
1705 function hlClicked(event, id) {
1707 if (event.which == 2) {
1710 } else if (event.ctrlKey) {
1711 toggleSelected(id, true);
1712 toggleUnread(id, 0, false);
1713 openArticleInNewWindow(id);
1721 exception_error("hlClicked");
1725 function getFirstVisibleHeadlineId() {
1726 var rows = getVisibleArticleIds();
1731 function getLastVisibleHeadlineId() {
1732 var rows = getVisibleArticleIds();
1733 return rows[rows.length-1];
1736 function openArticleInNewWindow(id) {
1737 toggleUnread(id, 0, false);
1738 window.open("backend.php?op=article&method=redirect&id=" + id);
1741 function isCdmMode() {
1742 return getInitParam("combined_display_mode");
1745 function markHeadline(id, marked) {
1746 if (marked == undefined) marked = true;
1748 var row = $("RROW-" + id);
1750 var check = dijit.byId("RCHK-" + id);
1753 check.attr("checked", marked);
1757 row.addClassName("Selected");
1759 row.removeClassName("Selected");
1763 function getRelativePostIds(id, limit) {
1769 if (!limit) limit = 6; //3
1771 var ids = getVisibleArticleIds();
1773 for (var i = 0; i < ids.length; i++) {
1775 for (var k = 1; k <= limit; k++) {
1776 //if (i > k-1) tmp.push(ids[i-k]);
1777 if (i < ids.length-k) tmp.push(ids[i+k]);
1784 exception_error("getRelativePostIds", e);
1790 function correctHeadlinesOffset(id) {
1794 var container = $("headlines-frame");
1795 var row = $("RROW-" + id);
1797 if (!container || !row) return;
1799 var viewport = container.offsetHeight;
1801 var rel_offset_top = row.offsetTop - container.scrollTop;
1802 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1804 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1805 //console.log("Vport: " + viewport);
1807 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1808 container.scrollTop = row.offsetTop;
1809 } else if (rel_offset_bottom > viewport) {
1811 /* doesn't properly work with Opera in some cases because
1812 Opera fucks up element scrolling */
1814 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1818 exception_error("correctHeadlinesOffset", e);
1823 function headlineActionsChange(elem) {
1826 elem.attr('value', 'false');
1828 exception_error("headlineActionsChange", e);
1832 function closeArticlePanel() {
1834 if (dijit.byId("content-insert"))
1835 dijit.byId("headlines-wrap-inner").removeChild(
1836 dijit.byId("content-insert"));
1839 function initHeadlinesMenu() {
1841 if (dijit.byId("headlinesMenu"))
1842 dijit.byId("headlinesMenu").destroyRecursive();
1847 nodes = $$("#headlines-frame > div[id*=RROW]");
1849 nodes = $$("#headlines-frame span[id*=RTITLE]");
1852 nodes.each(function(node) {
1856 var menu = new dijit.Menu({
1857 id: "headlinesMenu",
1861 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1862 var callerNode = event.target, match = null, tries = 0;
1864 while (match == null && callerNode && tries <= 3) {
1865 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1866 callerNode = callerNode.parentNode;
1870 if (match) this.callerRowId = parseInt(match[1]);
1874 /* if (!isCdmMode())
1875 menu.addChild(new dijit.MenuItem({
1876 label: __("View article"),
1877 onClick: function(event) {
1878 view(this.getParent().callerRowId);
1881 menu.addChild(new dijit.MenuItem({
1882 label: __("Open original article"),
1883 onClick: function(event) {
1884 openArticleInNewWindow(this.getParent().callerRowId);
1887 menu.addChild(new dijit.MenuItem({
1888 label: __("Display article URL"),
1889 onClick: function(event) {
1890 displayArticleUrl(this.getParent().callerRowId);
1893 menu.addChild(new dijit.MenuSeparator());
1895 menu.addChild(new dijit.MenuItem({
1896 label: __("Mark above as read"),
1897 onClick: function(event) {
1898 catchupRelativeToArticle(0, this.getParent().callerRowId);
1901 menu.addChild(new dijit.MenuItem({
1902 label: __("Mark below as read"),
1903 onClick: function(event) {
1904 catchupRelativeToArticle(1, this.getParent().callerRowId);
1908 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1912 menu.addChild(new dijit.MenuSeparator());
1914 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1915 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1917 labels.each(function(label) {
1918 var id = label.id[0];
1919 var bare_id = id.substr(id.indexOf(":")+1);
1920 var name = label.name[0];
1922 bare_id = -11-bare_id;
1924 labelAddMenu.addChild(new dijit.MenuItem({
1927 onClick: function(event) {
1928 var ids = getSelectedArticleIds2();
1930 var id = this.getParent().ownerMenu.callerRowId + "";
1932 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1934 selectionAssignLabel(this.labelId, ids);
1937 labelDelMenu.addChild(new dijit.MenuItem({
1940 onClick: function(event) {
1941 var ids = getSelectedArticleIds2();
1943 var id = this.getParent().ownerMenu.callerRowId + "";
1945 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1947 selectionRemoveLabel(this.labelId, ids);
1952 menu.addChild(new dijit.PopupMenuItem({
1953 label: __("Assign label"),
1954 popup: labelAddMenu,
1957 menu.addChild(new dijit.PopupMenuItem({
1958 label: __("Remove label"),
1959 popup: labelDelMenu,
1967 exception_error("initHeadlinesMenu", e);
1972 function player(elem) {
1973 var aid = elem.getAttribute("audio-id");
1974 var status = elem.getAttribute("status");
1982 elem.innerHTML = __("Playing...");
1983 elem.title = __("Click to pause");
1984 elem.addClassName("playing");
1988 elem.innerHTML = __("Play");
1989 elem.title = __("Click to play");
1990 elem.removeClassName("playing");
1993 elem.setAttribute("status", status);
1995 alert("Your browser doesn't seem to support HTML5 audio.");
1999 function cache_set(id, obj) {
2000 //console.log("cache_set: " + id);
2003 sessionStorage[id] = obj;
2005 sessionStorage.clear();
2009 function cache_get(id) {
2011 return sessionStorage[id];
2014 function cache_clear() {
2016 sessionStorage.clear();
2019 function cache_delete(id) {
2021 sessionStorage.removeItem(id);
2024 function cancelSearch() {
2029 exception_error("cancelSearch", e);
2033 function setSelectionScore() {
2035 var ids = getSelectedArticleIds2();
2037 if (ids.length > 0) {
2040 var score = prompt(__("Please enter new score for selected articles:"), score);
2042 if (score != undefined) {
2043 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2044 "&score=" + param_escape(score);
2046 new Ajax.Request("backend.php", {
2048 onComplete: function(transport) {
2049 var reply = JSON.parse(transport.responseText);
2053 ids.each(function(id) {
2054 var row = $("RROW-" + id);
2057 var pic = row.getElementsByClassName("hlScorePic")[0];
2060 pic.src = pic.src.replace(/score_.*?\.png/,
2061 reply["score_pic"]);
2062 pic.setAttribute("score", score);
2071 alert(__("No articles are selected."));
2074 exception_error("setSelectionScore", e);
2078 function changeScore(id, pic) {
2080 var score = pic.getAttribute("score");
2082 var new_score = prompt(__("Please enter new score for this article:"), score);
2084 if (new_score != undefined) {
2086 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2087 "&score=" + param_escape(new_score);
2089 new Ajax.Request("backend.php", {
2091 onComplete: function(transport) {
2092 var reply = JSON.parse(transport.responseText);
2095 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2096 pic.setAttribute("score", new_score);
2101 exception_error("changeScore", e);
2105 function displayArticleUrl(id) {
2107 var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
2109 new Ajax.Request("backend.php", {
2111 onComplete: function(transport) {
2112 var reply = JSON.parse(transport.responseText);
2114 if (reply && reply.link) {
2115 prompt(__("Article URL:"), reply.link);
2119 exception_error("changeScore", e);