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 current_top_article_id
= false;
18 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
20 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
22 handle_rpc_json(transport
);
24 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
32 reply
= JSON
.parse(transport
.responseText
);
39 is_cat
= reply
['headlines']['is_cat'];
40 feed_id
= reply
['headlines']['id'];
43 var content
= reply
['headlines']['content'];
45 content
= content
+ "<div id='headlines-spacer'></div>";
49 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
52 /* dijit.getEnclosingWidget(
53 document.forms["main_toolbar_form"].update).attr('disabled',
54 is_cat || feed_id <= 0); */
57 if (infscroll_req
== false) {
58 $("headlines-frame").scrollTop
= 0;
60 $("floatingTitle").style
.visibility
= "hidden";
61 $("floatingTitle").setAttribute("rowid", 0);
62 $("floatingTitle").innerHTML
= "";
66 $("headlines-frame").removeClassName("cdm");
67 $("headlines-frame").removeClassName("normal");
69 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
71 var headlines_count
= reply
['headlines-info']['count'];
73 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
75 if (parseInt(headlines_count
) < 30) {
76 _infscroll_disable
= 1;
78 _infscroll_disable
= 0;
81 var counters
= reply
['counters'];
82 var articles
= reply
['articles'];
83 //var runtime_info = reply['runtime-info'];
85 if (infscroll_req
== false) {
86 loaded_article_ids
= [];
87 current_top_article_id
= false;
89 dijit
.byId("headlines-frame").attr('content',
90 reply
['headlines']['content']);
92 //dijit.byId("headlines-toolbar").attr('content',
93 // reply['headlines']['toolbar']);
95 dojo
.html
.set($("headlines-toolbar"),
96 reply
['headlines']['toolbar'],
97 {parseContent
: true});
99 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
100 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
101 row
.parentNode
.removeChild(row
);
103 loaded_article_ids
.push(row
.id
);
107 if (loaded_article_ids
.size() > 0) {
108 current_top_article_id
= parseInt(loaded_article_ids
[0].replace("RROW-", ""));
111 var hsp
= $("headlines-spacer");
112 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
113 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
117 if (_infscroll_disable
)
118 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
119 __("Click to open next unread feed.") + "</a>";
122 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
123 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
129 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
130 console
.log("adding some more headlines: " + headlines_count
);
132 var c
= dijit
.byId("headlines-frame");
133 var ids
= getSelectedArticleIds2();
136 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
138 var hsp
= $("headlines-spacer");
141 c
.domNode
.removeChild(hsp
);
143 $$("#headlines-tmp > div").each(function(row
) {
144 if (row
.className
== 'cdmFeedTitle') {
145 row
.style
.display
= 'none';
146 c
.domNode
.appendChild(row
);
148 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
149 row
.style
.display
= 'none';
150 c
.domNode
.appendChild(row
);
152 loaded_article_ids
.push(row
.id
);
154 row
.parentNode
.removeChild(row
);
158 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
160 // if (getInitParam("cdm_auto_catchup") == 1) {
161 c
.domNode
.appendChild(hsp
);
164 console
.log("added " + new_elems
.size() + " headlines");
166 if (new_elems
.size() == 0)
167 _infscroll_disable
= true;
169 console
.log("restore selected ids: " + ids
);
171 for (var i
= 0; i
< ids
.length
; i
++) {
172 markHeadline(ids
[i
]);
177 new_elems
.each(function(child
) {
178 dojo
.parser
.parse(child
);
180 if (!Element
.visible(child
))
181 new Effect
.Appear(child
, { duration
: 0.5 });
185 console
.log("no new headlines received");
187 var hsp
= $("headlines-spacer");
189 if (hsp
) hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
190 __("Click to open next unread feed.") + "</a>";
195 for (var i
= 0; i
< articles
.length
; i
++) {
196 var a_id
= articles
[i
]['id'];
197 cache_set("article:" + a_id
, articles
[i
]['content']);
200 console
.log("no cached articles received");
204 parse_counters(counters
);
206 request_counters(true);
209 console
.error("Invalid object received: " + transport
.responseText
);
210 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
211 __('Could not update headlines (invalid object received - see error console for details)') +
215 _infscroll_request_sent
= 0;
216 _last_headlines_update
= new Date().getTime();
218 unpackVisibleHeadlines();
220 // if we have some more space in the buffer, why not try to fill it
222 if (!_infscroll_disable
&& $("headlines-spacer") &&
223 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
225 window
.setTimeout(function() {
233 exception_error("headlines_callback2", e
, transport
);
237 function render_article(article
) {
239 dijit
.byId("headlines-wrap-inner").addChild(
240 dijit
.byId("content-insert"));
242 var c
= dijit
.byId("content-insert");
245 c
.domNode
.scrollTop
= 0;
248 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
250 c
.attr('content', article
);
252 correctHeadlinesOffset(getActiveArticleId());
259 exception_error("render_article", e
);
263 function showArticleInHeadlines(id
, noexpand
) {
266 selectArticles("none");
268 var crow
= $("RROW-" + id
);
272 var article_is_unread
= crow
.hasClassName("Unread");
275 crow
.removeClassName("Unread");
276 crow
.addClassName("active");
278 selectArticles('none');
280 var view_mode
= false;
283 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
284 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
291 if (article_is_unread
&& !noexpand
)
292 _force_scheduled_update
= true;
295 exception_error("showArticleInHeadlines", e
);
299 function article_callback2(transport
, id
) {
301 console
.log("article_callback2 " + id
);
303 handle_rpc_json(transport
);
308 reply
= JSON
.parse(transport
.responseText
);
315 reply
.each(function(article
) {
316 if (getActiveArticleId() == article
['id']) {
317 render_article(article
['content']);
319 cids_requested
.remove(article
['id']);
321 cache_set("article:" + article
['id'], article
['content']);
324 // if (id != last_requested_article) {
325 // console.log("requested article id is out of sequence, aborting");
330 console
.error("Invalid object received: " + transport
.responseText
);
332 render_article("<div class='whiteBox'>" +
333 __('Could not display article (invalid object received - see error console for details)') + "</div>");
336 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
337 request_counters(unread_in_buffer
== 0);
339 //headlines_scroll_handler($("headlines-frame"));
342 if (!_infscroll_disable &&
343 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
353 exception_error("article_callback2", e
, transport
);
357 function view(id
, activefeed
, noexpand
) {
359 var oldrow
= $("RROW-" + getActiveArticleId());
360 if (oldrow
) oldrow
.removeClassName("active");
362 var crow
= $("RROW-" + id
);
366 setActiveArticleId(id
);
367 showArticleInHeadlines(id
, noexpand
);
371 console
.log("loading article: " + id
);
373 var cached_article
= cache_get("article:" + id
);
375 console
.log("cache check result: " + (cached_article
!= false));
377 var query
= "?op=article&method=view&id=" + param_escape(id
);
379 var neighbor_ids
= getRelativePostIds(id
);
381 /* only request uncached articles */
383 var cids_to_request
= [];
385 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
386 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
387 if (!cache_get("article:" + neighbor_ids
[i
])) {
388 cids_to_request
.push(neighbor_ids
[i
]);
389 cids_requested
.push(neighbor_ids
[i
]);
393 console
.log("additional ids: " + cids_to_request
.toString());
395 query
= query
+ "&cids=" + cids_to_request
.toString();
397 var article_is_unread
= crow
.hasClassName("Unread");
399 setActiveArticleId(id
);
400 showArticleInHeadlines(id
);
402 if (cached_article
&& article_is_unread
) {
404 query
= query
+ "&mode=prefetch";
406 render_article(cached_article
);
408 } else if (cached_article
) {
410 query
= query
+ "&mode=prefetch_old";
411 render_article(cached_article
);
413 // if we don't need to request any relative ids, we might as well skip
414 // the server roundtrip altogether
415 if (cids_to_request
.length
== 0) {
418 if (!_infscroll_disable &&
419 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
427 //headlines_scroll_handler($("headlines-frame"));
433 last_requested_article
= id
;
437 if (article_is_unread
) {
438 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
441 new Ajax
.Request("backend.php", {
443 onComplete: function(transport
) {
444 article_callback2(transport
, id
);
450 exception_error("view", e
);
454 function toggleMark(id
, client_only
) {
456 var query
= "?op=rpc&id=" + id
+ "&method=mark";
458 var row
= $("RROW-" + id
);
463 var row_imgs
= row
.getElementsByClassName("markedPic");
465 for (var i
= 0; i
< row_imgs
.length
; i
++)
466 imgs
.push(row_imgs
[i
]);
468 var ft
= $("floatingTitle");
470 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
471 var fte
= ft
.getElementsByClassName("markedPic");
473 for (var i
= 0; i
< fte
.length
; i
++)
477 for (i
= 0; i
< imgs
.length
; i
++) {
480 if (!row
.hasClassName("marked")) {
481 img
.src
= img
.src
.replace("mark_unset", "mark_set");
482 img
.alt
= __("Unstar article");
483 query
= query
+ "&mark=1";
485 img
.src
= img
.src
.replace("mark_set", "mark_unset");
486 img
.alt
= __("Star article");
487 query
= query
+ "&mark=0";
491 row
.toggleClassName("marked");
494 new Ajax
.Request("backend.php", {
496 onComplete: function(transport
) {
497 handle_rpc_json(transport
);
502 exception_error("toggleMark", e
);
506 function togglePub(id
, client_only
, no_effects
, note
) {
508 var query
= "?op=rpc&id=" + id
+ "&method=publ";
510 if (note
!= undefined) {
511 query
= query
+ "¬e=" + param_escape(note
);
513 query
= query
+ "¬e=undefined";
516 var row
= $("RROW-" + id
);
521 var row_imgs
= row
.getElementsByClassName("pubPic");
523 for (var i
= 0; i
< row_imgs
.length
; i
++)
524 imgs
.push(row_imgs
[i
]);
526 var ft
= $("floatingTitle");
528 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
529 var fte
= ft
.getElementsByClassName("pubPic");
531 for (var i
= 0; i
< fte
.length
; i
++)
535 for (i
= 0; i
< imgs
.length
; i
++) {
538 if (!row
.hasClassName("published") || note
!= undefined) {
539 img
.src
= img
.src
.replace("pub_unset", "pub_set");
540 img
.alt
= __("Unpublish article");
541 query
= query
+ "&pub=1";
543 img
.src
= img
.src
.replace("pub_set", "pub_unset");
544 img
.alt
= __("Publish article");
545 query
= query
+ "&pub=0";
549 if (note
!= undefined)
550 row
.addClassName("published");
552 row
.toggleClassName("published");
555 new Ajax
.Request("backend.php", {
557 onComplete: function(transport
) {
558 handle_rpc_json(transport
);
563 exception_error("togglePub", e
);
567 function moveToPost(mode
, noscroll
, noexpand
) {
571 var rows
= getVisibleArticleIds();
576 if (!$('RROW-' + getActiveArticleId())) {
577 setActiveArticleId(0);
580 if (!getActiveArticleId()) {
582 prev_id
= rows
[rows
.length
-1]
584 for (var i
= 0; i
< rows
.length
; i
++) {
585 if (rows
[i
] == getActiveArticleId()) {
587 // Account for adjacent identical article ids.
588 if (i
> 0) prev_id
= rows
[i
-1];
590 for (var j
= i
+1; j
< rows
.length
; j
++) {
591 if (rows
[j
] != getActiveArticleId()) {
601 if (mode
== "next") {
602 if (next_id
|| getActiveArticleId()) {
605 var article
= $("RROW-" + getActiveArticleId());
606 var ctr
= $("headlines-frame");
608 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
609 ctr
.scrollTop
+ ctr
.offsetHeight
) {
611 scrollArticle(ctr
.offsetHeight
/4);
613 } else if (next_id
) {
614 cdmExpandArticle(next_id
, noexpand
);
615 cdmScrollToArticleId(next_id
, true);
618 } else if (next_id
) {
619 correctHeadlinesOffset(next_id
);
620 view(next_id
, getActiveFeedId(), noexpand
);
625 if (mode
== "prev") {
626 if (prev_id
|| getActiveArticleId()) {
629 var article
= $("RROW-" + getActiveArticleId());
630 var prev_article
= $("RROW-" + prev_id
);
631 var ctr
= $("headlines-frame");
633 if (!getInitParam("cdm_expanded")) {
635 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
636 scrollArticle(-ctr
.offsetHeight
/4);
638 cdmExpandArticle(prev_id
, noexpand
);
639 cdmScrollToArticleId(prev_id
, true);
643 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
644 scrollArticle(-ctr
.offsetHeight
/3);
645 } else if (!noscroll
&& prev_article
&&
646 prev_article
.offsetTop
< ctr
.scrollTop
) {
647 cdmExpandArticle(prev_id
, noexpand
);
648 scrollArticle(-ctr
.offsetHeight
/4);
649 } else if (prev_id
) {
650 cdmExpandArticle(prev_id
, noexpand
);
651 cdmScrollToArticleId(prev_id
, noscroll
);
655 } else if (prev_id
) {
656 correctHeadlinesOffset(prev_id
);
657 view(prev_id
, getActiveFeedId(), noexpand
);
663 exception_error("moveToPost", e
);
667 function toggleSelected(id
, force_on
) {
669 var row
= $("RROW-" + id
);
672 var cb
= dijit
.getEnclosingWidget(
673 row
.getElementsByClassName("rchk")[0]);
675 if (row
.hasClassName('Selected') && !force_on
) {
676 row
.removeClassName('Selected');
677 if (cb
) cb
.attr("checked", false);
679 row
.addClassName('Selected');
680 if (cb
) cb
.attr("checked", true);
684 updateSelectedPrompt();
686 exception_error("toggleSelected", e
);
690 function updateSelectedPrompt() {
692 var count
= getSelectedArticleIds2().size();
693 var elem
= $("selected_prompt");
696 elem
.innerHTML
= ngettext("%d article selected",
697 "%d articles selected", count
).replace("%d", count
);
706 exception_error("updateSelectedPrompt", e
);
710 function toggleUnread_afh(effect
) {
713 var elem
= effect
.element
;
714 elem
.style
.backgroundColor
= "";
717 exception_error("toggleUnread_afh", e
);
721 function toggleUnread(id
, cmode
, effect
) {
724 var row
= $("RROW-" + id
);
726 if (cmode
== undefined || cmode
== 2) {
727 if (row
.hasClassName("Unread")) {
728 row
.removeClassName("Unread");
731 row
.addClassName("Unread");
734 } else if (cmode
== 0) {
736 row
.removeClassName("Unread");
738 } else if (cmode
== 1) {
739 row
.addClassName("Unread");
742 if (cmode
== undefined) cmode
= 2;
744 var query
= "?op=rpc&method=catchupSelected" +
745 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
747 // notify_progress("Loading, please wait...");
749 new Ajax
.Request("backend.php", {
751 onComplete: function(transport
) {
752 handle_rpc_json(transport
);
758 exception_error("toggleUnread", e
);
762 function selectionRemoveLabel(id
, ids
) {
765 if (!ids
) ids
= getSelectedArticleIds2();
767 if (ids
.length
== 0) {
768 alert(__("No articles are selected."));
772 var query
= "?op=article&method=removeFromLabel&ids=" +
773 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
777 new Ajax
.Request("backend.php", {
779 onComplete: function(transport
) {
780 handle_rpc_json(transport
);
781 show_labels_in_headlines(transport
);
785 exception_error("selectionAssignLabel", e
);
790 function selectionAssignLabel(id
, ids
) {
793 if (!ids
) ids
= getSelectedArticleIds2();
795 if (ids
.length
== 0) {
796 alert(__("No articles are selected."));
800 var query
= "?op=article&method=assignToLabel&ids=" +
801 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
805 new Ajax
.Request("backend.php", {
807 onComplete: function(transport
) {
808 handle_rpc_json(transport
);
809 show_labels_in_headlines(transport
);
813 exception_error("selectionAssignLabel", e
);
818 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
820 var rows
= ids
? ids
: getSelectedArticleIds2();
822 if (rows
.length
== 0 && !no_error
) {
823 alert(__("No articles are selected."));
827 for (var i
= 0; i
< rows
.length
; i
++) {
828 var row
= $("RROW-" + rows
[i
]);
830 if (set_state
== undefined) {
831 if (row
.hasClassName("Unread")) {
832 row
.removeClassName("Unread");
834 row
.addClassName("Unread");
838 if (set_state
== false) {
839 row
.removeClassName("Unread");
842 if (set_state
== true) {
843 row
.addClassName("Unread");
848 updateFloatingTitle(true);
850 if (rows
.length
> 0) {
854 if (set_state
== undefined) {
856 } else if (set_state
== true) {
858 } else if (set_state
== false) {
862 var query
= "?op=rpc&method=catchupSelected" +
863 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
865 notify_progress("Loading, please wait...");
867 new Ajax
.Request("backend.php", {
869 onComplete: function(transport
) {
870 handle_rpc_json(transport
);
871 if (callback
) callback(transport
);
877 exception_error("selectionToggleUnread", e
);
882 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
885 var rows
= ids
? ids
: getSelectedArticleIds2();
887 if (rows
.length
== 0 && !no_error
) {
888 alert(__("No articles are selected."));
892 for (var i
= 0; i
< rows
.length
; i
++) {
893 toggleMark(rows
[i
], true, true);
896 if (rows
.length
> 0) {
898 var query
= "?op=rpc&method=markSelected&ids=" +
899 param_escape(rows
.toString()) + "&cmode=2";
901 new Ajax
.Request("backend.php", {
903 onComplete: function(transport
) {
904 handle_rpc_json(transport
);
905 if (callback
) callback(transport
);
911 exception_error("selectionToggleMarked", e
);
916 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
919 var rows
= ids
? ids
: getSelectedArticleIds2();
921 if (rows
.length
== 0 && !no_error
) {
922 alert(__("No articles are selected."));
926 for (var i
= 0; i
< rows
.length
; i
++) {
927 togglePub(rows
[i
], true, true);
930 if (rows
.length
> 0) {
932 var query
= "?op=rpc&method=publishSelected&ids=" +
933 param_escape(rows
.toString()) + "&cmode=2";
935 new Ajax
.Request("backend.php", {
937 onComplete: function(transport
) {
938 handle_rpc_json(transport
);
944 exception_error("selectionToggleMarked", e
);
948 function getSelectedArticleIds2() {
952 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
954 rv
.push(child
.id
.replace("RROW-", ""));
960 function getLoadedArticleIds() {
963 var children
= $$("#headlines-frame > div[id*=RROW-]");
965 children
.each(function(child
) {
966 rv
.push(child
.id
.replace("RROW-", ""));
973 // mode = all,none,unread,invert,marked,published
974 function selectArticles(mode
, query
) {
977 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
979 var children
= $$(query
);
981 children
.each(function(child
) {
982 var id
= child
.id
.replace("RROW-", "");
984 var cb
= dijit
.getEnclosingWidget(
985 child
.getElementsByClassName("rchk")[0]);
988 child
.addClassName("Selected");
989 if (cb
) cb
.attr("checked", true);
990 } else if (mode
== "unread") {
991 if (child
.hasClassName("Unread")) {
992 child
.addClassName("Selected");
993 if (cb
) cb
.attr("checked", true);
995 child
.removeClassName("Selected");
996 if (cb
) cb
.attr("checked", false);
998 } else if (mode
== "marked") {
999 if (child
.hasClassName("marked")) {
1000 child
.addClassName("Selected");
1001 if (cb
) cb
.attr("checked", true);
1003 child
.removeClassName("Selected");
1004 if (cb
) cb
.attr("checked", false);
1006 } else if (mode
== "published") {
1007 if (child
.hasClassName("published")) {
1008 child
.addClassName("Selected");
1009 if (cb
) cb
.attr("checked", true);
1011 child
.removeClassName("Selected");
1012 if (cb
) cb
.attr("checked", false);
1015 } else if (mode
== "invert") {
1016 if (child
.hasClassName("Selected")) {
1017 child
.removeClassName("Selected");
1018 if (cb
) cb
.attr("checked", false);
1020 child
.addClassName("Selected");
1021 if (cb
) cb
.attr("checked", true);
1025 child
.removeClassName("Selected");
1026 if (cb
) cb
.attr("checked", false);
1030 updateSelectedPrompt();
1033 exception_error("selectArticles", e
);
1037 function deleteSelection() {
1041 var rows
= getSelectedArticleIds2();
1043 if (rows
.length
== 0) {
1044 alert(__("No articles are selected."));
1048 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1051 if (getActiveFeedId() != 0) {
1052 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1054 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1057 str
= str
.replace("%d", rows
.length
);
1058 str
= str
.replace("%s", fn
);
1060 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1064 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1068 new Ajax
.Request("backend.php", {
1070 onComplete: function(transport
) {
1071 handle_rpc_json(transport
);
1076 exception_error("deleteSelection", e
);
1080 function archiveSelection() {
1084 var rows
= getSelectedArticleIds2();
1086 if (rows
.length
== 0) {
1087 alert(__("No articles are selected."));
1091 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1095 if (getActiveFeedId() != 0) {
1096 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1099 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1101 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1106 str
= str
.replace("%d", rows
.length
);
1107 str
= str
.replace("%s", fn
);
1109 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1113 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1117 for (var i
= 0; i
< rows
.length
; i
++) {
1118 cache_delete("article:" + rows
[i
]);
1121 new Ajax
.Request("backend.php", {
1123 onComplete: function(transport
) {
1124 handle_rpc_json(transport
);
1129 exception_error("archiveSelection", e
);
1133 function catchupSelection() {
1137 var rows
= getSelectedArticleIds2();
1139 if (rows
.length
== 0) {
1140 alert(__("No articles are selected."));
1144 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1146 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1148 str
= str
.replace("%d", rows
.length
);
1149 str
= str
.replace("%s", fn
);
1151 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1155 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1158 exception_error("catchupSelection", e
);
1162 function editArticleTags(id
) {
1163 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1165 if (dijit
.byId("editTagsDlg"))
1166 dijit
.byId("editTagsDlg").destroyRecursive();
1168 dialog
= new dijit
.Dialog({
1170 title
: __("Edit article Tags"),
1171 style
: "width: 600px",
1172 execute: function() {
1173 if (this.validate()) {
1174 var query
= dojo
.objectToQuery(this.attr('value'));
1176 notify_progress("Saving article tags...", true);
1178 new Ajax
.Request("backend.php", {
1180 onComplete: function(transport
) {
1185 var data
= JSON
.parse(transport
.responseText
);
1192 var tags
= $("ATSTR-" + id
);
1193 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1195 if (tags
) tags
.innerHTML
= data
.content
;
1196 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1199 exception_error("editArticleTags/inner", e
);
1208 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1209 dojo
.disconnect(tmph
);
1211 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1212 "backend.php?op=article&method=completeTags",
1213 { tokens
: ',', paramName
: "search" });
1220 function cdmScrollToArticleId(id
, force
) {
1222 var ctr
= $("headlines-frame");
1223 var e
= $("RROW-" + id
);
1225 if (!e
|| !ctr
) return;
1227 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1228 e
.offsetTop
< ctr
.scrollTop
) {
1230 // expanded cdm has a 4px margin now
1231 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1235 exception_error("cdmScrollToArticleId", e
);
1239 function setActiveArticleId(id
) {
1240 _active_article_id
= id
;
1241 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1244 function getActiveArticleId() {
1245 return _active_article_id
;
1248 function postMouseIn(e
, id
) {
1249 post_under_pointer
= id
;
1252 function postMouseOut(id
) {
1253 post_under_pointer
= false;
1256 function unpackVisibleHeadlines() {
1258 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1260 $$("#headlines-frame > div[id*=RROW]").each(
1262 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1263 $("headlines-frame").offsetHeight
) {
1265 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1268 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1270 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1271 cencw
.setAttribute('id', '');
1272 Element
.show(cencw
);
1279 exception_error("unpackVisibleHeadlines", e
);
1283 function headlines_scroll_handler(e
) {
1285 var hsp
= $("headlines-spacer");
1287 unpackVisibleHeadlines();
1289 // set topmost child in the buffer as active
1290 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1291 getSelectedArticleIds2().length
<= 1 &&
1292 getInitParam("cdm_expanded")) {
1293 var rows
= $$("#headlines-frame > div[id*=RROW]");
1295 for (var i
= 0; i
< rows
.length
; i
++) {
1296 var child
= rows
[i
];
1298 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1299 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1300 child
.id
.replace("RROW-", "") != _active_article_id
) {
1302 if (_active_article_id
) {
1303 var row
= $("RROW-" + _active_article_id
);
1304 if (row
) row
.removeClassName("active");
1307 _active_article_id
= child
.id
.replace("RROW-", "");
1308 showArticleInHeadlines(_active_article_id
, true);
1309 updateSelectedPrompt();
1315 if (!_infscroll_disable
) {
1316 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1317 (e
.scrollHeight
!= 0 &&
1318 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1321 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1322 __("Loading, please wait...") + "</span>";
1324 loadMoreHeadlines();
1330 if (_infscroll_disable
)
1331 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
1332 __("Click to open next unread feed.") + "</a>";
1338 updateFloatingTitle();
1341 if (getInitParam("cdm_auto_catchup") == 1) {
1343 // let's get DOM some time to settle down
1344 var ts
= new Date().getTime();
1345 if (ts
- _last_headlines_update
< 100) return;
1347 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1349 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1350 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1352 var id
= child
.id
.replace("RROW-", "");
1354 if (catchup_id_batch
.indexOf(id
) == -1)
1355 catchup_id_batch
.push(id
);
1357 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1362 if (catchup_id_batch
.length
> 0) {
1363 window
.clearTimeout(catchup_timeout_id
);
1365 if (!_infscroll_request_sent
) {
1366 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1371 if (_infscroll_disable
) {
1372 var child
= $$("#headlines-frame div[id*=RROW]").last();
1374 if (child
&& $("headlines-frame").scrollTop
>
1375 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1377 console
.log("we seem to be at an end");
1379 if (getInitParam("on_catchup_show_next_feed") == "1") {
1380 openNextUnreadFeed();
1387 console
.warn("headlines_scroll_handler: " + e
);
1391 function openNextUnreadFeed() {
1393 var is_cat
= activeFeedIsCat();
1394 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1395 if (nuf
) viewfeed(nuf
, '', is_cat
);
1397 exception_error("openNextUnreadFeed", e
);
1401 function catchupBatchedArticles() {
1403 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1405 // make a copy of the array
1406 var batch
= catchup_id_batch
.slice();
1407 var query
= "?op=rpc&method=catchupSelected" +
1408 "&cmode=0&ids=" + param_escape(batch
.toString());
1412 new Ajax
.Request("backend.php", {
1414 onComplete: function(transport
) {
1415 handle_rpc_json(transport
);
1417 reply
= JSON
.parse(transport
.responseText
);
1418 var batch
= reply
.ids
;
1420 batch
.each(function(id
) {
1422 var elem
= $("RROW-" + id
);
1423 if (elem
) elem
.removeClassName("Unread");
1424 catchup_id_batch
.remove(id
);
1427 updateFloatingTitle(true);
1433 exception_error("catchupBatchedArticles", e
);
1437 function catchupRelativeToArticle(below
, id
) {
1441 if (!id
) id
= getActiveArticleId();
1444 alert(__("No article is selected."));
1448 var visible_ids
= getVisibleArticleIds();
1450 var ids_to_mark
= new Array();
1453 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1454 if (visible_ids
[i
] != id
) {
1455 var e
= $("RROW-" + visible_ids
[i
]);
1457 if (e
&& e
.hasClassName("Unread")) {
1458 ids_to_mark
.push(visible_ids
[i
]);
1465 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1466 if (visible_ids
[i
] != id
) {
1467 var e
= $("RROW-" + visible_ids
[i
]);
1469 if (e
&& e
.hasClassName("Unread")) {
1470 ids_to_mark
.push(visible_ids
[i
]);
1478 if (ids_to_mark
.length
== 0) {
1479 alert(__("No articles found to mark"));
1481 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1483 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1485 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1486 var e
= $("RROW-" + ids_to_mark
[i
]);
1487 e
.removeClassName("Unread");
1490 var query
= "?op=rpc&method=catchupSelected" +
1491 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1493 new Ajax
.Request("backend.php", {
1495 onComplete: function(transport
) {
1496 handle_rpc_json(transport
);
1503 exception_error("catchupRelativeToArticle", e
);
1507 function cdmCollapseArticle(event
, id
, unmark
) {
1509 if (unmark
== undefined) unmark
= true;
1511 var row
= $("RROW-" + id
);
1512 var elem
= $("CICD-" + id
);
1515 var collapse
= $$("div#RROW-" + id
+
1516 " span[class='collapseBtn']")[0];
1519 Element
.show("CEXC-" + id
);
1520 Element
.hide(collapse
);
1523 row
.removeClassName("active");
1525 markHeadline(id
, false);
1527 if (id
== getActiveArticleId()) {
1528 setActiveArticleId(0);
1531 updateSelectedPrompt();
1534 if (event
) Event
.stop(event
);
1536 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1538 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1539 scrollToRowId(row
.id
);
1541 $("floatingTitle").style
.visibility
= "hidden";
1542 $("floatingTitle").setAttribute("rowid", false);
1546 exception_error("cdmCollapseArticle", e
);
1550 function cdmExpandArticle(id
, noexpand
) {
1552 console
.log("cdmExpandArticle " + id
);
1554 if (!$("RROW-" + id
)) return false;
1556 var oldrow
= $("RROW-" + getActiveArticleId());
1558 var elem
= $("CICD-" + getActiveArticleId());
1560 if (id
== getActiveArticleId() && Element
.visible(elem
))
1563 selectArticles("none");
1565 var old_offset
= $("RROW-" + id
).offsetTop
;
1567 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1568 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1569 " span[class='collapseBtn']")[0];
1572 Element
.show("CEXC-" + getActiveArticleId());
1573 Element
.hide(collapse
);
1576 if (oldrow
) oldrow
.removeClassName("active");
1578 setActiveArticleId(id
);
1580 elem
= $("CICD-" + id
);
1582 var collapse
= $$("div#RROW-" + id
+
1583 " span[class='collapseBtn']")[0];
1585 var cencw
= $("CENCW-" + id
);
1587 if (!Element
.visible(elem
) && !noexpand
) {
1589 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1590 cencw
.setAttribute('id', '');
1591 Element
.show(cencw
);
1595 Element
.hide("CEXC-" + id
);
1596 Element
.show(collapse
);
1599 var new_offset
= $("RROW-" + id
).offsetTop
;
1601 if (old_offset
> new_offset
)
1602 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1605 toggleUnread(id
, 0, true);
1607 $("RROW-" + id
).addClassName("active");
1609 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1612 exception_error("cdmExpandArticle", e
);
1618 function getArticleUnderPointer() {
1619 return post_under_pointer
;
1622 function scrollArticle(offset
) {
1625 var ci
= $("content-insert");
1627 ci
.scrollTop
+= offset
;
1630 var hi
= $("headlines-frame");
1632 hi
.scrollTop
+= offset
;
1637 exception_error("scrollArticle", e
);
1641 function show_labels_in_headlines(transport
) {
1643 var data
= JSON
.parse(transport
.responseText
);
1646 data
['info-for-headlines'].each(function(elem
) {
1647 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1648 ctr
.innerHTML
= elem
.labels
;
1653 exception_error("show_labels_in_headlines", e
);
1657 function dismissArticle(id
) {
1659 var elem
= $("RROW-" + id
);
1663 toggleUnread(id
, 0, true);
1665 new Effect
.Fade(elem
, {duration
: 0.5});
1667 // Remove the content, too
1668 var elem_content
= $("CICD-" + id
);
1670 Element
.remove(elem_content
);
1673 if (id
== getActiveArticleId()) {
1674 setActiveArticleId(0);
1678 exception_error("dismissArticle", e
);
1682 function dismissSelectedArticles() {
1685 var ids
= getVisibleArticleIds();
1689 for (var i
= 0; i
< ids
.length
; i
++) {
1690 var elem
= $("RROW-" + ids
[i
]);
1692 if (elem
.className
&& elem
.hasClassName("Selected") &&
1693 ids
[i
] != getActiveArticleId()) {
1694 new Effect
.Fade(elem
, {duration
: 0.5});
1697 // Remove the content, too
1698 var elem_content
= $("CICD-" + ids
[i
]);
1700 Element
.remove(elem_content
);
1708 selectionToggleUnread(false);
1712 exception_error("dismissSelectedArticles", e
);
1716 function dismissReadArticles() {
1719 var ids
= getVisibleArticleIds();
1722 for (var i
= 0; i
< ids
.length
; i
++) {
1723 var elem
= $("RROW-" + ids
[i
]);
1725 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1726 !elem
.hasClassName("Selected")) {
1728 new Effect
.Fade(elem
, {duration
: 0.5});
1730 // Remove the content, too
1731 var elem_content
= $("CICD-" + ids
[i
]);
1733 Element
.remove(elem_content
);
1741 exception_error("dismissReadArticles", e
);
1745 function getVisibleArticleIds() {
1750 getLoadedArticleIds().each(function(id
) {
1751 var elem
= $("RROW-" + id
);
1752 if (elem
&& Element
.visible(elem
))
1757 exception_error("getVisibleArticleIds", e
);
1763 function cdmClicked(event
, id
) {
1765 //var shift_key = event.shiftKey;
1767 if (!event
.ctrlKey
) {
1769 if (!getInitParam("cdm_expanded")) {
1770 return cdmExpandArticle(id
);
1773 var elem
= $("RROW-" + getActiveArticleId());
1775 if (elem
) elem
.removeClassName("active");
1777 selectArticles("none");
1780 var elem
= $("RROW-" + id
);
1781 var article_is_unread
= elem
.hasClassName("Unread");
1783 elem
.removeClassName("Unread");
1784 elem
.addClassName("active");
1786 setActiveArticleId(id
);
1788 if (article_is_unread
) {
1789 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1790 updateFloatingTitle(true);
1793 var query
= "?op=rpc&method=catchupSelected" +
1794 "&cmode=0&ids=" + param_escape(id
);
1796 new Ajax
.Request("backend.php", {
1798 onComplete: function(transport
) {
1799 handle_rpc_json(transport
);
1802 return !event
.shiftKey
;
1805 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1807 toggleSelected(id
, true);
1809 var elem
= $("RROW-" + id
);
1810 var article_is_unread
= elem
.hasClassName("Unread");
1812 if (article_is_unread
) {
1813 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1816 toggleUnread(id
, 0, false);
1818 openArticleInNewWindow(id
);
1821 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1822 request_counters(unread_in_buffer
== 0);
1825 exception_error("cdmClicked");
1831 function hlClicked(event
, id
) {
1833 if (event
.which
== 2) {
1836 } else if (event
.ctrlKey
) {
1837 toggleSelected(id
, true);
1838 toggleUnread(id
, 0, false);
1839 openArticleInNewWindow(id
);
1847 exception_error("hlClicked");
1851 function getFirstVisibleHeadlineId() {
1852 var rows
= getVisibleArticleIds();
1857 function getLastVisibleHeadlineId() {
1858 var rows
= getVisibleArticleIds();
1859 return rows
[rows
.length
-1];
1862 function openArticleInNewWindow(id
) {
1863 toggleUnread(id
, 0, false);
1864 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1867 function isCdmMode() {
1868 return getInitParam("combined_display_mode");
1871 function markHeadline(id
, marked
) {
1872 if (marked
== undefined) marked
= true;
1874 var row
= $("RROW-" + id
);
1876 var check
= dijit
.getEnclosingWidget(
1877 row
.getElementsByClassName("rchk")[0]);
1880 check
.attr("checked", marked
);
1884 row
.addClassName("Selected");
1886 row
.removeClassName("Selected");
1890 function getRelativePostIds(id
, limit
) {
1896 if (!limit
) limit
= 6; //3
1898 var ids
= getVisibleArticleIds();
1900 for (var i
= 0; i
< ids
.length
; i
++) {
1902 for (var k
= 1; k
<= limit
; k
++) {
1903 //if (i > k-1) tmp.push(ids[i-k]);
1904 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1911 exception_error("getRelativePostIds", e
);
1917 function correctHeadlinesOffset(id
) {
1921 var container
= $("headlines-frame");
1922 var row
= $("RROW-" + id
);
1924 if (!container
|| !row
) return;
1926 var viewport
= container
.offsetHeight
;
1928 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1929 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1931 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1932 //console.log("Vport: " + viewport);
1934 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1935 container
.scrollTop
= row
.offsetTop
;
1936 } else if (rel_offset_bottom
> viewport
) {
1938 /* doesn't properly work with Opera in some cases because
1939 Opera fucks up element scrolling */
1941 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1945 exception_error("correctHeadlinesOffset", e
);
1950 function headlineActionsChange(elem
) {
1953 elem
.attr('value', 'false');
1955 exception_error("headlineActionsChange", e
);
1959 function closeArticlePanel() {
1961 if (dijit
.byId("content-insert"))
1962 dijit
.byId("headlines-wrap-inner").removeChild(
1963 dijit
.byId("content-insert"));
1966 function initFloatingMenu() {
1968 if (dijit
.byId("floatingMenu"))
1969 dijit
.byId("floatingMenu").destroyRecursive();
1971 var menu
= new dijit
.Menu({
1973 targetNodeIds
: ["floatingTitle"]
1976 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1978 headlinesMenuCommon(menu
, id
);
1982 exception_error("initFloatingMenu", e
);
1986 function headlinesMenuCommon(menu
, base_id
) {
1989 menu
.addChild(new dijit
.MenuItem({
1990 label
: __("Open original article"),
1991 onClick: function(event
) {
1992 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1995 menu
.addChild(new dijit
.MenuItem({
1996 label
: __("Display article URL"),
1997 onClick: function(event
) {
1998 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
2001 menu
.addChild(new dijit
.MenuSeparator());
2003 menu
.addChild(new dijit
.MenuItem({
2004 label
: __("Toggle unread"),
2005 onClick: function(event
) {
2006 var ids
= getSelectedArticleIds2();
2008 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2009 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2011 selectionToggleUnread(undefined, false, true, ids
);
2014 menu
.addChild(new dijit
.MenuItem({
2015 label
: __("Toggle starred"),
2016 onClick: function(event
) {
2017 var ids
= getSelectedArticleIds2();
2019 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2020 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2022 selectionToggleMarked(undefined, false, true, ids
);
2025 menu
.addChild(new dijit
.MenuItem({
2026 label
: __("Toggle published"),
2027 onClick: function(event
) {
2028 var ids
= getSelectedArticleIds2();
2030 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2031 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2033 selectionTogglePublished(undefined, false, true, ids
);
2036 menu
.addChild(new dijit
.MenuSeparator());
2038 menu
.addChild(new dijit
.MenuItem({
2039 label
: __("Mark above as read"),
2040 onClick: function(event
) {
2041 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2044 menu
.addChild(new dijit
.MenuItem({
2045 label
: __("Mark below as read"),
2046 onClick: function(event
) {
2047 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2051 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2055 menu
.addChild(new dijit
.MenuSeparator());
2057 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2058 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2060 labels
.each(function(label
) {
2061 var id
= label
.id
[0];
2062 var bare_id
= id
.substr(id
.indexOf(":")+1);
2063 var name
= label
.name
[0];
2065 bare_id
= feed_to_label_id(bare_id
);
2067 labelAddMenu
.addChild(new dijit
.MenuItem({
2070 onClick: function(event
) {
2071 var ids
= getSelectedArticleIds2();
2073 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2075 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2077 selectionAssignLabel(this.labelId
, ids
);
2080 labelDelMenu
.addChild(new dijit
.MenuItem({
2083 onClick: function(event
) {
2084 var ids
= getSelectedArticleIds2();
2086 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2088 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2090 selectionRemoveLabel(this.labelId
, ids
);
2095 menu
.addChild(new dijit
.PopupMenuItem({
2096 label
: __("Assign label"),
2097 popup
: labelAddMenu
,
2100 menu
.addChild(new dijit
.PopupMenuItem({
2101 label
: __("Remove label"),
2102 popup
: labelDelMenu
,
2109 exception_error("headlinesMenuCommon", e
);
2113 function initHeadlinesMenu() {
2115 if (dijit
.byId("headlinesMenu"))
2116 dijit
.byId("headlinesMenu").destroyRecursive();
2121 nodes
= $$("#headlines-frame > div[id*=RROW]");
2123 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2126 nodes
.each(function(node
) {
2130 var menu
= new dijit
.Menu({
2131 id
: "headlinesMenu",
2135 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2136 var callerNode
= event
.target
, match
= null, tries
= 0;
2138 while (match
== null && callerNode
&& tries
<= 3) {
2139 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2140 callerNode
= callerNode
.parentNode
;
2144 if (match
) this.callerRowId
= parseInt(match
[1]);
2148 headlinesMenuCommon(menu
, false);
2152 /* vgroup feed title menu */
2154 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2157 nodes
.each(function(node
) {
2161 if (ids
.length
> 0) {
2162 if (dijit
.byId("headlinesFeedTitleMenu"))
2163 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2165 var menu
= new dijit
.Menu({
2166 id
: "headlinesFeedTitleMenu",
2170 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2171 var callerNode
= event
.target
, match
= null, tries
= 0;
2173 while (match
== null && callerNode
&& tries
<= 3) {
2174 console
.log(callerNode
.id
);
2176 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2177 callerNode
= callerNode
.parentNode
;
2180 console
.log(match
[1]);
2183 if (match
) this.callerRowId
= parseInt(match
[1]);
2187 menu
.addChild(new dijit
.MenuItem({
2188 label
: __("Select articles in group"),
2189 onClick: function(event
) {
2190 selectArticles("all",
2191 "#headlines-frame > div[id*=RROW]"+
2192 "[orig-feed-id='"+menu
.callerRowId
+"']");
2196 menu
.addChild(new dijit
.MenuItem({
2197 label
: __("Mark group as read"),
2198 onClick: function(event
) {
2199 selectArticles("none");
2200 selectArticles("all",
2201 "#headlines-frame > div[id*=RROW]"+
2202 "[orig-feed-id='"+menu
.callerRowId
+"']");
2208 menu
.addChild(new dijit
.MenuItem({
2209 label
: __("Mark feed as read"),
2210 onClick: function(event
) {
2211 catchupFeedInGroup(menu
.callerRowId
);
2219 exception_error("initHeadlinesMenu", e
);
2223 function cache_set(id
, obj
) {
2224 //console.log("cache_set: " + id);
2227 sessionStorage
[id
] = obj
;
2229 sessionStorage
.clear();
2233 function cache_get(id
) {
2235 return sessionStorage
[id
];
2238 function cache_clear() {
2240 sessionStorage
.clear();
2243 function cache_delete(id
) {
2245 sessionStorage
.removeItem(id
);
2248 function cancelSearch() {
2253 exception_error("cancelSearch", e
);
2257 function setSelectionScore() {
2259 var ids
= getSelectedArticleIds2();
2261 if (ids
.length
> 0) {
2264 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2266 if (score
!= undefined) {
2267 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2268 "&score=" + param_escape(score
);
2270 new Ajax
.Request("backend.php", {
2272 onComplete: function(transport
) {
2273 var reply
= JSON
.parse(transport
.responseText
);
2277 ids
.each(function(id
) {
2278 var row
= $("RROW-" + id
);
2281 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2284 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2285 reply
["score_pic"]);
2286 pic
.setAttribute("score", score
);
2295 alert(__("No articles are selected."));
2298 exception_error("setSelectionScore", e
);
2302 function updateScore(id
) {
2304 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2308 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2310 new Ajax
.Request("backend.php", {
2312 onComplete: function(transport
) {
2313 console
.log(transport
.responseText
);
2315 var reply
= JSON
.parse(transport
.responseText
);
2318 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2319 pic
.setAttribute("score", reply
["score"]);
2320 pic
.setAttribute("title", reply
["score"]);
2326 exception_error("updateScore", e
);
2330 function changeScore(id
, pic
) {
2332 var score
= pic
.getAttribute("score");
2334 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2336 if (new_score
!= undefined) {
2338 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2339 "&score=" + param_escape(new_score
);
2341 new Ajax
.Request("backend.php", {
2343 onComplete: function(transport
) {
2344 var reply
= JSON
.parse(transport
.responseText
);
2347 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2348 pic
.setAttribute("score", new_score
);
2349 pic
.setAttribute("title", new_score
);
2354 exception_error("changeScore", e
);
2358 function displayArticleUrl(id
) {
2360 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2362 new Ajax
.Request("backend.php", {
2364 onComplete: function(transport
) {
2365 var reply
= JSON
.parse(transport
.responseText
);
2367 if (reply
&& reply
.link
) {
2368 prompt(__("Article URL:"), reply
.link
);
2372 exception_error("changeScore", e
);
2376 function openSelectedAttachment(elem
) {
2378 var url
= elem
[elem
.selectedIndex
].value
;
2382 elem
.selectedIndex
= 0;
2386 exception_error("openSelectedAttachment", e
);
2390 function scrollToRowId(id
) {
2395 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2398 exception_error("scrollToRowId", e
);
2402 function updateFloatingTitle(unread_only
) {
2404 if (!isCdmMode()) return;
2406 var hf
= $("headlines-frame");
2408 var elems
= $$("#headlines-frame > div[id*=RROW]");
2410 for (var i
= 0; i
< elems
.length
; i
++) {
2412 var child
= elems
[i
];
2414 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2416 var header
= child
.getElementsByClassName("cdmHeader")[0];
2418 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2419 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2420 $("floatingTitle").setAttribute("rowid", child
.id
);
2421 $("floatingTitle").innerHTML
= header
.innerHTML
;
2422 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2426 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2429 cb
.parentNode
.removeChild(cb
);
2432 if (child
.hasClassName("Unread"))
2433 $("floatingTitle").addClassName("Unread");
2435 $("floatingTitle").removeClassName("Unread");
2437 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2440 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2441 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2442 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2443 $("floatingTitle").style
.visibility
= "visible";
2445 $("floatingTitle").style
.visibility
= "hidden";
2453 exception_error("updateFloatingTitle", e
);
2457 function cdmFooterClick(event
) {
2458 event
.stopPropagation();