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
);
153 while (tmp
.hasChildNodes()) {
154 var row
= tmp
.removeChild(tmp
.firstChild
);
156 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
157 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
159 loaded_article_ids
.push(row
.id
);
163 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
164 c
.domNode
.appendChild(hsp
);
166 if (headlines_count
< 30) _infscroll_disable
= true;
168 console
.log("restore selected ids: " + ids
);
170 for (var i
= 0; i
< ids
.length
; i
++) {
171 markHeadline(ids
[i
]);
176 if (_infscroll_disable
) {
177 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
178 __("Click to open next unread feed.") + "</a>";
182 console
.log("no new headlines received");
184 var first_id_changed
= reply
['headlines']['first_id_changed'];
185 console
.log("first id changed:" + first_id_changed
);
187 var hsp
= $("headlines-spacer");
190 if (first_id_changed
) {
191 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
192 __("New articles found, reload feed to continue.") + "</a>";
194 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
195 __("Click to open next unread feed.") + "</a>";
204 for (var i
= 0; i
< articles
.length
; i
++) {
205 var a_id
= articles
[i
]['id'];
206 cache_set("article:" + a_id
, articles
[i
]['content']);
209 console
.log("no cached articles received");
213 parse_counters(counters
);
215 request_counters(true);
218 console
.error("Invalid object received: " + transport
.responseText
);
219 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
220 __('Could not update headlines (invalid object received - see error console for details)') +
224 _infscroll_request_sent
= 0;
225 _last_headlines_update
= new Date().getTime();
227 unpackVisibleHeadlines();
229 // if we have some more space in the buffer, why not try to fill it
231 if (!_infscroll_disable
&& $("headlines-spacer") &&
232 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
234 window
.setTimeout(function() {
242 exception_error("headlines_callback2", e
, transport
);
246 function render_article(article
) {
248 cleanup_memory("content-insert");
250 dijit
.byId("headlines-wrap-inner").addChild(
251 dijit
.byId("content-insert"));
253 var c
= dijit
.byId("content-insert");
256 c
.domNode
.scrollTop
= 0;
259 c
.attr('content', article
);
260 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
262 correctHeadlinesOffset(getActiveArticleId());
269 exception_error("render_article", e
);
273 function showArticleInHeadlines(id
, noexpand
) {
276 var row
= $("RROW-" + id
);
280 row
.removeClassName("Unread");
282 row
.addClassName("active");
284 selectArticles('none');
289 exception_error("showArticleInHeadlines", e
);
293 function article_callback2(transport
, id
) {
295 console
.log("article_callback2 " + id
);
297 handle_rpc_json(transport
);
302 reply
= JSON
.parse(transport
.responseText
);
309 reply
.each(function(article
) {
310 if (getActiveArticleId() == article
['id']) {
311 render_article(article
['content']);
313 cids_requested
.remove(article
['id']);
315 cache_set("article:" + article
['id'], article
['content']);
318 // if (id != last_requested_article) {
319 // console.log("requested article id is out of sequence, aborting");
324 console
.error("Invalid object received: " + transport
.responseText
);
326 render_article("<div class='whiteBox'>" +
327 __('Could not display article (invalid object received - see error console for details)') + "</div>");
330 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
331 request_counters(unread_in_buffer
== 0);
335 exception_error("article_callback2", e
, transport
);
339 function view(id
, activefeed
, noexpand
) {
341 var oldrow
= $("RROW-" + getActiveArticleId());
342 if (oldrow
) oldrow
.removeClassName("active");
344 var crow
= $("RROW-" + id
);
348 setActiveArticleId(id
);
349 showArticleInHeadlines(id
, noexpand
);
353 console
.log("loading article: " + id
);
355 var cached_article
= cache_get("article:" + id
);
357 console
.log("cache check result: " + (cached_article
!= false));
359 var query
= "?op=article&method=view&id=" + param_escape(id
);
361 var neighbor_ids
= getRelativePostIds(id
);
363 /* only request uncached articles */
365 var cids_to_request
= [];
367 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
368 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
369 if (!cache_get("article:" + neighbor_ids
[i
])) {
370 cids_to_request
.push(neighbor_ids
[i
]);
371 cids_requested
.push(neighbor_ids
[i
]);
375 console
.log("additional ids: " + cids_to_request
.toString());
377 query
= query
+ "&cids=" + cids_to_request
.toString();
379 var article_is_unread
= crow
.hasClassName("Unread");
381 setActiveArticleId(id
);
382 showArticleInHeadlines(id
);
384 if (cached_article
&& article_is_unread
) {
386 query
= query
+ "&mode=prefetch";
388 render_article(cached_article
);
390 } else if (cached_article
) {
392 query
= query
+ "&mode=prefetch_old";
393 render_article(cached_article
);
395 // if we don't need to request any relative ids, we might as well skip
396 // the server roundtrip altogether
397 if (cids_to_request
.length
== 0) {
402 last_requested_article
= id
;
406 if (article_is_unread
) {
407 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
410 new Ajax
.Request("backend.php", {
412 onComplete: function(transport
) {
413 article_callback2(transport
, id
);
419 exception_error("view", e
);
423 function toggleMark(id
, client_only
) {
425 var query
= "?op=rpc&id=" + id
+ "&method=mark";
427 var row
= $("RROW-" + id
);
432 var row_imgs
= row
.getElementsByClassName("markedPic");
434 for (var i
= 0; i
< row_imgs
.length
; i
++)
435 imgs
.push(row_imgs
[i
]);
437 var ft
= $("floatingTitle");
439 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
440 var fte
= ft
.getElementsByClassName("markedPic");
442 for (var i
= 0; i
< fte
.length
; i
++)
446 for (i
= 0; i
< imgs
.length
; i
++) {
449 if (!row
.hasClassName("marked")) {
450 img
.src
= img
.src
.replace("mark_unset", "mark_set");
451 img
.alt
= __("Unstar article");
452 query
= query
+ "&mark=1";
454 img
.src
= img
.src
.replace("mark_set", "mark_unset");
455 img
.alt
= __("Star article");
456 query
= query
+ "&mark=0";
460 row
.toggleClassName("marked");
463 new Ajax
.Request("backend.php", {
465 onComplete: function(transport
) {
466 handle_rpc_json(transport
);
471 exception_error("toggleMark", e
);
475 function togglePub(id
, client_only
, no_effects
, note
) {
477 var query
= "?op=rpc&id=" + id
+ "&method=publ";
479 if (note
!= undefined) {
480 query
= query
+ "¬e=" + param_escape(note
);
482 query
= query
+ "¬e=undefined";
485 var row
= $("RROW-" + id
);
490 var row_imgs
= row
.getElementsByClassName("pubPic");
492 for (var i
= 0; i
< row_imgs
.length
; i
++)
493 imgs
.push(row_imgs
[i
]);
495 var ft
= $("floatingTitle");
497 if (ft
&& ft
.getAttribute("data-article-id") == id
) {
498 var fte
= ft
.getElementsByClassName("pubPic");
500 for (var i
= 0; i
< fte
.length
; i
++)
504 for (i
= 0; i
< imgs
.length
; i
++) {
507 if (!row
.hasClassName("published") || note
!= undefined) {
508 img
.src
= img
.src
.replace("pub_unset", "pub_set");
509 img
.alt
= __("Unpublish article");
510 query
= query
+ "&pub=1";
512 img
.src
= img
.src
.replace("pub_set", "pub_unset");
513 img
.alt
= __("Publish article");
514 query
= query
+ "&pub=0";
518 if (note
!= undefined)
519 row
.addClassName("published");
521 row
.toggleClassName("published");
524 new Ajax
.Request("backend.php", {
526 onComplete: function(transport
) {
527 handle_rpc_json(transport
);
532 exception_error("togglePub", e
);
536 function moveToPost(mode
, noscroll
, noexpand
) {
540 var rows
= getLoadedArticleIds();
545 if (!$('RROW-' + getActiveArticleId())) {
546 setActiveArticleId(0);
549 if (!getActiveArticleId()) {
551 prev_id
= rows
[rows
.length
-1]
553 for (var i
= 0; i
< rows
.length
; i
++) {
554 if (rows
[i
] == getActiveArticleId()) {
556 // Account for adjacent identical article ids.
557 if (i
> 0) prev_id
= rows
[i
-1];
559 for (var j
= i
+1; j
< rows
.length
; j
++) {
560 if (rows
[j
] != getActiveArticleId()) {
570 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
572 if (mode
== "next") {
573 if (next_id
|| getActiveArticleId()) {
576 var article
= $("RROW-" + getActiveArticleId());
577 var ctr
= $("headlines-frame");
579 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
580 ctr
.scrollTop
+ ctr
.offsetHeight
) {
582 scrollArticle(ctr
.offsetHeight
/4);
584 } else if (next_id
) {
585 cdmExpandArticle(next_id
, noexpand
);
586 cdmScrollToArticleId(next_id
, true);
589 } else if (next_id
) {
590 correctHeadlinesOffset(next_id
);
591 view(next_id
, getActiveFeedId(), noexpand
);
596 if (mode
== "prev") {
597 if (prev_id
|| getActiveArticleId()) {
600 var article
= $("RROW-" + getActiveArticleId());
601 var prev_article
= $("RROW-" + prev_id
);
602 var ctr
= $("headlines-frame");
604 if (!getInitParam("cdm_expanded")) {
606 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
607 scrollArticle(-ctr
.offsetHeight
/4);
609 cdmExpandArticle(prev_id
, noexpand
);
610 cdmScrollToArticleId(prev_id
, true);
614 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
615 scrollArticle(-ctr
.offsetHeight
/3);
616 } else if (!noscroll
&& prev_article
&&
617 prev_article
.offsetTop
< ctr
.scrollTop
) {
618 cdmExpandArticle(prev_id
, noexpand
);
619 scrollArticle(-ctr
.offsetHeight
/4);
620 } else if (prev_id
) {
621 cdmExpandArticle(prev_id
, noexpand
);
622 cdmScrollToArticleId(prev_id
, noscroll
);
626 } else if (prev_id
) {
627 correctHeadlinesOffset(prev_id
);
628 view(prev_id
, getActiveFeedId(), noexpand
);
634 exception_error("moveToPost", e
);
638 function toggleSelected(id
, force_on
) {
640 var row
= $("RROW-" + id
);
643 var cb
= dijit
.getEnclosingWidget(
644 row
.getElementsByClassName("rchk")[0]);
646 if (row
.hasClassName('Selected') && !force_on
) {
647 row
.removeClassName('Selected');
648 if (cb
) cb
.attr("checked", false);
650 row
.addClassName('Selected');
651 if (cb
) cb
.attr("checked", true);
655 updateSelectedPrompt();
657 exception_error("toggleSelected", e
);
661 function updateSelectedPrompt() {
663 var count
= getSelectedArticleIds2().size();
664 var elem
= $("selected_prompt");
667 elem
.innerHTML
= ngettext("%d article selected",
668 "%d articles selected", count
).replace("%d", count
);
677 exception_error("updateSelectedPrompt", e
);
681 function toggleUnread(id
, cmode
, effect
) {
684 var row
= $("RROW-" + id
);
686 var tmpClassName
= row
.className
;
688 if (cmode
== undefined || cmode
== 2) {
689 if (row
.hasClassName("Unread")) {
690 row
.removeClassName("Unread");
693 row
.addClassName("Unread");
696 } else if (cmode
== 0) {
698 row
.removeClassName("Unread");
700 } else if (cmode
== 1) {
701 row
.addClassName("Unread");
704 if (cmode
== undefined) cmode
= 2;
706 var query
= "?op=rpc&method=catchupSelected" +
707 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
709 // notify_progress("Loading, please wait...");
711 if (tmpClassName
!= row
.className
) {
712 new Ajax
.Request("backend.php", {
714 onComplete: function (transport
) {
715 handle_rpc_json(transport
);
723 exception_error("toggleUnread", e
);
727 function selectionRemoveLabel(id
, ids
) {
730 if (!ids
) ids
= getSelectedArticleIds2();
732 if (ids
.length
== 0) {
733 alert(__("No articles are selected."));
737 var query
= "?op=article&method=removeFromLabel&ids=" +
738 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
742 new Ajax
.Request("backend.php", {
744 onComplete: function(transport
) {
745 handle_rpc_json(transport
);
746 show_labels_in_headlines(transport
);
750 exception_error("selectionAssignLabel", e
);
755 function selectionAssignLabel(id
, ids
) {
758 if (!ids
) ids
= getSelectedArticleIds2();
760 if (ids
.length
== 0) {
761 alert(__("No articles are selected."));
765 var query
= "?op=article&method=assignToLabel&ids=" +
766 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
770 new Ajax
.Request("backend.php", {
772 onComplete: function(transport
) {
773 handle_rpc_json(transport
);
774 show_labels_in_headlines(transport
);
778 exception_error("selectionAssignLabel", e
);
783 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
785 var rows
= ids
? ids
: getSelectedArticleIds2();
787 if (rows
.length
== 0 && !no_error
) {
788 alert(__("No articles are selected."));
792 for (var i
= 0; i
< rows
.length
; i
++) {
793 var row
= $("RROW-" + rows
[i
]);
795 if (set_state
== undefined) {
796 if (row
.hasClassName("Unread")) {
797 row
.removeClassName("Unread");
799 row
.addClassName("Unread");
803 if (set_state
== false) {
804 row
.removeClassName("Unread");
807 if (set_state
== true) {
808 row
.addClassName("Unread");
813 updateFloatingTitle(true);
815 if (rows
.length
> 0) {
819 if (set_state
== undefined) {
821 } else if (set_state
== true) {
823 } else if (set_state
== false) {
827 var query
= "?op=rpc&method=catchupSelected" +
828 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
830 notify_progress("Loading, please wait...");
832 new Ajax
.Request("backend.php", {
834 onComplete: function(transport
) {
835 handle_rpc_json(transport
);
836 if (callback
) callback(transport
);
842 exception_error("selectionToggleUnread", e
);
847 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
850 var rows
= ids
? ids
: getSelectedArticleIds2();
852 if (rows
.length
== 0 && !no_error
) {
853 alert(__("No articles are selected."));
857 for (var i
= 0; i
< rows
.length
; i
++) {
858 toggleMark(rows
[i
], true, true);
861 if (rows
.length
> 0) {
863 var query
= "?op=rpc&method=markSelected&ids=" +
864 param_escape(rows
.toString()) + "&cmode=2";
866 new Ajax
.Request("backend.php", {
868 onComplete: function(transport
) {
869 handle_rpc_json(transport
);
870 if (callback
) callback(transport
);
876 exception_error("selectionToggleMarked", e
);
881 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
884 var rows
= ids
? ids
: getSelectedArticleIds2();
886 if (rows
.length
== 0 && !no_error
) {
887 alert(__("No articles are selected."));
891 for (var i
= 0; i
< rows
.length
; i
++) {
892 togglePub(rows
[i
], true, true);
895 if (rows
.length
> 0) {
897 var query
= "?op=rpc&method=publishSelected&ids=" +
898 param_escape(rows
.toString()) + "&cmode=2";
900 new Ajax
.Request("backend.php", {
902 onComplete: function(transport
) {
903 handle_rpc_json(transport
);
909 exception_error("selectionToggleMarked", e
);
913 function getSelectedArticleIds2() {
917 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
919 rv
.push(child
.getAttribute("data-article-id"));
925 function getLoadedArticleIds() {
928 var children
= $$("#headlines-frame > div[id*=RROW-]");
930 children
.each(function(child
) {
931 if (Element
.visible(child
)) {
932 rv
.push(child
.getAttribute("data-article-id"));
940 // mode = all,none,unread,invert,marked,published
941 function selectArticles(mode
, query
) {
944 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
946 var children
= $$(query
);
948 children
.each(function(child
) {
949 var id
= child
.getAttribute("data-article-id");
951 var cb
= dijit
.getEnclosingWidget(
952 child
.getElementsByClassName("rchk")[0]);
955 child
.addClassName("Selected");
956 if (cb
) cb
.attr("checked", true);
957 } else if (mode
== "unread") {
958 if (child
.hasClassName("Unread")) {
959 child
.addClassName("Selected");
960 if (cb
) cb
.attr("checked", true);
962 child
.removeClassName("Selected");
963 if (cb
) cb
.attr("checked", false);
965 } else if (mode
== "marked") {
966 if (child
.hasClassName("marked")) {
967 child
.addClassName("Selected");
968 if (cb
) cb
.attr("checked", true);
970 child
.removeClassName("Selected");
971 if (cb
) cb
.attr("checked", false);
973 } else if (mode
== "published") {
974 if (child
.hasClassName("published")) {
975 child
.addClassName("Selected");
976 if (cb
) cb
.attr("checked", true);
978 child
.removeClassName("Selected");
979 if (cb
) cb
.attr("checked", false);
982 } else if (mode
== "invert") {
983 if (child
.hasClassName("Selected")) {
984 child
.removeClassName("Selected");
985 if (cb
) cb
.attr("checked", false);
987 child
.addClassName("Selected");
988 if (cb
) cb
.attr("checked", true);
992 child
.removeClassName("Selected");
993 if (cb
) cb
.attr("checked", false);
997 updateSelectedPrompt();
1000 exception_error("selectArticles", e
);
1004 function deleteSelection() {
1008 var rows
= getSelectedArticleIds2();
1010 if (rows
.length
== 0) {
1011 alert(__("No articles are selected."));
1015 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1018 if (getActiveFeedId() != 0) {
1019 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1021 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1024 str
= str
.replace("%d", rows
.length
);
1025 str
= str
.replace("%s", fn
);
1027 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1031 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1035 new Ajax
.Request("backend.php", {
1037 onComplete: function(transport
) {
1038 handle_rpc_json(transport
);
1043 exception_error("deleteSelection", e
);
1047 function archiveSelection() {
1051 var rows
= getSelectedArticleIds2();
1053 if (rows
.length
== 0) {
1054 alert(__("No articles are selected."));
1058 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1062 if (getActiveFeedId() != 0) {
1063 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1066 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1068 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1073 str
= str
.replace("%d", rows
.length
);
1074 str
= str
.replace("%s", fn
);
1076 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1080 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1084 for (var i
= 0; i
< rows
.length
; i
++) {
1085 cache_delete("article:" + rows
[i
]);
1088 new Ajax
.Request("backend.php", {
1090 onComplete: function(transport
) {
1091 handle_rpc_json(transport
);
1096 exception_error("archiveSelection", e
);
1100 function catchupSelection() {
1104 var rows
= getSelectedArticleIds2();
1106 if (rows
.length
== 0) {
1107 alert(__("No articles are selected."));
1111 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1113 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1115 str
= str
.replace("%d", rows
.length
);
1116 str
= str
.replace("%s", fn
);
1118 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1122 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1125 exception_error("catchupSelection", e
);
1129 function editArticleTags(id
) {
1130 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1132 if (dijit
.byId("editTagsDlg"))
1133 dijit
.byId("editTagsDlg").destroyRecursive();
1135 dialog
= new dijit
.Dialog({
1137 title
: __("Edit article Tags"),
1138 style
: "width: 600px",
1139 execute: function() {
1140 if (this.validate()) {
1141 var query
= dojo
.objectToQuery(this.attr('value'));
1143 notify_progress("Saving article tags...", true);
1145 new Ajax
.Request("backend.php", {
1147 onComplete: function(transport
) {
1152 var data
= JSON
.parse(transport
.responseText
);
1159 var tags
= $("ATSTR-" + id
);
1160 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1162 if (tags
) tags
.innerHTML
= data
.content
;
1163 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1166 exception_error("editArticleTags/inner", e
);
1175 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1176 dojo
.disconnect(tmph
);
1178 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1179 "backend.php?op=article&method=completeTags",
1180 { tokens
: ',', paramName
: "search" });
1187 function cdmScrollToArticleId(id
, force
) {
1189 var ctr
= $("headlines-frame");
1190 var e
= $("RROW-" + id
);
1192 if (!e
|| !ctr
) return;
1194 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1195 e
.offsetTop
< ctr
.scrollTop
) {
1197 // expanded cdm has a 4px margin now
1198 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1202 exception_error("cdmScrollToArticleId", e
);
1206 function setActiveArticleId(id
) {
1207 console
.log("setActiveArticleId:" + id
);
1209 _active_article_id
= id
;
1210 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1213 function getActiveArticleId() {
1214 return _active_article_id
;
1217 function postMouseIn(e
, id
) {
1218 post_under_pointer
= id
;
1221 function postMouseOut(id
) {
1222 post_under_pointer
= false;
1225 function unpackVisibleHeadlines() {
1227 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1229 $$("#headlines-frame span.cencw[id]").each(
1231 var row
= $("RROW-" + child
.id
.replace("CENCW-", ""));
1233 if (row
&& row
.offsetTop
<= $("headlines-frame").scrollTop
+
1234 $("headlines-frame").offsetHeight
) {
1236 //console.log("unpacking: " + child.id);
1238 child
.innerHTML
= htmlspecialchars_decode(child
.innerHTML
);
1239 child
.removeAttribute('id');
1241 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, row
);
1243 Element
.show(child
);
1249 exception_error("unpackVisibleHeadlines", e
);
1253 function headlines_scroll_handler(e
) {
1256 // rate-limit in case of smooth scrolling and similar abominations
1257 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1261 _headlines_scroll_offset
= e
.scrollTop
;
1263 var hsp
= $("headlines-spacer");
1265 unpackVisibleHeadlines();
1267 // set topmost child in the buffer as active
1268 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1269 getSelectedArticleIds2().length
<= 1 &&
1270 getInitParam("cdm_expanded")) {
1272 var rows
= $$("#headlines-frame > div[id*=RROW]");
1274 for (var i
= 0; i
< rows
.length
; i
++) {
1275 var child
= rows
[i
];
1277 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1278 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1279 child
.getAttribute("data-article-id") != _active_article_id
) {
1281 if (_active_article_id
) {
1282 var row
= $("RROW-" + _active_article_id
);
1283 if (row
) row
.removeClassName("active");
1286 _active_article_id
= child
.getAttribute("data-article-id");
1287 showArticleInHeadlines(_active_article_id
, true);
1288 updateSelectedPrompt();
1294 if (!_infscroll_disable
) {
1295 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1297 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1298 __("Loading, please wait...") + "</span>";
1300 loadMoreHeadlines();
1307 updateFloatingTitle();
1310 catchupCurrentBatchIfNeeded();
1312 if (getInitParam("cdm_auto_catchup") == 1) {
1314 // let's get DOM some time to settle down
1315 var ts
= new Date().getTime();
1316 if (ts
- _last_headlines_update
< 100) return;
1318 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1320 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1321 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1323 var id
= child
.getAttribute("data-article-id")
1325 if (catchup_id_batch
.indexOf(id
) == -1)
1326 catchup_id_batch
.push(id
);
1328 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1333 if (_infscroll_disable
) {
1334 var child
= $$("#headlines-frame div[id*=RROW]").last();
1336 if (child
&& $("headlines-frame").scrollTop
>
1337 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1339 console
.log("we seem to be at an end");
1341 if (getInitParam("on_catchup_show_next_feed") == "1") {
1342 openNextUnreadFeed();
1349 console
.warn("headlines_scroll_handler: " + e
);
1353 function openNextUnreadFeed() {
1355 var is_cat
= activeFeedIsCat();
1356 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1357 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1359 exception_error("openNextUnreadFeed", e
);
1363 function catchupBatchedArticles() {
1365 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1367 console
.log("catchupBatchedArticles: working");
1369 // make a copy of the array
1370 var batch
= catchup_id_batch
.slice();
1371 var query
= "?op=rpc&method=catchupSelected" +
1372 "&cmode=0&ids=" + param_escape(batch
.toString());
1376 _catchup_request_sent
= true;
1378 new Ajax
.Request("backend.php", {
1380 onComplete: function(transport
) {
1381 handle_rpc_json(transport
);
1383 _catchup_request_sent
= false;
1385 reply
= JSON
.parse(transport
.responseText
);
1386 var batch
= reply
.ids
;
1388 batch
.each(function(id
) {
1390 var elem
= $("RROW-" + id
);
1391 if (elem
) elem
.removeClassName("Unread");
1392 catchup_id_batch
.remove(id
);
1395 updateFloatingTitle(true);
1401 exception_error("catchupBatchedArticles", e
);
1405 function catchupRelativeToArticle(below
, id
) {
1409 if (!id
) id
= getActiveArticleId();
1412 alert(__("No article is selected."));
1416 var visible_ids
= getLoadedArticleIds();
1418 var ids_to_mark
= new Array();
1421 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1422 if (visible_ids
[i
] != id
) {
1423 var e
= $("RROW-" + visible_ids
[i
]);
1425 if (e
&& e
.hasClassName("Unread")) {
1426 ids_to_mark
.push(visible_ids
[i
]);
1433 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1434 if (visible_ids
[i
] != id
) {
1435 var e
= $("RROW-" + visible_ids
[i
]);
1437 if (e
&& e
.hasClassName("Unread")) {
1438 ids_to_mark
.push(visible_ids
[i
]);
1446 if (ids_to_mark
.length
== 0) {
1447 alert(__("No articles found to mark"));
1449 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1451 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1453 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1454 var e
= $("RROW-" + ids_to_mark
[i
]);
1455 e
.removeClassName("Unread");
1458 var query
= "?op=rpc&method=catchupSelected" +
1459 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1461 new Ajax
.Request("backend.php", {
1463 onComplete: function(transport
) {
1464 handle_rpc_json(transport
);
1471 exception_error("catchupRelativeToArticle", e
);
1475 function cdmCollapseArticle(event
, id
, unmark
) {
1477 if (unmark
== undefined) unmark
= true;
1479 var row
= $("RROW-" + id
);
1480 var elem
= $("CICD-" + id
);
1483 var collapse
= row
.select("span[class='collapseBtn']")[0];
1486 Element
.show("CEXC-" + id
);
1487 Element
.hide(collapse
);
1490 row
.removeClassName("active");
1492 markHeadline(id
, false);
1494 if (id
== getActiveArticleId()) {
1495 setActiveArticleId(0);
1498 updateSelectedPrompt();
1501 if (event
) Event
.stop(event
);
1503 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1505 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1506 scrollToRowId(row
.id
);
1508 $("floatingTitle").style
.visibility
= "hidden";
1509 $("floatingTitle").setAttribute("data-article-id", 0);
1513 exception_error("cdmCollapseArticle", e
);
1517 function cdmExpandArticle(id
, noexpand
) {
1519 console
.log("cdmExpandArticle " + id
);
1521 var row
= $("RROW-" + id
);
1523 if (!row
) return false;
1525 var oldrow
= $("RROW-" + getActiveArticleId());
1527 var elem
= $("CICD-" + getActiveArticleId());
1529 if (id
== getActiveArticleId() && Element
.visible(elem
))
1532 selectArticles("none");
1534 var old_offset
= row
.offsetTop
;
1536 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1537 var collapse
= oldrow
.select("span[class='collapseBtn']")[0];
1540 Element
.show("CEXC-" + getActiveArticleId());
1541 Element
.hide(collapse
);
1544 if (oldrow
) oldrow
.removeClassName("active");
1546 setActiveArticleId(id
);
1548 elem
= $("CICD-" + id
);
1550 var collapse
= row
.select("span[class='collapseBtn']")[0];
1552 var cencw
= $("CENCW-" + id
);
1554 if (!Element
.visible(elem
) && !noexpand
) {
1556 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1557 cencw
.setAttribute('id', '');
1558 Element
.show(cencw
);
1562 Element
.hide("CEXC-" + id
);
1563 Element
.show(collapse
);
1566 var new_offset
= row
.offsetTop
;
1568 if (old_offset
> new_offset
)
1569 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1572 if (catchup_id_batch
.indexOf(id
) == -1)
1573 catchup_id_batch
.push(id
);
1575 catchupCurrentBatchIfNeeded();
1579 row
.addClassName("active");
1581 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1584 exception_error("cdmExpandArticle", e
);
1590 function getArticleUnderPointer() {
1591 return post_under_pointer
;
1594 function scrollArticle(offset
) {
1597 var ci
= $("content-insert");
1599 ci
.scrollTop
+= offset
;
1602 var hi
= $("headlines-frame");
1604 hi
.scrollTop
+= offset
;
1609 exception_error("scrollArticle", e
);
1613 function show_labels_in_headlines(transport
) {
1615 var data
= JSON
.parse(transport
.responseText
);
1618 data
['info-for-headlines'].each(function(elem
) {
1619 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1620 ctr
.innerHTML
= elem
.labels
;
1625 exception_error("show_labels_in_headlines", e
);
1629 function cdmClicked(event
, id
) {
1631 //var shift_key = event.shiftKey;
1633 if (!event
.ctrlKey
&& !event
.metaKey
) {
1635 if (!getInitParam("cdm_expanded")) {
1636 return cdmExpandArticle(id
);
1639 var elem
= $("RROW-" + getActiveArticleId());
1641 if (elem
) elem
.removeClassName("active");
1643 selectArticles("none");
1646 var elem
= $("RROW-" + id
);
1647 var article_is_unread
= elem
.hasClassName("Unread");
1649 elem
.removeClassName("Unread");
1650 elem
.addClassName("active");
1652 setActiveArticleId(id
);
1654 if (article_is_unread
) {
1655 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1656 updateFloatingTitle(true);
1659 var query
= "?op=rpc&method=catchupSelected" +
1660 "&cmode=0&ids=" + param_escape(id
);
1662 new Ajax
.Request("backend.php", {
1664 onComplete: function(transport
) {
1665 handle_rpc_json(transport
);
1668 return !event
.shiftKey
;
1671 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1673 toggleSelected(id
, true);
1675 var elem
= $("RROW-" + id
);
1676 var article_is_unread
= elem
.hasClassName("Unread");
1678 if (article_is_unread
) {
1679 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1682 toggleUnread(id
, 0, false);
1684 openArticleInNewWindow(id
);
1687 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1688 request_counters(unread_in_buffer
== 0);
1691 exception_error("cdmClicked");
1697 function hlClicked(event
, id
) {
1699 if (event
.which
== 2) {
1702 } else if (event
.ctrlKey
|| event
.metaKey
) {
1703 toggleSelected(id
, true);
1704 toggleUnread(id
, 0, false);
1705 openArticleInNewWindow(id
);
1713 exception_error("hlClicked");
1717 function openArticleInNewWindow(id
) {
1718 toggleUnread(id
, 0, false);
1720 var w
= window
.open("");
1722 w
.location
= "backend.php?op=article&method=redirect&id=" + id
;
1725 function isCdmMode() {
1726 return getInitParam("combined_display_mode");
1729 function markHeadline(id
, marked
) {
1730 if (marked
== undefined) marked
= true;
1732 var row
= $("RROW-" + id
);
1734 var check
= dijit
.getEnclosingWidget(
1735 row
.getElementsByClassName("rchk")[0]);
1738 check
.attr("checked", marked
);
1742 row
.addClassName("Selected");
1744 row
.removeClassName("Selected");
1748 function getRelativePostIds(id
, limit
) {
1754 if (!limit
) limit
= 6; //3
1756 var ids
= getLoadedArticleIds();
1758 for (var i
= 0; i
< ids
.length
; i
++) {
1760 for (var k
= 1; k
<= limit
; k
++) {
1761 //if (i > k-1) tmp.push(ids[i-k]);
1762 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1769 exception_error("getRelativePostIds", e
);
1775 function correctHeadlinesOffset(id
) {
1779 var container
= $("headlines-frame");
1780 var row
= $("RROW-" + id
);
1782 if (!container
|| !row
) return;
1784 var viewport
= container
.offsetHeight
;
1786 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1787 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1789 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1790 //console.log("Vport: " + viewport);
1792 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1793 container
.scrollTop
= row
.offsetTop
;
1794 } else if (rel_offset_bottom
> viewport
) {
1796 /* doesn't properly work with Opera in some cases because
1797 Opera fucks up element scrolling */
1799 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1803 exception_error("correctHeadlinesOffset", e
);
1808 function headlineActionsChange(elem
) {
1811 elem
.attr('value', 'false');
1813 exception_error("headlineActionsChange", e
);
1817 function closeArticlePanel() {
1819 if (dijit
.byId("content-insert"))
1820 dijit
.byId("headlines-wrap-inner").removeChild(
1821 dijit
.byId("content-insert"));
1824 function initFloatingMenu() {
1826 if (!dijit
.byId("floatingMenu")) {
1828 var menu
= new dijit
.Menu({
1830 targetNodeIds
: ["floatingTitle"]
1833 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1834 var callerNode
= event
.target
, match
= null, tries
= 0;
1836 while (match
== null && callerNode
&& tries
<= 3) {
1837 match
= callerNode
.getAttribute("data-article-id");
1838 callerNode
= callerNode
.parentNode
;
1842 if (match
) this.callerRowId
= match
;
1846 headlinesMenuCommon(menu
);
1852 exception_error("initFloatingMenu", e
);
1856 function headlinesMenuCommon(menu
) {
1859 menu
.addChild(new dijit
.MenuItem({
1860 label
: __("Open original article"),
1861 onClick: function(event
) {
1862 openArticleInNewWindow(this.getParent().callerRowId
);
1865 menu
.addChild(new dijit
.MenuItem({
1866 label
: __("Display article URL"),
1867 onClick: function(event
) {
1868 displayArticleUrl(this.getParent().callerRowId
);
1871 menu
.addChild(new dijit
.MenuSeparator());
1873 menu
.addChild(new dijit
.MenuItem({
1874 label
: __("Toggle unread"),
1875 onClick: function(event
) {
1876 var ids
= getSelectedArticleIds2();
1878 var id
= (this.getParent().callerRowId
) + "";
1879 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1881 selectionToggleUnread(undefined, false, true, ids
);
1884 menu
.addChild(new dijit
.MenuItem({
1885 label
: __("Toggle starred"),
1886 onClick: function(event
) {
1887 var ids
= getSelectedArticleIds2();
1889 var id
= (this.getParent().callerRowId
) + "";
1890 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1892 selectionToggleMarked(undefined, false, true, ids
);
1895 menu
.addChild(new dijit
.MenuItem({
1896 label
: __("Toggle published"),
1897 onClick: function(event
) {
1898 var ids
= getSelectedArticleIds2();
1900 var id
= (this.getParent().callerRowId
) + "";
1901 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1903 selectionTogglePublished(undefined, false, true, ids
);
1906 menu
.addChild(new dijit
.MenuSeparator());
1908 menu
.addChild(new dijit
.MenuItem({
1909 label
: __("Mark above as read"),
1910 onClick: function(event
) {
1911 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1914 menu
.addChild(new dijit
.MenuItem({
1915 label
: __("Mark below as read"),
1916 onClick: function(event
) {
1917 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1921 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1925 menu
.addChild(new dijit
.MenuSeparator());
1927 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1928 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1930 labels
.each(function(label
) {
1931 var id
= label
.id
[0];
1932 var bare_id
= id
.substr(id
.indexOf(":")+1);
1933 var name
= label
.name
[0];
1935 bare_id
= feed_to_label_id(bare_id
);
1937 labelAddMenu
.addChild(new dijit
.MenuItem({
1940 onClick: function(event
) {
1941 var ids
= getSelectedArticleIds2();
1943 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1945 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1947 selectionAssignLabel(this.labelId
, ids
);
1950 labelDelMenu
.addChild(new dijit
.MenuItem({
1953 onClick: function(event
) {
1954 var ids
= getSelectedArticleIds2();
1956 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1958 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1960 selectionRemoveLabel(this.labelId
, ids
);
1965 menu
.addChild(new dijit
.PopupMenuItem({
1966 label
: __("Assign label"),
1970 menu
.addChild(new dijit
.PopupMenuItem({
1971 label
: __("Remove label"),
1979 exception_error("headlinesMenuCommon", e
);
1983 function initHeadlinesMenu() {
1985 if (!dijit
.byId("headlinesMenu")) {
1987 var menu
= new dijit
.Menu({
1988 id
: "headlinesMenu",
1989 targetNodeIds
: ["headlines-frame"],
1990 selector
: ".hlMenuAttach"
1993 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1994 var callerNode
= event
.target
, match
= null, tries
= 0;
1996 while (match
== null && callerNode
&& tries
<= 3) {
1998 match
= callerNode
.getAttribute("data-article-id")
1999 callerNode
= callerNode
.parentNode
;
2003 if (match
) this.callerRowId
= match
;
2007 headlinesMenuCommon(menu
);
2012 /* vgroup feed title menu */
2014 if (!dijit
.byId("headlinesFeedTitleMenu")) {
2016 var menu
= new dijit
.Menu({
2017 id
: "headlinesFeedTitleMenu",
2018 targetNodeIds
: ["headlines-frame"],
2019 selector
: "div.cdmFeedTitle"
2022 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2023 var callerNode
= event
.target
, match
= null, tries
= 0;
2025 while (match
== null && callerNode
&& tries
<= 3) {
2026 match
= callerNode
.getAttribute("data-feed-id")
2027 callerNode
= callerNode
.parentNode
;
2031 if (match
) this.callerRowId
= match
;
2035 menu
.addChild(new dijit
.MenuItem({
2036 label
: __("Select articles in group"),
2037 onClick: function (event
) {
2038 selectArticles("all",
2039 "#headlines-frame > div[id*=RROW]" +
2040 "[data-orig-feed-id='" + menu
.callerRowId
+ "']");
2045 menu
.addChild(new dijit
.MenuItem({
2046 label
: __("Mark group as read"),
2047 onClick: function (event
) {
2048 selectArticles("none");
2049 selectArticles("all",
2050 "#headlines-frame > div[id*=RROW]" +
2051 "[data-orig-feed-id='" + menu
.callerRowId
+ "']");
2057 menu
.addChild(new dijit
.MenuItem({
2058 label
: __("Mark feed as read"),
2059 onClick: function (event
) {
2060 catchupFeedInGroup(menu
.callerRowId
);
2064 menu
.addChild(new dijit
.MenuItem({
2065 label
: __("Edit feed"),
2066 onClick: function (event
) {
2067 editFeed(menu
.callerRowId
);
2075 exception_error("initHeadlinesMenu", e
);
2079 function cache_set(id
, obj
) {
2080 //console.log("cache_set: " + id);
2083 sessionStorage
[id
] = obj
;
2085 sessionStorage
.clear();
2089 function cache_get(id
) {
2091 return sessionStorage
[id
];
2094 function cache_clear() {
2096 sessionStorage
.clear();
2099 function cache_delete(id
) {
2101 sessionStorage
.removeItem(id
);
2104 function cancelSearch() {
2109 exception_error("cancelSearch", e
);
2113 function setSelectionScore() {
2115 var ids
= getSelectedArticleIds2();
2117 if (ids
.length
> 0) {
2120 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2122 if (score
!= undefined) {
2123 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2124 "&score=" + param_escape(score
);
2126 new Ajax
.Request("backend.php", {
2128 onComplete: function(transport
) {
2129 var reply
= JSON
.parse(transport
.responseText
);
2133 ids
.each(function(id
) {
2134 var row
= $("RROW-" + id
);
2137 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2140 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2141 reply
["score_pic"]);
2142 pic
.setAttribute("score", score
);
2151 alert(__("No articles are selected."));
2154 exception_error("setSelectionScore", e
);
2158 function updateScore(id
) {
2160 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2164 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2166 new Ajax
.Request("backend.php", {
2168 onComplete: function(transport
) {
2169 console
.log(transport
.responseText
);
2171 var reply
= JSON
.parse(transport
.responseText
);
2174 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2175 pic
.setAttribute("score", reply
["score"]);
2176 pic
.setAttribute("title", reply
["score"]);
2182 exception_error("updateScore", e
);
2186 function changeScore(id
, pic
) {
2188 var score
= pic
.getAttribute("score");
2190 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2192 if (new_score
!= undefined) {
2194 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2195 "&score=" + param_escape(new_score
);
2197 new Ajax
.Request("backend.php", {
2199 onComplete: function(transport
) {
2200 var reply
= JSON
.parse(transport
.responseText
);
2203 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2204 pic
.setAttribute("score", new_score
);
2205 pic
.setAttribute("title", new_score
);
2210 exception_error("changeScore", e
);
2214 function displayArticleUrl(id
) {
2216 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2218 new Ajax
.Request("backend.php", {
2220 onComplete: function(transport
) {
2221 var reply
= JSON
.parse(transport
.responseText
);
2223 if (reply
&& reply
.link
) {
2224 prompt(__("Article URL:"), reply
.link
);
2228 exception_error("changeScore", e
);
2232 function scrollToRowId(id
) {
2237 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2240 exception_error("scrollToRowId", e
);
2244 function updateFloatingTitle(unread_only
) {
2246 if (!isCdmMode()) return;
2248 var hf
= $("headlines-frame");
2250 var elems
= $$("#headlines-frame > div[id*=RROW]");
2252 for (var i
= 0; i
< elems
.length
; i
++) {
2254 var child
= elems
[i
];
2256 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2258 var header
= child
.getElementsByClassName("cdmHeader")[0];
2260 if (unread_only
|| child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2261 if (child
.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
2263 $("floatingTitle").setAttribute("data-article-id", child
.getAttribute("data-article-id"));
2264 $("floatingTitle").innerHTML
= header
.innerHTML
;
2265 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2269 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2272 cb
.parentNode
.removeChild(cb
);
2275 if (child
.hasClassName("Unread"))
2276 $("floatingTitle").addClassName("Unread");
2278 $("floatingTitle").removeClassName("Unread");
2280 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2283 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2284 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2285 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2286 $("floatingTitle").style
.visibility
= "visible";
2288 $("floatingTitle").style
.visibility
= "hidden";
2296 exception_error("updateFloatingTitle", e
);
2300 function catchupCurrentBatchIfNeeded() {
2301 if (catchup_id_batch
.length
> 0) {
2302 window
.clearTimeout(catchup_timeout_id
);
2303 catchup_timeout_id
= window
.setTimeout(catchupBatchedArticles
, 1000);
2305 if (catchup_id_batch
.length
>= 10) {
2306 catchupBatchedArticles();
2311 function cdmFooterClick(event
) {
2312 event
.stopPropagation();