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 let 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 const 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 const counters = reply['counters'];
85 const 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>)" +
135 } else if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
136 console.log("adding some more headlines: " + headlines_count);
138 const c = dijit.byId("headlines-frame");
139 const ids = getSelectedArticleIds2();
141 var hsp = $("headlines-spacer");
144 c.domNode.removeChild(hsp);
146 var tmp = new Element("div");
147 tmp.innerHTML = reply['headlines']['content'];
148 dojo.parser.parse(tmp);
150 while (tmp.hasChildNodes()) {
151 var row = tmp.removeChild(tmp.firstChild);
153 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
154 dijit.byId("headlines-frame").domNode.appendChild(row);
156 loaded_article_ids.push(row.id);
160 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
161 c.domNode.appendChild(hsp);
163 if (headlines_count < 30) _infscroll_disable = true;
165 console.log("restore selected ids: " + ids);
167 for (var i = 0; i < ids.length; i++) {
168 markHeadline(ids[i]);
173 if (_infscroll_disable) {
174 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
175 __("Click to open next unread feed.") + "</a>";
179 console.log("no new headlines received");
181 const first_id_changed = reply['headlines']['first_id_changed'];
182 console.log("first id changed:" + first_id_changed);
184 var hsp = $("headlines-spacer");
187 if (first_id_changed) {
188 hsp.innerHTML = "<a href='#' onclick='viewCurrentFeed()'>" +
189 __("New articles found, reload feed to continue.") + "</a>";
191 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
192 __("Click to open next unread feed.") + "</a>";
200 for (var i = 0; i < articles.length; i++) {
201 const a_id = articles[i]['id'];
202 cache_set("article:" + a_id, articles[i]['content']);
205 console.log("no cached articles received");
209 parse_counters(counters);
214 console.error("Invalid object received: " + transport.responseText);
215 dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
216 __('Could not update headlines (invalid object received - see error console for details)') +
220 _infscroll_request_sent = 0;
221 _last_headlines_update = new Date().getTime();
223 unpackVisibleHeadlines();
225 // if we have some more space in the buffer, why not try to fill it
227 if (!_infscroll_disable && $("headlines-spacer") &&
228 $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
230 window.setTimeout(function() {
238 function render_article(article) {
239 cleanup_memory("content-insert");
241 dijit.byId("headlines-wrap-inner").addChild(
242 dijit.byId("content-insert"));
244 const c = dijit.byId("content-insert");
247 c.domNode.scrollTop = 0;
250 c.attr('content', article);
251 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode);
253 correctHeadlinesOffset(getActiveArticleId());
260 function showArticleInHeadlines(id, noexpand) {
261 const row = $("RROW-" + id);
265 row.removeClassName("Unread");
267 row.addClassName("active");
269 selectArticles('none');
274 function article_callback2(transport, id) {
275 console.log("article_callback2 " + id);
277 handle_rpc_json(transport);
282 reply = JSON.parse(transport.responseText);
289 reply.each(function(article) {
290 if (getActiveArticleId() == article['id']) {
291 render_article(article['content']);
293 cids_requested.remove(article['id']);
295 cache_set("article:" + article['id'], article['content']);
298 // if (id != last_requested_article) {
299 // console.log("requested article id is out of sequence, aborting");
304 console.error("Invalid object received: " + transport.responseText);
306 render_article("<div class='whiteBox'>" +
307 __('Could not display article (invalid object received - see error console for details)') + "</div>");
310 const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
311 request_counters(unread_in_buffer == 0);
316 function view(id, activefeed, noexpand) {
317 const oldrow = $("RROW-" + getActiveArticleId());
318 if (oldrow) oldrow.removeClassName("active");
320 const crow = $("RROW-" + id);
324 setActiveArticleId(id);
325 showArticleInHeadlines(id, noexpand);
329 console.log("loading article: " + id);
331 const cached_article = cache_get("article:" + id);
333 console.log("cache check result: " + (cached_article != false));
335 let query = "?op=article&method=view&id=" + param_escape(id);
337 const neighbor_ids = getRelativePostIds(id);
339 /* only request uncached articles */
341 const cids_to_request = [];
343 for (let i = 0; i < neighbor_ids.length; i++) {
344 if (cids_requested.indexOf(neighbor_ids[i]) == -1)
345 if (!cache_get("article:" + neighbor_ids[i])) {
346 cids_to_request.push(neighbor_ids[i]);
347 cids_requested.push(neighbor_ids[i]);
351 console.log("additional ids: " + cids_to_request.toString());
353 query = query + "&cids=" + cids_to_request.toString();
355 const article_is_unread = crow.hasClassName("Unread");
357 setActiveArticleId(id);
358 showArticleInHeadlines(id);
360 if (cached_article && article_is_unread) {
362 query = query + "&mode=prefetch";
364 render_article(cached_article);
366 } else if (cached_article) {
368 query = query + "&mode=prefetch_old";
369 render_article(cached_article);
371 // if we don't need to request any relative ids, we might as well skip
372 // the server roundtrip altogether
373 if (cids_to_request.length == 0) {
378 last_requested_article = id;
382 if (article_is_unread) {
383 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
386 new Ajax.Request("backend.php", {
388 onComplete: function(transport) {
389 article_callback2(transport, id);
396 function toggleMark(id, client_only) {
397 let query = "?op=rpc&id=" + id + "&method=mark";
399 const row = $("RROW-" + id);
404 const row_imgs = row.getElementsByClassName("markedPic");
406 for (var i = 0; i < row_imgs.length; i++)
407 imgs.push(row_imgs[i]);
409 const ft = $("floatingTitle");
411 if (ft && ft.getAttribute("data-article-id") == id) {
412 const fte = ft.getElementsByClassName("markedPic");
414 for (var i = 0; i < fte.length; i++)
418 for (i = 0; i < imgs.length; i++) {
421 if (!row.hasClassName("marked")) {
422 img.src = img.src.replace("mark_unset", "mark_set");
423 query = query + "&mark=1";
425 img.src = img.src.replace("mark_set", "mark_unset");
426 query = query + "&mark=0";
430 row.toggleClassName("marked");
433 new Ajax.Request("backend.php", {
435 onComplete: function (transport) {
436 handle_rpc_json(transport);
442 function togglePub(id, client_only, no_effects, note) {
443 let query = "?op=rpc&id=" + id + "&method=publ";
445 if (note != undefined) {
446 query = query + "¬e=" + param_escape(note);
448 query = query + "¬e=undefined";
451 const row = $("RROW-" + id);
456 const row_imgs = row.getElementsByClassName("pubPic");
458 for (var i = 0; i < row_imgs.length; i++)
459 imgs.push(row_imgs[i]);
461 const ft = $("floatingTitle");
463 if (ft && ft.getAttribute("data-article-id") == id) {
464 const fte = ft.getElementsByClassName("pubPic");
466 for (var i = 0; i < fte.length; i++)
470 for (var i = 0; i < imgs.length; i++) {
473 if (!row.hasClassName("published") || note != undefined) {
474 img.src = img.src.replace("pub_unset", "pub_set");
475 query = query + "&pub=1";
477 img.src = img.src.replace("pub_set", "pub_unset");
478 query = query + "&pub=0";
482 if (note != undefined)
483 row.addClassName("published");
485 row.toggleClassName("published");
488 new Ajax.Request("backend.php", {
490 onComplete: function(transport) {
491 handle_rpc_json(transport);
497 function moveToPost(mode, noscroll, noexpand) {
498 const rows = getLoadedArticleIds();
503 if (!$('RROW-' + getActiveArticleId())) {
504 setActiveArticleId(0);
507 if (!getActiveArticleId()) {
509 prev_id = rows[rows.length-1]
511 for (let i = 0; i < rows.length; i++) {
512 if (rows[i] == getActiveArticleId()) {
514 // Account for adjacent identical article ids.
515 if (i > 0) prev_id = rows[i-1];
517 for (let j = i+1; j < rows.length; j++) {
518 if (rows[j] != getActiveArticleId()) {
528 console.log("cur: " + getActiveArticleId() + " next: " + next_id);
530 if (mode == "next") {
531 if (next_id || getActiveArticleId()) {
534 var article = $("RROW-" + getActiveArticleId());
535 var ctr = $("headlines-frame");
537 if (!noscroll && article && article.offsetTop + article.offsetHeight >
538 ctr.scrollTop + ctr.offsetHeight) {
540 scrollArticle(ctr.offsetHeight/4);
542 } else if (next_id) {
543 cdmExpandArticle(next_id, noexpand);
544 cdmScrollToArticleId(next_id, true);
547 } else if (next_id) {
548 correctHeadlinesOffset(next_id);
549 view(next_id, getActiveFeedId(), noexpand);
554 if (mode == "prev") {
555 if (prev_id || getActiveArticleId()) {
558 var article = $("RROW-" + getActiveArticleId());
559 const prev_article = $("RROW-" + prev_id);
560 var ctr = $("headlines-frame");
562 if (!getInitParam("cdm_expanded")) {
564 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
565 scrollArticle(-ctr.offsetHeight/4);
567 cdmExpandArticle(prev_id, noexpand);
568 cdmScrollToArticleId(prev_id, true);
570 } else if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
571 scrollArticle(-ctr.offsetHeight/3);
572 } else if (!noscroll && prev_article &&
573 prev_article.offsetTop < ctr.scrollTop) {
574 cdmExpandArticle(prev_id, noexpand);
575 scrollArticle(-ctr.offsetHeight/4);
576 } else if (prev_id) {
577 cdmExpandArticle(prev_id, noexpand);
578 cdmScrollToArticleId(prev_id, noscroll);
581 } else if (prev_id) {
582 correctHeadlinesOffset(prev_id);
583 view(prev_id, getActiveFeedId(), noexpand);
590 function toggleSelected(id, force_on) {
591 const row = $("RROW-" + id);
594 const cb = dijit.getEnclosingWidget(
595 row.getElementsByClassName("rchk")[0]);
597 if (row.hasClassName('Selected') && !force_on) {
598 row.removeClassName('Selected');
599 if (cb) cb.attr("checked", false);
601 row.addClassName('Selected');
602 if (cb) cb.attr("checked", true);
606 updateSelectedPrompt();
609 function updateSelectedPrompt() {
610 const count = getSelectedArticleIds2().size();
611 const elem = $("selected_prompt");
614 elem.innerHTML = ngettext("%d article selected",
615 "%d articles selected", count).replace("%d", count);
625 function toggleUnread(id, cmode, effect) {
626 const row = $("RROW-" + id);
628 const tmpClassName = row.className;
630 if (cmode == undefined || cmode == 2) {
631 if (row.hasClassName("Unread")) {
632 row.removeClassName("Unread");
635 row.addClassName("Unread");
638 } else if (cmode == 0) {
640 row.removeClassName("Unread");
642 } else if (cmode == 1) {
643 row.addClassName("Unread");
646 if (cmode == undefined) cmode = 2;
648 const query = "?op=rpc&method=catchupSelected" +
649 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
651 // notify_progress("Loading, please wait...");
653 if (tmpClassName != row.className) {
654 new Ajax.Request("backend.php", {
656 onComplete: function (transport) {
657 handle_rpc_json(transport);
665 function selectionRemoveLabel(id, ids) {
666 if (!ids) ids = getSelectedArticleIds2();
668 if (ids.length == 0) {
669 alert(__("No articles are selected."));
673 const query = "?op=article&method=removeFromLabel&ids=" +
674 param_escape(ids.toString()) + "&lid=" + param_escape(id);
678 new Ajax.Request("backend.php", {
680 onComplete: function(transport) {
681 handle_rpc_json(transport);
682 show_labels_in_headlines(transport);
687 function selectionAssignLabel(id, ids) {
688 if (!ids) ids = getSelectedArticleIds2();
690 if (ids.length == 0) {
691 alert(__("No articles are selected."));
695 const query = "?op=article&method=assignToLabel&ids=" +
696 param_escape(ids.toString()) + "&lid=" + param_escape(id);
700 new Ajax.Request("backend.php", {
702 onComplete: function(transport) {
703 handle_rpc_json(transport);
704 show_labels_in_headlines(transport);
708 function selectionToggleUnread(set_state, callback, no_error, ids) {
709 const rows = ids ? ids : getSelectedArticleIds2();
711 if (rows.length == 0 && !no_error) {
712 alert(__("No articles are selected."));
716 for (let i = 0; i < rows.length; i++) {
717 const row = $("RROW-" + rows[i]);
719 if (set_state == undefined) {
720 if (row.hasClassName("Unread")) {
721 row.removeClassName("Unread");
723 row.addClassName("Unread");
727 if (set_state == false) {
728 row.removeClassName("Unread");
731 if (set_state == true) {
732 row.addClassName("Unread");
737 updateFloatingTitle(true);
739 if (rows.length > 0) {
743 if (set_state == undefined) {
745 } else if (set_state == true) {
747 } else if (set_state == false) {
751 const query = "?op=rpc&method=catchupSelected" +
752 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
754 notify_progress("Loading, please wait...");
756 new Ajax.Request("backend.php", {
758 onComplete: function(transport) {
759 handle_rpc_json(transport);
760 if (callback) callback(transport);
767 function selectionToggleMarked(sel_state, callback, no_error, ids) {
768 const rows = ids ? ids : getSelectedArticleIds2();
770 if (rows.length == 0 && !no_error) {
771 alert(__("No articles are selected."));
775 for (let i = 0; i < rows.length; i++) {
776 toggleMark(rows[i], true, true);
779 if (rows.length > 0) {
781 const query = "?op=rpc&method=markSelected&ids=" +
782 param_escape(rows.toString()) + "&cmode=2";
784 new Ajax.Request("backend.php", {
786 onComplete: function(transport) {
787 handle_rpc_json(transport);
788 if (callback) callback(transport);
795 function selectionTogglePublished(sel_state, callback, no_error, ids) {
796 const rows = ids ? ids : getSelectedArticleIds2();
798 if (rows.length == 0 && !no_error) {
799 alert(__("No articles are selected."));
803 for (let i = 0; i < rows.length; i++) {
804 togglePub(rows[i], true, true);
807 if (rows.length > 0) {
809 const query = "?op=rpc&method=publishSelected&ids=" +
810 param_escape(rows.toString()) + "&cmode=2";
812 new Ajax.Request("backend.php", {
814 onComplete: function(transport) {
815 handle_rpc_json(transport);
821 function getSelectedArticleIds2() {
825 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
827 rv.push(child.getAttribute("data-article-id"));
833 function getLoadedArticleIds() {
836 const children = $$("#headlines-frame > div[id*=RROW-]");
838 children.each(function(child) {
839 if (Element.visible(child)) {
840 rv.push(child.getAttribute("data-article-id"));
848 // mode = all,none,unread,invert,marked,published
849 function selectArticles(mode, query) {
850 if (!query) query = "#headlines-frame > div[id*=RROW]";
852 const children = $$(query);
854 children.each(function(child) {
855 const id = child.getAttribute("data-article-id");
857 const cb = dijit.getEnclosingWidget(
858 child.getElementsByClassName("rchk")[0]);
861 child.addClassName("Selected");
862 if (cb) cb.attr("checked", true);
863 } else if (mode == "unread") {
864 if (child.hasClassName("Unread")) {
865 child.addClassName("Selected");
866 if (cb) cb.attr("checked", true);
868 child.removeClassName("Selected");
869 if (cb) cb.attr("checked", false);
871 } else if (mode == "marked") {
872 if (child.hasClassName("marked")) {
873 child.addClassName("Selected");
874 if (cb) cb.attr("checked", true);
876 child.removeClassName("Selected");
877 if (cb) cb.attr("checked", false);
879 } else if (mode == "published") {
880 if (child.hasClassName("published")) {
881 child.addClassName("Selected");
882 if (cb) cb.attr("checked", true);
884 child.removeClassName("Selected");
885 if (cb) cb.attr("checked", false);
888 } else if (mode == "invert") {
889 if (child.hasClassName("Selected")) {
890 child.removeClassName("Selected");
891 if (cb) cb.attr("checked", false);
893 child.addClassName("Selected");
894 if (cb) cb.attr("checked", true);
898 child.removeClassName("Selected");
899 if (cb) cb.attr("checked", false);
903 updateSelectedPrompt();
906 function deleteSelection() {
908 const rows = getSelectedArticleIds2();
910 if (rows.length == 0) {
911 alert(__("No articles are selected."));
915 const fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
918 if (getActiveFeedId() != 0) {
919 str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows.length);
921 str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
924 str = str.replace("%d", rows.length);
925 str = str.replace("%s", fn);
927 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
931 const query = "?op=rpc&method=delete&ids=" + param_escape(rows);
935 new Ajax.Request("backend.php", {
937 onComplete: function (transport) {
938 handle_rpc_json(transport);
944 function archiveSelection() {
946 const rows = getSelectedArticleIds2();
948 if (rows.length == 0) {
949 alert(__("No articles are selected."));
953 const fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
957 if (getActiveFeedId() != 0) {
958 str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
961 str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
963 str += " " + __("Please note that unstarred articles might get purged on next feed update.");
968 str = str.replace("%d", rows.length);
969 str = str.replace("%s", fn);
971 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
975 const query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
979 for (let i = 0; i < rows.length; i++) {
980 cache_delete("article:" + rows[i]);
983 new Ajax.Request("backend.php", {
985 onComplete: function(transport) {
986 handle_rpc_json(transport);
992 function catchupSelection() {
994 const rows = getSelectedArticleIds2();
996 if (rows.length == 0) {
997 alert(__("No articles are selected."));
1001 const fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1003 let str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
1005 str = str.replace("%d", rows.length);
1006 str = str.replace("%s", fn);
1008 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1012 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1015 function editArticleTags(id) {
1016 const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id);
1018 if (dijit.byId("editTagsDlg"))
1019 dijit.byId("editTagsDlg").destroyRecursive();
1021 var dialog = new dijit.Dialog({
1023 title: __("Edit article Tags"),
1024 style: "width: 600px",
1025 execute: function() {
1026 if (this.validate()) {
1027 const query = dojo.objectToQuery(this.attr('value'));
1029 notify_progress("Saving article tags...", true);
1031 new Ajax.Request("backend.php", {
1033 onComplete: function(transport) {
1038 const data = JSON.parse(transport.responseText);
1045 const tags = $("ATSTR-" + id);
1046 const tooltip = dijit.byId("ATSTRTIP-" + id);
1048 if (tags) tags.innerHTML = data.content;
1049 if (tooltip) tooltip.attr('label', data.content_full);
1061 var tmph = dojo.connect(dialog, 'onLoad', function() {
1062 dojo.disconnect(tmph);
1064 new Ajax.Autocompleter('tags_str', 'tags_choices',
1065 "backend.php?op=article&method=completeTags",
1066 { tokens: ',', paramName: "search" });
1073 function cdmScrollToArticleId(id, force) {
1074 const ctr = $("headlines-frame");
1075 const e = $("RROW-" + id);
1077 if (!e || !ctr) return;
1079 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1080 e.offsetTop < ctr.scrollTop) {
1082 // expanded cdm has a 4px margin now
1083 ctr.scrollTop = parseInt(e.offsetTop) - 4;
1087 function setActiveArticleId(id) {
1088 console.log("setActiveArticleId:" + id);
1090 _active_article_id = id;
1091 PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
1094 function getActiveArticleId() {
1095 return _active_article_id;
1098 function postMouseIn(e, id) {
1099 post_under_pointer = id;
1102 function postMouseOut(id) {
1103 post_under_pointer = false;
1106 function unpackVisibleHeadlines() {
1107 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1109 $$("#headlines-frame span.cencw[id]").each(
1111 const row = $("RROW-" + child.id.replace("CENCW-", ""));
1113 if (row && row.offsetTop <= $("headlines-frame").scrollTop +
1114 $("headlines-frame").offsetHeight) {
1116 //console.log("unpacking: " + child.id);
1118 child.innerHTML = htmlspecialchars_decode(child.innerHTML);
1119 child.removeAttribute('id');
1121 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row);
1123 Element.show(child);
1129 function headlines_scroll_handler(e) {
1132 // rate-limit in case of smooth scrolling and similar abominations
1133 if (Math.max(e.scrollTop, _headlines_scroll_offset) - Math.min(e.scrollTop, _headlines_scroll_offset) < 25) {
1137 _headlines_scroll_offset = e.scrollTop;
1139 const hsp = $("headlines-spacer");
1141 unpackVisibleHeadlines();
1143 // set topmost child in the buffer as active
1144 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1145 getSelectedArticleIds2().length <= 1 &&
1146 getInitParam("cdm_expanded")) {
1148 const rows = $$("#headlines-frame > div[id*=RROW]");
1150 for (let i = 0; i < rows.length; i++) {
1151 var child = rows[i];
1153 if ($("headlines-frame").scrollTop <= child.offsetTop &&
1154 child.offsetTop - $("headlines-frame").scrollTop < 100 &&
1155 child.getAttribute("data-article-id") != _active_article_id) {
1157 if (_active_article_id) {
1158 const row = $("RROW-" + _active_article_id);
1159 if (row) row.removeClassName("active");
1162 _active_article_id = child.getAttribute("data-article-id");
1163 showArticleInHeadlines(_active_article_id, true);
1164 updateSelectedPrompt();
1170 if (!_infscroll_disable) {
1171 if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) {
1173 hsp.innerHTML = "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1174 __("Loading, please wait...") + "</span>";
1176 loadMoreHeadlines();
1183 updateFloatingTitle();
1186 catchupCurrentBatchIfNeeded();
1188 if (getInitParam("cdm_auto_catchup") == 1) {
1190 // let's get DOM some time to settle down
1191 const ts = new Date().getTime();
1192 if (ts - _last_headlines_update < 100) return;
1194 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1196 if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
1197 (child.offsetTop + child.offsetHeight/2)) {
1199 const id = child.getAttribute("data-article-id")
1201 if (catchup_id_batch.indexOf(id) == -1)
1202 catchup_id_batch.push(id);
1204 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1209 if (_infscroll_disable) {
1210 var child = $$("#headlines-frame div[id*=RROW]").last();
1212 if (child && $("headlines-frame").scrollTop >
1213 (child.offsetTop + child.offsetHeight - 50)) {
1215 console.log("we seem to be at an end");
1217 if (getInitParam("on_catchup_show_next_feed") == "1") {
1218 openNextUnreadFeed();
1225 console.warn("headlines_scroll_handler: " + e);
1229 function openNextUnreadFeed() {
1230 const is_cat = activeFeedIsCat();
1231 const nuf = getNextUnreadFeed(getActiveFeedId(), is_cat);
1232 if (nuf) viewfeed({feed: nuf, is_cat: is_cat});
1235 function catchupBatchedArticles() {
1236 if (catchup_id_batch.length > 0 && !_infscroll_request_sent && !_catchup_request_sent) {
1238 console.log("catchupBatchedArticles: working");
1240 // make a copy of the array
1241 const batch = catchup_id_batch.slice();
1242 const query = "?op=rpc&method=catchupSelected" +
1243 "&cmode=0&ids=" + param_escape(batch.toString());
1247 _catchup_request_sent = true;
1249 new Ajax.Request("backend.php", {
1251 onComplete: function (transport) {
1252 handle_rpc_json(transport);
1254 _catchup_request_sent = false;
1256 const reply = JSON.parse(transport.responseText);
1257 const batch = reply.ids;
1259 batch.each(function (id) {
1261 const elem = $("RROW-" + id);
1262 if (elem) elem.removeClassName("Unread");
1263 catchup_id_batch.remove(id);
1266 updateFloatingTitle(true);
1273 function catchupRelativeToArticle(below, id) {
1275 if (!id) id = getActiveArticleId();
1278 alert(__("No article is selected."));
1282 const visible_ids = getLoadedArticleIds();
1284 const ids_to_mark = new Array();
1287 for (var i = 0; i < visible_ids.length; i++) {
1288 if (visible_ids[i] != id) {
1289 var e = $("RROW-" + visible_ids[i]);
1291 if (e && e.hasClassName("Unread")) {
1292 ids_to_mark.push(visible_ids[i]);
1299 for (var i = visible_ids.length - 1; i >= 0; i--) {
1300 if (visible_ids[i] != id) {
1301 var e = $("RROW-" + visible_ids[i]);
1303 if (e && e.hasClassName("Unread")) {
1304 ids_to_mark.push(visible_ids[i]);
1312 if (ids_to_mark.length == 0) {
1313 alert(__("No articles found to mark"));
1315 const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
1317 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1319 for (var i = 0; i < ids_to_mark.length; i++) {
1320 var e = $("RROW-" + ids_to_mark[i]);
1321 e.removeClassName("Unread");
1324 const query = "?op=rpc&method=catchupSelected" +
1325 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1327 new Ajax.Request("backend.php", {
1329 onComplete: function (transport) {
1330 handle_rpc_json(transport);
1338 function cdmCollapseArticle(event, id, unmark) {
1339 if (unmark == undefined) unmark = true;
1341 const row = $("RROW-" + id);
1342 const elem = $("CICD-" + id);
1345 const collapse = row.select("span[class='collapseBtn']")[0];
1348 Element.show("CEXC-" + id);
1349 Element.hide(collapse);
1352 row.removeClassName("active");
1354 markHeadline(id, false);
1356 if (id == getActiveArticleId()) {
1357 setActiveArticleId(0);
1360 updateSelectedPrompt();
1363 if (event) Event.stop(event);
1365 PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
1367 if (row.offsetTop < $("headlines-frame").scrollTop)
1368 scrollToRowId(row.id);
1370 $("floatingTitle").style.visibility = "hidden";
1371 $("floatingTitle").setAttribute("data-article-id", 0);
1375 function cdmExpandArticle(id, noexpand) {
1376 console.log("cdmExpandArticle " + id);
1378 const row = $("RROW-" + id);
1380 if (!row) return false;
1382 const oldrow = $("RROW-" + getActiveArticleId());
1384 let elem = $("CICD-" + getActiveArticleId());
1386 if (id == getActiveArticleId() && Element.visible(elem))
1389 selectArticles("none");
1391 const old_offset = row.offsetTop;
1393 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1394 var collapse = oldrow.select("span[class='collapseBtn']")[0];
1397 Element.show("CEXC-" + getActiveArticleId());
1398 Element.hide(collapse);
1401 if (oldrow) oldrow.removeClassName("active");
1403 setActiveArticleId(id);
1405 elem = $("CICD-" + id);
1407 var collapse = row.select("span[class='collapseBtn']")[0];
1409 const cencw = $("CENCW-" + id);
1411 if (!Element.visible(elem) && !noexpand) {
1413 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1414 cencw.setAttribute('id', '');
1415 Element.show(cencw);
1419 Element.hide("CEXC-" + id);
1420 Element.show(collapse);
1423 const new_offset = row.offsetTop;
1425 if (old_offset > new_offset)
1426 $("headlines-frame").scrollTop -= (old_offset - new_offset);
1429 if (catchup_id_batch.indexOf(id) == -1)
1430 catchup_id_batch.push(id);
1432 catchupCurrentBatchIfNeeded();
1436 row.addClassName("active");
1438 PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id);
1443 function getArticleUnderPointer() {
1444 return post_under_pointer;
1447 function scrollArticle(offset) {
1449 const ci = $("content-insert");
1451 ci.scrollTop += offset;
1454 const hi = $("headlines-frame");
1456 hi.scrollTop += offset;
1462 function show_labels_in_headlines(transport) {
1463 const data = JSON.parse(transport.responseText);
1466 data['info-for-headlines'].each(function (elem) {
1467 $$(".HLLCTR-" + elem.id).each(function (ctr) {
1468 ctr.innerHTML = elem.labels;
1474 function cdmClicked(event, id, in_body) {
1475 //var shift_key = event.shiftKey;
1477 if (!event.ctrlKey && !event.metaKey) {
1479 if (!getInitParam("cdm_expanded")) {
1480 return cdmExpandArticle(id);
1483 var elem = $("RROW-" + getActiveArticleId());
1485 if (elem) elem.removeClassName("active");
1487 selectArticles("none");
1490 var elem = $("RROW-" + id);
1491 var article_is_unread = elem.hasClassName("Unread");
1493 elem.removeClassName("Unread");
1494 elem.addClassName("active");
1496 setActiveArticleId(id);
1498 if (article_is_unread) {
1499 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1500 updateFloatingTitle(true);
1503 const query = "?op=rpc&method=catchupSelected" +
1504 "&cmode=0&ids=" + param_escape(id);
1506 new Ajax.Request("backend.php", {
1508 onComplete: function (transport) {
1509 handle_rpc_json(transport);
1513 return !event.shiftKey;
1516 } else if (!in_body) {
1518 toggleSelected(id, true);
1520 var elem = $("RROW-" + id);
1521 var article_is_unread = elem.hasClassName("Unread");
1523 if (article_is_unread) {
1524 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1527 toggleUnread(id, 0, false);
1529 openArticleInNewWindow(id);
1534 const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1535 request_counters(unread_in_buffer == 0);
1540 function hlClicked(event, id) {
1541 if (event.which == 2) {
1544 } else if (event.ctrlKey || event.metaKey) {
1545 openArticleInNewWindow(id);
1553 function openArticleInNewWindow(id) {
1554 toggleUnread(id, 0, false);
1556 const w = window.open("");
1558 w.location = "backend.php?op=article&method=redirect&id=" + id;
1561 function isCdmMode() {
1562 return getInitParam("combined_display_mode");
1565 function markHeadline(id, marked) {
1566 if (marked == undefined) marked = true;
1568 const row = $("RROW-" + id);
1570 const check = dijit.getEnclosingWidget(
1571 row.getElementsByClassName("rchk")[0]);
1574 check.attr("checked", marked);
1578 row.addClassName("Selected");
1580 row.removeClassName("Selected");
1584 function getRelativePostIds(id, limit) {
1588 if (!limit) limit = 6; //3
1590 const ids = getLoadedArticleIds();
1592 for (let i = 0; i < ids.length; i++) {
1594 for (let k = 1; k <= limit; k++) {
1595 //if (i > k-1) tmp.push(ids[i-k]);
1596 if (i < ids.length - k) tmp.push(ids[i + k]);
1605 function correctHeadlinesOffset(id) {
1607 const container = $("headlines-frame");
1608 const row = $("RROW-" + id);
1610 if (!container || !row) return;
1612 const viewport = container.offsetHeight;
1614 const rel_offset_top = row.offsetTop - container.scrollTop;
1615 const rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1617 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1618 //console.log("Vport: " + viewport);
1620 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1621 container.scrollTop = row.offsetTop;
1622 } else if (rel_offset_bottom > viewport) {
1624 /* doesn't properly work with Opera in some cases because
1625 Opera fucks up element scrolling */
1627 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1631 function headlineActionsChange(elem) {
1633 elem.attr('value', 'false');
1636 function closeArticlePanel() {
1638 if (dijit.byId("content-insert"))
1639 dijit.byId("headlines-wrap-inner").removeChild(
1640 dijit.byId("content-insert"));
1643 function initFloatingMenu() {
1644 if (!dijit.byId("floatingMenu")) {
1646 const menu = new dijit.Menu({
1648 targetNodeIds: ["floatingTitle"]
1651 headlinesMenuCommon(menu);
1657 function headlinesMenuCommon(menu) {
1659 menu.addChild(new dijit.MenuItem({
1660 label: __("Open original article"),
1661 onClick: function (event) {
1662 openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id"));
1666 menu.addChild(new dijit.MenuItem({
1667 label: __("Display article URL"),
1668 onClick: function (event) {
1669 displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id"));
1673 menu.addChild(new dijit.MenuSeparator());
1675 menu.addChild(new dijit.MenuItem({
1676 label: __("Toggle unread"),
1677 onClick: function (event) {
1679 let ids = getSelectedArticleIds2();
1681 const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1682 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1684 selectionToggleUnread(undefined, false, true, ids);
1688 menu.addChild(new dijit.MenuItem({
1689 label: __("Toggle starred"),
1690 onClick: function (event) {
1691 let ids = getSelectedArticleIds2();
1693 const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1694 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1696 selectionToggleMarked(undefined, false, true, ids);
1700 menu.addChild(new dijit.MenuItem({
1701 label: __("Toggle published"),
1702 onClick: function (event) {
1703 let ids = getSelectedArticleIds2();
1705 const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
1706 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1708 selectionTogglePublished(undefined, false, true, ids);
1712 menu.addChild(new dijit.MenuSeparator());
1714 menu.addChild(new dijit.MenuItem({
1715 label: __("Mark above as read"),
1716 onClick: function (event) {
1717 catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id"));
1721 menu.addChild(new dijit.MenuItem({
1722 label: __("Mark below as read"),
1723 onClick: function (event) {
1724 catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id"));
1729 const labels = getInitParam("labels");
1731 if (labels && labels.length) {
1733 menu.addChild(new dijit.MenuSeparator());
1735 const labelAddMenu = new dijit.Menu({ownerMenu: menu});
1736 const labelDelMenu = new dijit.Menu({ownerMenu: menu});
1738 labels.each(function (label) {
1739 const bare_id = label.id;
1740 const name = label.caption;
1742 labelAddMenu.addChild(new dijit.MenuItem({
1745 onClick: function (event) {
1747 let ids = getSelectedArticleIds2();
1749 const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
1751 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1753 selectionAssignLabel(this.labelId, ids);
1757 labelDelMenu.addChild(new dijit.MenuItem({
1760 onClick: function (event) {
1761 let ids = getSelectedArticleIds2();
1763 const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
1765 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1767 selectionRemoveLabel(this.labelId, ids);
1773 menu.addChild(new dijit.PopupMenuItem({
1774 label: __("Assign label"),
1778 menu.addChild(new dijit.PopupMenuItem({
1779 label: __("Remove label"),
1786 function initHeadlinesMenu() {
1787 if (!dijit.byId("headlinesMenu")) {
1789 var menu = new dijit.Menu({
1790 id: "headlinesMenu",
1791 targetNodeIds: ["headlines-frame"],
1792 selector: ".hlMenuAttach"
1795 headlinesMenuCommon(menu);
1800 /* vgroup feed title menu */
1802 if (!dijit.byId("headlinesFeedTitleMenu")) {
1804 var menu = new dijit.Menu({
1805 id: "headlinesFeedTitleMenu",
1806 targetNodeIds: ["headlines-frame"],
1807 selector: "div.cdmFeedTitle"
1810 menu.addChild(new dijit.MenuItem({
1811 label: __("Select articles in group"),
1812 onClick: function (event) {
1813 selectArticles("all",
1814 "#headlines-frame > div[id*=RROW]" +
1815 "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
1820 menu.addChild(new dijit.MenuItem({
1821 label: __("Mark group as read"),
1822 onClick: function (event) {
1823 selectArticles("none");
1824 selectArticles("all",
1825 "#headlines-frame > div[id*=RROW]" +
1826 "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
1832 menu.addChild(new dijit.MenuItem({
1833 label: __("Mark feed as read"),
1834 onClick: function (event) {
1835 catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id"));
1839 menu.addChild(new dijit.MenuItem({
1840 label: __("Edit feed"),
1841 onClick: function (event) {
1842 editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
1850 function cache_set(id, obj) {
1851 //console.log("cache_set: " + id);
1854 sessionStorage[id] = obj;
1856 sessionStorage.clear();
1860 function cache_get(id) {
1862 return sessionStorage[id];
1865 function cache_clear() {
1867 sessionStorage.clear();
1870 function cache_delete(id) {
1872 sessionStorage.removeItem(id);
1875 function cancelSearch() {
1880 function setSelectionScore() {
1881 const ids = getSelectedArticleIds2();
1883 if (ids.length > 0) {
1886 var score = prompt(__("Please enter new score for selected articles:"), score);
1888 if (score != undefined) {
1889 const query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
1890 "&score=" + param_escape(score);
1892 new Ajax.Request("backend.php", {
1894 onComplete: function (transport) {
1895 const reply = JSON.parse(transport.responseText);
1899 ids.each(function (id) {
1900 const row = $("RROW-" + id);
1903 const pic = row.getElementsByClassName("hlScorePic")[0];
1906 pic.src = pic.src.replace(/score_.*?\.png/,
1907 reply["score_pic"]);
1908 pic.setAttribute("score", score);
1918 alert(__("No articles are selected."));
1922 function updateScore(id) {
1923 const pic = $$("#RROW-" + id + " .hlScorePic")[0];
1927 const query = "op=article&method=getScore&id=" + param_escape(id);
1929 new Ajax.Request("backend.php", {
1931 onComplete: function (transport) {
1932 console.log(transport.responseText);
1934 const reply = JSON.parse(transport.responseText);
1937 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
1938 pic.setAttribute("score", reply["score"]);
1939 pic.setAttribute("title", reply["score"]);
1946 function changeScore(id, pic) {
1947 const score = pic.getAttribute("score");
1949 const new_score = prompt(__("Please enter new score for this article:"), score);
1951 if (new_score != undefined) {
1953 const query = "op=article&method=setScore&id=" + param_escape(id) +
1954 "&score=" + param_escape(new_score);
1956 new Ajax.Request("backend.php", {
1958 onComplete: function (transport) {
1959 const reply = JSON.parse(transport.responseText);
1962 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
1963 pic.setAttribute("score", new_score);
1964 pic.setAttribute("title", new_score);
1971 function displayArticleUrl(id) {
1972 const query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
1974 new Ajax.Request("backend.php", {
1976 onComplete: function (transport) {
1977 const reply = JSON.parse(transport.responseText);
1979 if (reply && reply.link) {
1980 prompt(__("Article URL:"), reply.link);
1986 function scrollToRowId(id) {
1990 $("headlines-frame").scrollTop = row.offsetTop - 4;
1993 function updateFloatingTitle(unread_only) {
1994 if (!isCdmMode()) return;
1996 const hf = $("headlines-frame");
1998 const elems = $$("#headlines-frame > div[id*=RROW]");
2000 for (let i = 0; i < elems.length; i++) {
2002 const child = elems[i];
2004 if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
2006 const header = child.getElementsByClassName("cdmHeader")[0];
2008 if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2009 if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2011 $("floatingTitle").setAttribute("data-article-id", child.getAttribute("data-article-id"));
2012 $("floatingTitle").innerHTML = header.innerHTML;
2013 $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('" + child.id + "')\">" + $("floatingTitle").firstChild.innerHTML;
2017 const cb = $$("#floatingTitle .dijitCheckBox")[0];
2020 cb.parentNode.removeChild(cb);
2023 if (child.hasClassName("Unread"))
2024 $("floatingTitle").addClassName("Unread");
2026 $("floatingTitle").removeClassName("Unread");
2028 PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
2031 $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
2032 if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
2033 child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
2034 $("floatingTitle").style.visibility = "visible";
2036 $("floatingTitle").style.visibility = "hidden";
2044 function catchupCurrentBatchIfNeeded() {
2045 if (catchup_id_batch.length > 0) {
2046 window.clearTimeout(catchup_timeout_id);
2047 catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000);
2049 if (catchup_id_batch.length >= 10) {
2050 catchupBatchedArticles();
2055 function cdmFooterClick(event) {
2056 event.stopPropagation();