1 var _active_article_id = 0;
3 var vgroup_last_feed = false;
4 var post_under_pointer = false;
6 var last_requested_article = false;
8 var catchup_id_batch = [];
9 var catchup_timeout_id = false;
11 var cids_requested = [];
12 var loaded_article_ids = [];
13 var _last_headlines_update = 0;
14 var _headlines_scroll_offset = 0;
15 var current_first_id = 0;
16 var last_search_query;
18 var _catchup_request_sent = false;
20 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
22 function headlines_callback2(transport, offset, background, infscroll_req) {
23 handle_rpc_json(transport);
25 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
33 reply = JSON.parse(transport.responseText);
40 is_cat = reply['headlines']['is_cat'];
41 feed_id = reply['headlines']['id'];
42 last_search_query = reply['headlines']['search_query'];
45 var content = reply['headlines']['content'];
47 content = content + "<div id='headlines-spacer'></div>";
51 if (feed_id != -7 && (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()))
54 /* dijit.getEnclosingWidget(
55 document.forms["main_toolbar_form"].update).attr('disabled',
56 is_cat || feed_id <= 0); */
59 if (infscroll_req == false) {
60 $("headlines-frame").scrollTop = 0;
62 $("floatingTitle").style.visibility = "hidden";
63 $("floatingTitle").setAttribute("data-article-id", 0);
64 $("floatingTitle").innerHTML = "";
68 $("headlines-frame").removeClassName("cdm");
69 $("headlines-frame").removeClassName("normal");
71 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
73 var headlines_count = reply['headlines-info']['count'];
75 vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
77 if (parseInt(headlines_count) < 30) {
78 _infscroll_disable = 1;
80 _infscroll_disable = 0;
83 current_first_id = reply['headlines']['first_id'];
84 var counters = reply['counters'];
85 var articles = reply['articles'];
86 //var runtime_info = reply['runtime-info'];
88 if (infscroll_req == false) {
89 loaded_article_ids = [];
91 dojo.html.set($("headlines-toolbar"),
92 reply['headlines']['toolbar'],
93 {parseContent: true});
95 /*dojo.html.set($("headlines-frame"),
96 reply['headlines']['content'],
97 {parseContent: true});
99 $$("#headlines-frame div[id*='RROW']").each(function(row) {
100 loaded_article_ids.push(row.id);
103 $("headlines-frame").innerHTML = '';
105 var tmp = new Element("div");
106 tmp.innerHTML = reply['headlines']['content'];
107 dojo.parser.parse(tmp);
109 while (tmp.hasChildNodes()) {
110 var row = tmp.removeChild(tmp.firstChild);
112 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
113 dijit.byId("headlines-frame").domNode.appendChild(row);
115 loaded_article_ids.push(row.id);
119 var hsp = $("headlines-spacer");
120 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
121 dijit.byId('headlines-frame').domNode.appendChild(hsp);
125 if (_infscroll_disable)
126 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
127 __("Click to open next unread feed.") + "</a>";
130 $("feed_title").innerHTML += "<span id='cancel_search'>" +
131 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
137 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
138 console.log("adding some more headlines: " + headlines_count);
140 var c = dijit.byId("headlines-frame");
141 var ids = getSelectedArticleIds2();
143 var hsp = $("headlines-spacer");
146 c.domNode.removeChild(hsp);
148 var tmp = new Element("div");
149 tmp.innerHTML = reply['headlines']['content'];
150 dojo.parser.parse(tmp);
152 while (tmp.hasChildNodes()) {
153 var row = tmp.removeChild(tmp.firstChild);
155 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
156 dijit.byId("headlines-frame").domNode.appendChild(row);
158 loaded_article_ids.push(row.id);
162 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
163 c.domNode.appendChild(hsp);
165 if (headlines_count < 30) _infscroll_disable = true;
167 console.log("restore selected ids: " + ids);
169 for (var i = 0; i < ids.length; i++) {
170 markHeadline(ids[i]);
175 if (_infscroll_disable) {
176 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
177 __("Click to open next unread feed.") + "</a>";
181 console.log("no new headlines received");
183 var first_id_changed = reply['headlines']['first_id_changed'];
184 console.log("first id changed:" + first_id_changed);
186 var hsp = $("headlines-spacer");
189 if (first_id_changed) {
190 hsp.innerHTML = "<a href='#' onclick='viewCurrentFeed()'>" +
191 __("New articles found, reload feed to continue.") + "</a>";
193 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
194 __("Click to open next unread feed.") + "</a>";
203 for (var i = 0; i < articles.length; i++) {
204 var a_id = articles[i]['id'];
205 cache_set("article:" + a_id, articles[i]['content']);
208 console.log("no cached articles received");
212 parse_counters(counters);
217 console.error("Invalid object received: " + transport.responseText);
218 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
219 __('Could not update headlines (invalid object received - see error console for details)') +
223 _infscroll_request_sent = 0;
224 _last_headlines_update = new Date().getTime();
226 unpackVisibleHeadlines();
228 // if we have some more space in the buffer, why not try to fill it
230 if (!_infscroll_disable && $("headlines-spacer") &&
231 $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
233 window.setTimeout(function() {
241 function render_article(article) {
242 cleanup_memory("content-insert");
244 dijit.byId("headlines-wrap-inner").addChild(
245 dijit.byId("content-insert"));
247 var c = dijit.byId("content-insert");
250 c.domNode.scrollTop = 0;
253 c.attr('content', article);
254 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
256 correctHeadlinesOffset(getActiveArticleId());
263 function showArticleInHeadlines(id, noexpand) {
264 var row = $("RROW-" + id);
268 row.removeClassName("Unread");
270 row.addClassName("active");
272 selectArticles('none');
277 function article_callback2(transport, id) {
278 console.log("article_callback2 " + id);
280 handle_rpc_json(transport);
285 reply = JSON.parse(transport.responseText);
292 reply.each(function(article) {
293 if (getActiveArticleId() == article['id']) {
294 render_article(article['content']);
296 cids_requested.remove(article['id']);
298 cache_set("article:" + article['id'], article['content']);
301 // if (id != last_requested_article) {
302 // console.log("requested article id is out of sequence, aborting");
307 console.error("Invalid object received: " + transport.responseText);
309 render_article("<div class='whiteBox'>" +
310 __('Could not display article (invalid object received - see error console for details)') + "</div>");
313 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
314 request_counters(unread_in_buffer == 0);
319 function view(id, activefeed, noexpand) {
320 var oldrow = $("RROW-" + getActiveArticleId());
321 if (oldrow) oldrow.removeClassName("active");
323 var crow = $("RROW-" + id);
327 setActiveArticleId(id);
328 showArticleInHeadlines(id, noexpand);
332 console.log("loading article: " + id);
334 var cached_article = cache_get("article:" + id);
336 console.log("cache check result: " + (cached_article != false));
338 var query = "?op=article&method=view&id=" + param_escape(id);
340 var neighbor_ids = getRelativePostIds(id);
342 /* only request uncached articles */
344 var cids_to_request = [];
346 for (var i = 0; i < neighbor_ids.length; i++) {
347 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
348 if (!cache_get("article:" + neighbor_ids[i])) {
349 cids_to_request.push(neighbor_ids[i]);
350 cids_requested.push(neighbor_ids[i]);
354 console.log("additional ids: " + cids_to_request.toString());
356 query = query + "&cids=" + cids_to_request.toString();
358 var article_is_unread = crow.hasClassName("Unread");
360 setActiveArticleId(id);
361 showArticleInHeadlines(id);
363 if (cached_article && article_is_unread) {
365 query = query + "&mode=prefetch";
367 render_article(cached_article);
369 } else if (cached_article) {
371 query = query + "&mode=prefetch_old";
372 render_article(cached_article);
374 // if we don't need to request any relative ids, we might as well skip
375 // the server roundtrip altogether
376 if (cids_to_request.length == 0) {
381 last_requested_article = id;
385 if (article_is_unread) {
386 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
389 new Ajax.Request("backend.php", {
391 onComplete: function(transport) {
392 article_callback2(transport, id);
399 function toggleMark(id, client_only) {
400 var query = "?op=rpc&id=" + id + "&method=mark";
402 var row = $("RROW-" + id);
407 var row_imgs = row.getElementsByClassName("markedPic");
409 for (var i = 0; i < row_imgs.length; i++)
410 imgs.push(row_imgs[i]);
412 var ft = $("floatingTitle");
414 if (ft && ft.getAttribute("data-article-id") == id) {
415 var fte = ft.getElementsByClassName("markedPic");
417 for (var i = 0; i < fte.length; i++)
421 for (i = 0; i < imgs.length; i++) {
424 if (!row.hasClassName("marked")) {
425 img.src = img.src.replace("mark_unset", "mark_set");
426 query = query + "&mark=1";
428 img.src = img.src.replace("mark_set", "mark_unset");
429 query = query + "&mark=0";
433 row.toggleClassName("marked");
436 new Ajax.Request("backend.php", {
438 onComplete: function (transport) {
439 handle_rpc_json(transport);
445 function togglePub(id, client_only, no_effects, note) {
446 var query = "?op=rpc&id=" + id + "&method=publ";
448 if (note != undefined) {
449 query = query + "¬e=" + param_escape(note);
451 query = query + "¬e=undefined";
454 var row = $("RROW-" + id);
459 var row_imgs = row.getElementsByClassName("pubPic");
461 for (var i = 0; i < row_imgs.length; i++)
462 imgs.push(row_imgs[i]);
464 var ft = $("floatingTitle");
466 if (ft && ft.getAttribute("data-article-id") == id) {
467 var fte = ft.getElementsByClassName("pubPic");
469 for (var i = 0; i < fte.length; i++)
473 for (i = 0; i < imgs.length; i++) {
476 if (!row.hasClassName("published") || note != undefined) {
477 img.src = img.src.replace("pub_unset", "pub_set");
478 query = query + "&pub=1";
480 img.src = img.src.replace("pub_set", "pub_unset");
481 query = query + "&pub=0";
485 if (note != undefined)
486 row.addClassName("published");
488 row.toggleClassName("published");
491 new Ajax.Request("backend.php", {
493 onComplete: function(transport) {
494 handle_rpc_json(transport);
500 function moveToPost(mode, noscroll, noexpand) {
501 var rows = getLoadedArticleIds();
506 if (!$('RROW-' + getActiveArticleId())) {
507 setActiveArticleId(0);
510 if (!getActiveArticleId()) {
512 prev_id = rows[rows.length-1]
514 for (var i = 0; i < rows.length; i++) {
515 if (rows[i] == getActiveArticleId()) {
517 // Account for adjacent identical article ids.
518 if (i > 0) prev_id = rows[i-1];
520 for (var j = i+1; j < rows.length; j++) {
521 if (rows[j] != getActiveArticleId()) {
531 console.log("cur: " + getActiveArticleId() + " next: " + next_id);
533 if (mode == "next") {
534 if (next_id || getActiveArticleId()) {
537 var article = $("RROW-" + getActiveArticleId());
538 var ctr = $("headlines-frame");
540 if (!noscroll && article && article.offsetTop + article.offsetHeight >
541 ctr.scrollTop + ctr.offsetHeight) {
543 scrollArticle(ctr.offsetHeight/4);
545 } else if (next_id) {
546 cdmExpandArticle(next_id, noexpand);
547 cdmScrollToArticleId(next_id, true);
550 } else if (next_id) {
551 correctHeadlinesOffset(next_id);
552 view(next_id, getActiveFeedId(), noexpand);
557 if (mode == "prev") {
558 if (prev_id || getActiveArticleId()) {
561 var article = $("RROW-" + getActiveArticleId());
562 var prev_article = $("RROW-" + prev_id);
563 var ctr = $("headlines-frame");
565 if (!getInitParam("cdm_expanded")) {
567 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
568 scrollArticle(-ctr.offsetHeight/4);
570 cdmExpandArticle(prev_id, noexpand);
571 cdmScrollToArticleId(prev_id, true);
575 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
576 scrollArticle(-ctr.offsetHeight/3);
577 } else if (!noscroll && prev_article &&
578 prev_article.offsetTop < ctr.scrollTop) {
579 cdmExpandArticle(prev_id, noexpand);
580 scrollArticle(-ctr.offsetHeight/4);
581 } else if (prev_id) {
582 cdmExpandArticle(prev_id, noexpand);
583 cdmScrollToArticleId(prev_id, noscroll);
587 } else if (prev_id) {
588 correctHeadlinesOffset(prev_id);
589 view(prev_id, getActiveFeedId(), noexpand);
596 function toggleSelected(id, force_on) {
597 var row = $("RROW-" + id);
600 var cb = dijit.getEnclosingWidget(
601 row.getElementsByClassName("rchk")[0]);
603 if (row.hasClassName('Selected') && !force_on) {
604 row.removeClassName('Selected');
605 if (cb) cb.attr("checked", false);
607 row.addClassName('Selected');
608 if (cb) cb.attr("checked", true);
612 updateSelectedPrompt();
615 function updateSelectedPrompt() {
616 var count = getSelectedArticleIds2().size();
617 var elem = $("selected_prompt");
620 elem.innerHTML = ngettext("%d article selected",
621 "%d articles selected", count).replace("%d", count);
631 function toggleUnread(id, cmode, effect) {
632 var row = $("RROW-" + id);
634 var tmpClassName = row.className;
636 if (cmode == undefined || cmode == 2) {
637 if (row.hasClassName("Unread")) {
638 row.removeClassName("Unread");
641 row.addClassName("Unread");
644 } else if (cmode == 0) {
646 row.removeClassName("Unread");
648 } else if (cmode == 1) {
649 row.addClassName("Unread");
652 if (cmode == undefined) cmode = 2;
654 var query = "?op=rpc&method=catchupSelected" +
655 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
657 // notify_progress("Loading, please wait...");
659 if (tmpClassName != row.className) {
660 new Ajax.Request("backend.php", {
662 onComplete: function (transport) {
663 handle_rpc_json(transport);
671 function selectionRemoveLabel(id, ids) {
672 if (!ids) ids = getSelectedArticleIds2();
674 if (ids.length == 0) {
675 alert(__("No articles are selected."));
679 var query = "?op=article&method=removeFromLabel&ids=" +
680 param_escape(ids.toString()) + "&lid=" + param_escape(id);
684 new Ajax.Request("backend.php", {
686 onComplete: function(transport) {
687 handle_rpc_json(transport);
688 show_labels_in_headlines(transport);
693 function selectionAssignLabel(id, ids) {
694 if (!ids) ids = getSelectedArticleIds2();
696 if (ids.length == 0) {
697 alert(__("No articles are selected."));
701 var query = "?op=article&method=assignToLabel&ids=" +
702 param_escape(ids.toString()) + "&lid=" + param_escape(id);
706 new Ajax.Request("backend.php", {
708 onComplete: function(transport) {
709 handle_rpc_json(transport);
710 show_labels_in_headlines(transport);
714 function selectionToggleUnread(set_state, callback, no_error, ids) {
715 var rows = ids ? ids : getSelectedArticleIds2();
717 if (rows.length == 0 && !no_error) {
718 alert(__("No articles are selected."));
722 for (var i = 0; i < rows.length; i++) {
723 var row = $("RROW-" + rows[i]);
725 if (set_state == undefined) {
726 if (row.hasClassName("Unread")) {
727 row.removeClassName("Unread");
729 row.addClassName("Unread");
733 if (set_state == false) {
734 row.removeClassName("Unread");
737 if (set_state == true) {
738 row.addClassName("Unread");
743 updateFloatingTitle(true);
745 if (rows.length > 0) {
749 if (set_state == undefined) {
751 } else if (set_state == true) {
753 } else if (set_state == false) {
757 var query = "?op=rpc&method=catchupSelected" +
758 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
760 notify_progress("Loading, please wait...");
762 new Ajax.Request("backend.php", {
764 onComplete: function(transport) {
765 handle_rpc_json(transport);
766 if (callback) callback(transport);
773 function selectionToggleMarked(sel_state, callback, no_error, ids) {
774 var rows = ids ? ids : getSelectedArticleIds2();
776 if (rows.length == 0 && !no_error) {
777 alert(__("No articles are selected."));
781 for (var i = 0; i < rows.length; i++) {
782 toggleMark(rows[i], true, true);
785 if (rows.length > 0) {
787 var query = "?op=rpc&method=markSelected&ids=" +
788 param_escape(rows.toString()) + "&cmode=2";
790 new Ajax.Request("backend.php", {
792 onComplete: function(transport) {
793 handle_rpc_json(transport);
794 if (callback) callback(transport);
801 function selectionTogglePublished(sel_state, callback, no_error, ids) {
802 var rows = ids ? ids : getSelectedArticleIds2();
804 if (rows.length == 0 && !no_error) {
805 alert(__("No articles are selected."));
809 for (var i = 0; i < rows.length; i++) {
810 togglePub(rows[i], true, true);
813 if (rows.length > 0) {
815 var query = "?op=rpc&method=publishSelected&ids=" +
816 param_escape(rows.toString()) + "&cmode=2";
818 new Ajax.Request("backend.php", {
820 onComplete: function(transport) {
821 handle_rpc_json(transport);
827 function getSelectedArticleIds2() {
831 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
833 rv.push(child.getAttribute("data-article-id"));
839 function getLoadedArticleIds() {
842 var children = $$("#headlines-frame > div[id*=RROW-]");
844 children.each(function(child) {
845 if (Element.visible(child)) {
846 rv.push(child.getAttribute("data-article-id"));
854 // mode = all,none,unread,invert,marked,published
855 function selectArticles(mode, query) {
856 if (!query) query = "#headlines-frame > div[id*=RROW]";
858 var children = $$(query);
860 children.each(function(child) {
861 var id = child.getAttribute("data-article-id");
863 var cb = dijit.getEnclosingWidget(
864 child.getElementsByClassName("rchk")[0]);
867 child.addClassName("Selected");
868 if (cb) cb.attr("checked", true);
869 } else if (mode == "unread") {
870 if (child.hasClassName("Unread")) {
871 child.addClassName("Selected");
872 if (cb) cb.attr("checked", true);
874 child.removeClassName("Selected");
875 if (cb) cb.attr("checked", false);
877 } else if (mode == "marked") {
878 if (child.hasClassName("marked")) {
879 child.addClassName("Selected");
880 if (cb) cb.attr("checked", true);
882 child.removeClassName("Selected");
883 if (cb) cb.attr("checked", false);
885 } else if (mode == "published") {
886 if (child.hasClassName("published")) {
887 child.addClassName("Selected");
888 if (cb) cb.attr("checked", true);
890 child.removeClassName("Selected");
891 if (cb) cb.attr("checked", false);
894 } else if (mode == "invert") {
895 if (child.hasClassName("Selected")) {
896 child.removeClassName("Selected");
897 if (cb) cb.attr("checked", false);
899 child.addClassName("Selected");
900 if (cb) cb.attr("checked", true);
904 child.removeClassName("Selected");
905 if (cb) cb.attr("checked", false);
909 updateSelectedPrompt();
912 function deleteSelection() {
914 var rows = getSelectedArticleIds2();
916 if (rows.length == 0) {
917 alert(__("No articles are selected."));
921 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
924 if (getActiveFeedId() != 0) {
925 str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows.length);
927 str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
930 str = str.replace("%d", rows.length);
931 str = str.replace("%s", fn);
933 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
937 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
941 new Ajax.Request("backend.php", {
943 onComplete: function (transport) {
944 handle_rpc_json(transport);
950 function archiveSelection() {
952 var rows = getSelectedArticleIds2();
954 if (rows.length == 0) {
955 alert(__("No articles are selected."));
959 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
963 if (getActiveFeedId() != 0) {
964 str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
967 str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
969 str += " " + __("Please note that unstarred articles might get purged on next feed update.");
974 str = str.replace("%d", rows.length);
975 str = str.replace("%s", fn);
977 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
981 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
985 for (var i = 0; i < rows.length; i++) {
986 cache_delete("article:" + rows[i]);
989 new Ajax.Request("backend.php", {
991 onComplete: function(transport) {
992 handle_rpc_json(transport);
998 function catchupSelection() {
1000 var rows = getSelectedArticleIds2();
1002 if (rows.length == 0) {
1003 alert(__("No articles are selected."));
1007 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1009 var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
1011 str = str.replace("%d", rows.length);
1012 str = str.replace("%s", fn);
1014 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1018 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1021 function editArticleTags(id) {
1022 var query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id);
1024 if (dijit.byId("editTagsDlg"))
1025 dijit.byId("editTagsDlg").destroyRecursive();
1027 dialog = new dijit.Dialog({
1029 title: __("Edit article Tags"),
1030 style: "width: 600px",
1031 execute: function() {
1032 if (this.validate()) {
1033 var query = dojo.objectToQuery(this.attr('value'));
1035 notify_progress("Saving article tags...", true);
1037 new Ajax.Request("backend.php", {
1039 onComplete: function(transport) {
1044 var data = JSON.parse(transport.responseText);
1051 var tags = $("ATSTR-" + id);
1052 var tooltip = dijit.byId("ATSTRTIP-" + id);
1054 if (tags) tags.innerHTML = data.content;
1055 if (tooltip) tooltip.attr('label', data.content_full);
1067 var tmph = dojo.connect(dialog, 'onLoad', function() {
1068 dojo.disconnect(tmph);
1070 new Ajax.Autocompleter('tags_str', 'tags_choices',
1071 "backend.php?op=article&method=completeTags",
1072 { tokens: ',', paramName: "search" });
1079 function cdmScrollToArticleId(id, force) {
1080 var ctr = $("headlines-frame");
1081 var e = $("RROW-" + id);
1083 if (!e || !ctr) return;
1085 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1086 e.offsetTop < ctr.scrollTop) {
1088 // expanded cdm has a 4px margin now
1089 ctr.scrollTop = parseInt(e.offsetTop) - 4;
1093 function setActiveArticleId(id) {
1094 console.log("setActiveArticleId:" + id);
1096 _active_article_id = id;
1097 PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
1100 function getActiveArticleId() {
1101 return _active_article_id;
1104 function postMouseIn(e, id) {
1105 post_under_pointer = id;
1108 function postMouseOut(id) {
1109 post_under_pointer = false;
1112 function unpackVisibleHeadlines() {
1113 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1115 $$("#headlines-frame span.cencw[id]").each(
1117 var row = $("RROW-" + child.id.replace("CENCW-", ""));
1119 if (row && row.offsetTop <= $("headlines-frame").scrollTop +
1120 $("headlines-frame").offsetHeight) {
1122 //console.log("unpacking: " + child.id);
1124 child.innerHTML = htmlspecialchars_decode(child.innerHTML);
1125 child.removeAttribute('id');
1127 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row);
1129 Element.show(child);
1135 function headlines_scroll_handler(e) {
1138 // rate-limit in case of smooth scrolling and similar abominations
1139 if (Math.max(e.scrollTop, _headlines_scroll_offset) - Math.min(e.scrollTop, _headlines_scroll_offset) < 25) {
1143 _headlines_scroll_offset = e.scrollTop;
1145 var hsp = $("headlines-spacer");
1147 unpackVisibleHeadlines();
1149 // set topmost child in the buffer as active
1150 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1151 getSelectedArticleIds2().length <= 1 &&
1152 getInitParam("cdm_expanded")) {
1154 var rows = $$("#headlines-frame > div[id*=RROW]");
1156 for (var i = 0; i < rows.length; i++) {
1157 var child = rows[i];
1159 if ($("headlines-frame").scrollTop <= child.offsetTop &&
1160 child.offsetTop - $("headlines-frame").scrollTop < 100 &&
1161 child.getAttribute("data-article-id") != _active_article_id) {
1163 if (_active_article_id) {
1164 var row = $("RROW-" + _active_article_id);
1165 if (row) row.removeClassName("active");
1168 _active_article_id = child.getAttribute("data-article-id");
1169 showArticleInHeadlines(_active_article_id, true);
1170 updateSelectedPrompt();
1176 if (!_infscroll_disable) {
1177 if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) {
1179 hsp.innerHTML = "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1180 __("Loading, please wait...") + "</span>";
1182 loadMoreHeadlines();
1189 updateFloatingTitle();
1192 catchupCurrentBatchIfNeeded();
1194 if (getInitParam("cdm_auto_catchup") == 1) {
1196 // let's get DOM some time to settle down
1197 var ts = new Date().getTime();
1198 if (ts - _last_headlines_update < 100) return;
1200 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1202 if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
1203 (child.offsetTop + child.offsetHeight/2)) {
1205 var id = child.getAttribute("data-article-id")
1207 if (catchup_id_batch.indexOf(id) == -1)
1208 catchup_id_batch.push(id);
1210 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1215 if (_infscroll_disable) {
1216 var child = $$("#headlines-frame div[id*=RROW]").last();
1218 if (child && $("headlines-frame").scrollTop >
1219 (child.offsetTop + child.offsetHeight - 50)) {
1221 console.log("we seem to be at an end");
1223 if (getInitParam("on_catchup_show_next_feed") == "1") {
1224 openNextUnreadFeed();
1231 console.warn("headlines_scroll_handler: " + e);
1235 function openNextUnreadFeed() {
1236 var is_cat = activeFeedIsCat();
1237 var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat);
1238 if (nuf) viewfeed({feed: nuf, is_cat: is_cat});
1241 function catchupBatchedArticles() {
1242 if (catchup_id_batch.length > 0 && !_infscroll_request_sent && !_catchup_request_sent) {
1244 console.log("catchupBatchedArticles: working");
1246 // make a copy of the array
1247 var batch = catchup_id_batch.slice();
1248 var query = "?op=rpc&method=catchupSelected" +
1249 "&cmode=0&ids=" + param_escape(batch.toString());
1253 _catchup_request_sent = true;
1255 new Ajax.Request("backend.php", {
1257 onComplete: function (transport) {
1258 handle_rpc_json(transport);
1260 _catchup_request_sent = false;
1262 reply = JSON.parse(transport.responseText);
1263 var batch = reply.ids;
1265 batch.each(function (id) {
1267 var elem = $("RROW-" + id);
1268 if (elem) elem.removeClassName("Unread");
1269 catchup_id_batch.remove(id);
1272 updateFloatingTitle(true);
1279 function catchupRelativeToArticle(below, id) {
1281 if (!id) id = getActiveArticleId();
1284 alert(__("No article is selected."));
1288 var visible_ids = getLoadedArticleIds();
1290 var ids_to_mark = new Array();
1293 for (var i = 0; i < visible_ids.length; i++) {
1294 if (visible_ids[i] != id) {
1295 var e = $("RROW-" + visible_ids[i]);
1297 if (e && e.hasClassName("Unread")) {
1298 ids_to_mark.push(visible_ids[i]);
1305 for (var i = visible_ids.length - 1; i >= 0; i--) {
1306 if (visible_ids[i] != id) {
1307 var e = $("RROW-" + visible_ids[i]);
1309 if (e && e.hasClassName("Unread")) {
1310 ids_to_mark.push(visible_ids[i]);
1318 if (ids_to_mark.length == 0) {
1319 alert(__("No articles found to mark"));
1321 var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
1323 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1325 for (var i = 0; i < ids_to_mark.length; i++) {
1326 var e = $("RROW-" + ids_to_mark[i]);
1327 e.removeClassName("Unread");
1330 var query = "?op=rpc&method=catchupSelected" +
1331 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1333 new Ajax.Request("backend.php", {
1335 onComplete: function (transport) {
1336 handle_rpc_json(transport);
1344 function cdmCollapseArticle(event, id, unmark) {
1345 if (unmark == undefined) unmark = true;
1347 var row = $("RROW-" + id);
1348 var elem = $("CICD-" + id);
1351 var collapse = row.select("span[class='collapseBtn']")[0];
1354 Element.show("CEXC-" + id);
1355 Element.hide(collapse);
1358 row.removeClassName("active");
1360 markHeadline(id, false);
1362 if (id == getActiveArticleId()) {
1363 setActiveArticleId(0);
1366 updateSelectedPrompt();
1369 if (event) Event.stop(event);
1371 PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
1373 if (row.offsetTop < $("headlines-frame").scrollTop)
1374 scrollToRowId(row.id);
1376 $("floatingTitle").style.visibility = "hidden";
1377 $("floatingTitle").setAttribute("data-article-id", 0);
1381 function cdmExpandArticle(id, noexpand) {
1382 console.log("cdmExpandArticle " + id);
1384 var row = $("RROW-" + id);
1386 if (!row) return false;
1388 var oldrow = $("RROW-" + getActiveArticleId());
1390 var elem = $("CICD-" + getActiveArticleId());
1392 if (id == getActiveArticleId() && Element.visible(elem))
1395 selectArticles("none");
1397 var old_offset = row.offsetTop;
1399 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1400 var collapse = oldrow.select("span[class='collapseBtn']")[0];
1403 Element.show("CEXC-" + getActiveArticleId());
1404 Element.hide(collapse);
1407 if (oldrow) oldrow.removeClassName("active");
1409 setActiveArticleId(id);
1411 elem = $("CICD-" + id);
1413 var collapse = row.select("span[class='collapseBtn']")[0];
1415 var cencw = $("CENCW-" + id);
1417 if (!Element.visible(elem) && !noexpand) {
1419 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1420 cencw.setAttribute('id', '');
1421 Element.show(cencw);
1425 Element.hide("CEXC-" + id);
1426 Element.show(collapse);
1429 var new_offset = row.offsetTop;
1431 if (old_offset > new_offset)
1432 $("headlines-frame").scrollTop -= (old_offset - new_offset);
1435 if (catchup_id_batch.indexOf(id) == -1)
1436 catchup_id_batch.push(id);
1438 catchupCurrentBatchIfNeeded();
1442 row.addClassName("active");
1444 PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id);
1449 function getArticleUnderPointer() {
1450 return post_under_pointer;
1453 function scrollArticle(offset) {
1455 var ci = $("content-insert");
1457 ci.scrollTop += offset;
1460 var hi = $("headlines-frame");
1462 hi.scrollTop += offset;
1468 function show_labels_in_headlines(transport) {
1469 var data = JSON.parse(transport.responseText);
1472 data['info-for-headlines'].each(function (elem) {
1473 $$(".HLLCTR-" + elem.id).each(function (ctr) {
1474 ctr.innerHTML = elem.labels;
1480 function cdmClicked(event, id, in_body) {
1481 //var shift_key = event.shiftKey;
1483 if (!event.ctrlKey && !event.metaKey) {
1485 if (!getInitParam("cdm_expanded")) {
1486 return cdmExpandArticle(id);
1489 var elem = $("RROW-" + getActiveArticleId());
1491 if (elem) elem.removeClassName("active");
1493 selectArticles("none");
1496 var elem = $("RROW-" + id);
1497 var article_is_unread = elem.hasClassName("Unread");
1499 elem.removeClassName("Unread");
1500 elem.addClassName("active");
1502 setActiveArticleId(id);
1504 if (article_is_unread) {
1505 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1506 updateFloatingTitle(true);
1509 var query = "?op=rpc&method=catchupSelected" +
1510 "&cmode=0&ids=" + param_escape(id);
1512 new Ajax.Request("backend.php", {
1514 onComplete: function (transport) {
1515 handle_rpc_json(transport);
1519 return !event.shiftKey;
1522 } else if (!in_body) {
1524 toggleSelected(id, true);
1526 var elem = $("RROW-" + id);
1527 var article_is_unread = elem.hasClassName("Unread");
1529 if (article_is_unread) {
1530 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1533 toggleUnread(id, 0, false);
1535 openArticleInNewWindow(id);
1540 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1541 request_counters(unread_in_buffer == 0);
1546 function hlClicked(event, id) {
1547 if (event.which == 2) {
1550 } else if (event.ctrlKey || event.metaKey) {
1551 toggleSelected(id, true);
1552 toggleUnread(id, 0, false);
1553 openArticleInNewWindow(id);
1561 function openArticleInNewWindow(id) {
1562 toggleUnread(id, 0, false);
1564 var w = window.open("");
1566 w.location = "backend.php?op=article&method=redirect&id=" + id;
1569 function isCdmMode() {
1570 return getInitParam("combined_display_mode");
1573 function markHeadline(id, marked) {
1574 if (marked == undefined) marked = true;
1576 var row = $("RROW-" + id);
1578 var check = dijit.getEnclosingWidget(
1579 row.getElementsByClassName("rchk")[0]);
1582 check.attr("checked", marked);
1586 row.addClassName("Selected");
1588 row.removeClassName("Selected");
1592 function getRelativePostIds(id, limit) {
1596 if (!limit) limit = 6; //3
1598 var ids = getLoadedArticleIds();
1600 for (var i = 0; i < ids.length; i++) {
1602 for (var k = 1; k <= limit; k++) {
1603 //if (i > k-1) tmp.push(ids[i-k]);
1604 if (i < ids.length - k) tmp.push(ids[i + k]);
1613 function correctHeadlinesOffset(id) {
1615 var container = $("headlines-frame");
1616 var row = $("RROW-" + id);
1618 if (!container || !row) return;
1620 var viewport = container.offsetHeight;
1622 var rel_offset_top = row.offsetTop - container.scrollTop;
1623 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1625 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1626 //console.log("Vport: " + viewport);
1628 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1629 container.scrollTop = row.offsetTop;
1630 } else if (rel_offset_bottom > viewport) {
1632 /* doesn't properly work with Opera in some cases because
1633 Opera fucks up element scrolling */
1635 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1639 function headlineActionsChange(elem) {
1641 elem.attr('value', 'false');
1644 function closeArticlePanel() {
1646 if (dijit.byId("content-insert"))
1647 dijit.byId("headlines-wrap-inner").removeChild(
1648 dijit.byId("content-insert"));
1651 function initFloatingMenu() {
1652 if (!dijit.byId("floatingMenu")) {
1654 var menu = new dijit.Menu({
1656 targetNodeIds: ["floatingTitle"]
1659 headlinesMenuCommon(menu);
1665 function headlinesMenuCommon(menu) {
1667 menu.addChild(new dijit.MenuItem({
1668 label: __("Open original article"),
1669 onClick: function (event) {
1670 openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id"));
1674 menu.addChild(new dijit.MenuItem({
1675 label: __("Display article URL"),
1676 onClick: function (event) {
1677 displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id"));
1681 menu.addChild(new dijit.MenuSeparator());
1683 menu.addChild(new dijit.MenuItem({
1684 label: __("Toggle unread"),
1685 onClick: function (event) {
1687 var ids = getSelectedArticleIds2();
1689 var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1690 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1692 selectionToggleUnread(undefined, false, true, ids);
1696 menu.addChild(new dijit.MenuItem({
1697 label: __("Toggle starred"),
1698 onClick: function (event) {
1699 var ids = getSelectedArticleIds2();
1701 var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1702 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1704 selectionToggleMarked(undefined, false, true, ids);
1708 menu.addChild(new dijit.MenuItem({
1709 label: __("Toggle published"),
1710 onClick: function (event) {
1711 var ids = getSelectedArticleIds2();
1713 var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1714 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1716 selectionTogglePublished(undefined, false, true, ids);
1720 menu.addChild(new dijit.MenuSeparator());
1722 menu.addChild(new dijit.MenuItem({
1723 label: __("Mark above as read"),
1724 onClick: function (event) {
1725 catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id"));
1729 menu.addChild(new dijit.MenuItem({
1730 label: __("Mark below as read"),
1731 onClick: function (event) {
1732 catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id"));
1737 var labels = getInitParam("labels");
1739 if (labels && labels.length) {
1741 menu.addChild(new dijit.MenuSeparator());
1743 var labelAddMenu = new dijit.Menu({ownerMenu: menu});
1744 var labelDelMenu = new dijit.Menu({ownerMenu: menu});
1746 labels.each(function (label) {
1747 var bare_id = label.id;
1748 var name = label.caption;
1750 labelAddMenu.addChild(new dijit.MenuItem({
1753 onClick: function (event) {
1755 var ids = getSelectedArticleIds2();
1757 var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
1759 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1761 selectionAssignLabel(this.labelId, ids);
1765 labelDelMenu.addChild(new dijit.MenuItem({
1768 onClick: function (event) {
1769 var ids = getSelectedArticleIds2();
1771 var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
1773 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1775 selectionRemoveLabel(this.labelId, ids);
1781 menu.addChild(new dijit.PopupMenuItem({
1782 label: __("Assign label"),
1786 menu.addChild(new dijit.PopupMenuItem({
1787 label: __("Remove label"),
1794 function initHeadlinesMenu() {
1795 if (!dijit.byId("headlinesMenu")) {
1797 var menu = new dijit.Menu({
1798 id: "headlinesMenu",
1799 targetNodeIds: ["headlines-frame"],
1800 selector: ".hlMenuAttach"
1803 headlinesMenuCommon(menu);
1808 /* vgroup feed title menu */
1810 if (!dijit.byId("headlinesFeedTitleMenu")) {
1812 var menu = new dijit.Menu({
1813 id: "headlinesFeedTitleMenu",
1814 targetNodeIds: ["headlines-frame"],
1815 selector: "div.cdmFeedTitle"
1818 menu.addChild(new dijit.MenuItem({
1819 label: __("Select articles in group"),
1820 onClick: function (event) {
1821 selectArticles("all",
1822 "#headlines-frame > div[id*=RROW]" +
1823 "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
1828 menu.addChild(new dijit.MenuItem({
1829 label: __("Mark group as read"),
1830 onClick: function (event) {
1831 selectArticles("none");
1832 selectArticles("all",
1833 "#headlines-frame > div[id*=RROW]" +
1834 "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
1840 menu.addChild(new dijit.MenuItem({
1841 label: __("Mark feed as read"),
1842 onClick: function (event) {
1843 catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id"));
1847 menu.addChild(new dijit.MenuItem({
1848 label: __("Edit feed"),
1849 onClick: function (event) {
1850 editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
1858 function cache_set(id, obj) {
1859 //console.log("cache_set: " + id);
1862 sessionStorage[id] = obj;
1864 sessionStorage.clear();
1868 function cache_get(id) {
1870 return sessionStorage[id];
1873 function cache_clear() {
1875 sessionStorage.clear();
1878 function cache_delete(id) {
1880 sessionStorage.removeItem(id);
1883 function cancelSearch() {
1888 function setSelectionScore() {
1889 var ids = getSelectedArticleIds2();
1891 if (ids.length > 0) {
1894 var score = prompt(__("Please enter new score for selected articles:"), score);
1896 if (score != undefined) {
1897 var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
1898 "&score=" + param_escape(score);
1900 new Ajax.Request("backend.php", {
1902 onComplete: function (transport) {
1903 var reply = JSON.parse(transport.responseText);
1907 ids.each(function (id) {
1908 var row = $("RROW-" + id);
1911 var pic = row.getElementsByClassName("hlScorePic")[0];
1914 pic.src = pic.src.replace(/score_.*?\.png/,
1915 reply["score_pic"]);
1916 pic.setAttribute("score", score);
1926 alert(__("No articles are selected."));
1930 function updateScore(id) {
1931 var pic = $$("#RROW-" + id + " .hlScorePic")[0];
1935 var query = "op=article&method=getScore&id=" + param_escape(id);
1937 new Ajax.Request("backend.php", {
1939 onComplete: function (transport) {
1940 console.log(transport.responseText);
1942 var reply = JSON.parse(transport.responseText);
1945 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
1946 pic.setAttribute("score", reply["score"]);
1947 pic.setAttribute("title", reply["score"]);
1954 function changeScore(id, pic) {
1955 var score = pic.getAttribute("score");
1957 var new_score = prompt(__("Please enter new score for this article:"), score);
1959 if (new_score != undefined) {
1961 var query = "op=article&method=setScore&id=" + param_escape(id) +
1962 "&score=" + param_escape(new_score);
1964 new Ajax.Request("backend.php", {
1966 onComplete: function (transport) {
1967 var reply = JSON.parse(transport.responseText);
1970 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
1971 pic.setAttribute("score", new_score);
1972 pic.setAttribute("title", new_score);
1979 function displayArticleUrl(id) {
1980 var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
1982 new Ajax.Request("backend.php", {
1984 onComplete: function (transport) {
1985 var reply = JSON.parse(transport.responseText);
1987 if (reply && reply.link) {
1988 prompt(__("Article URL:"), reply.link);
1994 function scrollToRowId(id) {
1998 $("headlines-frame").scrollTop = row.offsetTop - 4;
2001 function updateFloatingTitle(unread_only) {
2002 if (!isCdmMode()) return;
2004 var hf = $("headlines-frame");
2006 var elems = $$("#headlines-frame > div[id*=RROW]");
2008 for (var i = 0; i < elems.length; i++) {
2010 var child = elems[i];
2012 if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
2014 var header = child.getElementsByClassName("cdmHeader")[0];
2016 if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2017 if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2019 $("floatingTitle").setAttribute("data-article-id", child.getAttribute("data-article-id"));
2020 $("floatingTitle").innerHTML = header.innerHTML;
2021 $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('" + child.id + "')\">" + $("floatingTitle").firstChild.innerHTML;
2025 var cb = $$("#floatingTitle .dijitCheckBox")[0];
2028 cb.parentNode.removeChild(cb);
2031 if (child.hasClassName("Unread"))
2032 $("floatingTitle").addClassName("Unread");
2034 $("floatingTitle").removeClassName("Unread");
2036 PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
2039 $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
2040 if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
2041 child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
2042 $("floatingTitle").style.visibility = "visible";
2044 $("floatingTitle").style.visibility = "hidden";
2052 function catchupCurrentBatchIfNeeded() {
2053 if (catchup_id_batch.length > 0) {
2054 window.clearTimeout(catchup_timeout_id);
2055 catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000);
2057 if (catchup_id_batch.length >= 10) {
2058 catchupBatchedArticles();
2063 function cdmFooterClick(event) {
2064 event.stopPropagation();