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);
328 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
329 request_counters(unread_in_buffer == 0);
331 headlines_scroll_handler($("headlines-frame"));
334 if (!_infscroll_disable &&
335 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
345 exception_error("article_callback2", e, transport);
351 var crow = $("RROW-" + id);
355 console.log("loading article: " + id);
357 var cached_article = cache_get("article:" + id);
359 console.log("cache check result: " + (cached_article != false));
363 var query = "?op=article&method=view&id=" + param_escape(id);
365 var neighbor_ids = getRelativePostIds(id);
367 /* only request uncached articles */
369 var cids_to_request = [];
371 for (var i = 0; i < neighbor_ids.length; i++) {
372 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
373 if (!cache_get("article:" + neighbor_ids[i])) {
374 cids_to_request.push(neighbor_ids[i]);
375 cids_requested.push(neighbor_ids[i]);
379 console.log("additional ids: " + cids_to_request.toString());
381 query = query + "&cids=" + cids_to_request.toString();
383 var article_is_unread = crow.hasClassName("Unread");
386 showArticleInHeadlines(id);
388 precache_headlines();
390 if (cached_article && article_is_unread) {
392 query = query + "&mode=prefetch";
394 render_article(cached_article);
396 } else if (cached_article) {
398 query = query + "&mode=prefetch_old";
399 render_article(cached_article);
401 // if we don't need to request any relative ids, we might as well skip
402 // the server roundtrip altogether
403 if (cids_to_request.length == 0) {
406 if (!_infscroll_disable &&
407 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
415 headlines_scroll_handler($("headlines-frame"));
421 last_requested_article = id;
425 if (article_is_unread) {
426 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
429 new Ajax.Request("backend.php", {
431 onComplete: function(transport) {
432 article_callback2(transport, id);
438 exception_error("view", e);
442 function toggleMark(id, client_only) {
444 var query = "?op=rpc&id=" + id + "&method=mark";
446 var img = $("FMPIC-" + id);
450 if (img.src.match("mark_unset")) {
451 img.src = img.src.replace("mark_unset", "mark_set");
452 img.alt = __("Unstar article");
453 query = query + "&mark=1";
456 img.src = img.src.replace("mark_set", "mark_unset");
457 img.alt = __("Star article");
458 query = query + "&mark=0";
461 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
464 new Ajax.Request("backend.php", {
466 onComplete: function(transport) {
467 handle_rpc_json(transport);
472 exception_error("toggleMark", e);
476 function togglePub(id, client_only, no_effects, note) {
478 var query = "?op=rpc&id=" + id + "&method=publ";
480 if (note != undefined) {
481 query = query + "¬e=" + param_escape(note);
483 query = query + "¬e=undefined";
486 var img = $("FPPIC-" + id);
490 if (img.src.match("pub_unset") || note != undefined) {
491 img.src = img.src.replace("pub_unset", "pub_set");
492 img.alt = __("Unpublish article");
493 query = query + "&pub=1";
496 img.src = img.src.replace("pub_set", "pub_unset");
497 img.alt = __("Publish article");
499 query = query + "&pub=0";
502 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
505 new Ajax.Request("backend.php", {
507 onComplete: function(transport) {
508 handle_rpc_json(transport);
513 exception_error("togglePub", e);
517 function moveToPost(mode) {
521 var rows = getVisibleArticleIds();
526 if (!$('RROW-' + active_post_id)) {
527 active_post_id = false;
530 if (active_post_id == false) {
532 prev_id = rows[rows.length-1]
534 for (var i = 0; i < rows.length; i++) {
535 if (rows[i] == active_post_id) {
537 // Account for adjacent identical article ids.
538 if (i > 0) prev_id = rows[i-1];
540 for (var j = i+1; j < rows.length; j++) {
541 if (rows[j] != active_post_id) {
551 if (mode == "next") {
552 if (next_id || active_post_id) {
555 var article = $("RROW-" + active_post_id);
556 var ctr = $("headlines-frame");
558 if (article && article.offsetTop + article.offsetHeight >
559 ctr.scrollTop + ctr.offsetHeight) {
561 scrollArticle(ctr.offsetHeight/2);
563 } else if (next_id) {
564 cdmExpandArticle(next_id);
565 cdmScrollToArticleId(next_id);
568 } else if (next_id) {
569 correctHeadlinesOffset(next_id);
570 view(next_id, getActiveFeedId());
575 if (mode == "prev") {
576 if (prev_id || active_post_id) {
579 var article = $("RROW-" + active_post_id);
580 var prev_article = $("RROW-" + prev_id);
581 var ctr = $("headlines-frame");
583 if (article && article.offsetTop < ctr.scrollTop) {
584 scrollArticle(-ctr.offsetHeight/2);
585 } else if (prev_article && prev_article.offsetTop < ctr.scrollTop) {
586 cdmExpandArticle(prev_id);
587 scrollArticle(-ctr.offsetHeight/2);
588 } else if (prev_id) {
589 cdmExpandArticle(prev_id);
590 cdmScrollToArticleId(prev_id);
592 } else if (prev_id) {
593 correctHeadlinesOffset(prev_id);
594 view(prev_id, getActiveFeedId());
600 exception_error("moveToPost", e);
604 function toggleSelected(id, force_on) {
607 var cb = dijit.byId("RCHK-" + id);
608 var row = $("RROW-" + id);
611 if (row.hasClassName('Selected') && !force_on) {
612 row.removeClassName('Selected');
613 if (cb) cb.attr("checked", false);
615 row.addClassName('Selected');
616 if (cb) cb.attr("checked", true);
620 exception_error("toggleSelected", e);
624 function toggleUnread_afh(effect) {
627 var elem = effect.element;
628 elem.style.backgroundColor = "";
631 exception_error("toggleUnread_afh", e);
635 function toggleUnread(id, cmode, effect) {
638 var row = $("RROW-" + id);
640 if (cmode == undefined || cmode == 2) {
641 if (row.hasClassName("Unread")) {
642 row.removeClassName("Unread");
645 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
646 afterFinish: toggleUnread_afh,
647 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
651 row.addClassName("Unread");
654 } else if (cmode == 0) {
656 row.removeClassName("Unread");
659 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
660 afterFinish: toggleUnread_afh,
661 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
664 } else if (cmode == 1) {
665 row.addClassName("Unread");
668 if (cmode == undefined) cmode = 2;
670 var query = "?op=rpc&method=catchupSelected" +
671 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
673 // notify_progress("Loading, please wait...");
675 new Ajax.Request("backend.php", {
677 onComplete: function(transport) {
678 handle_rpc_json(transport);
684 exception_error("toggleUnread", e);
688 function selectionRemoveLabel(id, ids) {
691 if (!ids) ids = getSelectedArticleIds2();
693 if (ids.length == 0) {
694 alert(__("No articles are selected."));
698 var query = "?op=rpc&method=removeFromLabel&ids=" +
699 param_escape(ids.toString()) + "&lid=" + param_escape(id);
703 new Ajax.Request("backend.php", {
705 onComplete: function(transport) {
706 handle_rpc_json(transport);
707 show_labels_in_headlines(transport);
711 exception_error("selectionAssignLabel", e);
716 function selectionAssignLabel(id, ids) {
719 if (!ids) ids = getSelectedArticleIds2();
721 if (ids.length == 0) {
722 alert(__("No articles are selected."));
726 var query = "?op=rpc&method=assignToLabel&ids=" +
727 param_escape(ids.toString()) + "&lid=" + param_escape(id);
731 new Ajax.Request("backend.php", {
733 onComplete: function(transport) {
734 handle_rpc_json(transport);
735 show_labels_in_headlines(transport);
739 exception_error("selectionAssignLabel", e);
744 function selectionToggleUnread(set_state, callback, no_error) {
746 var rows = getSelectedArticleIds2();
748 if (rows.length == 0 && !no_error) {
749 alert(__("No articles are selected."));
753 for (var i = 0; i < rows.length; i++) {
754 var row = $("RROW-" + rows[i]);
756 if (set_state == undefined) {
757 if (row.hasClassName("Unread")) {
758 row.removeClassName("Unread");
760 row.addClassName("Unread");
764 if (set_state == false) {
765 row.removeClassName("Unread");
768 if (set_state == true) {
769 row.addClassName("Unread");
774 if (rows.length > 0) {
778 if (set_state == undefined) {
780 } else if (set_state == true) {
782 } else if (set_state == false) {
786 var query = "?op=rpc&method=catchupSelected" +
787 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
789 notify_progress("Loading, please wait...");
791 new Ajax.Request("backend.php", {
793 onComplete: function(transport) {
794 handle_rpc_json(transport);
795 if (callback) callback(transport);
801 exception_error("selectionToggleUnread", e);
805 function selectionToggleMarked() {
808 var rows = getSelectedArticleIds2();
810 if (rows.length == 0) {
811 alert(__("No articles are selected."));
815 for (var i = 0; i < rows.length; i++) {
816 toggleMark(rows[i], true, true);
819 if (rows.length > 0) {
821 var query = "?op=rpc&method=markSelected&ids=" +
822 param_escape(rows.toString()) + "&cmode=2";
824 new Ajax.Request("backend.php", {
826 onComplete: function(transport) {
827 handle_rpc_json(transport);
833 exception_error("selectionToggleMarked", e);
837 function selectionTogglePublished() {
840 var rows = getSelectedArticleIds2();
842 if (rows.length == 0) {
843 alert(__("No articles are selected."));
847 for (var i = 0; i < rows.length; i++) {
848 togglePub(rows[i], true, true);
851 if (rows.length > 0) {
853 var query = "?op=rpc&method=publishSelected&ids=" +
854 param_escape(rows.toString()) + "&cmode=2";
856 new Ajax.Request("backend.php", {
858 onComplete: function(transport) {
859 handle_rpc_json(transport);
865 exception_error("selectionToggleMarked", e);
869 function getSelectedArticleIds2() {
873 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
875 rv.push(child.id.replace("RROW-", ""));
881 function getLoadedArticleIds() {
884 var children = $$("#headlines-frame > div[id*=RROW-]");
886 children.each(function(child) {
887 rv.push(child.id.replace("RROW-", ""));
894 // mode = all,none,unread,invert,marked,published
895 function selectArticles(mode) {
898 var children = $$("#headlines-frame > div[id*=RROW]");
900 children.each(function(child) {
901 var id = child.id.replace("RROW-", "");
902 var cb = dijit.byId("RCHK-" + id);
905 child.addClassName("Selected");
906 if (cb) cb.attr("checked", true);
907 } else if (mode == "unread") {
908 if (child.hasClassName("Unread")) {
909 child.addClassName("Selected");
910 if (cb) cb.attr("checked", true);
912 child.removeClassName("Selected");
913 if (cb) cb.attr("checked", false);
915 } else if (mode == "marked") {
916 var img = $("FMPIC-" + child.id.replace("RROW-", ""));
918 if (img && img.src.match("mark_set")) {
919 child.addClassName("Selected");
920 if (cb) cb.attr("checked", true);
922 child.removeClassName("Selected");
923 if (cb) cb.attr("checked", false);
925 } else if (mode == "published") {
926 var img = $("FPPIC-" + child.id.replace("RROW-", ""));
928 if (img && img.src.match("pub_set")) {
929 child.addClassName("Selected");
930 if (cb) cb.attr("checked", true);
932 child.removeClassName("Selected");
933 if (cb) cb.attr("checked", false);
936 } else if (mode == "invert") {
937 if (child.hasClassName("Selected")) {
938 child.removeClassName("Selected");
939 if (cb) cb.attr("checked", false);
941 child.addClassName("Selected");
942 if (cb) cb.attr("checked", true);
946 child.removeClassName("Selected");
947 if (cb) cb.attr("checked", false);
952 exception_error("selectArticles", e);
956 function catchupPage() {
958 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
960 var str = __("Mark all visible articles in %s as read?");
962 str = str.replace("%s", fn);
964 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
968 selectArticles('all');
969 selectionToggleUnread(false, 'viewCurrentFeed()', true);
970 selectArticles('none');
973 function deleteSelection() {
977 var rows = getSelectedArticleIds2();
979 if (rows.length == 0) {
980 alert(__("No articles are selected."));
984 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
987 if (getActiveFeedId() != 0) {
988 str = __("Delete %d selected articles in %s?");
990 str = __("Delete %d selected articles?");
993 str = str.replace("%d", rows.length);
994 str = str.replace("%s", fn);
996 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1000 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
1004 new Ajax.Request("backend.php", {
1006 onComplete: function(transport) {
1007 handle_rpc_json(transport);
1012 exception_error("deleteSelection", e);
1016 function archiveSelection() {
1020 var rows = getSelectedArticleIds2();
1022 if (rows.length == 0) {
1023 alert(__("No articles are selected."));
1027 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1031 if (getActiveFeedId() != 0) {
1032 str = __("Archive %d selected articles in %s?");
1035 str = __("Move %d archived articles back?");
1039 str = str.replace("%d", rows.length);
1040 str = str.replace("%s", fn);
1042 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1046 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1050 for (var i = 0; i < rows.length; i++) {
1051 cache_delete("article:" + rows[i]);
1054 new Ajax.Request("backend.php", {
1056 onComplete: function(transport) {
1057 handle_rpc_json(transport);
1062 exception_error("archiveSelection", e);
1066 function catchupSelection() {
1070 var rows = getSelectedArticleIds2();
1072 if (rows.length == 0) {
1073 alert(__("No articles are selected."));
1077 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1079 var str = __("Mark %d selected articles in %s as read?");
1081 str = str.replace("%d", rows.length);
1082 str = str.replace("%s", fn);
1084 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1088 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1091 exception_error("catchupSelection", e);
1095 function editArticleTags(id) {
1096 var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id);
1098 if (dijit.byId("editTagsDlg"))
1099 dijit.byId("editTagsDlg").destroyRecursive();
1101 dialog = new dijit.Dialog({
1103 title: __("Edit article Tags"),
1104 style: "width: 600px",
1105 execute: function() {
1106 if (this.validate()) {
1107 var query = dojo.objectToQuery(this.attr('value'));
1109 notify_progress("Saving article tags...", true);
1111 new Ajax.Request("backend.php", {
1113 onComplete: function(transport) {
1117 var data = JSON.parse(transport.responseText);
1120 var tags_str = article.tags;
1121 var id = tags_str.id;
1123 var tags = $("ATSTR-" + id);
1124 var tooltip = dijit.byId("ATSTRTIP-" + id);
1126 if (tags) tags.innerHTML = tags_str.content;
1127 if (tooltip) tooltip.attr('label', tags_str.content_full);
1129 cache_delete("article:" + id);
1138 var tmph = dojo.connect(dialog, 'onLoad', function() {
1139 dojo.disconnect(tmph);
1141 new Ajax.Autocompleter('tags_str', 'tags_choices',
1142 "backend.php?op=rpc&method=completeTags",
1143 { tokens: ',', paramName: "search" });
1150 function cdmScrollToArticleId(id) {
1152 var ctr = $("headlines-frame");
1153 var e = $("RROW-" + id);
1155 if (!e || !ctr) return;
1157 if (e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1158 e.offsetTop < ctr.scrollTop) {
1160 ctr.scrollTop = e.offsetTop;
1164 exception_error("cdmScrollToArticleId", e);
1168 function getActiveArticleId() {
1169 return active_post_id;
1172 function postMouseIn(id) {
1173 post_under_pointer = id;
1176 function postMouseOut(id) {
1177 post_under_pointer = false;
1180 function headlines_scroll_handler(e) {
1182 var hsp = $("headlines-spacer");
1184 if (!_infscroll_disable) {
1185 if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1186 (e.scrollHeight != 0 &&
1187 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1190 hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
1191 __("Loading, please wait...");
1193 loadMoreHeadlines();
1198 if (hsp) hsp.innerHTML = "";
1201 if (getInitParam("cdm_auto_catchup") == 1) {
1203 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1205 if ($("headlines-frame").scrollTop >
1206 (child.offsetTop + child.offsetHeight/2)) {
1208 var id = child.id.replace("RROW-", "");
1210 if (catchup_id_batch.indexOf(id) == -1)
1211 catchup_id_batch.push(id);
1213 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1217 if (catchup_id_batch.length > 0) {
1218 window.clearTimeout(catchup_timeout_id);
1220 if (!_infscroll_request_sent) {
1221 catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1228 console.warn("headlines_scroll_handler: " + e);
1232 function catchupBatchedArticles() {
1234 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1236 // make a copy of the array
1237 var batch = catchup_id_batch.slice();
1238 var query = "?op=rpc&method=catchupSelected" +
1239 "&cmode=0&ids=" + param_escape(batch.toString());
1243 new Ajax.Request("backend.php", {
1245 onComplete: function(transport) {
1246 handle_rpc_json(transport);
1248 batch.each(function(id) {
1249 var elem = $("RROW-" + id);
1250 if (elem) elem.removeClassName("Unread");
1251 catchup_id_batch.remove(id);
1258 exception_error("catchupBatchedArticles", e);
1262 function catchupRelativeToArticle(below, id) {
1266 if (!id) id = getActiveArticleId();
1269 alert(__("No article is selected."));
1273 var visible_ids = getVisibleArticleIds();
1275 var ids_to_mark = new Array();
1278 for (var i = 0; i < visible_ids.length; i++) {
1279 if (visible_ids[i] != id) {
1280 var e = $("RROW-" + visible_ids[i]);
1282 if (e && e.hasClassName("Unread")) {
1283 ids_to_mark.push(visible_ids[i]);
1290 for (var i = visible_ids.length-1; i >= 0; i--) {
1291 if (visible_ids[i] != id) {
1292 var e = $("RROW-" + visible_ids[i]);
1294 if (e && e.hasClassName("Unread")) {
1295 ids_to_mark.push(visible_ids[i]);
1303 if (ids_to_mark.length == 0) {
1304 alert(__("No articles found to mark"));
1306 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
1308 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1310 for (var i = 0; i < ids_to_mark.length; i++) {
1311 var e = $("RROW-" + ids_to_mark[i]);
1312 e.removeClassName("Unread");
1315 var query = "?op=rpc&method=catchupSelected" +
1316 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1318 new Ajax.Request("backend.php", {
1320 onComplete: function(transport) {
1321 handle_rpc_json(transport);
1328 exception_error("catchupRelativeToArticle", e);
1332 function cdmExpandArticle(id) {
1337 var elem = $("CICD-" + active_post_id);
1339 if (id == active_post_id && Element.visible(elem))
1342 selectArticles("none");
1344 var old_offset = $("RROW-" + id).offsetTop;
1346 if (active_post_id && elem && !getInitParam("cdm_expanded")) {
1348 Element.show("CEXC-" + active_post_id);
1351 active_post_id = id;
1353 elem = $("CICD-" + id);
1355 if (!Element.visible(elem)) {
1357 Element.hide("CEXC-" + id);
1360 var new_offset = $("RROW-" + id).offsetTop;
1362 $("headlines-frame").scrollTop += (new_offset-old_offset);
1364 if ($("RROW-" + id).offsetTop != old_offset)
1365 $("headlines-frame").scrollTop = new_offset;
1367 toggleUnread(id, 0, true);
1371 exception_error("cdmExpandArticle", e);
1377 function fixHeadlinesOrder(ids) {
1379 for (var i = 0; i < ids.length; i++) {
1380 var e = $("RROW-" + ids[i]);
1384 e.removeClassName("even");
1385 e.addClassName("odd");
1387 e.removeClassName("odd");
1388 e.addClassName("even");
1393 exception_error("fixHeadlinesOrder", e);
1397 function getArticleUnderPointer() {
1398 return post_under_pointer;
1401 function scrollArticle(offset) {
1404 var ci = $("content-insert");
1406 ci.scrollTop += offset;
1409 var hi = $("headlines-frame");
1411 hi.scrollTop += offset;
1416 exception_error("scrollArticle", e);
1420 function show_labels_in_headlines(transport) {
1422 var data = JSON.parse(transport.responseText);
1425 data['info-for-headlines'].each(function(elem) {
1426 var ctr = $("HLLCTR-" + elem.id);
1428 if (ctr) ctr.innerHTML = elem.labels;
1431 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
1435 exception_error("show_labels_in_headlines", e);
1439 function dismissArticle(id) {
1441 var elem = $("RROW-" + id);
1443 toggleUnread(id, 0, true);
1445 new Effect.Fade(elem, {duration : 0.5});
1447 active_post_id = false;
1450 exception_error("dismissArticle", e);
1454 function dismissSelectedArticles() {
1457 var ids = getVisibleArticleIds();
1461 for (var i = 0; i < ids.length; i++) {
1462 var elem = $("RROW-" + ids[i]);
1464 if (elem.className && elem.hasClassName("Selected") &&
1465 ids[i] != active_post_id) {
1466 new Effect.Fade(elem, {duration : 0.5});
1474 selectionToggleUnread(false);
1476 fixHeadlinesOrder(tmp);
1479 exception_error("dismissSelectedArticles", e);
1483 function dismissReadArticles() {
1486 var ids = getVisibleArticleIds();
1489 for (var i = 0; i < ids.length; i++) {
1490 var elem = $("RROW-" + ids[i]);
1492 if (elem.className && !elem.hasClassName("Unread") &&
1493 !elem.hasClassName("Selected")) {
1495 new Effect.Fade(elem, {duration : 0.5});
1501 fixHeadlinesOrder(tmp);
1504 exception_error("dismissSelectedArticles", e);
1508 function getVisibleArticleIds() {
1513 getLoadedArticleIds().each(function(id) {
1514 var elem = $("RROW-" + id);
1515 if (elem && Element.visible(elem))
1520 exception_error("getVisibleArticleIds", e);
1526 function cdmClicked(event, id) {
1528 //var shift_key = event.shiftKey;
1532 if (!event.ctrlKey) {
1534 if (!getInitParam("cdm_expanded")) {
1535 return cdmExpandArticle(id);
1538 selectArticles("none");
1541 var elem = $("RROW-" + id);
1542 var article_is_unread = elem.hasClassName("Unread");
1545 elem.removeClassName("Unread");
1547 active_post_id = id;
1549 if (article_is_unread) {
1550 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1553 var query = "?op=rpc&method=catchupSelected" +
1554 "&cmode=0&ids=" + param_escape(id);
1556 new Ajax.Request("backend.php", {
1558 onComplete: function(transport) {
1559 handle_rpc_json(transport);
1566 toggleSelected(id, true);
1568 var elem = $("RROW-" + id);
1569 var article_is_unread = elem.hasClassName("Unread");
1571 if (article_is_unread) {
1572 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1575 toggleUnread(id, 0, false);
1577 openArticleInNewWindow(id);
1580 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1581 request_counters(unread_in_buffer == 0);
1584 exception_error("cdmClicked");
1590 function hlClicked(event, id) {
1592 if (event.which == 2) {
1595 } else if (event.ctrlKey) {
1596 toggleSelected(id, true);
1597 toggleUnread(id, 0, false);
1598 openArticleInNewWindow(id);
1606 exception_error("hlClicked");
1610 function getFirstVisibleHeadlineId() {
1611 var rows = getVisibleArticleIds();
1616 function getLastVisibleHeadlineId() {
1617 var rows = getVisibleArticleIds();
1618 return rows[rows.length-1];
1621 function openArticleInNewWindow(id) {
1622 toggleUnread(id, 0, false);
1623 window.open("backend.php?op=article&method=redirect&id=" + id);
1626 function isCdmMode() {
1627 return getInitParam("combined_display_mode");
1630 function markHeadline(id) {
1631 var row = $("RROW-" + id);
1633 var check = dijit.byId("RCHK-" + id);
1636 check.attr("checked", true);
1639 row.addClassName("Selected");
1643 function getRelativePostIds(id, limit) {
1649 if (!limit) limit = 6; //3
1651 var ids = getVisibleArticleIds();
1653 for (var i = 0; i < ids.length; i++) {
1655 for (var k = 1; k <= limit; k++) {
1656 //if (i > k-1) tmp.push(ids[i-k]);
1657 if (i < ids.length-k) tmp.push(ids[i+k]);
1664 exception_error("getRelativePostIds", e);
1670 function correctHeadlinesOffset(id) {
1674 var container = $("headlines-frame");
1675 var row = $("RROW-" + id);
1677 if (!container || !row) return;
1679 var viewport = container.offsetHeight;
1681 var rel_offset_top = row.offsetTop - container.scrollTop;
1682 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1684 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1685 //console.log("Vport: " + viewport);
1687 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1688 container.scrollTop = row.offsetTop;
1689 } else if (rel_offset_bottom > viewport) {
1691 /* doesn't properly work with Opera in some cases because
1692 Opera fucks up element scrolling */
1694 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1698 exception_error("correctHeadlinesOffset", e);
1703 function headlineActionsChange(elem) {
1706 elem.attr('value', 'false');
1708 exception_error("headlineActionsChange", e);
1712 function closeArticlePanel() {
1714 if (dijit.byId("content-insert"))
1715 dijit.byId("headlines-wrap-inner").removeChild(
1716 dijit.byId("content-insert"));
1719 function initHeadlinesMenu() {
1721 if (dijit.byId("headlinesMenu"))
1722 dijit.byId("headlinesMenu").destroyRecursive();
1727 nodes = $$("#headlines-frame > div[id*=RROW]");
1729 nodes = $$("#headlines-frame span[id*=RTITLE]");
1732 nodes.each(function(node) {
1736 var menu = new dijit.Menu({
1737 id: "headlinesMenu",
1741 var tmph = dojo.connect(menu, '_openMyself', function (event) {
1742 var callerNode = event.target, match = null, tries = 0;
1744 while (match == null && callerNode && tries <= 3) {
1745 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
1746 callerNode = callerNode.parentNode;
1750 if (match) this.callerRowId = parseInt(match[1]);
1754 /* if (!isCdmMode())
1755 menu.addChild(new dijit.MenuItem({
1756 label: __("View article"),
1757 onClick: function(event) {
1758 view(this.getParent().callerRowId);
1761 menu.addChild(new dijit.MenuItem({
1762 label: __("Open original article"),
1763 onClick: function(event) {
1764 openArticleInNewWindow(this.getParent().callerRowId);
1767 menu.addChild(new dijit.MenuSeparator());
1769 menu.addChild(new dijit.MenuItem({
1770 label: __("Mark above as read"),
1771 onClick: function(event) {
1772 catchupRelativeToArticle(0, this.getParent().callerRowId);
1775 menu.addChild(new dijit.MenuItem({
1776 label: __("Mark below as read"),
1777 onClick: function(event) {
1778 catchupRelativeToArticle(1, this.getParent().callerRowId);
1782 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
1786 menu.addChild(new dijit.MenuSeparator());
1788 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1789 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1791 labels.each(function(label) {
1792 var id = label.id[0];
1793 var bare_id = id.substr(id.indexOf(":")+1);
1794 var name = label.name[0];
1796 bare_id = -11-bare_id;
1798 labelAddMenu.addChild(new dijit.MenuItem({
1801 onClick: function(event) {
1802 var ids = getSelectedArticleIds2();
1804 var id = this.getParent().ownerMenu.callerRowId + "";
1806 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1808 selectionAssignLabel(this.labelId, ids);
1811 labelDelMenu.addChild(new dijit.MenuItem({
1814 onClick: function(event) {
1815 var ids = getSelectedArticleIds2();
1817 var id = this.getParent().ownerMenu.callerRowId + "";
1819 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1821 selectionRemoveLabel(this.labelId, ids);
1826 menu.addChild(new dijit.PopupMenuItem({
1827 label: __("Assign label"),
1828 popup: labelAddMenu,
1831 menu.addChild(new dijit.PopupMenuItem({
1832 label: __("Remove label"),
1833 popup: labelDelMenu,
1841 exception_error("initHeadlinesMenu", e);
1846 function player(elem) {
1847 var aid = elem.getAttribute("audio-id");
1848 var status = elem.getAttribute("status");
1856 elem.innerHTML = __("Playing...");
1857 elem.title = __("Click to pause");
1858 elem.addClassName("playing");
1862 elem.innerHTML = __("Play");
1863 elem.title = __("Click to play");
1864 elem.removeClassName("playing");
1867 elem.setAttribute("status", status);
1869 alert("Your browser doesn't seem to support HTML5 audio.");
1873 function cache_set(id, obj) {
1874 //console.log("cache_set: " + id);
1877 sessionStorage[id] = obj;
1879 sessionStorage.clear();
1883 function cache_get(id) {
1885 return sessionStorage[id];
1888 function cache_clear() {
1890 sessionStorage.clear();
1893 function cache_delete(id) {
1895 sessionStorage.removeItem(id);
1898 function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
1899 if (toolbar_obj && content_obj) {
1900 cache_set("feed:" + feed + ":" + is_cat,
1901 JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
1904 obj = cache_get("feed:" + feed + ":" + is_cat);
1907 obj = JSON.parse(obj);
1909 if (toolbar_obj) obj.toolbar = toolbar_obj;
1910 if (content_obj) obj.content = content_obj;
1912 cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
1916 console.warn("cache_headlines failed: " + e);
1921 function render_local_headlines(feed, is_cat, obj) {
1924 dijit.byId("headlines-toolbar").attr('content',
1927 dijit.byId("headlines-frame").attr('content',
1930 dojo.parser.parse('headlines-toolbar');
1932 $("headlines-frame").scrollTop = 0;
1933 selectArticles('none');
1934 setActiveFeedId(feed, is_cat);
1935 initHeadlinesMenu();
1937 dijit.getEnclosingWidget(
1938 document.forms["main_toolbar_form"].update).attr('disabled',
1939 is_cat || feed <= 0);
1941 precache_headlines();
1944 exception_error("render_local_headlines", e);
1948 function precache_headlines_idle() {
1950 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
1951 if (get_timestamp() - _viewfeed_last > 120) {
1953 var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
1956 feeds.each(function(item) {
1957 if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
1958 uncached.push(item);
1961 if (uncached.length > 0) {
1962 var rf = uncached[Math.floor(Math.random()*uncached.length)];
1963 viewfeed(rf[0], '', rf[1], 0, true);
1967 precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
1970 exception_error("precache_headlines_idle", e);
1974 function precache_headlines() {
1976 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
1978 feed_precache_timeout_id = window.setTimeout(function() {
1979 var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
1980 var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
1982 if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
1983 viewfeed(nuf, '', activeFeedIsCat(), 0, true);
1985 if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
1986 viewfeed(nf[0], '', nf[1], 0, true);
1988 window.setTimeout(function() {
1989 feed_precache_timeout_id = false;
1995 exception_error("precache_headlines", e);
1999 function cancelSearch() {
2004 exception_error("cancelSearch", e);
2008 function setSelectionScore() {
2010 var ids = getSelectedArticleIds2();
2012 if (ids.length > 0) {
2015 var score = prompt(__("Please enter new score for selected articles:"), score);
2017 if (score != undefined) {
2018 var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
2019 "&score=" + param_escape(score);
2021 new Ajax.Request("backend.php", {
2023 onComplete: function(transport) {
2024 var reply = JSON.parse(transport.responseText);
2028 ids.each(function(id) {
2029 var row = $("RROW-" + id);
2032 var pic = row.getElementsByClassName("hlScorePic")[0];
2035 pic.src = pic.src.replace(/score_.*?\.png/,
2036 reply["score_pic"]);
2037 pic.setAttribute("score", score);
2046 alert(__("No articles are selected."));
2049 exception_error("setSelectionScore", e);
2053 function changeScore(id, pic) {
2055 var score = pic.getAttribute("score");
2057 var new_score = prompt(__("Please enter new score for this article:"), score);
2059 if (new_score != undefined) {
2061 var query = "op=rpc&method=setScore&id=" + param_escape(id) +
2062 "&score=" + param_escape(new_score);
2064 new Ajax.Request("backend.php", {
2066 onComplete: function(transport) {
2067 var reply = JSON.parse(transport.responseText);
2070 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2071 pic.setAttribute("score", new_score);
2076 exception_error("changeScore", e);