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("rowid", 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("rowid") == "RROW-" + 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("rowid") == "RROW-" + 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
.id
.replace("RROW-", ""));
925 function getLoadedArticleIds() {
928 var children
= $$("#headlines-frame > div[id*=RROW-]");
930 children
.each(function(child
) {
931 rv
.push(child
.id
.replace("RROW-", ""));
938 // mode = all,none,unread,invert,marked,published
939 function selectArticles(mode
, query
) {
942 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
944 var children
= $$(query
);
946 children
.each(function(child
) {
947 var id
= child
.id
.replace("RROW-", "");
949 var cb
= dijit
.getEnclosingWidget(
950 child
.getElementsByClassName("rchk")[0]);
953 child
.addClassName("Selected");
954 if (cb
) cb
.attr("checked", true);
955 } else if (mode
== "unread") {
956 if (child
.hasClassName("Unread")) {
957 child
.addClassName("Selected");
958 if (cb
) cb
.attr("checked", true);
960 child
.removeClassName("Selected");
961 if (cb
) cb
.attr("checked", false);
963 } else if (mode
== "marked") {
964 if (child
.hasClassName("marked")) {
965 child
.addClassName("Selected");
966 if (cb
) cb
.attr("checked", true);
968 child
.removeClassName("Selected");
969 if (cb
) cb
.attr("checked", false);
971 } else if (mode
== "published") {
972 if (child
.hasClassName("published")) {
973 child
.addClassName("Selected");
974 if (cb
) cb
.attr("checked", true);
976 child
.removeClassName("Selected");
977 if (cb
) cb
.attr("checked", false);
980 } else if (mode
== "invert") {
981 if (child
.hasClassName("Selected")) {
982 child
.removeClassName("Selected");
983 if (cb
) cb
.attr("checked", false);
985 child
.addClassName("Selected");
986 if (cb
) cb
.attr("checked", true);
990 child
.removeClassName("Selected");
991 if (cb
) cb
.attr("checked", false);
995 updateSelectedPrompt();
998 exception_error("selectArticles", e
);
1002 function deleteSelection() {
1006 var rows
= getSelectedArticleIds2();
1008 if (rows
.length
== 0) {
1009 alert(__("No articles are selected."));
1013 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1016 if (getActiveFeedId() != 0) {
1017 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1019 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1022 str
= str
.replace("%d", rows
.length
);
1023 str
= str
.replace("%s", fn
);
1025 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1029 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1033 new Ajax
.Request("backend.php", {
1035 onComplete: function(transport
) {
1036 handle_rpc_json(transport
);
1041 exception_error("deleteSelection", e
);
1045 function archiveSelection() {
1049 var rows
= getSelectedArticleIds2();
1051 if (rows
.length
== 0) {
1052 alert(__("No articles are selected."));
1056 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1060 if (getActiveFeedId() != 0) {
1061 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1064 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1066 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1071 str
= str
.replace("%d", rows
.length
);
1072 str
= str
.replace("%s", fn
);
1074 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1078 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1082 for (var i
= 0; i
< rows
.length
; i
++) {
1083 cache_delete("article:" + rows
[i
]);
1086 new Ajax
.Request("backend.php", {
1088 onComplete: function(transport
) {
1089 handle_rpc_json(transport
);
1094 exception_error("archiveSelection", e
);
1098 function catchupSelection() {
1102 var rows
= getSelectedArticleIds2();
1104 if (rows
.length
== 0) {
1105 alert(__("No articles are selected."));
1109 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1111 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1113 str
= str
.replace("%d", rows
.length
);
1114 str
= str
.replace("%s", fn
);
1116 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1120 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1123 exception_error("catchupSelection", e
);
1127 function editArticleTags(id
) {
1128 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1130 if (dijit
.byId("editTagsDlg"))
1131 dijit
.byId("editTagsDlg").destroyRecursive();
1133 dialog
= new dijit
.Dialog({
1135 title
: __("Edit article Tags"),
1136 style
: "width: 600px",
1137 execute: function() {
1138 if (this.validate()) {
1139 var query
= dojo
.objectToQuery(this.attr('value'));
1141 notify_progress("Saving article tags...", true);
1143 new Ajax
.Request("backend.php", {
1145 onComplete: function(transport
) {
1150 var data
= JSON
.parse(transport
.responseText
);
1157 var tags
= $("ATSTR-" + id
);
1158 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1160 if (tags
) tags
.innerHTML
= data
.content
;
1161 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1164 exception_error("editArticleTags/inner", e
);
1173 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1174 dojo
.disconnect(tmph
);
1176 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1177 "backend.php?op=article&method=completeTags",
1178 { tokens
: ',', paramName
: "search" });
1185 function cdmScrollToArticleId(id
, force
) {
1187 var ctr
= $("headlines-frame");
1188 var e
= $("RROW-" + id
);
1190 if (!e
|| !ctr
) return;
1192 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1193 e
.offsetTop
< ctr
.scrollTop
) {
1195 // expanded cdm has a 4px margin now
1196 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1200 exception_error("cdmScrollToArticleId", e
);
1204 function setActiveArticleId(id
) {
1205 console
.log("setActiveArticleId:" + id
);
1207 _active_article_id
= id
;
1208 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1211 function getActiveArticleId() {
1212 return _active_article_id
;
1215 function postMouseIn(e
, id
) {
1216 post_under_pointer
= id
;
1219 function postMouseOut(id
) {
1220 post_under_pointer
= false;
1223 function unpackVisibleHeadlines() {
1225 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1227 $$("#headlines-frame > div[id*=RROW]").each(
1229 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1230 $("headlines-frame").offsetHeight
) {
1232 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1235 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1236 cencw
.setAttribute('id', '');
1238 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1240 Element
.show(cencw
);
1247 exception_error("unpackVisibleHeadlines", e
);
1251 function headlines_scroll_handler(e
) {
1254 // rate-limit in case of smooth scrolling and similar abominations
1255 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1259 _headlines_scroll_offset
= e
.scrollTop
;
1261 var hsp
= $("headlines-spacer");
1263 unpackVisibleHeadlines();
1265 // set topmost child in the buffer as active
1266 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1267 getSelectedArticleIds2().length
<= 1 &&
1268 getInitParam("cdm_expanded")) {
1270 var rows
= $$("#headlines-frame > div[id*=RROW]");
1272 for (var i
= 0; i
< rows
.length
; i
++) {
1273 var child
= rows
[i
];
1275 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1276 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1277 child
.id
.replace("RROW-", "") != _active_article_id
) {
1279 if (_active_article_id
) {
1280 var row
= $("RROW-" + _active_article_id
);
1281 if (row
) row
.removeClassName("active");
1284 _active_article_id
= child
.id
.replace("RROW-", "");
1285 showArticleInHeadlines(_active_article_id
, true);
1286 updateSelectedPrompt();
1292 if (!_infscroll_disable
) {
1293 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1295 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1296 __("Loading, please wait...") + "</span>";
1298 loadMoreHeadlines();
1305 updateFloatingTitle();
1308 catchupCurrentBatchIfNeeded();
1310 if (getInitParam("cdm_auto_catchup") == 1) {
1312 // let's get DOM some time to settle down
1313 var ts
= new Date().getTime();
1314 if (ts
- _last_headlines_update
< 100) return;
1316 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1318 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1319 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1321 var id
= child
.id
.replace("RROW-", "");
1323 if (catchup_id_batch
.indexOf(id
) == -1)
1324 catchup_id_batch
.push(id
);
1326 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1331 if (_infscroll_disable
) {
1332 var child
= $$("#headlines-frame div[id*=RROW]").last();
1334 if (child
&& $("headlines-frame").scrollTop
>
1335 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1337 console
.log("we seem to be at an end");
1339 if (getInitParam("on_catchup_show_next_feed") == "1") {
1340 openNextUnreadFeed();
1347 console
.warn("headlines_scroll_handler: " + e
);
1351 function openNextUnreadFeed() {
1353 var is_cat
= activeFeedIsCat();
1354 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1355 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1357 exception_error("openNextUnreadFeed", e
);
1361 function catchupBatchedArticles() {
1363 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1365 console
.log("catchupBatchedArticles: working");
1367 // make a copy of the array
1368 var batch
= catchup_id_batch
.slice();
1369 var query
= "?op=rpc&method=catchupSelected" +
1370 "&cmode=0&ids=" + param_escape(batch
.toString());
1374 _catchup_request_sent
= true;
1376 new Ajax
.Request("backend.php", {
1378 onComplete: function(transport
) {
1379 handle_rpc_json(transport
);
1381 _catchup_request_sent
= false;
1383 reply
= JSON
.parse(transport
.responseText
);
1384 var batch
= reply
.ids
;
1386 batch
.each(function(id
) {
1388 var elem
= $("RROW-" + id
);
1389 if (elem
) elem
.removeClassName("Unread");
1390 catchup_id_batch
.remove(id
);
1393 updateFloatingTitle(true);
1399 exception_error("catchupBatchedArticles", e
);
1403 function catchupRelativeToArticle(below
, id
) {
1407 if (!id
) id
= getActiveArticleId();
1410 alert(__("No article is selected."));
1414 var visible_ids
= getLoadedArticleIds();
1416 var ids_to_mark
= new Array();
1419 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1420 if (visible_ids
[i
] != id
) {
1421 var e
= $("RROW-" + visible_ids
[i
]);
1423 if (e
&& e
.hasClassName("Unread")) {
1424 ids_to_mark
.push(visible_ids
[i
]);
1431 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1432 if (visible_ids
[i
] != id
) {
1433 var e
= $("RROW-" + visible_ids
[i
]);
1435 if (e
&& e
.hasClassName("Unread")) {
1436 ids_to_mark
.push(visible_ids
[i
]);
1444 if (ids_to_mark
.length
== 0) {
1445 alert(__("No articles found to mark"));
1447 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1449 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1451 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1452 var e
= $("RROW-" + ids_to_mark
[i
]);
1453 e
.removeClassName("Unread");
1456 var query
= "?op=rpc&method=catchupSelected" +
1457 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1459 new Ajax
.Request("backend.php", {
1461 onComplete: function(transport
) {
1462 handle_rpc_json(transport
);
1469 exception_error("catchupRelativeToArticle", e
);
1473 function cdmCollapseArticle(event
, id
, unmark
) {
1475 if (unmark
== undefined) unmark
= true;
1477 var row
= $("RROW-" + id
);
1478 var elem
= $("CICD-" + id
);
1481 var collapse
= $$("div#RROW-" + id
+
1482 " span[class='collapseBtn']")[0];
1485 Element
.show("CEXC-" + id
);
1486 Element
.hide(collapse
);
1489 row
.removeClassName("active");
1491 markHeadline(id
, false);
1493 if (id
== getActiveArticleId()) {
1494 setActiveArticleId(0);
1497 updateSelectedPrompt();
1500 if (event
) Event
.stop(event
);
1502 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1504 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1505 scrollToRowId(row
.id
);
1507 $("floatingTitle").style
.visibility
= "hidden";
1508 $("floatingTitle").setAttribute("rowid", false);
1512 exception_error("cdmCollapseArticle", e
);
1516 function cdmExpandArticle(id
, noexpand
) {
1518 console
.log("cdmExpandArticle " + id
);
1520 if (!$("RROW-" + id
)) return false;
1522 var oldrow
= $("RROW-" + getActiveArticleId());
1524 var elem
= $("CICD-" + getActiveArticleId());
1526 if (id
== getActiveArticleId() && Element
.visible(elem
))
1529 selectArticles("none");
1531 var old_offset
= $("RROW-" + id
).offsetTop
;
1533 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1534 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1535 " span[class='collapseBtn']")[0];
1538 Element
.show("CEXC-" + getActiveArticleId());
1539 Element
.hide(collapse
);
1542 if (oldrow
) oldrow
.removeClassName("active");
1544 setActiveArticleId(id
);
1546 elem
= $("CICD-" + id
);
1548 var collapse
= $$("div#RROW-" + id
+
1549 " span[class='collapseBtn']")[0];
1551 var cencw
= $("CENCW-" + id
);
1553 if (!Element
.visible(elem
) && !noexpand
) {
1555 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1556 cencw
.setAttribute('id', '');
1557 Element
.show(cencw
);
1561 Element
.hide("CEXC-" + id
);
1562 Element
.show(collapse
);
1565 var new_offset
= $("RROW-" + id
).offsetTop
;
1567 if (old_offset
> new_offset
)
1568 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1571 if (catchup_id_batch
.indexOf(id
) == -1)
1572 catchup_id_batch
.push(id
);
1574 catchupCurrentBatchIfNeeded();
1578 $("RROW-" + id
).addClassName("active");
1580 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1583 exception_error("cdmExpandArticle", e
);
1589 function getArticleUnderPointer() {
1590 return post_under_pointer
;
1593 function scrollArticle(offset
) {
1596 var ci
= $("content-insert");
1598 ci
.scrollTop
+= offset
;
1601 var hi
= $("headlines-frame");
1603 hi
.scrollTop
+= offset
;
1608 exception_error("scrollArticle", e
);
1612 function show_labels_in_headlines(transport
) {
1614 var data
= JSON
.parse(transport
.responseText
);
1617 data
['info-for-headlines'].each(function(elem
) {
1618 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1619 ctr
.innerHTML
= elem
.labels
;
1624 exception_error("show_labels_in_headlines", e
);
1628 function cdmClicked(event
, id
) {
1630 //var shift_key = event.shiftKey;
1632 if (!event
.ctrlKey
&& !event
.metaKey
) {
1634 if (!getInitParam("cdm_expanded")) {
1635 return cdmExpandArticle(id
);
1638 var elem
= $("RROW-" + getActiveArticleId());
1640 if (elem
) elem
.removeClassName("active");
1642 selectArticles("none");
1645 var elem
= $("RROW-" + id
);
1646 var article_is_unread
= elem
.hasClassName("Unread");
1648 elem
.removeClassName("Unread");
1649 elem
.addClassName("active");
1651 setActiveArticleId(id
);
1653 if (article_is_unread
) {
1654 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1655 updateFloatingTitle(true);
1658 var query
= "?op=rpc&method=catchupSelected" +
1659 "&cmode=0&ids=" + param_escape(id
);
1661 new Ajax
.Request("backend.php", {
1663 onComplete: function(transport
) {
1664 handle_rpc_json(transport
);
1667 return !event
.shiftKey
;
1670 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1672 toggleSelected(id
, true);
1674 var elem
= $("RROW-" + id
);
1675 var article_is_unread
= elem
.hasClassName("Unread");
1677 if (article_is_unread
) {
1678 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1681 toggleUnread(id
, 0, false);
1683 openArticleInNewWindow(id
);
1686 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1687 request_counters(unread_in_buffer
== 0);
1690 exception_error("cdmClicked");
1696 function hlClicked(event
, id
) {
1698 if (event
.which
== 2) {
1701 } else if (event
.ctrlKey
|| event
.metaKey
) {
1702 toggleSelected(id
, true);
1703 toggleUnread(id
, 0, false);
1704 openArticleInNewWindow(id
);
1712 exception_error("hlClicked");
1716 function openArticleInNewWindow(id
) {
1717 toggleUnread(id
, 0, false);
1718 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1721 function isCdmMode() {
1722 return getInitParam("combined_display_mode");
1725 function markHeadline(id
, marked
) {
1726 if (marked
== undefined) marked
= true;
1728 var row
= $("RROW-" + id
);
1730 var check
= dijit
.getEnclosingWidget(
1731 row
.getElementsByClassName("rchk")[0]);
1734 check
.attr("checked", marked
);
1738 row
.addClassName("Selected");
1740 row
.removeClassName("Selected");
1744 function getRelativePostIds(id
, limit
) {
1750 if (!limit
) limit
= 6; //3
1752 var ids
= getLoadedArticleIds();
1754 for (var i
= 0; i
< ids
.length
; i
++) {
1756 for (var k
= 1; k
<= limit
; k
++) {
1757 //if (i > k-1) tmp.push(ids[i-k]);
1758 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1765 exception_error("getRelativePostIds", e
);
1771 function correctHeadlinesOffset(id
) {
1775 var container
= $("headlines-frame");
1776 var row
= $("RROW-" + id
);
1778 if (!container
|| !row
) return;
1780 var viewport
= container
.offsetHeight
;
1782 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1783 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1785 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1786 //console.log("Vport: " + viewport);
1788 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1789 container
.scrollTop
= row
.offsetTop
;
1790 } else if (rel_offset_bottom
> viewport
) {
1792 /* doesn't properly work with Opera in some cases because
1793 Opera fucks up element scrolling */
1795 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1799 exception_error("correctHeadlinesOffset", e
);
1804 function headlineActionsChange(elem
) {
1807 elem
.attr('value', 'false');
1809 exception_error("headlineActionsChange", e
);
1813 function closeArticlePanel() {
1815 if (dijit
.byId("content-insert"))
1816 dijit
.byId("headlines-wrap-inner").removeChild(
1817 dijit
.byId("content-insert"));
1820 function initFloatingMenu() {
1822 if (!dijit
.byId("floatingMenu")) {
1824 var menu
= new dijit
.Menu({
1826 targetNodeIds
: ["floatingTitle"]
1829 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1830 var callerNode
= event
.target
, match
= null, tries
= 0;
1832 while (match
== null && callerNode
&& tries
<= 3) {
1833 match
= callerNode
.getAttribute("rowid").match("^[A-Z]+[-]([0-9]+)$");
1834 callerNode
= callerNode
.parentNode
;
1838 if (match
) this.callerRowId
= parseInt(match
[1]);
1842 headlinesMenuCommon(menu
);
1848 exception_error("initFloatingMenu", e
);
1852 function headlinesMenuCommon(menu
) {
1855 menu
.addChild(new dijit
.MenuItem({
1856 label
: __("Open original article"),
1857 onClick: function(event
) {
1858 openArticleInNewWindow(this.getParent().callerRowId
);
1861 menu
.addChild(new dijit
.MenuItem({
1862 label
: __("Display article URL"),
1863 onClick: function(event
) {
1864 displayArticleUrl(this.getParent().callerRowId
);
1867 menu
.addChild(new dijit
.MenuSeparator());
1869 menu
.addChild(new dijit
.MenuItem({
1870 label
: __("Toggle unread"),
1871 onClick: function(event
) {
1872 var ids
= getSelectedArticleIds2();
1874 var id
= (this.getParent().callerRowId
) + "";
1875 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1877 selectionToggleUnread(undefined, false, true, ids
);
1880 menu
.addChild(new dijit
.MenuItem({
1881 label
: __("Toggle starred"),
1882 onClick: function(event
) {
1883 var ids
= getSelectedArticleIds2();
1885 var id
= (this.getParent().callerRowId
) + "";
1886 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1888 selectionToggleMarked(undefined, false, true, ids
);
1891 menu
.addChild(new dijit
.MenuItem({
1892 label
: __("Toggle published"),
1893 onClick: function(event
) {
1894 var ids
= getSelectedArticleIds2();
1896 var id
= (this.getParent().callerRowId
) + "";
1897 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1899 selectionTogglePublished(undefined, false, true, ids
);
1902 menu
.addChild(new dijit
.MenuSeparator());
1904 menu
.addChild(new dijit
.MenuItem({
1905 label
: __("Mark above as read"),
1906 onClick: function(event
) {
1907 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1910 menu
.addChild(new dijit
.MenuItem({
1911 label
: __("Mark below as read"),
1912 onClick: function(event
) {
1913 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1917 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1921 menu
.addChild(new dijit
.MenuSeparator());
1923 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1924 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1926 labels
.each(function(label
) {
1927 var id
= label
.id
[0];
1928 var bare_id
= id
.substr(id
.indexOf(":")+1);
1929 var name
= label
.name
[0];
1931 bare_id
= feed_to_label_id(bare_id
);
1933 labelAddMenu
.addChild(new dijit
.MenuItem({
1936 onClick: function(event
) {
1937 var ids
= getSelectedArticleIds2();
1939 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1941 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1943 selectionAssignLabel(this.labelId
, ids
);
1946 labelDelMenu
.addChild(new dijit
.MenuItem({
1949 onClick: function(event
) {
1950 var ids
= getSelectedArticleIds2();
1952 var id
= (this.getParent().ownerMenu
.callerRowId
) + "";
1954 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1956 selectionRemoveLabel(this.labelId
, ids
);
1961 menu
.addChild(new dijit
.PopupMenuItem({
1962 label
: __("Assign label"),
1966 menu
.addChild(new dijit
.PopupMenuItem({
1967 label
: __("Remove label"),
1975 exception_error("headlinesMenuCommon", e
);
1979 function initHeadlinesMenu() {
1981 if (dijit
.byId("headlinesMenu"))
1982 dijit
.byId("headlinesMenu").destroyRecursive();
1987 nodes
= $$("#headlines-frame > div[id*=RROW]");
1989 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1992 nodes
.each(function(node
) {
1996 var menu
= new dijit
.Menu({
1997 id
: "headlinesMenu",
2001 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2002 var callerNode
= event
.target
, match
= null, tries
= 0;
2004 while (match
== null && callerNode
&& tries
<= 3) {
2005 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2006 callerNode
= callerNode
.parentNode
;
2010 if (match
) this.callerRowId
= parseInt(match
[1]);
2014 headlinesMenuCommon(menu
);
2018 /* vgroup feed title menu */
2020 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2023 nodes
.each(function(node
) {
2027 if (ids
.length
> 0) {
2028 if (dijit
.byId("headlinesFeedTitleMenu"))
2029 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2031 var menu
= new dijit
.Menu({
2032 id
: "headlinesFeedTitleMenu",
2036 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2037 var callerNode
= event
.target
, match
= null, tries
= 0;
2039 while (match
== null && callerNode
&& tries
<= 3) {
2040 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2041 callerNode
= callerNode
.parentNode
;
2045 if (match
) this.callerRowId
= parseInt(match
[1]);
2049 menu
.addChild(new dijit
.MenuItem({
2050 label
: __("Select articles in group"),
2051 onClick: function(event
) {
2052 selectArticles("all",
2053 "#headlines-frame > div[id*=RROW]"+
2054 "[orig-feed-id='"+menu
.callerRowId
+"']");
2058 menu
.addChild(new dijit
.MenuItem({
2059 label
: __("Mark group as read"),
2060 onClick: function(event
) {
2061 selectArticles("none");
2062 selectArticles("all",
2063 "#headlines-frame > div[id*=RROW]"+
2064 "[orig-feed-id='"+menu
.callerRowId
+"']");
2070 menu
.addChild(new dijit
.MenuItem({
2071 label
: __("Mark feed as read"),
2072 onClick: function(event
) {
2073 catchupFeedInGroup(menu
.callerRowId
);
2076 menu
.addChild(new dijit
.MenuItem({
2077 label
: __("Edit feed"),
2078 onClick: function(event
) {
2079 editFeed(menu
.callerRowId
);
2087 exception_error("initHeadlinesMenu", e
);
2091 function cache_set(id
, obj
) {
2092 //console.log("cache_set: " + id);
2095 sessionStorage
[id
] = obj
;
2097 sessionStorage
.clear();
2101 function cache_get(id
) {
2103 return sessionStorage
[id
];
2106 function cache_clear() {
2108 sessionStorage
.clear();
2111 function cache_delete(id
) {
2113 sessionStorage
.removeItem(id
);
2116 function cancelSearch() {
2121 exception_error("cancelSearch", e
);
2125 function setSelectionScore() {
2127 var ids
= getSelectedArticleIds2();
2129 if (ids
.length
> 0) {
2132 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2134 if (score
!= undefined) {
2135 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2136 "&score=" + param_escape(score
);
2138 new Ajax
.Request("backend.php", {
2140 onComplete: function(transport
) {
2141 var reply
= JSON
.parse(transport
.responseText
);
2145 ids
.each(function(id
) {
2146 var row
= $("RROW-" + id
);
2149 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2152 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2153 reply
["score_pic"]);
2154 pic
.setAttribute("score", score
);
2163 alert(__("No articles are selected."));
2166 exception_error("setSelectionScore", e
);
2170 function updateScore(id
) {
2172 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2176 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2178 new Ajax
.Request("backend.php", {
2180 onComplete: function(transport
) {
2181 console
.log(transport
.responseText
);
2183 var reply
= JSON
.parse(transport
.responseText
);
2186 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2187 pic
.setAttribute("score", reply
["score"]);
2188 pic
.setAttribute("title", reply
["score"]);
2194 exception_error("updateScore", e
);
2198 function changeScore(id
, pic
) {
2200 var score
= pic
.getAttribute("score");
2202 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2204 if (new_score
!= undefined) {
2206 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2207 "&score=" + param_escape(new_score
);
2209 new Ajax
.Request("backend.php", {
2211 onComplete: function(transport
) {
2212 var reply
= JSON
.parse(transport
.responseText
);
2215 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2216 pic
.setAttribute("score", new_score
);
2217 pic
.setAttribute("title", new_score
);
2222 exception_error("changeScore", e
);
2226 function displayArticleUrl(id
) {
2228 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2230 new Ajax
.Request("backend.php", {
2232 onComplete: function(transport
) {
2233 var reply
= JSON
.parse(transport
.responseText
);
2235 if (reply
&& reply
.link
) {
2236 prompt(__("Article URL:"), reply
.link
);
2240 exception_error("changeScore", e
);
2244 function scrollToRowId(id
) {
2249 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2252 exception_error("scrollToRowId", e
);
2256 function updateFloatingTitle(unread_only
) {
2258 if (!isCdmMode()) return;
2260 var hf
= $("headlines-frame");
2262 var elems
= $$("#headlines-frame > div[id*=RROW]");
2264 for (var i
= 0; i
< elems
.length
; i
++) {
2266 var child
= elems
[i
];
2268 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2270 var header
= child
.getElementsByClassName("cdmHeader")[0];
2272 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2273 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2274 $("floatingTitle").setAttribute("rowid", child
.id
);
2275 $("floatingTitle").innerHTML
= header
.innerHTML
;
2276 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2280 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2283 cb
.parentNode
.removeChild(cb
);
2286 if (child
.hasClassName("Unread"))
2287 $("floatingTitle").addClassName("Unread");
2289 $("floatingTitle").removeClassName("Unread");
2291 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2294 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2295 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2296 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2297 $("floatingTitle").style
.visibility
= "visible";
2299 $("floatingTitle").style
.visibility
= "hidden";
2307 exception_error("updateFloatingTitle", e
);
2311 function catchupCurrentBatchIfNeeded() {
2312 if (catchup_id_batch
.length
> 0) {
2313 window
.clearTimeout(catchup_timeout_id
);
2314 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2316 if (catchup_id_batch
.length
>= 10) {
2317 catchupBatchedArticles();
2322 function cdmFooterClick(event
) {
2323 event
.stopPropagation();