3 let _active_article_id
= 0;
5 let vgroup_last_feed
= false;
6 let post_under_pointer
= false;
8 let last_requested_article
= 0;
10 let catchup_id_batch
= [];
11 let catchup_timeout_id
= false;
13 let cids_requested
= [];
14 let loaded_article_ids
= [];
15 let _last_headlines_update
= 0;
16 let _headlines_scroll_offset
= 0;
17 let current_first_id
= 0;
18 let last_search_query
;
20 let _catchup_request_sent
= false;
22 let has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
24 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
25 const reply
= handle_rpc_json(transport
);
27 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
37 is_cat
= reply
['headlines']['is_cat'];
38 feed_id
= reply
['headlines']['id'];
39 last_search_query
= reply
['headlines']['search_query'];
41 if (feed_id
!= -7 && (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat()))
45 if (infscroll_req
== false) {
46 $("headlines-frame").scrollTop
= 0;
48 $("floatingTitle").style
.visibility
= "hidden";
49 $("floatingTitle").setAttribute("data-article-id", 0);
50 $("floatingTitle").innerHTML
= "";
54 $("headlines-frame").removeClassName("cdm");
55 $("headlines-frame").removeClassName("normal");
57 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
59 const headlines_count
= reply
['headlines-info']['count'];
61 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
63 if (parseInt(headlines_count
) < 30) {
64 _infscroll_disable
= 1;
66 _infscroll_disable
= 0;
69 current_first_id
= reply
['headlines']['first_id'];
70 const counters
= reply
['counters'];
71 const articles
= reply
['articles'];
73 if (infscroll_req
== false) {
74 loaded_article_ids
= [];
76 dojo
.html
.set($("headlines-toolbar"),
77 reply
['headlines']['toolbar'],
78 {parseContent
: true});
80 $("headlines-frame").innerHTML
= '';
82 let tmp
= document
.createElement("div");
83 tmp
.innerHTML
= reply
['headlines']['content'];
84 dojo
.parser
.parse(tmp
);
86 while (tmp
.hasChildNodes()) {
87 var row
= tmp
.removeChild(tmp
.firstChild
);
89 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("feed-title")) {
90 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
92 loaded_article_ids
.push(row
.id
);
96 let hsp
= $("headlines-spacer");
97 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
98 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
102 if (_infscroll_disable
)
103 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
104 __("Click to open next unread feed.") + "</a>";
107 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
108 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
112 } else if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
113 console
.log("adding some more headlines: " + headlines_count
);
115 const c
= dijit
.byId("headlines-frame");
116 const ids
= getSelectedArticleIds2();
118 let hsp
= $("headlines-spacer");
121 c
.domNode
.removeChild(hsp
);
123 let tmp
= document
.createElement("div");
124 tmp
.innerHTML
= reply
['headlines']['content'];
125 dojo
.parser
.parse(tmp
);
127 while (tmp
.hasChildNodes()) {
128 let row
= tmp
.removeChild(tmp
.firstChild
);
130 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("feed-title")) {
131 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
133 loaded_article_ids
.push(row
.id
);
137 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
138 c
.domNode
.appendChild(hsp
);
140 if (headlines_count
< 30) _infscroll_disable
= true;
142 console
.log("restore selected ids: " + ids
);
144 for (let i
= 0; i
< ids
.length
; i
++) {
145 markHeadline(ids
[i
]);
150 if (_infscroll_disable
) {
151 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
152 __("Click to open next unread feed.") + "</a>";
156 console
.log("no new headlines received");
158 const first_id_changed
= reply
['headlines']['first_id_changed'];
159 console
.log("first id changed:" + first_id_changed
);
161 let hsp
= $("headlines-spacer");
164 if (first_id_changed
) {
165 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
166 __("New articles found, reload feed to continue.") + "</a>";
168 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
169 __("Click to open next unread feed.") + "</a>";
177 for (let i
= 0; i
< articles
.length
; i
++) {
178 const a_id
= articles
[i
]['id'];
179 cache_set("article:" + a_id
, articles
[i
]['content']);
182 console
.log("no cached articles received");
186 parse_counters(counters
);
191 console
.error("Invalid object received: " + transport
.responseText
);
192 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
193 __('Could not update headlines (invalid object received - see error console for details)') +
197 _infscroll_request_sent
= 0;
198 _last_headlines_update
= new Date().getTime();
200 unpackVisibleHeadlines();
202 // if we have some more space in the buffer, why not try to fill it
204 if (!_infscroll_disable
&& $("headlines-spacer") &&
205 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
207 window
.setTimeout(function() {
215 function render_article(article
) {
216 cleanup_memory("content-insert");
218 dijit
.byId("headlines-wrap-inner").addChild(
219 dijit
.byId("content-insert"));
221 const c
= dijit
.byId("content-insert");
224 c
.domNode
.scrollTop
= 0;
227 c
.attr('content', article
);
228 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
230 correctHeadlinesOffset(getActiveArticleId());
237 function showArticleInHeadlines(id
, noexpand
) {
238 const row
= $("RROW-" + id
);
242 row
.removeClassName("Unread");
244 row
.addClassName("active");
246 selectArticles('none');
251 function article_callback2(transport
, id
) {
252 console
.log("article_callback2 " + id
);
254 const reply
= handle_rpc_json(transport
);
258 reply
.each(function(article
) {
259 if (getActiveArticleId() == article
['id']) {
260 render_article(article
['content']);
262 cids_requested
.remove(article
['id']);
264 cache_set("article:" + article
['id'], article
['content']);
268 console
.error("Invalid object received: " + transport
.responseText
);
270 render_article("<div class='whiteBox'>" +
271 __('Could not display article (invalid object received - see error console for details)') + "</div>");
274 const unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
;
275 request_counters(unread_in_buffer
== 0);
280 function view(id
, activefeed
, noexpand
) {
281 const oldrow
= $("RROW-" + getActiveArticleId());
282 if (oldrow
) oldrow
.removeClassName("active");
284 const crow
= $("RROW-" + id
);
288 setActiveArticleId(id
);
289 showArticleInHeadlines(id
, noexpand
);
293 console
.log("loading article: " + id
);
295 const cached_article
= cache_get("article:" + id
);
297 console
.log("cache check result: " + (cached_article
!= false));
299 const query
= {op
: "article", method
: "view", id
: id
};
301 const neighbor_ids
= getRelativePostIds(id
);
303 /* only request uncached articles */
305 const cids_to_request
= [];
307 for (let i
= 0; i
< neighbor_ids
.length
; i
++) {
308 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
309 if (!cache_get("article:" + neighbor_ids
[i
])) {
310 cids_to_request
.push(neighbor_ids
[i
]);
311 cids_requested
.push(neighbor_ids
[i
]);
315 console
.log("additional ids: " + cids_to_request
.toString());
317 query
.cids
= cids_to_request
.toString();
319 const article_is_unread
= crow
.hasClassName("Unread");
321 setActiveArticleId(id
);
322 showArticleInHeadlines(id
);
324 if (cached_article
&& article_is_unread
) {
325 query
.mode
= "prefetch";
326 render_article(cached_article
);
327 } else if (cached_article
) {
328 query
.mode
= "prefetch_old";
329 render_article(cached_article
);
331 // if we don't need to request any relative ids, we might as well skip
332 // the server roundtrip altogether
333 if (cids_to_request
.length
== 0) {
338 last_requested_article
= id
;
342 if (article_is_unread
) {
343 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
346 xhrPost("backend.php", query
, (transport
) => {
347 article_callback2(transport
, id
);
354 function toggleMark(id
, client_only
) {
355 const query
= { op
: "rpc", id
: id
, method
: "mark" };
357 const row
= $("RROW-" + id
);
362 const row_imgs
= row
.getElementsByClassName("markedPic");
364 for (let i
= 0; i
< row_imgs
.length
; i
++)
365 imgs
.push(row_imgs
[i
]);
367 const ft
= $("floatingTitle");
369 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
370 const fte
= ft
.getElementsByClassName("markedPic");
372 for (var i
= 0; i
< fte
.length
; i
++)
376 for (i
= 0; i
< imgs
.length
; i
++) {
379 if (!row
.hasClassName("marked")) {
380 img
.src
= img
.src
.replace("mark_unset", "mark_set");
383 img
.src
= img
.src
.replace("mark_set", "mark_unset");
388 row
.toggleClassName("marked");
391 xhrPost("backend.php", query
, (transport
) => {
392 handle_rpc_json(transport
);
396 function togglePub(id
, client_only
, no_effects
, note
) {
397 const query
= { op
: "rpc", id
: id
, method
: "publ" };
399 if (note
!= undefined) {
402 query
.note
= "undefined";
405 const row
= $("RROW-" + id
);
410 const row_imgs
= row
.getElementsByClassName("pubPic");
412 for (let i
= 0; i
< row_imgs
.length
; i
++)
413 imgs
.push(row_imgs
[i
]);
415 const ft
= $("floatingTitle");
417 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
418 const fte
= ft
.getElementsByClassName("pubPic");
420 for (let i
= 0; i
< fte
.length
; i
++)
424 for (let i
= 0; i
< imgs
.length
; i
++) {
427 if (!row
.hasClassName("published") || note
!= undefined) {
428 img
.src
= img
.src
.replace("pub_unset", "pub_set");
431 img
.src
= img
.src
.replace("pub_set", "pub_unset");
436 if (note
!= undefined)
437 row
.addClassName("published");
439 row
.toggleClassName("published");
442 xhrPost("backend.php", query
, (transport
) => {
443 handle_rpc_json(transport
);
447 function moveToPost(mode
, noscroll
, noexpand
) {
448 const rows
= getLoadedArticleIds();
453 if (!$('RROW-' + getActiveArticleId())) {
454 setActiveArticleId(0);
457 if (!getActiveArticleId()) {
459 prev_id
= rows
[rows
.length
-1]
461 for (let i
= 0; i
< rows
.length
; i
++) {
462 if (rows
[i
] == getActiveArticleId()) {
464 // Account for adjacent identical article ids.
465 if (i
> 0) prev_id
= rows
[i
-1];
467 for (let j
= i
+1; j
< rows
.length
; j
++) {
468 if (rows
[j
] != getActiveArticleId()) {
478 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
480 if (mode
== "next") {
481 if (next_id
|| getActiveArticleId()) {
484 var article
= $("RROW-" + getActiveArticleId());
485 var ctr
= $("headlines-frame");
487 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
488 ctr
.scrollTop
+ ctr
.offsetHeight
) {
490 scrollArticle(ctr
.offsetHeight
/4);
492 } else if (next_id
) {
493 cdmScrollToArticleId(next_id
, true);
496 } else if (next_id
) {
497 correctHeadlinesOffset(next_id
);
498 view(next_id
, getActiveFeedId(), noexpand
);
503 if (mode
== "prev") {
504 if (prev_id
|| getActiveArticleId()) {
507 var article
= $("RROW-" + getActiveArticleId());
508 const prev_article
= $("RROW-" + prev_id
);
509 var ctr
= $("headlines-frame");
511 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
512 scrollArticle(-ctr
.offsetHeight
/3);
513 } else if (!noscroll
&& prev_article
&&
514 prev_article
.offsetTop
< ctr
.scrollTop
) {
515 scrollArticle(-ctr
.offsetHeight
/4);
516 } else if (prev_id
) {
517 cdmScrollToArticleId(prev_id
, noscroll
);
520 } else if (prev_id
) {
521 correctHeadlinesOffset(prev_id
);
522 view(prev_id
, getActiveFeedId(), noexpand
);
529 function toggleSelected(id
, force_on
) {
530 const row
= $("RROW-" + id
);
533 const cb
= dijit
.getEnclosingWidget(
534 row
.getElementsByClassName("rchk")[0]);
536 if (row
.hasClassName('Selected') && !force_on
) {
537 row
.removeClassName('Selected');
538 if (cb
) cb
.attr("checked", false);
540 row
.addClassName('Selected');
541 if (cb
) cb
.attr("checked", true);
545 updateSelectedPrompt();
548 function updateSelectedPrompt() {
549 const count
= getSelectedArticleIds2().length
;
550 const elem
= $("selected_prompt");
553 elem
.innerHTML
= ngettext("%d article selected",
554 "%d articles selected", count
).replace("%d", count
);
564 function toggleUnread(id
, cmode
) {
565 const row
= $("RROW-" + id
);
567 const tmpClassName
= row
.className
;
569 if (cmode
== undefined || cmode
== 2) {
570 if (row
.hasClassName("Unread")) {
571 row
.removeClassName("Unread");
574 row
.addClassName("Unread");
577 } else if (cmode
== 0) {
579 row
.removeClassName("Unread");
581 } else if (cmode
== 1) {
582 row
.addClassName("Unread");
585 if (tmpClassName
!= row
.className
) {
586 if (cmode
== undefined) cmode
= 2;
588 const query
= {op
: "rpc", method
: "catchupSelected",
589 cmode
: cmode
, ids
: id
};
591 xhrPost("backend.php", query
, (transport
) => {
592 handle_rpc_json(transport
);
599 function selectionRemoveLabel(id
, ids
) {
600 if (!ids
) ids
= getSelectedArticleIds2();
602 if (ids
.length
== 0) {
603 alert(__("No articles are selected."));
607 const query
= { op
: "article", method
: "removeFromLabel",
608 ids
: ids
.toString(), lid
: id
};
610 xhrPost("backend.php", query
, (transport
) => {
611 handle_rpc_json(transport
);
612 show_labels_in_headlines(transport
);
616 function selectionAssignLabel(id
, ids
) {
617 if (!ids
) ids
= getSelectedArticleIds2();
619 if (ids
.length
== 0) {
620 alert(__("No articles are selected."));
624 const query
= { op
: "article", method
: "assignToLabel",
625 ids
: ids
.toString(), lid
: id
};
627 xhrPost("backend.php", query
, (transport
) => {
628 handle_rpc_json(transport
);
629 show_labels_in_headlines(transport
);
633 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
634 const rows
= ids
? ids
: getSelectedArticleIds2();
636 if (rows
.length
== 0 && !no_error
) {
637 alert(__("No articles are selected."));
641 for (let i
= 0; i
< rows
.length
; i
++) {
642 const row
= $("RROW-" + rows
[i
]);
644 if (set_state
== undefined) {
645 if (row
.hasClassName("Unread")) {
646 row
.removeClassName("Unread");
648 row
.addClassName("Unread");
652 if (set_state
== false) {
653 row
.removeClassName("Unread");
656 if (set_state
== true) {
657 row
.addClassName("Unread");
662 updateFloatingTitle(true);
664 if (rows
.length
> 0) {
668 if (set_state
== undefined) {
670 } else if (set_state
== true) {
672 } else if (set_state
== false) {
676 const query
= {op
: "rpc", method
: "catchupSelected",
677 cmode
: cmode
, ids
: rows
.toString() };
679 notify_progress("Loading, please wait...");
681 xhrPost("backend.php", query
, (transport
) => {
682 handle_rpc_json(transport
);
683 if (callback
) callback(transport
);
690 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
691 const rows
= ids
? ids
: getSelectedArticleIds2();
693 if (rows
.length
== 0 && !no_error
) {
694 alert(__("No articles are selected."));
698 for (let i
= 0; i
< rows
.length
; i
++) {
699 toggleMark(rows
[i
], true, true);
702 if (rows
.length
> 0) {
703 const query
= { op
: "rpc", method
: "markSelected",
704 ids
: rows
.toString(), cmode
: 2 };
706 xhrPost("backend.php", query
, (transport
) => {
707 handle_rpc_json(transport
);
708 if (callback
) callback(transport
);
714 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
715 const rows
= ids
? ids
: getSelectedArticleIds2();
717 if (rows
.length
== 0 && !no_error
) {
718 alert(__("No articles are selected."));
722 for (let i
= 0; i
< rows
.length
; i
++) {
723 togglePub(rows
[i
], true, true);
726 if (rows
.length
> 0) {
727 const query
= { op
: "rpc", method
: "publishSelected",
728 ids
: rows
.toString(), cmode
: 2 };
730 xhrPost("backend.php", query
, (transport
) => {
731 handle_rpc_json(transport
);
732 if (callback
) callback(transport
);
737 function getSelectedArticleIds2() {
741 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
743 rv
.push(child
.getAttribute("data-article-id"));
749 function getLoadedArticleIds() {
752 const children
= $$("#headlines-frame > div[id*=RROW-]");
754 children
.each(function(child
) {
755 if (Element
.visible(child
)) {
756 rv
.push(child
.getAttribute("data-article-id"));
764 // mode = all,none,unread,invert,marked,published
765 function selectArticles(mode
, query
) {
766 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
768 const children
= $$(query
);
770 children
.each(function(child
) {
771 //const id = child.getAttribute("data-article-id");
773 const cb
= dijit
.getEnclosingWidget(
774 child
.getElementsByClassName("rchk")[0]);
777 child
.addClassName("Selected");
778 if (cb
) cb
.attr("checked", true);
779 } else if (mode
== "unread") {
780 if (child
.hasClassName("Unread")) {
781 child
.addClassName("Selected");
782 if (cb
) cb
.attr("checked", true);
784 child
.removeClassName("Selected");
785 if (cb
) cb
.attr("checked", false);
787 } else if (mode
== "marked") {
788 if (child
.hasClassName("marked")) {
789 child
.addClassName("Selected");
790 if (cb
) cb
.attr("checked", true);
792 child
.removeClassName("Selected");
793 if (cb
) cb
.attr("checked", false);
795 } else if (mode
== "published") {
796 if (child
.hasClassName("published")) {
797 child
.addClassName("Selected");
798 if (cb
) cb
.attr("checked", true);
800 child
.removeClassName("Selected");
801 if (cb
) cb
.attr("checked", false);
804 } else if (mode
== "invert") {
805 if (child
.hasClassName("Selected")) {
806 child
.removeClassName("Selected");
807 if (cb
) cb
.attr("checked", false);
809 child
.addClassName("Selected");
810 if (cb
) cb
.attr("checked", true);
814 child
.removeClassName("Selected");
815 if (cb
) cb
.attr("checked", false);
819 updateSelectedPrompt();
822 function deleteSelection() {
824 const rows
= getSelectedArticleIds2();
826 if (rows
.length
== 0) {
827 alert(__("No articles are selected."));
831 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
834 if (getActiveFeedId() != 0) {
835 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows
.length
);
837 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
840 str
= str
.replace("%d", rows
.length
);
841 str
= str
.replace("%s", fn
);
843 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
847 const query
= { op
: "rpc", method
: "delete", ids
: rows
.toString() };
849 xhrPost("backend.php", query
, (transport
) => {
850 handle_rpc_json(transport
);
855 function archiveSelection() {
857 const rows
= getSelectedArticleIds2();
859 if (rows
.length
== 0) {
860 alert(__("No articles are selected."));
864 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
868 if (getActiveFeedId() != 0) {
869 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
872 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
874 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
879 str
= str
.replace("%d", rows
.length
);
880 str
= str
.replace("%s", fn
);
882 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
886 for (let i
= 0; i
< rows
.length
; i
++) {
887 cache_delete("article:" + rows
[i
]);
890 const query
= {op
: "rpc", method
: op
, ids
: rows
.toString()};
892 xhrPost("backend.php", query
, (transport
) => {
893 handle_rpc_json(transport
);
898 function catchupSelection() {
900 const rows
= getSelectedArticleIds2();
902 if (rows
.length
== 0) {
903 alert(__("No articles are selected."));
907 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
909 let str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
911 str
= str
.replace("%d", rows
.length
);
912 str
= str
.replace("%s", fn
);
914 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
918 selectionToggleUnread(false, 'viewCurrentFeed()', true);
921 function editArticleTags(id
) {
922 const query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
924 if (dijit
.byId("editTagsDlg"))
925 dijit
.byId("editTagsDlg").destroyRecursive();
927 const dialog
= new dijit
.Dialog({
929 title
: __("Edit article Tags"),
930 style
: "width: 600px",
931 execute: function() {
932 if (this.validate()) {
933 const query
= dojo
.objectToQuery(this.attr('value'));
935 notify_progress("Saving article tags...", true);
937 xhrPost("backend.php", this.attr('value'), (transport
) => {
942 const data
= JSON
.parse(transport
.responseText
);
947 const tags
= $("ATSTR-" + id
);
948 const tooltip
= dijit
.byId("ATSTRTIP-" + id
);
950 if (tags
) tags
.innerHTML
= data
.content
;
951 if (tooltip
) tooltip
.attr('label', data
.content_full
);
962 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
963 dojo
.disconnect(tmph
);
965 new Ajax
.Autocompleter('tags_str', 'tags_choices',
966 "backend.php?op=article&method=completeTags",
967 { tokens
: ',', paramName
: "search" });
974 function cdmScrollToArticleId(id
, force
) {
975 const ctr
= $("headlines-frame");
976 const e
= $("RROW-" + id
);
978 if (!e
|| !ctr
) return;
980 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
981 e
.offsetTop
< ctr
.scrollTop
) {
983 // expanded cdm has a 4px margin now
984 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
986 // article is selected manually, set it read
987 toggleUnread(id
, 0);1
991 function setActiveArticleId(id
) {
992 console
.log("setActiveArticleId:" + id
);
994 _active_article_id
= id
;
995 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
998 function getActiveArticleId() {
999 return _active_article_id
;
1002 function postMouseIn(e
, id
) {
1003 post_under_pointer
= id
;
1006 function postMouseOut(id
) {
1007 post_under_pointer
= false;
1010 function unpackVisibleHeadlines() {
1011 if (!isCdmMode()) return;
1013 const rows
= $$("#headlines-frame div[id*=RROW][data-content]");
1014 const threshold
= $("headlines-frame").scrollTop
+ $("headlines-frame").offsetHeight
+ 300;
1016 for (let i
= 0; i
< rows
.length
; i
++) {
1017 const row
= rows
[i
];
1019 if (row
.offsetTop
<= threshold
) {
1020 console
.log("unpacking: " + row
.id
);
1022 const content
= row
.getAttribute("data-content");
1024 row
.select(".content-inner")[0].innerHTML
= content
;
1025 row
.removeAttribute("data-content");
1027 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, row
);
1034 function headlines_scroll_handler(e
) {
1037 // rate-limit in case of smooth scrolling and similar abominations
1038 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1042 _headlines_scroll_offset
= e
.scrollTop
;
1044 unpackVisibleHeadlines();
1046 // set topmost child in the buffer as active
1047 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1048 getSelectedArticleIds2().length
<= 1) {
1050 const rows
= $$("#headlines-frame > div[id*=RROW]");
1052 for (let i
= 0; i
< rows
.length
; i
++) {
1053 const row
= rows
[i
];
1055 if ($("headlines-frame").scrollTop
<= row
.offsetTop
&&
1056 row
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1057 row
.getAttribute("data-article-id") != _active_article_id
) {
1059 if (_active_article_id
) {
1060 const row
= $("RROW-" + _active_article_id
);
1061 if (row
) row
.removeClassName("active");
1064 _active_article_id
= row
.getAttribute("data-article-id");
1065 showArticleInHeadlines(_active_article_id
, true);
1066 updateSelectedPrompt();
1072 if (!_infscroll_disable
) {
1073 const hsp
= $("headlines-spacer");
1075 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1077 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1078 __("Loading, please wait...") + "</span>";
1080 loadMoreHeadlines();
1087 updateFloatingTitle();
1090 if (getInitParam("cdm_auto_catchup") == 1) {
1092 let rows
= $$("#headlines-frame > div[id*=RROW][class*=Unread]");
1094 for (let i
= 0; i
< rows
.length
; i
++) {
1095 const row
= rows
[i
];
1097 if ($("headlines-frame").scrollTop
> (row
.offsetTop
+ row
.offsetHeight
/2)) {
1099 const id
= row
.getAttribute("data-article-id")
1101 if (catchup_id_batch
.indexOf(id
) == -1)
1102 catchup_id_batch
.push(id
);
1104 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1110 if (_infscroll_disable
) {
1111 const row
= $$("#headlines-frame div[id*=RROW]").last();
1113 if (row
&& $("headlines-frame").scrollTop
>
1114 (row
.offsetTop
+ row
.offsetHeight
- 50)) {
1116 console
.log("we seem to be at an end");
1118 if (getInitParam("on_catchup_show_next_feed") == "1") {
1119 openNextUnreadFeed();
1126 console
.warn("headlines_scroll_handler: " + e
);
1130 function openNextUnreadFeed() {
1131 const is_cat
= activeFeedIsCat();
1132 const nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1133 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1136 function catchupBatchedArticles() {
1137 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1139 console
.log("catchupBatchedArticles, size=", catchup_id_batch
.length
);
1141 // make a copy of the array
1142 const batch
= catchup_id_batch
.slice();
1143 const query
= { op
: "rpc", method
: "catchupSelected",
1144 cmode
: 0, ids
: batch
.toString() };
1146 _catchup_request_sent
= true;
1148 xhrPost("backend.php", query
, (transport
) => {
1149 const reply
= handle_rpc_json(transport
);
1151 _catchup_request_sent
= false;
1154 const batch
= reply
.ids
;
1156 batch
.each(function (id
) {
1157 const elem
= $("RROW-" + id
);
1158 if (elem
) elem
.removeClassName("Unread");
1159 catchup_id_batch
.remove(id
);
1163 updateFloatingTitle(true);
1168 function catchupRelativeToArticle(below
, id
) {
1170 if (!id
) id
= getActiveArticleId();
1173 alert(__("No article is selected."));
1177 const visible_ids
= getLoadedArticleIds();
1179 const ids_to_mark
= [];
1182 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1183 if (visible_ids
[i
] != id
) {
1184 var e
= $("RROW-" + visible_ids
[i
]);
1186 if (e
&& e
.hasClassName("Unread")) {
1187 ids_to_mark
.push(visible_ids
[i
]);
1194 for (var i
= visible_ids
.length
- 1; i
>= 0; i
--) {
1195 if (visible_ids
[i
] != id
) {
1196 var e
= $("RROW-" + visible_ids
[i
]);
1198 if (e
&& e
.hasClassName("Unread")) {
1199 ids_to_mark
.push(visible_ids
[i
]);
1207 if (ids_to_mark
.length
== 0) {
1208 alert(__("No articles found to mark"));
1210 const msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1212 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1214 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1215 var e
= $("RROW-" + ids_to_mark
[i
]);
1216 e
.removeClassName("Unread");
1219 const query
= { op
: "rpc", method
: "catchupSelected",
1220 cmode
: 0, ids
: ids_to_mark
.toString() };
1222 xhrPost("backend.php", query
, (transport
) => {
1223 handle_rpc_json(transport
);
1229 function getArticleUnderPointer() {
1230 return post_under_pointer
;
1233 function scrollArticle(offset
) {
1235 const ci
= $("content-insert");
1237 ci
.scrollTop
+= offset
;
1240 const hi
= $("headlines-frame");
1242 hi
.scrollTop
+= offset
;
1248 function show_labels_in_headlines(transport
) {
1249 const data
= JSON
.parse(transport
.responseText
);
1252 data
['info-for-headlines'].each(function (elem
) {
1253 $$(".HLLCTR-" + elem
.id
).each(function (ctr
) {
1254 ctr
.innerHTML
= elem
.labels
;
1260 function cdmClicked(event
, id
, in_body
) {
1261 //var shift_key = event.shiftKey;
1263 if (!event
.ctrlKey
&& !event
.metaKey
) {
1265 let elem
= $("RROW-" + getActiveArticleId());
1267 if (elem
) elem
.removeClassName("active");
1269 selectArticles("none");
1272 elem
= $("RROW-" + id
);
1273 const article_is_unread
= elem
.hasClassName("Unread");
1275 elem
.removeClassName("Unread");
1276 elem
.addClassName("active");
1278 setActiveArticleId(id
);
1280 if (article_is_unread
) {
1281 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1282 updateFloatingTitle(true);
1285 op
: "rpc", method
: "catchupSelected",
1289 xhrPost("backend.php", query
, (transport
) => {
1290 handle_rpc_json(transport
);
1294 return !event
.shiftKey
;
1296 } else if (!in_body
) {
1298 toggleSelected(id
, true);
1300 let elem
= $("RROW-" + id
);
1301 const article_is_unread
= elem
.hasClassName("Unread");
1303 if (article_is_unread
) {
1304 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1307 toggleUnread(id
, 0, false);
1309 openArticleInNewWindow(id
);
1314 const unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1315 request_counters(unread_in_buffer
== 0);
1320 function hlClicked(event
, id
) {
1321 if (event
.which
== 2) {
1324 } else if (event
.ctrlKey
|| event
.metaKey
) {
1325 openArticleInNewWindow(id
);
1333 function openArticleInNewWindow(id
) {
1334 toggleUnread(id
, 0, false);
1336 const w
= window
.open("");
1338 w
.location
= "backend.php?op=article&method=redirect&id=" + id
;
1341 function isCdmMode() {
1342 return getInitParam("combined_display_mode");
1345 function markHeadline(id
, marked
) {
1346 if (marked
== undefined) marked
= true;
1348 const row
= $("RROW-" + id
);
1350 const check
= dijit
.getEnclosingWidget(
1351 row
.getElementsByClassName("rchk")[0]);
1354 check
.attr("checked", marked
);
1358 row
.addClassName("Selected");
1360 row
.removeClassName("Selected");
1364 function getRelativePostIds(id
, limit
) {
1368 if (!limit
) limit
= 6; //3
1370 const ids
= getLoadedArticleIds();
1372 for (let i
= 0; i
< ids
.length
; i
++) {
1374 for (let k
= 1; k
<= limit
; k
++) {
1375 //if (i > k-1) tmp.push(ids[i-k]);
1376 if (i
< ids
.length
- k
) tmp
.push(ids
[i
+ k
]);
1385 function correctHeadlinesOffset(id
) {
1387 const container
= $("headlines-frame");
1388 const row
= $("RROW-" + id
);
1390 if (!container
|| !row
) return;
1392 const viewport
= container
.offsetHeight
;
1394 const rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1395 const rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1397 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1398 //console.log("Vport: " + viewport);
1400 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1401 container
.scrollTop
= row
.offsetTop
;
1402 } else if (rel_offset_bottom
> viewport
) {
1404 /* doesn't properly work with Opera in some cases because
1405 Opera fucks up element scrolling */
1407 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1411 function headlineActionsChange(elem
) {
1413 elem
.attr('value', 'false');
1416 function closeArticlePanel() {
1418 if (dijit
.byId("content-insert"))
1419 dijit
.byId("headlines-wrap-inner").removeChild(
1420 dijit
.byId("content-insert"));
1423 function initFloatingMenu() {
1424 if (!dijit
.byId("floatingMenu")) {
1426 const menu
= new dijit
.Menu({
1428 targetNodeIds
: ["floatingTitle"]
1431 headlinesMenuCommon(menu
);
1437 function headlinesMenuCommon(menu
) {
1439 menu
.addChild(new dijit
.MenuItem({
1440 label
: __("Open original article"),
1441 onClick: function (event
) {
1442 openArticleInNewWindow(this.getParent().currentTarget
.getAttribute("data-article-id"));
1446 menu
.addChild(new dijit
.MenuItem({
1447 label
: __("Display article URL"),
1448 onClick: function (event
) {
1449 displayArticleUrl(this.getParent().currentTarget
.getAttribute("data-article-id"));
1453 menu
.addChild(new dijit
.MenuSeparator());
1455 menu
.addChild(new dijit
.MenuItem({
1456 label
: __("Toggle unread"),
1457 onClick: function () {
1459 let ids
= getSelectedArticleIds2();
1461 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1462 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1464 selectionToggleUnread(undefined, false, true, ids
);
1468 menu
.addChild(new dijit
.MenuItem({
1469 label
: __("Toggle starred"),
1470 onClick: function () {
1471 let ids
= getSelectedArticleIds2();
1473 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1474 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1476 selectionToggleMarked(undefined, false, true, ids
);
1480 menu
.addChild(new dijit
.MenuItem({
1481 label
: __("Toggle published"),
1482 onClick: function () {
1483 let ids
= getSelectedArticleIds2();
1485 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1486 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1488 selectionTogglePublished(undefined, false, true, ids
);
1492 menu
.addChild(new dijit
.MenuSeparator());
1494 menu
.addChild(new dijit
.MenuItem({
1495 label
: __("Mark above as read"),
1496 onClick: function () {
1497 catchupRelativeToArticle(0, this.getParent().currentTarget
.getAttribute("data-article-id"));
1501 menu
.addChild(new dijit
.MenuItem({
1502 label
: __("Mark below as read"),
1503 onClick: function () {
1504 catchupRelativeToArticle(1, this.getParent().currentTarget
.getAttribute("data-article-id"));
1509 const labels
= getInitParam("labels");
1511 if (labels
&& labels
.length
) {
1513 menu
.addChild(new dijit
.MenuSeparator());
1515 const labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1516 const labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1518 labels
.each(function (label
) {
1519 const bare_id
= label
.id
;
1520 const name
= label
.caption
;
1522 labelAddMenu
.addChild(new dijit
.MenuItem({
1525 onClick: function () {
1527 let ids
= getSelectedArticleIds2();
1529 const id
= (this.getParent().ownerMenu
.currentTarget
.getAttribute("data-article-id")) + "";
1531 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1533 selectionAssignLabel(this.labelId
, ids
);
1537 labelDelMenu
.addChild(new dijit
.MenuItem({
1540 onClick: function () {
1541 let ids
= getSelectedArticleIds2();
1543 const id
= (this.getParent().ownerMenu
.currentTarget
.getAttribute("data-article-id")) + "";
1545 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1547 selectionRemoveLabel(this.labelId
, ids
);
1553 menu
.addChild(new dijit
.PopupMenuItem({
1554 label
: __("Assign label"),
1558 menu
.addChild(new dijit
.PopupMenuItem({
1559 label
: __("Remove label"),
1566 function initHeadlinesMenu() {
1567 if (!dijit
.byId("headlinesMenu")) {
1569 const menu
= new dijit
.Menu({
1570 id
: "headlinesMenu",
1571 targetNodeIds
: ["headlines-frame"],
1572 selector
: ".hlMenuAttach"
1575 headlinesMenuCommon(menu
);
1580 /* vgroup feed title menu */
1582 if (!dijit
.byId("headlinesFeedTitleMenu")) {
1584 const menu
= new dijit
.Menu({
1585 id
: "headlinesFeedTitleMenu",
1586 targetNodeIds
: ["headlines-frame"],
1587 selector
: "div.cdmFeedTitle"
1590 menu
.addChild(new dijit
.MenuItem({
1591 label
: __("Select articles in group"),
1592 onClick: function (event
) {
1593 selectArticles("all",
1594 "#headlines-frame > div[id*=RROW]" +
1595 "[data-orig-feed-id='" + this.getParent().currentTarget
.getAttribute("data-feed-id") + "']");
1600 menu
.addChild(new dijit
.MenuItem({
1601 label
: __("Mark group as read"),
1602 onClick: function () {
1603 selectArticles("none");
1604 selectArticles("all",
1605 "#headlines-frame > div[id*=RROW]" +
1606 "[data-orig-feed-id='" + this.getParent().currentTarget
.getAttribute("data-feed-id") + "']");
1612 menu
.addChild(new dijit
.MenuItem({
1613 label
: __("Mark feed as read"),
1614 onClick: function () {
1615 catchupFeedInGroup(this.getParent().currentTarget
.getAttribute("data-feed-id"));
1619 menu
.addChild(new dijit
.MenuItem({
1620 label
: __("Edit feed"),
1621 onClick: function () {
1622 editFeed(this.getParent().currentTarget
.getAttribute("data-feed-id"));
1630 function cache_set(id
, obj
) {
1631 //console.log("cache_set: " + id);
1634 sessionStorage
[id
] = obj
;
1636 sessionStorage
.clear();
1640 function cache_get(id
) {
1642 return sessionStorage
[id
];
1645 function cache_clear() {
1647 sessionStorage
.clear();
1650 function cache_delete(id
) {
1652 sessionStorage
.removeItem(id
);
1655 function cancelSearch() {
1660 function setSelectionScore() {
1661 const ids
= getSelectedArticleIds2();
1663 if (ids
.length
> 0) {
1666 const score
= prompt(__("Please enter new score for selected articles:"));
1668 if (score
!= undefined) {
1669 const query
= { op
: "article", method
: "setScore", id
: ids
.toString(),
1672 xhrJson("backend.php", query
, (reply
) => {
1674 reply
.id
.each((id
) => {
1675 const row
= $("RROW-" + id
);
1678 const pic
= row
.getElementsByClassName("score-pic")[0];
1681 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
1682 reply
["score_pic"]);
1683 pic
.setAttribute("score", reply
["score"]);
1692 alert(__("No articles are selected."));
1696 function changeScore(id
, pic
) {
1697 const score
= pic
.getAttribute("score");
1699 const new_score
= prompt(__("Please enter new score for this article:"), score
);
1701 if (new_score
!= undefined) {
1702 const query
= { op
: "article", method
: "setScore", id
: id
, score
: new_score
};
1704 xhrJson("backend.php", query
, (reply
) => {
1706 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
1707 pic
.setAttribute("score", new_score
);
1708 pic
.setAttribute("title", new_score
);
1714 function displayArticleUrl(id
) {
1715 const query
= { op
: "rpc", method
: "getlinktitlebyid", id
: id
};
1717 xhrJson("backend.php", query
, (reply
) => {
1718 if (reply
&& reply
.link
) {
1719 prompt(__("Article URL:"), reply
.link
);
1725 function scrollToRowId(id
) {
1729 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
1732 function updateFloatingTitle(unread_only
) {
1733 if (!isCdmMode()) return;
1735 const hf
= $("headlines-frame");
1737 const elems
= $$("#headlines-frame > div[id*=RROW]");
1739 for (let i
= 0; i
< elems
.length
; i
++) {
1741 const child
= elems
[i
];
1743 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
1745 const header
= child
.getElementsByClassName("header")[0];
1747 if (unread_only
|| child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
1748 if (child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
1750 $("floatingTitle").setAttribute("data-article-id", child
.getAttribute("data-article-id"));
1751 $("floatingTitle").innerHTML
= header
.innerHTML
;
1752 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('" + child
.id
+ "')\">" + $("floatingTitle").firstChild
.innerHTML
;
1756 const cb
= $$("#floatingTitle .dijitCheckBox")[0];
1759 cb
.parentNode
.removeChild(cb
);
1762 if (child
.hasClassName("Unread"))
1763 $("floatingTitle").addClassName("Unread");
1765 $("floatingTitle").removeClassName("Unread");
1767 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
1770 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
1771 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
1772 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
1773 $("floatingTitle").style
.visibility
= "visible";
1775 $("floatingTitle").style
.visibility
= "hidden";