1 var article_cache
= new Array();
3 var _active_article_id
= 0;
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
13 var cids_requested
= [];
14 var loaded_article_ids
= [];
15 var _last_headlines_update
= 0;
16 var _headlines_scroll_offset
= 0;
17 var current_first_id
= 0;
19 var _catchup_request_sent
= false;
21 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
23 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
25 handle_rpc_json(transport
);
27 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
35 reply
= JSON
.parse(transport
.responseText
);
42 is_cat
= reply
['headlines']['is_cat'];
43 feed_id
= reply
['headlines']['id'];
46 var content
= reply
['headlines']['content'];
48 content
= content
+ "<div id='headlines-spacer'></div>";
52 if (feed_id
!= -7 && (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat()))
55 /* dijit.getEnclosingWidget(
56 document.forms["main_toolbar_form"].update).attr('disabled',
57 is_cat || feed_id <= 0); */
60 if (infscroll_req
== false) {
61 $("headlines-frame").scrollTop
= 0;
63 $("floatingTitle").style
.visibility
= "hidden";
64 $("floatingTitle").setAttribute("data-article-id", 0);
65 $("floatingTitle").innerHTML
= "";
69 $("headlines-frame").removeClassName("cdm");
70 $("headlines-frame").removeClassName("normal");
72 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
74 var headlines_count
= reply
['headlines-info']['count'];
76 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
78 if (parseInt(headlines_count
) < 30) {
79 _infscroll_disable
= 1;
81 _infscroll_disable
= 0;
84 current_first_id
= reply
['headlines']['first_id'];
85 var counters
= reply
['counters'];
86 var articles
= reply
['articles'];
87 //var runtime_info = reply['runtime-info'];
89 if (infscroll_req
== false) {
90 loaded_article_ids
= [];
92 dojo
.html
.set($("headlines-toolbar"),
93 reply
['headlines']['toolbar'],
94 {parseContent
: true});
96 /*dojo.html.set($("headlines-frame"),
97 reply['headlines']['content'],
98 {parseContent: true});
100 $$("#headlines-frame div[id*='RROW']").each(function(row) {
101 loaded_article_ids.push(row.id);
104 $("headlines-frame").innerHTML
= '';
106 var tmp
= new Element("div");
107 tmp
.innerHTML
= reply
['headlines']['content'];
108 dojo
.parser
.parse(tmp
);
110 while (tmp
.hasChildNodes()) {
111 var row
= tmp
.removeChild(tmp
.firstChild
);
113 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
114 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
116 loaded_article_ids
.push(row
.id
);
120 var hsp
= $("headlines-spacer");
121 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
122 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
126 if (_infscroll_disable
)
127 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
128 __("Click to open next unread feed.") + "</a>";
131 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
132 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
138 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
139 console
.log("adding some more headlines: " + headlines_count
);
141 var c
= dijit
.byId("headlines-frame");
142 var ids
= getSelectedArticleIds2();
144 var hsp
= $("headlines-spacer");
147 c
.domNode
.removeChild(hsp
);
149 var tmp
= new Element("div");
150 tmp
.innerHTML
= reply
['headlines']['content'];
151 dojo
.parser
.parse(tmp
);
155 while (tmp
.hasChildNodes()) {
156 var row
= tmp
.removeChild(tmp
.firstChild
);
158 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
159 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
161 loaded_article_ids
.push(row
.id
);
166 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
167 c
.domNode
.appendChild(hsp
);
169 if (headlines_count
< 30) _infscroll_disable
= true;
171 console
.log("restore selected ids: " + ids
);
173 for (var i
= 0; i
< ids
.length
; i
++) {
174 markHeadline(ids
[i
]);
177 initHeadlinesMenu(new_rows
);
179 if (_infscroll_disable
) {
180 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
181 __("Click to open next unread feed.") + "</a>";
185 console
.log("no new headlines received");
187 var first_id_changed
= reply
['headlines']['first_id_changed'];
188 console
.log("first id changed:" + first_id_changed
);
190 var hsp
= $("headlines-spacer");
193 if (first_id_changed
) {
194 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
195 __("New articles found, reload feed to continue.") + "</a>";
197 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
198 __("Click to open next unread feed.") + "</a>";
207 for (var i
= 0; i
< articles
.length
; i
++) {
208 var a_id
= articles
[i
]['id'];
209 cache_set("article:" + a_id
, articles
[i
]['content']);
212 console
.log("no cached articles received");
216 parse_counters(counters
);
218 request_counters(true);
221 console
.error("Invalid object received: " + transport
.responseText
);
222 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
223 __('Could not update headlines (invalid object received - see error console for details)') +
227 _infscroll_request_sent
= 0;
228 _last_headlines_update
= new Date().getTime();
230 unpackVisibleHeadlines();
232 // if we have some more space in the buffer, why not try to fill it
234 if (!_infscroll_disable
&& $("headlines-spacer") &&
235 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
237 window
.setTimeout(function() {
245 exception_error("headlines_callback2", e
, transport
);
249 function render_article(article
) {
251 cleanup_memory("content-insert");
253 dijit
.byId("headlines-wrap-inner").addChild(
254 dijit
.byId("content-insert"));
256 var c
= dijit
.byId("content-insert");
259 c
.domNode
.scrollTop
= 0;
262 c
.attr('content', article
);
263 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
265 correctHeadlinesOffset(getActiveArticleId());
272 exception_error("render_article", e
);
276 function showArticleInHeadlines(id
, noexpand
) {
279 var row
= $("RROW-" + id
);
283 row
.removeClassName("Unread");
285 row
.addClassName("active");
287 selectArticles('none');
292 exception_error("showArticleInHeadlines", e
);
296 function article_callback2(transport
, id
) {
298 console
.log("article_callback2 " + id
);
300 handle_rpc_json(transport
);
305 reply
= JSON
.parse(transport
.responseText
);
312 reply
.each(function(article
) {
313 if (getActiveArticleId() == article
['id']) {
314 render_article(article
['content']);
316 cids_requested
.remove(article
['id']);
318 cache_set("article:" + article
['id'], article
['content']);
321 // if (id != last_requested_article) {
322 // console.log("requested article id is out of sequence, aborting");
327 console
.error("Invalid object received: " + transport
.responseText
);
329 render_article("<div class='whiteBox'>" +
330 __('Could not display article (invalid object received - see error console for details)') + "</div>");
333 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
334 request_counters(unread_in_buffer
== 0);
338 exception_error("article_callback2", e
, transport
);
342 function view(id
, activefeed
, noexpand
) {
344 var oldrow
= $("RROW-" + getActiveArticleId());
345 if (oldrow
) oldrow
.removeClassName("active");
347 var crow
= $("RROW-" + id
);
351 setActiveArticleId(id
);
352 showArticleInHeadlines(id
, noexpand
);
356 console
.log("loading article: " + id
);
358 var cached_article
= cache_get("article:" + id
);
360 console
.log("cache check result: " + (cached_article
!= false));
362 var query
= "?op=article&method=view&id=" + param_escape(id
);
364 var neighbor_ids
= getRelativePostIds(id
);
366 /* only request uncached articles */
368 var cids_to_request
= [];
370 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
371 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
372 if (!cache_get("article:" + neighbor_ids
[i
])) {
373 cids_to_request
.push(neighbor_ids
[i
]);
374 cids_requested
.push(neighbor_ids
[i
]);
378 console
.log("additional ids: " + cids_to_request
.toString());
380 query
= query
+ "&cids=" + cids_to_request
.toString();
382 var article_is_unread
= crow
.hasClassName("Unread");
384 setActiveArticleId(id
);
385 showArticleInHeadlines(id
);
387 if (cached_article
&& article_is_unread
) {
389 query
= query
+ "&mode=prefetch";
391 render_article(cached_article
);
393 } else if (cached_article
) {
395 query
= query
+ "&mode=prefetch_old";
396 render_article(cached_article
);
398 // if we don't need to request any relative ids, we might as well skip
399 // the server roundtrip altogether
400 if (cids_to_request
.length
== 0) {
405 last_requested_article
= id
;
409 if (article_is_unread
) {
410 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
413 new Ajax
.Request("backend.php", {
415 onComplete: function(transport
) {
416 article_callback2(transport
, id
);
422 exception_error("view", e
);
426 function toggleMark(id
, client_only
) {
428 var query
= "?op=rpc&id=" + id
+ "&method=mark";
430 var row
= $("RROW-" + id
);
435 var row_imgs
= row
.getElementsByClassName("markedPic");
437 for (var i
= 0; i
< row_imgs
.length
; i
++)
438 imgs
.push(row_imgs
[i
]);
440 var ft
= $("floatingTitle");
442 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
443 var fte
= ft
.getElementsByClassName("markedPic");
445 for (var i
= 0; i
< fte
.length
; i
++)
449 for (i
= 0; i
< imgs
.length
; i
++) {
452 if (!row
.hasClassName("marked")) {
453 img
.src
= img
.src
.replace("mark_unset", "mark_set");
454 img
.alt
= __("Unstar article");
455 query
= query
+ "&mark=1";
457 img
.src
= img
.src
.replace("mark_set", "mark_unset");
458 img
.alt
= __("Star article");
459 query
= query
+ "&mark=0";
463 row
.toggleClassName("marked");
466 new Ajax
.Request("backend.php", {
468 onComplete: function(transport
) {
469 handle_rpc_json(transport
);
474 exception_error("toggleMark", e
);
478 function togglePub(id
, client_only
, no_effects
, note
) {
480 var query
= "?op=rpc&id=" + id
+ "&method=publ";
482 if (note
!= undefined) {
483 query
= query
+ "¬e=" + param_escape(note
);
485 query
= query
+ "¬e=undefined";
488 var row
= $("RROW-" + id
);
493 var row_imgs
= row
.getElementsByClassName("pubPic");
495 for (var i
= 0; i
< row_imgs
.length
; i
++)
496 imgs
.push(row_imgs
[i
]);
498 var ft
= $("floatingTitle");
500 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
501 var fte
= ft
.getElementsByClassName("pubPic");
503 for (var i
= 0; i
< fte
.length
; i
++)
507 for (i
= 0; i
< imgs
.length
; i
++) {
510 if (!row
.hasClassName("published") || note
!= undefined) {
511 img
.src
= img
.src
.replace("pub_unset", "pub_set");
512 img
.alt
= __("Unpublish article");
513 query
= query
+ "&pub=1";
515 img
.src
= img
.src
.replace("pub_set", "pub_unset");
516 img
.alt
= __("Publish article");
517 query
= query
+ "&pub=0";
521 if (note
!= undefined)
522 row
.addClassName("published");
524 row
.toggleClassName("published");
527 new Ajax
.Request("backend.php", {
529 onComplete: function(transport
) {
530 handle_rpc_json(transport
);
535 exception_error("togglePub", e
);
539 function moveToPost(mode
, noscroll
, noexpand
) {
543 var rows
= getLoadedArticleIds();
548 if (!$('RROW-' + getActiveArticleId())) {
549 setActiveArticleId(0);
552 if (!getActiveArticleId()) {
554 prev_id
= rows
[rows
.length
-1]
556 for (var i
= 0; i
< rows
.length
; i
++) {
557 if (rows
[i
] == getActiveArticleId()) {
559 // Account for adjacent identical article ids.
560 if (i
> 0) prev_id
= rows
[i
-1];
562 for (var j
= i
+1; j
< rows
.length
; j
++) {
563 if (rows
[j
] != getActiveArticleId()) {
573 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
575 if (mode
== "next") {
576 if (next_id
|| getActiveArticleId()) {
579 var article
= $("RROW-" + getActiveArticleId());
580 var ctr
= $("headlines-frame");
582 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
583 ctr
.scrollTop
+ ctr
.offsetHeight
) {
585 scrollArticle(ctr
.offsetHeight
/4);
587 } else if (next_id
) {
588 cdmExpandArticle(next_id
, noexpand
);
589 cdmScrollToArticleId(next_id
, true);
592 } else if (next_id
) {
593 correctHeadlinesOffset(next_id
);
594 view(next_id
, getActiveFeedId(), noexpand
);
599 if (mode
== "prev") {
600 if (prev_id
|| getActiveArticleId()) {
603 var article
= $("RROW-" + getActiveArticleId());
604 var prev_article
= $("RROW-" + prev_id
);
605 var ctr
= $("headlines-frame");
607 if (!getInitParam("cdm_expanded")) {
609 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
610 scrollArticle(-ctr
.offsetHeight
/4);
612 cdmExpandArticle(prev_id
, noexpand
);
613 cdmScrollToArticleId(prev_id
, true);
617 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
618 scrollArticle(-ctr
.offsetHeight
/3);
619 } else if (!noscroll
&& prev_article
&&
620 prev_article
.offsetTop
< ctr
.scrollTop
) {
621 cdmExpandArticle(prev_id
, noexpand
);
622 scrollArticle(-ctr
.offsetHeight
/4);
623 } else if (prev_id
) {
624 cdmExpandArticle(prev_id
, noexpand
);
625 cdmScrollToArticleId(prev_id
, noscroll
);
629 } else if (prev_id
) {
630 correctHeadlinesOffset(prev_id
);
631 view(prev_id
, getActiveFeedId(), noexpand
);
637 exception_error("moveToPost", e
);
641 function toggleSelected(id
, force_on
) {
643 var row
= $("RROW-" + id
);
646 var cb
= dijit
.getEnclosingWidget(
647 row
.getElementsByClassName("rchk")[0]);
649 if (row
.hasClassName('Selected') && !force_on
) {
650 row
.removeClassName('Selected');
651 if (cb
) cb
.attr("checked", false);
653 row
.addClassName('Selected');
654 if (cb
) cb
.attr("checked", true);
658 updateSelectedPrompt();
660 exception_error("toggleSelected", e
);
664 function updateSelectedPrompt() {
666 var count
= getSelectedArticleIds2().size();
667 var elem
= $("selected_prompt");
670 elem
.innerHTML
= ngettext("%d article selected",
671 "%d articles selected", count
).replace("%d", count
);
680 exception_error("updateSelectedPrompt", e
);
684 function toggleUnread(id
, cmode
, effect
) {
687 var row
= $("RROW-" + id
);
689 var tmpClassName
= row
.className
;
691 if (cmode
== undefined || cmode
== 2) {
692 if (row
.hasClassName("Unread")) {
693 row
.removeClassName("Unread");
696 row
.addClassName("Unread");
699 } else if (cmode
== 0) {
701 row
.removeClassName("Unread");
703 } else if (cmode
== 1) {
704 row
.addClassName("Unread");
707 if (cmode
== undefined) cmode
= 2;
709 var query
= "?op=rpc&method=catchupSelected" +
710 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
712 // notify_progress("Loading, please wait...");
714 if (tmpClassName
!= row
.className
) {
715 new Ajax
.Request("backend.php", {
717 onComplete: function (transport
) {
718 handle_rpc_json(transport
);
726 exception_error("toggleUnread", e
);
730 function selectionRemoveLabel(id
, ids
) {
733 if (!ids
) ids
= getSelectedArticleIds2();
735 if (ids
.length
== 0) {
736 alert(__("No articles are selected."));
740 var query
= "?op=article&method=removeFromLabel&ids=" +
741 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
745 new Ajax
.Request("backend.php", {
747 onComplete: function(transport
) {
748 handle_rpc_json(transport
);
749 show_labels_in_headlines(transport
);
753 exception_error("selectionAssignLabel", e
);
758 function selectionAssignLabel(id
, ids
) {
761 if (!ids
) ids
= getSelectedArticleIds2();
763 if (ids
.length
== 0) {
764 alert(__("No articles are selected."));
768 var query
= "?op=article&method=assignToLabel&ids=" +
769 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
773 new Ajax
.Request("backend.php", {
775 onComplete: function(transport
) {
776 handle_rpc_json(transport
);
777 show_labels_in_headlines(transport
);
781 exception_error("selectionAssignLabel", e
);
786 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
788 var rows
= ids
? ids
: getSelectedArticleIds2();
790 if (rows
.length
== 0 && !no_error
) {
791 alert(__("No articles are selected."));
795 for (var i
= 0; i
< rows
.length
; i
++) {
796 var row
= $("RROW-" + rows
[i
]);
798 if (set_state
== undefined) {
799 if (row
.hasClassName("Unread")) {
800 row
.removeClassName("Unread");
802 row
.addClassName("Unread");
806 if (set_state
== false) {
807 row
.removeClassName("Unread");
810 if (set_state
== true) {
811 row
.addClassName("Unread");
816 updateFloatingTitle(true);
818 if (rows
.length
> 0) {
822 if (set_state
== undefined) {
824 } else if (set_state
== true) {
826 } else if (set_state
== false) {
830 var query
= "?op=rpc&method=catchupSelected" +
831 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
833 notify_progress("Loading, please wait...");
835 new Ajax
.Request("backend.php", {
837 onComplete: function(transport
) {
838 handle_rpc_json(transport
);
839 if (callback
) callback(transport
);
845 exception_error("selectionToggleUnread", e
);
850 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
853 var rows
= ids
? ids
: getSelectedArticleIds2();
855 if (rows
.length
== 0 && !no_error
) {
856 alert(__("No articles are selected."));
860 for (var i
= 0; i
< rows
.length
; i
++) {
861 toggleMark(rows
[i
], true, true);
864 if (rows
.length
> 0) {
866 var query
= "?op=rpc&method=markSelected&ids=" +
867 param_escape(rows
.toString()) + "&cmode=2";
869 new Ajax
.Request("backend.php", {
871 onComplete: function(transport
) {
872 handle_rpc_json(transport
);
873 if (callback
) callback(transport
);
879 exception_error("selectionToggleMarked", e
);
884 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
887 var rows
= ids
? ids
: getSelectedArticleIds2();
889 if (rows
.length
== 0 && !no_error
) {
890 alert(__("No articles are selected."));
894 for (var i
= 0; i
< rows
.length
; i
++) {
895 togglePub(rows
[i
], true, true);
898 if (rows
.length
> 0) {
900 var query
= "?op=rpc&method=publishSelected&ids=" +
901 param_escape(rows
.toString()) + "&cmode=2";
903 new Ajax
.Request("backend.php", {
905 onComplete: function(transport
) {
906 handle_rpc_json(transport
);
912 exception_error("selectionToggleMarked", e
);
916 function getSelectedArticleIds2() {
920 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
922 rv
.push(child
.getAttribute("data-article-id"));
928 function getLoadedArticleIds() {
931 var children
= $$("#headlines-frame > div[id*=RROW-]");
933 children
.each(function(child
) {
934 if (Element
.visible(child
)) {
935 rv
.push(child
.getAttribute("data-article-id"));
943 // mode = all,none,unread,invert,marked,published
944 function selectArticles(mode
, query
) {
947 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
949 var children
= $$(query
);
951 children
.each(function(child
) {
952 var id
= child
.getAttribute("data-article-id");
954 var cb
= dijit
.getEnclosingWidget(
955 child
.getElementsByClassName("rchk")[0]);
958 child
.addClassName("Selected");
959 if (cb
) cb
.attr("checked", true);
960 } else if (mode
== "unread") {
961 if (child
.hasClassName("Unread")) {
962 child
.addClassName("Selected");
963 if (cb
) cb
.attr("checked", true);
965 child
.removeClassName("Selected");
966 if (cb
) cb
.attr("checked", false);
968 } else if (mode
== "marked") {
969 if (child
.hasClassName("marked")) {
970 child
.addClassName("Selected");
971 if (cb
) cb
.attr("checked", true);
973 child
.removeClassName("Selected");
974 if (cb
) cb
.attr("checked", false);
976 } else if (mode
== "published") {
977 if (child
.hasClassName("published")) {
978 child
.addClassName("Selected");
979 if (cb
) cb
.attr("checked", true);
981 child
.removeClassName("Selected");
982 if (cb
) cb
.attr("checked", false);
985 } else if (mode
== "invert") {
986 if (child
.hasClassName("Selected")) {
987 child
.removeClassName("Selected");
988 if (cb
) cb
.attr("checked", false);
990 child
.addClassName("Selected");
991 if (cb
) cb
.attr("checked", true);
995 child
.removeClassName("Selected");
996 if (cb
) cb
.attr("checked", false);
1000 updateSelectedPrompt();
1003 exception_error("selectArticles", e
);
1007 function deleteSelection() {
1011 var rows
= getSelectedArticleIds2();
1013 if (rows
.length
== 0) {
1014 alert(__("No articles are selected."));
1018 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1021 if (getActiveFeedId() != 0) {
1022 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1024 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1027 str
= str
.replace("%d", rows
.length
);
1028 str
= str
.replace("%s", fn
);
1030 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1034 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1038 new Ajax
.Request("backend.php", {
1040 onComplete: function(transport
) {
1041 handle_rpc_json(transport
);
1046 exception_error("deleteSelection", e
);
1050 function archiveSelection() {
1054 var rows
= getSelectedArticleIds2();
1056 if (rows
.length
== 0) {
1057 alert(__("No articles are selected."));
1061 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1065 if (getActiveFeedId() != 0) {
1066 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1069 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1071 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1076 str
= str
.replace("%d", rows
.length
);
1077 str
= str
.replace("%s", fn
);
1079 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1083 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1087 for (var i
= 0; i
< rows
.length
; i
++) {
1088 cache_delete("article:" + rows
[i
]);
1091 new Ajax
.Request("backend.php", {
1093 onComplete: function(transport
) {
1094 handle_rpc_json(transport
);
1099 exception_error("archiveSelection", e
);
1103 function catchupSelection() {
1107 var rows
= getSelectedArticleIds2();
1109 if (rows
.length
== 0) {
1110 alert(__("No articles are selected."));
1114 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1116 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1118 str
= str
.replace("%d", rows
.length
);
1119 str
= str
.replace("%s", fn
);
1121 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1125 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1128 exception_error("catchupSelection", e
);
1132 function editArticleTags(id
) {
1133 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1135 if (dijit
.byId("editTagsDlg"))
1136 dijit
.byId("editTagsDlg").destroyRecursive();
1138 dialog
= new dijit
.Dialog({
1140 title
: __("Edit article Tags"),
1141 style
: "width: 600px",
1142 execute: function() {
1143 if (this.validate()) {
1144 var query
= dojo
.objectToQuery(this.attr('value'));
1146 notify_progress("Saving article tags...", true);
1148 new Ajax
.Request("backend.php", {
1150 onComplete: function(transport
) {
1155 var data
= JSON
.parse(transport
.responseText
);
1162 var tags
= $("ATSTR-" + id
);
1163 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1165 if (tags
) tags
.innerHTML
= data
.content
;
1166 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1169 exception_error("editArticleTags/inner", e
);
1178 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1179 dojo
.disconnect(tmph
);
1181 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1182 "backend.php?op=article&method=completeTags",
1183 { tokens
: ',', paramName
: "search" });
1190 function cdmScrollToArticleId(id
, force
) {
1192 var ctr
= $("headlines-frame");
1193 var e
= $("RROW-" + id
);
1195 if (!e
|| !ctr
) return;
1197 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1198 e
.offsetTop
< ctr
.scrollTop
) {
1200 // expanded cdm has a 4px margin now
1201 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1205 exception_error("cdmScrollToArticleId", e
);
1209 function setActiveArticleId(id
) {
1210 console
.log("setActiveArticleId:" + id
);
1212 _active_article_id
= id
;
1213 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1216 function getActiveArticleId() {
1217 return _active_article_id
;
1220 function postMouseIn(e
, id
) {
1221 post_under_pointer
= id
;
1224 function postMouseOut(id
) {
1225 post_under_pointer
= false;
1228 function unpackVisibleHeadlines() {
1230 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1232 $$("#headlines-frame > div[id*=RROW]").each(
1234 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1235 $("headlines-frame").offsetHeight
) {
1237 var cencw
= $("CENCW-" + child
.getAttribute("data-article-id"));
1240 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1241 cencw
.setAttribute('id', '');
1243 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1245 Element
.show(cencw
);
1252 exception_error("unpackVisibleHeadlines", e
);
1256 function headlines_scroll_handler(e
) {
1259 // rate-limit in case of smooth scrolling and similar abominations
1260 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1264 _headlines_scroll_offset
= e
.scrollTop
;
1266 var hsp
= $("headlines-spacer");
1268 unpackVisibleHeadlines();
1270 // set topmost child in the buffer as active
1271 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1272 getSelectedArticleIds2().length
<= 1 &&
1273 getInitParam("cdm_expanded")) {
1275 var rows
= $$("#headlines-frame > div[id*=RROW]");
1277 for (var i
= 0; i
< rows
.length
; i
++) {
1278 var child
= rows
[i
];
1280 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1281 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1282 child
.getAttribute("data-article-id") != _active_article_id
) {
1284 if (_active_article_id
) {
1285 var row
= $("RROW-" + _active_article_id
);
1286 if (row
) row
.removeClassName("active");
1289 _active_article_id
= child
.getAttribute("data-article-id");
1290 showArticleInHeadlines(_active_article_id
, true);
1291 updateSelectedPrompt();
1297 if (!_infscroll_disable
) {
1298 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1300 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1301 __("Loading, please wait...") + "</span>";
1303 loadMoreHeadlines();
1310 updateFloatingTitle();
1313 catchupCurrentBatchIfNeeded();
1315 if (getInitParam("cdm_auto_catchup") == 1) {
1317 // let's get DOM some time to settle down
1318 var ts
= new Date().getTime();
1319 if (ts
- _last_headlines_update
< 100) return;
1321 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1323 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1324 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1326 var id
= child
.getAttribute("data-article-id")
1328 if (catchup_id_batch
.indexOf(id
) == -1)
1329 catchup_id_batch
.push(id
);
1331 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1336 if (_infscroll_disable
) {
1337 var child
= $$("#headlines-frame div[id*=RROW]").last();
1339 if (child
&& $("headlines-frame").scrollTop
>
1340 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1342 console
.log("we seem to be at an end");
1344 if (getInitParam("on_catchup_show_next_feed") == "1") {
1345 openNextUnreadFeed();
1352 console
.warn("headlines_scroll_handler: " + e
);
1356 function openNextUnreadFeed() {
1358 var is_cat
= activeFeedIsCat();
1359 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1360 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1362 exception_error("openNextUnreadFeed", e
);
1366 function catchupBatchedArticles() {
1368 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1370 console
.log("catchupBatchedArticles: working");
1372 // make a copy of the array
1373 var batch
= catchup_id_batch
.slice();
1374 var query
= "?op=rpc&method=catchupSelected" +
1375 "&cmode=0&ids=" + param_escape(batch
.toString());
1379 _catchup_request_sent
= true;
1381 new Ajax
.Request("backend.php", {
1383 onComplete: function(transport
) {
1384 handle_rpc_json(transport
);
1386 _catchup_request_sent
= false;
1388 reply
= JSON
.parse(transport
.responseText
);
1389 var batch
= reply
.ids
;
1391 batch
.each(function(id
) {
1393 var elem
= $("RROW-" + id
);
1394 if (elem
) elem
.removeClassName("Unread");
1395 catchup_id_batch
.remove(id
);
1398 updateFloatingTitle(true);
1404 exception_error("catchupBatchedArticles", e
);
1408 function catchupRelativeToArticle(below
, id
) {
1412 if (!id
) id
= getActiveArticleId();
1415 alert(__("No article is selected."));
1419 var visible_ids
= getLoadedArticleIds();
1421 var ids_to_mark
= new Array();
1424 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1425 if (visible_ids
[i
] != id
) {
1426 var e
= $("RROW-" + visible_ids
[i
]);
1428 if (e
&& e
.hasClassName("Unread")) {
1429 ids_to_mark
.push(visible_ids
[i
]);
1436 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1437 if (visible_ids
[i
] != id
) {
1438 var e
= $("RROW-" + visible_ids
[i
]);
1440 if (e
&& e
.hasClassName("Unread")) {
1441 ids_to_mark
.push(visible_ids
[i
]);
1449 if (ids_to_mark
.length
== 0) {
1450 alert(__("No articles found to mark"));
1452 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1454 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1456 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1457 var e
= $("RROW-" + ids_to_mark
[i
]);
1458 e
.removeClassName("Unread");
1461 var query
= "?op=rpc&method=catchupSelected" +
1462 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1464 new Ajax
.Request("backend.php", {
1466 onComplete: function(transport
) {
1467 handle_rpc_json(transport
);
1474 exception_error("catchupRelativeToArticle", e
);
1478 function cdmCollapseArticle(event
, id
, unmark
) {
1480 if (unmark
== undefined) unmark
= true;
1482 var row
= $("RROW-" + id
);
1483 var elem
= $("CICD-" + id
);
1486 var collapse
= $$("div#RROW-" + id
+
1487 " span[class='collapseBtn']")[0];
1490 Element
.show("CEXC-" + id
);
1491 Element
.hide(collapse
);
1494 row
.removeClassName("active");
1496 markHeadline(id
, false);
1498 if (id
== getActiveArticleId()) {
1499 setActiveArticleId(0);
1502 updateSelectedPrompt();
1505 if (event
) Event
.stop(event
);
1507 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1509 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1510 scrollToRowId(row
.id
);
1512 $("floatingTitle").style
.visibility
= "hidden";
1513 $("floatingTitle").setAttribute("data-article-id", 0);
1517 exception_error("cdmCollapseArticle", e
);
1521 function cdmExpandArticle(id
, noexpand
) {
1523 console
.log("cdmExpandArticle " + id
);
1525 if (!$("RROW-" + id
)) return false;
1527 var oldrow
= $("RROW-" + getActiveArticleId());
1529 var elem
= $("CICD-" + getActiveArticleId());
1531 if (id
== getActiveArticleId() && Element
.visible(elem
))
1534 selectArticles("none");
1536 var old_offset
= $("RROW-" + id
).offsetTop
;
1538 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1539 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1540 " span[class='collapseBtn']")[0];
1543 Element
.show("CEXC-" + getActiveArticleId());
1544 Element
.hide(collapse
);
1547 if (oldrow
) oldrow
.removeClassName("active");
1549 setActiveArticleId(id
);
1551 elem
= $("CICD-" + id
);
1553 var collapse
= $$("div#RROW-" + id
+
1554 " span[class='collapseBtn']")[0];
1556 var cencw
= $("CENCW-" + id
);
1558 if (!Element
.visible(elem
) && !noexpand
) {
1560 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1561 cencw
.setAttribute('id', '');
1562 Element
.show(cencw
);
1566 Element
.hide("CEXC-" + id
);
1567 Element
.show(collapse
);
1570 var new_offset
= $("RROW-" + id
).offsetTop
;
1572 if (old_offset
> new_offset
)
1573 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1576 if (catchup_id_batch
.indexOf(id
) == -1)
1577 catchup_id_batch
.push(id
);
1579 catchupCurrentBatchIfNeeded();
1583 $("RROW-" + id
).addClassName("active");
1585 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1588 exception_error("cdmExpandArticle", e
);
1594 function getArticleUnderPointer() {
1595 return post_under_pointer
;
1598 function scrollArticle(offset
) {
1601 var ci
= $("content-insert");
1603 ci
.scrollTop
+= offset
;
1606 var hi
= $("headlines-frame");
1608 hi
.scrollTop
+= offset
;
1613 exception_error("scrollArticle", e
);
1617 function show_labels_in_headlines(transport
) {
1619 var data
= JSON
.parse(transport
.responseText
);
1622 data
['info-for-headlines'].each(function(elem
) {
1623 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1624 ctr
.innerHTML
= elem
.labels
;
1629 exception_error("show_labels_in_headlines", e
);
1633 function cdmClicked(event
, id
) {
1635 //var shift_key = event.shiftKey;
1637 if (!event
.ctrlKey
&& !event
.metaKey
) {
1639 if (!getInitParam("cdm_expanded")) {
1640 return cdmExpandArticle(id
);
1643 var elem
= $("RROW-" + getActiveArticleId());
1645 if (elem
) elem
.removeClassName("active");
1647 selectArticles("none");
1650 var elem
= $("RROW-" + id
);
1651 var article_is_unread
= elem
.hasClassName("Unread");
1653 elem
.removeClassName("Unread");
1654 elem
.addClassName("active");
1656 setActiveArticleId(id
);
1658 if (article_is_unread
) {
1659 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1660 updateFloatingTitle(true);
1663 var query
= "?op=rpc&method=catchupSelected" +
1664 "&cmode=0&ids=" + param_escape(id
);
1666 new Ajax
.Request("backend.php", {
1668 onComplete: function(transport
) {
1669 handle_rpc_json(transport
);
1672 return !event
.shiftKey
;
1675 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1677 toggleSelected(id
, true);
1679 var elem
= $("RROW-" + id
);
1680 var article_is_unread
= elem
.hasClassName("Unread");
1682 if (article_is_unread
) {
1683 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1686 toggleUnread(id
, 0, false);
1688 openArticleInNewWindow(id
);
1691 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1692 request_counters(unread_in_buffer
== 0);
1695 exception_error("cdmClicked");
1701 function hlClicked(event
, id
) {
1703 if (event
.which
== 2) {
1706 } else if (event
.ctrlKey
|| event
.metaKey
) {
1707 toggleSelected(id
, true);
1708 toggleUnread(id
, 0, false);
1709 openArticleInNewWindow(id
);
1717 exception_error("hlClicked");
1721 function openArticleInNewWindow(id
) {
1722 toggleUnread(id
, 0, false);
1723 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1726 function isCdmMode() {
1727 return getInitParam("combined_display_mode");
1730 function markHeadline(id
, marked
) {
1731 if (marked
== undefined) marked
= true;
1733 var row
= $("RROW-" + id
);
1735 var check
= dijit
.getEnclosingWidget(
1736 row
.getElementsByClassName("rchk")[0]);
1739 check
.attr("checked", marked
);
1743 row
.addClassName("Selected");
1745 row
.removeClassName("Selected");
1749 function getRelativePostIds(id
, limit
) {
1755 if (!limit
) limit
= 6; //3
1757 var ids
= getLoadedArticleIds();
1759 for (var i
= 0; i
< ids
.length
; i
++) {
1761 for (var k
= 1; k
<= limit
; k
++) {
1762 //if (i > k-1) tmp.push(ids[i-k]);
1763 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1770 exception_error("getRelativePostIds", e
);
1776 function correctHeadlinesOffset(id
) {
1780 var container
= $("headlines-frame");
1781 var row
= $("RROW-" + id
);
1783 if (!container
|| !row
) return;
1785 var viewport
= container
.offsetHeight
;
1787 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1788 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1790 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1791 //console.log("Vport: " + viewport);
1793 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1794 container
.scrollTop
= row
.offsetTop
;
1795 } else if (rel_offset_bottom
> viewport
) {
1797 /* doesn't properly work with Opera in some cases because
1798 Opera fucks up element scrolling */
1800 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1804 exception_error("correctHeadlinesOffset", e
);
1809 function headlineActionsChange(elem
) {
1812 elem
.attr('value', 'false');
1814 exception_error("headlineActionsChange", e
);
1818 function closeArticlePanel() {
1820 if (dijit
.byId("content-insert"))
1821 dijit
.byId("headlines-wrap-inner").removeChild(
1822 dijit
.byId("content-insert"));
1825 function initFloatingMenu() {
1827 if (!dijit
.byId("floatingMenu")) {
1829 var menu
= new dijit
.Menu({
1831 targetNodeIds
: ["floatingTitle"]
1834 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1835 var callerNode
= event
.target
, match
= null, tries
= 0;
1837 while (match
== null && callerNode
&& tries
<= 3) {
1838 match
= callerNode
.getAttribute("data-article-id");
1839 callerNode
= callerNode
.parentNode
;
1843 if (match
) this.callerRowId
= match
;
1847 headlinesMenuCommon(menu
);
1853 exception_error("initFloatingMenu", e
);
1857 function headlinesMenuCommon(menu
) {
1860 menu
.addChild(new dijit
.MenuItem({
1861 label
: __("Open original article"),
1862 onClick: function(event
) {
1863 openArticleInNewWindow(this.getParent().callerRowId
);
1866 menu
.addChild(new dijit
.MenuItem({
1867 label
: __("Display article URL"),
1868 onClick: function(event
) {
1869 displayArticleUrl(this.getParent().callerRowId
);
1872 menu
.addChild(new dijit
.MenuSeparator());
1874 menu
.addChild(new dijit
.MenuItem({
1875 label
: __("Toggle unread"),
1876 onClick: function(event
) {
1877 var ids
= getSelectedArticleIds2();
1879 var id
= (this.getParent().callerRowId
) + "";
1880 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1882 selectionToggleUnread(undefined, false, true, ids
);
1885 menu
.addChild(new dijit
.MenuItem({
1886 label
: __("Toggle starred"),
1887 onClick: function(event
) {
1888 var ids
= getSelectedArticleIds2();
1890 var id
= (this.getParent().callerRowId
) + "";
1891 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1893 selectionToggleMarked(undefined, false, true, ids
);
1896 menu
.addChild(new dijit
.MenuItem({
1897 label
: __("Toggle published"),
1898 onClick: function(event
) {
1899 var ids
= getSelectedArticleIds2();
1901 var id
= (this.getParent().callerRowId
) + "";
1902 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1904 selectionTogglePublished(undefined, false, true, ids
);
1907 menu
.addChild(new dijit
.MenuSeparator());
1909 menu
.addChild(new dijit
.MenuItem({
1910 label
: __("Mark above as read"),
1911 onClick: function(event
) {
1912 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1915 menu
.addChild(new dijit
.MenuItem({
1916 label
: __("Mark below as read"),
1917 onClick: function(event
) {
1918 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1922 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1926 menu
.addChild(new dijit
.MenuSeparator());
1928 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1929 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1931 labels
.each(function(label
) {
1932 var id
= label
.id
[0];
1933 var bare_id
= id
.substr(id
.indexOf(":")+1);
1934 var name
= label
.name
[0];
1936 bare_id
= feed_to_label_id(bare_id
);
1938 labelAddMenu
.addChild(new dijit
.MenuItem({
1941 onClick: function(event
) {
1942 var ids
= getSelectedArticleIds2();
1944 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1946 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1948 selectionAssignLabel(this.labelId
, ids
);
1951 labelDelMenu
.addChild(new dijit
.MenuItem({
1954 onClick: function(event
) {
1955 var ids
= getSelectedArticleIds2();
1957 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1959 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1961 selectionRemoveLabel(this.labelId
, ids
);
1966 menu
.addChild(new dijit
.PopupMenuItem({
1967 label
: __("Assign label"),
1971 menu
.addChild(new dijit
.PopupMenuItem({
1972 label
: __("Remove label"),
1980 exception_error("headlinesMenuCommon", e
);
1984 function initHeadlinesMenu(append_rows
) {
1988 if (dijit
.byId("headlinesMenu"))
1989 dijit
.byId("headlinesMenu").destroyRecursive();
1994 nodes
= $$("#headlines-frame > div[id*=RROW]");
1996 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1999 nodes
.each(function (node
) {
2003 var menu
= new dijit
.Menu({
2004 id
: "headlinesMenu",
2008 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2009 var callerNode
= event
.target
, match
= null, tries
= 0;
2011 while (match
== null && callerNode
&& tries
<= 3) {
2013 match
= callerNode
.getAttribute("data-article-id")
2014 callerNode
= callerNode
.parentNode
;
2018 if (match
) this.callerRowId
= match
;
2022 headlinesMenuCommon(menu
);
2027 var menu
= dijit
.byId("headlinesMenu");
2029 append_rows
.each(function (row
) {
2030 if (!row
.hasClassName("cdmFeedTitle")) {
2031 menu
.bindDomNode(row
);
2036 /* vgroup feed title menu */
2040 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2043 nodes
.each(function(node
) {
2047 if (ids
.length
> 0) {
2048 if (dijit
.byId("headlinesFeedTitleMenu"))
2049 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2051 var menu
= new dijit
.Menu({
2052 id
: "headlinesFeedTitleMenu",
2056 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2057 var callerNode
= event
.target
, match
= null, tries
= 0;
2059 while (match
== null && callerNode
&& tries
<= 3) {
2060 match
= callerNode
.getAttribute("data-feed-id")
2061 callerNode
= callerNode
.parentNode
;
2065 if (match
) this.callerRowId
= match
;
2069 menu
.addChild(new dijit
.MenuItem({
2070 label
: __("Select articles in group"),
2071 onClick: function (event
) {
2072 selectArticles("all",
2073 "#headlines-frame > div[id*=RROW]" +
2074 "[data-orig-feed-id='" + menu
.callerRowId
+ "']");
2079 menu
.addChild(new dijit
.MenuItem({
2080 label
: __("Mark group as read"),
2081 onClick: function (event
) {
2082 selectArticles("none");
2083 selectArticles("all",
2084 "#headlines-frame > div[id*=RROW]" +
2085 "[data-orig-feed-id='" + menu
.callerRowId
+ "']");
2091 menu
.addChild(new dijit
.MenuItem({
2092 label
: __("Mark feed as read"),
2093 onClick: function (event
) {
2094 catchupFeedInGroup(menu
.callerRowId
);
2098 menu
.addChild(new dijit
.MenuItem({
2099 label
: __("Edit feed"),
2100 onClick: function (event
) {
2101 editFeed(menu
.callerRowId
);
2108 var menu
= dijit
.byId("headlinesFeedTitleMenu");
2110 console
.log(append_rows
);
2112 append_rows
.each(function (row
) {
2113 if (row
.hasClassName("cdmFeedTitle")) {
2114 menu
.bindDomNode(row
);
2120 exception_error("initHeadlinesMenu", e
);
2124 function cache_set(id
, obj
) {
2125 //console.log("cache_set: " + id);
2128 sessionStorage
[id
] = obj
;
2130 sessionStorage
.clear();
2134 function cache_get(id
) {
2136 return sessionStorage
[id
];
2139 function cache_clear() {
2141 sessionStorage
.clear();
2144 function cache_delete(id
) {
2146 sessionStorage
.removeItem(id
);
2149 function cancelSearch() {
2154 exception_error("cancelSearch", e
);
2158 function setSelectionScore() {
2160 var ids
= getSelectedArticleIds2();
2162 if (ids
.length
> 0) {
2165 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2167 if (score
!= undefined) {
2168 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2169 "&score=" + param_escape(score
);
2171 new Ajax
.Request("backend.php", {
2173 onComplete: function(transport
) {
2174 var reply
= JSON
.parse(transport
.responseText
);
2178 ids
.each(function(id
) {
2179 var row
= $("RROW-" + id
);
2182 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2185 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2186 reply
["score_pic"]);
2187 pic
.setAttribute("score", score
);
2196 alert(__("No articles are selected."));
2199 exception_error("setSelectionScore", e
);
2203 function updateScore(id
) {
2205 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2209 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2211 new Ajax
.Request("backend.php", {
2213 onComplete: function(transport
) {
2214 console
.log(transport
.responseText
);
2216 var reply
= JSON
.parse(transport
.responseText
);
2219 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2220 pic
.setAttribute("score", reply
["score"]);
2221 pic
.setAttribute("title", reply
["score"]);
2227 exception_error("updateScore", e
);
2231 function changeScore(id
, pic
) {
2233 var score
= pic
.getAttribute("score");
2235 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2237 if (new_score
!= undefined) {
2239 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2240 "&score=" + param_escape(new_score
);
2242 new Ajax
.Request("backend.php", {
2244 onComplete: function(transport
) {
2245 var reply
= JSON
.parse(transport
.responseText
);
2248 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2249 pic
.setAttribute("score", new_score
);
2250 pic
.setAttribute("title", new_score
);
2255 exception_error("changeScore", e
);
2259 function displayArticleUrl(id
) {
2261 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2263 new Ajax
.Request("backend.php", {
2265 onComplete: function(transport
) {
2266 var reply
= JSON
.parse(transport
.responseText
);
2268 if (reply
&& reply
.link
) {
2269 prompt(__("Article URL:"), reply
.link
);
2273 exception_error("changeScore", e
);
2277 function scrollToRowId(id
) {
2282 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2285 exception_error("scrollToRowId", e
);
2289 function updateFloatingTitle(unread_only
) {
2291 if (!isCdmMode()) return;
2293 var hf
= $("headlines-frame");
2295 var elems
= $$("#headlines-frame > div[id*=RROW]");
2297 for (var i
= 0; i
< elems
.length
; i
++) {
2299 var child
= elems
[i
];
2301 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2303 var header
= child
.getElementsByClassName("cdmHeader")[0];
2305 if (unread_only
|| child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2306 if (child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2308 $("floatingTitle").setAttribute("data-article-id", child
.getAttribute("data-article-id"));
2309 $("floatingTitle").innerHTML
= header
.innerHTML
;
2310 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2314 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2317 cb
.parentNode
.removeChild(cb
);
2320 if (child
.hasClassName("Unread"))
2321 $("floatingTitle").addClassName("Unread");
2323 $("floatingTitle").removeClassName("Unread");
2325 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2328 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2329 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2330 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2331 $("floatingTitle").style
.visibility
= "visible";
2333 $("floatingTitle").style
.visibility
= "hidden";
2341 exception_error("updateFloatingTitle", e
);
2345 function catchupCurrentBatchIfNeeded() {
2346 if (catchup_id_batch
.length
> 0) {
2347 window
.clearTimeout(catchup_timeout_id
);
2348 catchup_timeout_id
= window
.setTimeout(catchupBatchedArticles
, 1000);
2350 if (catchup_id_batch
.length
>= 10) {
2351 catchupBatchedArticles();
2356 function cdmFooterClick(event
) {
2357 event
.stopPropagation();