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);
494 toggleUnread(next_id
, 0);
497 } else if (next_id
) {
498 correctHeadlinesOffset(next_id
);
499 view(next_id
, getActiveFeedId(), noexpand
);
504 if (mode
== "prev") {
505 if (prev_id
|| getActiveArticleId()) {
508 var article
= $("RROW-" + getActiveArticleId());
509 const prev_article
= $("RROW-" + prev_id
);
510 var ctr
= $("headlines-frame");
512 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
513 scrollArticle(-ctr
.offsetHeight
/3);
514 } else if (!noscroll
&& prev_article
&&
515 prev_article
.offsetTop
< ctr
.scrollTop
) {
516 scrollArticle(-ctr
.offsetHeight
/4);
517 } else if (prev_id
) {
518 cdmScrollToArticleId(prev_id
, noscroll
);
519 toggleUnread(next_id
, 0);1
522 } else if (prev_id
) {
523 correctHeadlinesOffset(prev_id
);
524 view(prev_id
, getActiveFeedId(), noexpand
);
531 function toggleSelected(id
, force_on
) {
532 const row
= $("RROW-" + id
);
535 const cb
= dijit
.getEnclosingWidget(
536 row
.getElementsByClassName("rchk")[0]);
538 if (row
.hasClassName('Selected') && !force_on
) {
539 row
.removeClassName('Selected');
540 if (cb
) cb
.attr("checked", false);
542 row
.addClassName('Selected');
543 if (cb
) cb
.attr("checked", true);
547 updateSelectedPrompt();
550 function updateSelectedPrompt() {
551 const count
= getSelectedArticleIds2().length
;
552 const elem
= $("selected_prompt");
555 elem
.innerHTML
= ngettext("%d article selected",
556 "%d articles selected", count
).replace("%d", count
);
566 function toggleUnread(id
, cmode
) {
567 const row
= $("RROW-" + id
);
569 const tmpClassName
= row
.className
;
571 if (cmode
== undefined || cmode
== 2) {
572 if (row
.hasClassName("Unread")) {
573 row
.removeClassName("Unread");
576 row
.addClassName("Unread");
579 } else if (cmode
== 0) {
581 row
.removeClassName("Unread");
583 } else if (cmode
== 1) {
584 row
.addClassName("Unread");
587 if (tmpClassName
!= row
.className
) {
588 if (cmode
== undefined) cmode
= 2;
590 const query
= {op
: "rpc", method
: "catchupSelected",
591 cmode
: cmode
, ids
: id
};
593 xhrPost("backend.php", query
, (transport
) => {
594 handle_rpc_json(transport
);
601 function selectionRemoveLabel(id
, ids
) {
602 if (!ids
) ids
= getSelectedArticleIds2();
604 if (ids
.length
== 0) {
605 alert(__("No articles are selected."));
609 const query
= { op
: "article", method
: "removeFromLabel",
610 ids
: ids
.toString(), lid
: id
};
612 xhrPost("backend.php", query
, (transport
) => {
613 handle_rpc_json(transport
);
614 show_labels_in_headlines(transport
);
618 function selectionAssignLabel(id
, ids
) {
619 if (!ids
) ids
= getSelectedArticleIds2();
621 if (ids
.length
== 0) {
622 alert(__("No articles are selected."));
626 const query
= { op
: "article", method
: "assignToLabel",
627 ids
: ids
.toString(), lid
: id
};
629 xhrPost("backend.php", query
, (transport
) => {
630 handle_rpc_json(transport
);
631 show_labels_in_headlines(transport
);
635 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
636 const rows
= ids
? ids
: getSelectedArticleIds2();
638 if (rows
.length
== 0 && !no_error
) {
639 alert(__("No articles are selected."));
643 for (let i
= 0; i
< rows
.length
; i
++) {
644 const row
= $("RROW-" + rows
[i
]);
646 if (set_state
== undefined) {
647 if (row
.hasClassName("Unread")) {
648 row
.removeClassName("Unread");
650 row
.addClassName("Unread");
654 if (set_state
== false) {
655 row
.removeClassName("Unread");
658 if (set_state
== true) {
659 row
.addClassName("Unread");
664 updateFloatingTitle(true);
666 if (rows
.length
> 0) {
670 if (set_state
== undefined) {
672 } else if (set_state
== true) {
674 } else if (set_state
== false) {
678 const query
= {op
: "rpc", method
: "catchupSelected",
679 cmode
: cmode
, ids
: rows
.toString() };
681 notify_progress("Loading, please wait...");
683 xhrPost("backend.php", query
, (transport
) => {
684 handle_rpc_json(transport
);
685 if (callback
) callback(transport
);
692 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
693 const rows
= ids
? ids
: getSelectedArticleIds2();
695 if (rows
.length
== 0 && !no_error
) {
696 alert(__("No articles are selected."));
700 for (let i
= 0; i
< rows
.length
; i
++) {
701 toggleMark(rows
[i
], true, true);
704 if (rows
.length
> 0) {
705 const query
= { op
: "rpc", method
: "markSelected",
706 ids
: rows
.toString(), cmode
: 2 };
708 xhrPost("backend.php", query
, (transport
) => {
709 handle_rpc_json(transport
);
710 if (callback
) callback(transport
);
716 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
717 const rows
= ids
? ids
: getSelectedArticleIds2();
719 if (rows
.length
== 0 && !no_error
) {
720 alert(__("No articles are selected."));
724 for (let i
= 0; i
< rows
.length
; i
++) {
725 togglePub(rows
[i
], true, true);
728 if (rows
.length
> 0) {
729 const query
= { op
: "rpc", method
: "publishSelected",
730 ids
: rows
.toString(), cmode
: 2 };
732 xhrPost("backend.php", query
, (transport
) => {
733 handle_rpc_json(transport
);
734 if (callback
) callback(transport
);
739 function getSelectedArticleIds2() {
743 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
745 rv
.push(child
.getAttribute("data-article-id"));
751 function getLoadedArticleIds() {
754 const children
= $$("#headlines-frame > div[id*=RROW-]");
756 children
.each(function(child
) {
757 if (Element
.visible(child
)) {
758 rv
.push(child
.getAttribute("data-article-id"));
766 // mode = all,none,unread,invert,marked,published
767 function selectArticles(mode
, query
) {
768 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
770 const children
= $$(query
);
772 children
.each(function(child
) {
773 //const id = child.getAttribute("data-article-id");
775 const cb
= dijit
.getEnclosingWidget(
776 child
.getElementsByClassName("rchk")[0]);
779 child
.addClassName("Selected");
780 if (cb
) cb
.attr("checked", true);
781 } else if (mode
== "unread") {
782 if (child
.hasClassName("Unread")) {
783 child
.addClassName("Selected");
784 if (cb
) cb
.attr("checked", true);
786 child
.removeClassName("Selected");
787 if (cb
) cb
.attr("checked", false);
789 } else if (mode
== "marked") {
790 if (child
.hasClassName("marked")) {
791 child
.addClassName("Selected");
792 if (cb
) cb
.attr("checked", true);
794 child
.removeClassName("Selected");
795 if (cb
) cb
.attr("checked", false);
797 } else if (mode
== "published") {
798 if (child
.hasClassName("published")) {
799 child
.addClassName("Selected");
800 if (cb
) cb
.attr("checked", true);
802 child
.removeClassName("Selected");
803 if (cb
) cb
.attr("checked", false);
806 } else if (mode
== "invert") {
807 if (child
.hasClassName("Selected")) {
808 child
.removeClassName("Selected");
809 if (cb
) cb
.attr("checked", false);
811 child
.addClassName("Selected");
812 if (cb
) cb
.attr("checked", true);
816 child
.removeClassName("Selected");
817 if (cb
) cb
.attr("checked", false);
821 updateSelectedPrompt();
824 function deleteSelection() {
826 const rows
= getSelectedArticleIds2();
828 if (rows
.length
== 0) {
829 alert(__("No articles are selected."));
833 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
836 if (getActiveFeedId() != 0) {
837 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows
.length
);
839 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
842 str
= str
.replace("%d", rows
.length
);
843 str
= str
.replace("%s", fn
);
845 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
849 const query
= { op
: "rpc", method
: "delete", ids
: rows
.toString() };
851 xhrPost("backend.php", query
, (transport
) => {
852 handle_rpc_json(transport
);
857 function archiveSelection() {
859 const rows
= getSelectedArticleIds2();
861 if (rows
.length
== 0) {
862 alert(__("No articles are selected."));
866 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
870 if (getActiveFeedId() != 0) {
871 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
874 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
876 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
881 str
= str
.replace("%d", rows
.length
);
882 str
= str
.replace("%s", fn
);
884 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
888 for (let i
= 0; i
< rows
.length
; i
++) {
889 cache_delete("article:" + rows
[i
]);
892 const query
= {op
: "rpc", method
: op
, ids
: rows
.toString()};
894 xhrPost("backend.php", query
, (transport
) => {
895 handle_rpc_json(transport
);
900 function catchupSelection() {
902 const rows
= getSelectedArticleIds2();
904 if (rows
.length
== 0) {
905 alert(__("No articles are selected."));
909 const fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
911 let str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
913 str
= str
.replace("%d", rows
.length
);
914 str
= str
.replace("%s", fn
);
916 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
920 selectionToggleUnread(false, 'viewCurrentFeed()', true);
923 function editArticleTags(id
) {
924 const query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
926 if (dijit
.byId("editTagsDlg"))
927 dijit
.byId("editTagsDlg").destroyRecursive();
929 const dialog
= new dijit
.Dialog({
931 title
: __("Edit article Tags"),
932 style
: "width: 600px",
933 execute: function() {
934 if (this.validate()) {
935 const query
= dojo
.objectToQuery(this.attr('value'));
937 notify_progress("Saving article tags...", true);
939 xhrPost("backend.php", this.attr('value'), (transport
) => {
944 const data
= JSON
.parse(transport
.responseText
);
949 const tags
= $("ATSTR-" + id
);
950 const tooltip
= dijit
.byId("ATSTRTIP-" + id
);
952 if (tags
) tags
.innerHTML
= data
.content
;
953 if (tooltip
) tooltip
.attr('label', data
.content_full
);
964 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
965 dojo
.disconnect(tmph
);
967 new Ajax
.Autocompleter('tags_str', 'tags_choices',
968 "backend.php?op=article&method=completeTags",
969 { tokens
: ',', paramName
: "search" });
976 function cdmScrollToArticleId(id
, force
) {
977 const ctr
= $("headlines-frame");
978 const e
= $("RROW-" + id
);
980 if (!e
|| !ctr
) return;
982 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
983 e
.offsetTop
< ctr
.scrollTop
) {
985 // expanded cdm has a 4px margin now
986 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
990 function setActiveArticleId(id
) {
991 console
.log("setActiveArticleId:" + id
);
993 _active_article_id
= id
;
994 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
997 function getActiveArticleId() {
998 return _active_article_id
;
1001 function postMouseIn(e
, id
) {
1002 post_under_pointer
= id
;
1005 function postMouseOut(id
) {
1006 post_under_pointer
= false;
1009 function unpackVisibleHeadlines() {
1010 if (!isCdmMode()) return;
1012 const rows
= $$("#headlines-frame div[id*=RROW][data-content]");
1013 const threshold
= $("headlines-frame").scrollTop
+ $("headlines-frame").offsetHeight
+ 300;
1015 for (let i
= 0; i
< rows
.length
; i
++) {
1016 const row
= rows
[i
];
1018 if (row
.offsetTop
<= threshold
) {
1019 console
.log("unpacking: " + row
.id
);
1021 const content
= row
.getAttribute("data-content");
1023 row
.select(".content-inner")[0].innerHTML
= content
;
1024 row
.removeAttribute("data-content");
1026 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, row
);
1033 function headlines_scroll_handler(e
) {
1036 // rate-limit in case of smooth scrolling and similar abominations
1037 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1041 _headlines_scroll_offset
= e
.scrollTop
;
1043 unpackVisibleHeadlines();
1045 // set topmost child in the buffer as active
1046 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1047 getSelectedArticleIds2().length
<= 1) {
1049 const rows
= $$("#headlines-frame > div[id*=RROW]");
1051 for (let i
= 0; i
< rows
.length
; i
++) {
1052 const row
= rows
[i
];
1054 if ($("headlines-frame").scrollTop
<= row
.offsetTop
&&
1055 row
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1056 row
.getAttribute("data-article-id") != _active_article_id
) {
1058 if (_active_article_id
) {
1059 const row
= $("RROW-" + _active_article_id
);
1060 if (row
) row
.removeClassName("active");
1063 _active_article_id
= row
.getAttribute("data-article-id");
1064 showArticleInHeadlines(_active_article_id
, true);
1065 updateSelectedPrompt();
1071 if (!_infscroll_disable
) {
1072 const hsp
= $("headlines-spacer");
1074 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1076 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1077 __("Loading, please wait...") + "</span>";
1079 loadMoreHeadlines();
1086 updateFloatingTitle();
1089 if (getInitParam("cdm_auto_catchup") == 1) {
1091 let rows
= $$("#headlines-frame > div[id*=RROW][class*=Unread]");
1093 for (let i
= 0; i
< rows
.length
; i
++) {
1094 const row
= rows
[i
];
1096 if ($("headlines-frame").scrollTop
> (row
.offsetTop
+ row
.offsetHeight
/2)) {
1098 const id
= row
.getAttribute("data-article-id")
1100 if (catchup_id_batch
.indexOf(id
) == -1)
1101 catchup_id_batch
.push(id
);
1103 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1109 if (_infscroll_disable
) {
1110 const row
= $$("#headlines-frame div[id*=RROW]").last();
1112 if (row
&& $("headlines-frame").scrollTop
>
1113 (row
.offsetTop
+ row
.offsetHeight
- 50)) {
1115 console
.log("we seem to be at an end");
1117 if (getInitParam("on_catchup_show_next_feed") == "1") {
1118 openNextUnreadFeed();
1125 console
.warn("headlines_scroll_handler: " + e
);
1129 function openNextUnreadFeed() {
1130 const is_cat
= activeFeedIsCat();
1131 const nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1132 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1135 function catchupBatchedArticles() {
1136 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1138 console
.log("catchupBatchedArticles, size=", catchup_id_batch
.length
);
1140 // make a copy of the array
1141 const batch
= catchup_id_batch
.slice();
1142 const query
= { op
: "rpc", method
: "catchupSelected",
1143 cmode
: 0, ids
: batch
.toString() };
1145 _catchup_request_sent
= true;
1147 xhrPost("backend.php", query
, (transport
) => {
1148 const reply
= handle_rpc_json(transport
);
1150 _catchup_request_sent
= false;
1153 const batch
= reply
.ids
;
1155 batch
.each(function (id
) {
1156 const elem
= $("RROW-" + id
);
1157 if (elem
) elem
.removeClassName("Unread");
1158 catchup_id_batch
.remove(id
);
1162 updateFloatingTitle(true);
1167 function catchupRelativeToArticle(below
, id
) {
1169 if (!id
) id
= getActiveArticleId();
1172 alert(__("No article is selected."));
1176 const visible_ids
= getLoadedArticleIds();
1178 const ids_to_mark
= [];
1181 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1182 if (visible_ids
[i
] != id
) {
1183 var e
= $("RROW-" + visible_ids
[i
]);
1185 if (e
&& e
.hasClassName("Unread")) {
1186 ids_to_mark
.push(visible_ids
[i
]);
1193 for (var i
= visible_ids
.length
- 1; i
>= 0; i
--) {
1194 if (visible_ids
[i
] != id
) {
1195 var e
= $("RROW-" + visible_ids
[i
]);
1197 if (e
&& e
.hasClassName("Unread")) {
1198 ids_to_mark
.push(visible_ids
[i
]);
1206 if (ids_to_mark
.length
== 0) {
1207 alert(__("No articles found to mark"));
1209 const msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1211 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1213 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1214 var e
= $("RROW-" + ids_to_mark
[i
]);
1215 e
.removeClassName("Unread");
1218 const query
= { op
: "rpc", method
: "catchupSelected",
1219 cmode
: 0, ids
: ids_to_mark
.toString() };
1221 xhrPost("backend.php", query
, (transport
) => {
1222 handle_rpc_json(transport
);
1228 function getArticleUnderPointer() {
1229 return post_under_pointer
;
1232 function scrollArticle(offset
) {
1234 const ci
= $("content-insert");
1236 ci
.scrollTop
+= offset
;
1239 const hi
= $("headlines-frame");
1241 hi
.scrollTop
+= offset
;
1247 function show_labels_in_headlines(transport
) {
1248 const data
= JSON
.parse(transport
.responseText
);
1251 data
['info-for-headlines'].each(function (elem
) {
1252 $$(".HLLCTR-" + elem
.id
).each(function (ctr
) {
1253 ctr
.innerHTML
= elem
.labels
;
1259 function cdmClicked(event
, id
, in_body
) {
1260 //var shift_key = event.shiftKey;
1262 if (!event
.ctrlKey
&& !event
.metaKey
) {
1264 let elem
= $("RROW-" + getActiveArticleId());
1266 if (elem
) elem
.removeClassName("active");
1268 selectArticles("none");
1271 elem
= $("RROW-" + id
);
1272 const article_is_unread
= elem
.hasClassName("Unread");
1274 elem
.removeClassName("Unread");
1275 elem
.addClassName("active");
1277 setActiveArticleId(id
);
1279 if (article_is_unread
) {
1280 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1281 updateFloatingTitle(true);
1284 op
: "rpc", method
: "catchupSelected",
1288 xhrPost("backend.php", query
, (transport
) => {
1289 handle_rpc_json(transport
);
1293 return !event
.shiftKey
;
1295 } else if (!in_body
) {
1297 toggleSelected(id
, true);
1299 let elem
= $("RROW-" + id
);
1300 const article_is_unread
= elem
.hasClassName("Unread");
1302 if (article_is_unread
) {
1303 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1306 toggleUnread(id
, 0, false);
1308 openArticleInNewWindow(id
);
1313 const unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1314 request_counters(unread_in_buffer
== 0);
1319 function hlClicked(event
, id
) {
1320 if (event
.which
== 2) {
1323 } else if (event
.ctrlKey
|| event
.metaKey
) {
1324 openArticleInNewWindow(id
);
1332 function openArticleInNewWindow(id
) {
1333 toggleUnread(id
, 0, false);
1335 const w
= window
.open("");
1337 w
.location
= "backend.php?op=article&method=redirect&id=" + id
;
1340 function isCdmMode() {
1341 return getInitParam("combined_display_mode");
1344 function markHeadline(id
, marked
) {
1345 if (marked
== undefined) marked
= true;
1347 const row
= $("RROW-" + id
);
1349 const check
= dijit
.getEnclosingWidget(
1350 row
.getElementsByClassName("rchk")[0]);
1353 check
.attr("checked", marked
);
1357 row
.addClassName("Selected");
1359 row
.removeClassName("Selected");
1363 function getRelativePostIds(id
, limit
) {
1367 if (!limit
) limit
= 6; //3
1369 const ids
= getLoadedArticleIds();
1371 for (let i
= 0; i
< ids
.length
; i
++) {
1373 for (let k
= 1; k
<= limit
; k
++) {
1374 //if (i > k-1) tmp.push(ids[i-k]);
1375 if (i
< ids
.length
- k
) tmp
.push(ids
[i
+ k
]);
1384 function correctHeadlinesOffset(id
) {
1386 const container
= $("headlines-frame");
1387 const row
= $("RROW-" + id
);
1389 if (!container
|| !row
) return;
1391 const viewport
= container
.offsetHeight
;
1393 const rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1394 const rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1396 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1397 //console.log("Vport: " + viewport);
1399 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1400 container
.scrollTop
= row
.offsetTop
;
1401 } else if (rel_offset_bottom
> viewport
) {
1403 /* doesn't properly work with Opera in some cases because
1404 Opera fucks up element scrolling */
1406 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1410 function headlineActionsChange(elem
) {
1412 elem
.attr('value', 'false');
1415 function closeArticlePanel() {
1417 if (dijit
.byId("content-insert"))
1418 dijit
.byId("headlines-wrap-inner").removeChild(
1419 dijit
.byId("content-insert"));
1422 function initFloatingMenu() {
1423 if (!dijit
.byId("floatingMenu")) {
1425 const menu
= new dijit
.Menu({
1427 targetNodeIds
: ["floatingTitle"]
1430 headlinesMenuCommon(menu
);
1436 function headlinesMenuCommon(menu
) {
1438 menu
.addChild(new dijit
.MenuItem({
1439 label
: __("Open original article"),
1440 onClick: function (event
) {
1441 openArticleInNewWindow(this.getParent().currentTarget
.getAttribute("data-article-id"));
1445 menu
.addChild(new dijit
.MenuItem({
1446 label
: __("Display article URL"),
1447 onClick: function (event
) {
1448 displayArticleUrl(this.getParent().currentTarget
.getAttribute("data-article-id"));
1452 menu
.addChild(new dijit
.MenuSeparator());
1454 menu
.addChild(new dijit
.MenuItem({
1455 label
: __("Toggle unread"),
1456 onClick: function () {
1458 let ids
= getSelectedArticleIds2();
1460 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1461 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1463 selectionToggleUnread(undefined, false, true, ids
);
1467 menu
.addChild(new dijit
.MenuItem({
1468 label
: __("Toggle starred"),
1469 onClick: function () {
1470 let ids
= getSelectedArticleIds2();
1472 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1473 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1475 selectionToggleMarked(undefined, false, true, ids
);
1479 menu
.addChild(new dijit
.MenuItem({
1480 label
: __("Toggle published"),
1481 onClick: function () {
1482 let ids
= getSelectedArticleIds2();
1484 const id
= (this.getParent().currentTarget
.getAttribute("data-article-id")) + "";
1485 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1487 selectionTogglePublished(undefined, false, true, ids
);
1491 menu
.addChild(new dijit
.MenuSeparator());
1493 menu
.addChild(new dijit
.MenuItem({
1494 label
: __("Mark above as read"),
1495 onClick: function () {
1496 catchupRelativeToArticle(0, this.getParent().currentTarget
.getAttribute("data-article-id"));
1500 menu
.addChild(new dijit
.MenuItem({
1501 label
: __("Mark below as read"),
1502 onClick: function () {
1503 catchupRelativeToArticle(1, this.getParent().currentTarget
.getAttribute("data-article-id"));
1508 const labels
= getInitParam("labels");
1510 if (labels
&& labels
.length
) {
1512 menu
.addChild(new dijit
.MenuSeparator());
1514 const labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1515 const labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1517 labels
.each(function (label
) {
1518 const bare_id
= label
.id
;
1519 const name
= label
.caption
;
1521 labelAddMenu
.addChild(new dijit
.MenuItem({
1524 onClick: function () {
1526 let ids
= getSelectedArticleIds2();
1528 const id
= (this.getParent().ownerMenu
.currentTarget
.getAttribute("data-article-id")) + "";
1530 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1532 selectionAssignLabel(this.labelId
, ids
);
1536 labelDelMenu
.addChild(new dijit
.MenuItem({
1539 onClick: function () {
1540 let ids
= getSelectedArticleIds2();
1542 const id
= (this.getParent().ownerMenu
.currentTarget
.getAttribute("data-article-id")) + "";
1544 ids
= ids
.length
!= 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1546 selectionRemoveLabel(this.labelId
, ids
);
1552 menu
.addChild(new dijit
.PopupMenuItem({
1553 label
: __("Assign label"),
1557 menu
.addChild(new dijit
.PopupMenuItem({
1558 label
: __("Remove label"),
1565 function initHeadlinesMenu() {
1566 if (!dijit
.byId("headlinesMenu")) {
1568 const menu
= new dijit
.Menu({
1569 id
: "headlinesMenu",
1570 targetNodeIds
: ["headlines-frame"],
1571 selector
: ".hlMenuAttach"
1574 headlinesMenuCommon(menu
);
1579 /* vgroup feed title menu */
1581 if (!dijit
.byId("headlinesFeedTitleMenu")) {
1583 const menu
= new dijit
.Menu({
1584 id
: "headlinesFeedTitleMenu",
1585 targetNodeIds
: ["headlines-frame"],
1586 selector
: "div.cdmFeedTitle"
1589 menu
.addChild(new dijit
.MenuItem({
1590 label
: __("Select articles in group"),
1591 onClick: function (event
) {
1592 selectArticles("all",
1593 "#headlines-frame > div[id*=RROW]" +
1594 "[data-orig-feed-id='" + this.getParent().currentTarget
.getAttribute("data-feed-id") + "']");
1599 menu
.addChild(new dijit
.MenuItem({
1600 label
: __("Mark group as read"),
1601 onClick: function () {
1602 selectArticles("none");
1603 selectArticles("all",
1604 "#headlines-frame > div[id*=RROW]" +
1605 "[data-orig-feed-id='" + this.getParent().currentTarget
.getAttribute("data-feed-id") + "']");
1611 menu
.addChild(new dijit
.MenuItem({
1612 label
: __("Mark feed as read"),
1613 onClick: function () {
1614 catchupFeedInGroup(this.getParent().currentTarget
.getAttribute("data-feed-id"));
1618 menu
.addChild(new dijit
.MenuItem({
1619 label
: __("Edit feed"),
1620 onClick: function () {
1621 editFeed(this.getParent().currentTarget
.getAttribute("data-feed-id"));
1629 function cache_set(id
, obj
) {
1630 //console.log("cache_set: " + id);
1633 sessionStorage
[id
] = obj
;
1635 sessionStorage
.clear();
1639 function cache_get(id
) {
1641 return sessionStorage
[id
];
1644 function cache_clear() {
1646 sessionStorage
.clear();
1649 function cache_delete(id
) {
1651 sessionStorage
.removeItem(id
);
1654 function cancelSearch() {
1659 function setSelectionScore() {
1660 const ids
= getSelectedArticleIds2();
1662 if (ids
.length
> 0) {
1665 const score
= prompt(__("Please enter new score for selected articles:"));
1667 if (score
!= undefined) {
1668 const query
= { op
: "article", method
: "setScore", id
: ids
.toString(),
1671 xhrJson("backend.php", query
, (reply
) => {
1673 reply
.id
.each((id
) => {
1674 const row
= $("RROW-" + id
);
1677 const pic
= row
.getElementsByClassName("score-pic")[0];
1680 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
1681 reply
["score_pic"]);
1682 pic
.setAttribute("score", reply
["score"]);
1691 alert(__("No articles are selected."));
1695 function changeScore(id
, pic
) {
1696 const score
= pic
.getAttribute("score");
1698 const new_score
= prompt(__("Please enter new score for this article:"), score
);
1700 if (new_score
!= undefined) {
1701 const query
= { op
: "article", method
: "setScore", id
: id
, score
: new_score
};
1703 xhrJson("backend.php", query
, (reply
) => {
1705 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
1706 pic
.setAttribute("score", new_score
);
1707 pic
.setAttribute("title", new_score
);
1713 function displayArticleUrl(id
) {
1714 const query
= { op
: "rpc", method
: "getlinktitlebyid", id
: id
};
1716 xhrJson("backend.php", query
, (reply
) => {
1717 if (reply
&& reply
.link
) {
1718 prompt(__("Article URL:"), reply
.link
);
1724 function scrollToRowId(id
) {
1728 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
1731 function updateFloatingTitle(unread_only
) {
1732 if (!isCdmMode()) return;
1734 const hf
= $("headlines-frame");
1736 const elems
= $$("#headlines-frame > div[id*=RROW]");
1738 for (let i
= 0; i
< elems
.length
; i
++) {
1740 const child
= elems
[i
];
1742 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
1744 const header
= child
.getElementsByClassName("header")[0];
1746 if (unread_only
|| child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
1747 if (child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
1749 $("floatingTitle").setAttribute("data-article-id", child
.getAttribute("data-article-id"));
1750 $("floatingTitle").innerHTML
= header
.innerHTML
;
1751 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('" + child
.id
+ "')\">" + $("floatingTitle").firstChild
.innerHTML
;
1755 const cb
= $$("#floatingTitle .dijitCheckBox")[0];
1758 cb
.parentNode
.removeChild(cb
);
1761 if (child
.hasClassName("Unread"))
1762 $("floatingTitle").addClassName("Unread");
1764 $("floatingTitle").removeClassName("Unread");
1766 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
1769 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
1770 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
1771 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
1772 $("floatingTitle").style
.visibility
= "visible";
1774 $("floatingTitle").style
.visibility
= "hidden";