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;
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
21 handle_rpc_json(transport
);
23 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
31 reply
= JSON
.parse(transport
.responseText
);
38 is_cat
= reply
['headlines']['is_cat'];
39 feed_id
= reply
['headlines']['id'];
42 var content
= reply
['headlines']['content'];
44 content
= content
+ "<div id='headlines-spacer'></div>";
48 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
51 /* dijit.getEnclosingWidget(
52 document.forms["main_toolbar_form"].update).attr('disabled',
53 is_cat || feed_id <= 0); */
56 if (infscroll_req
== false) {
57 $("headlines-frame").scrollTop
= 0;
59 Element
.hide("floatingTitle");
60 $("floatingTitle").setAttribute("rowid", 0);
61 $("floatingTitle").innerHTML
= "";
65 $("headlines-frame").removeClassName("cdm");
66 $("headlines-frame").removeClassName("normal");
68 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
70 var headlines_count
= reply
['headlines-info']['count'];
72 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
74 if (parseInt(headlines_count
) < 30) {
75 _infscroll_disable
= 1;
77 _infscroll_disable
= 0;
80 var counters
= reply
['counters'];
81 var articles
= reply
['articles'];
82 //var runtime_info = reply['runtime-info'];
84 if (infscroll_req
== false) {
85 loaded_article_ids
= [];
87 dijit
.byId("headlines-frame").attr('content',
88 reply
['headlines']['content']);
90 //dijit.byId("headlines-toolbar").attr('content',
91 // reply['headlines']['toolbar']);
93 dojo
.html
.set($("headlines-toolbar"),
94 reply
['headlines']['toolbar'],
95 {parseContent
: true});
97 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
98 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
99 row
.parentNode
.removeChild(row
);
101 loaded_article_ids
.push(row
.id
);
105 var hsp
= $("headlines-spacer");
106 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
107 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
112 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
113 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
119 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
120 console
.log("adding some more headlines: " + headlines_count
);
122 var c
= dijit
.byId("headlines-frame");
123 var ids
= getSelectedArticleIds2();
126 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
128 var hsp
= $("headlines-spacer");
131 c
.domNode
.removeChild(hsp
);
133 $$("#headlines-tmp > div").each(function(row
) {
134 if (row
.className
== 'cdmFeedTitle') {
135 row
.style
.display
= 'none';
136 c
.domNode
.appendChild(row
);
138 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
139 row
.style
.display
= 'none';
140 c
.domNode
.appendChild(row
);
142 loaded_article_ids
.push(row
.id
);
144 row
.parentNode
.removeChild(row
);
148 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
150 if (getInitParam("cdm_auto_catchup") == 1) {
151 c
.domNode
.appendChild(hsp
);
154 console
.log("added " + new_elems
.size() + " headlines");
156 if (new_elems
.size() == 0)
157 _infscroll_disable
= true;
159 console
.log("restore selected ids: " + ids
);
161 for (var i
= 0; i
< ids
.length
; i
++) {
162 markHeadline(ids
[i
]);
167 new_elems
.each(function(child
) {
168 dojo
.parser
.parse(child
);
170 if (!Element
.visible(child
))
171 new Effect
.Appear(child
, { duration
: 0.5 });
175 console
.log("no new headlines received");
177 var hsp
= $("headlines-spacer");
179 if (hsp
) hsp
.innerHTML
= "";
184 for (var i
= 0; i
< articles
.length
; i
++) {
185 var a_id
= articles
[i
]['id'];
186 cache_set("article:" + a_id
, articles
[i
]['content']);
189 console
.log("no cached articles received");
193 parse_counters(counters
);
195 request_counters(true);
198 console
.error("Invalid object received: " + transport
.responseText
);
199 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
200 __('Could not update headlines (invalid object received - see error console for details)') +
204 _infscroll_request_sent
= 0;
205 _last_headlines_update
= new Date().getTime();
207 unpackVisibleHeadlines();
209 // if we have some more space in the buffer, why not try to fill it
211 if (!_infscroll_disable
&& $("headlines-spacer") &&
212 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
214 window
.setTimeout(function() {
222 exception_error("headlines_callback2", e
, transport
);
226 function render_article(article
) {
228 dijit
.byId("headlines-wrap-inner").addChild(
229 dijit
.byId("content-insert"));
231 var c
= dijit
.byId("content-insert");
234 c
.domNode
.scrollTop
= 0;
237 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
239 c
.attr('content', article
);
241 correctHeadlinesOffset(getActiveArticleId());
248 exception_error("render_article", e
);
252 function showArticleInHeadlines(id
, noexpand
) {
255 selectArticles("none");
257 var crow
= $("RROW-" + id
);
261 var article_is_unread
= crow
.hasClassName("Unread");
264 crow
.removeClassName("Unread");
265 crow
.addClassName("active");
267 selectArticles('none');
269 var view_mode
= false;
272 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
273 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
280 if (article_is_unread
&& !noexpand
)
281 _force_scheduled_update
= true;
284 exception_error("showArticleInHeadlines", e
);
288 function article_callback2(transport
, id
) {
290 console
.log("article_callback2 " + id
);
292 handle_rpc_json(transport
);
297 reply
= JSON
.parse(transport
.responseText
);
304 reply
.each(function(article
) {
305 if (getActiveArticleId() == article
['id']) {
306 render_article(article
['content']);
308 cids_requested
.remove(article
['id']);
310 cache_set("article:" + article
['id'], article
['content']);
313 // if (id != last_requested_article) {
314 // console.log("requested article id is out of sequence, aborting");
319 console
.error("Invalid object received: " + transport
.responseText
);
321 render_article("<div class='whiteBox'>" +
322 __('Could not display article (invalid object received - see error console for details)') + "</div>");
325 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
326 request_counters(unread_in_buffer
== 0);
328 //headlines_scroll_handler($("headlines-frame"));
331 if (!_infscroll_disable &&
332 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
342 exception_error("article_callback2", e
, transport
);
346 function view(id
, activefeed
, noexpand
) {
348 var oldrow
= $("RROW-" + getActiveArticleId());
349 if (oldrow
) oldrow
.removeClassName("active");
351 var crow
= $("RROW-" + id
);
355 setActiveArticleId(id
);
356 showArticleInHeadlines(id
, noexpand
);
360 console
.log("loading article: " + id
);
362 var cached_article
= cache_get("article:" + id
);
364 console
.log("cache check result: " + (cached_article
!= false));
366 var query
= "?op=article&method=view&id=" + param_escape(id
);
368 var neighbor_ids
= getRelativePostIds(id
);
370 /* only request uncached articles */
372 var cids_to_request
= [];
374 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
375 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
376 if (!cache_get("article:" + neighbor_ids
[i
])) {
377 cids_to_request
.push(neighbor_ids
[i
]);
378 cids_requested
.push(neighbor_ids
[i
]);
382 console
.log("additional ids: " + cids_to_request
.toString());
384 query
= query
+ "&cids=" + cids_to_request
.toString();
386 var article_is_unread
= crow
.hasClassName("Unread");
388 setActiveArticleId(id
);
389 showArticleInHeadlines(id
);
391 if (cached_article
&& article_is_unread
) {
393 query
= query
+ "&mode=prefetch";
395 render_article(cached_article
);
397 } else if (cached_article
) {
399 query
= query
+ "&mode=prefetch_old";
400 render_article(cached_article
);
402 // if we don't need to request any relative ids, we might as well skip
403 // the server roundtrip altogether
404 if (cids_to_request
.length
== 0) {
407 if (!_infscroll_disable &&
408 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
416 //headlines_scroll_handler($("headlines-frame"));
422 last_requested_article
= id
;
426 if (article_is_unread
) {
427 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
430 new Ajax
.Request("backend.php", {
432 onComplete: function(transport
) {
433 article_callback2(transport
, id
);
439 exception_error("view", e
);
443 function toggleMark(id
, client_only
) {
445 var query
= "?op=rpc&id=" + id
+ "&method=mark";
447 var row
= $("RROW-" + id
);
452 var row_imgs
= row
.getElementsByClassName("markedPic");
454 for (var i
= 0; i
< row_imgs
.length
; i
++)
455 imgs
.push(row_imgs
[i
]);
457 var ft
= $("floatingTitle");
459 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
460 var fte
= ft
.getElementsByClassName("markedPic");
462 for (var i
= 0; i
< fte
.length
; i
++)
466 for (i
= 0; i
< imgs
.length
; i
++) {
469 if (!row
.hasClassName("marked")) {
470 img
.src
= img
.src
.replace("mark_unset", "mark_set");
471 img
.alt
= __("Unstar article");
472 query
= query
+ "&mark=1";
474 img
.src
= img
.src
.replace("mark_set", "mark_unset");
475 img
.alt
= __("Star article");
476 query
= query
+ "&mark=0";
480 row
.toggleClassName("marked");
483 new Ajax
.Request("backend.php", {
485 onComplete: function(transport
) {
486 handle_rpc_json(transport
);
491 exception_error("toggleMark", e
);
495 function togglePub(id
, client_only
, no_effects
, note
) {
497 var query
= "?op=rpc&id=" + id
+ "&method=publ";
499 if (note
!= undefined) {
500 query
= query
+ "¬e=" + param_escape(note
);
502 query
= query
+ "¬e=undefined";
505 var row
= $("RROW-" + id
);
510 var row_imgs
= row
.getElementsByClassName("pubPic");
512 for (var i
= 0; i
< row_imgs
.length
; i
++)
513 imgs
.push(row_imgs
[i
]);
515 var ft
= $("floatingTitle");
517 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
518 var fte
= ft
.getElementsByClassName("pubPic");
520 for (var i
= 0; i
< fte
.length
; i
++)
524 for (i
= 0; i
< imgs
.length
; i
++) {
527 if (!row
.hasClassName("published") || note
!= undefined) {
528 img
.src
= img
.src
.replace("pub_unset", "pub_set");
529 img
.alt
= __("Unpublish article");
530 query
= query
+ "&pub=1";
532 img
.src
= img
.src
.replace("pub_set", "pub_unset");
533 img
.alt
= __("Publish article");
534 query
= query
+ "&pub=0";
538 if (note
!= undefined)
539 row
.addClassName("published");
541 row
.toggleClassName("published");
544 new Ajax
.Request("backend.php", {
546 onComplete: function(transport
) {
547 handle_rpc_json(transport
);
552 exception_error("togglePub", e
);
556 function moveToPost(mode
, noscroll
, noexpand
) {
560 var rows
= getVisibleArticleIds();
565 if (!$('RROW-' + getActiveArticleId())) {
566 setActiveArticleId(0);
569 if (!getActiveArticleId()) {
571 prev_id
= rows
[rows
.length
-1]
573 for (var i
= 0; i
< rows
.length
; i
++) {
574 if (rows
[i
] == getActiveArticleId()) {
576 // Account for adjacent identical article ids.
577 if (i
> 0) prev_id
= rows
[i
-1];
579 for (var j
= i
+1; j
< rows
.length
; j
++) {
580 if (rows
[j
] != getActiveArticleId()) {
590 if (mode
== "next") {
591 if (next_id
|| getActiveArticleId()) {
594 var article
= $("RROW-" + getActiveArticleId());
595 var ctr
= $("headlines-frame");
597 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
598 ctr
.scrollTop
+ ctr
.offsetHeight
) {
600 scrollArticle(ctr
.offsetHeight
/4);
602 } else if (next_id
) {
603 cdmExpandArticle(next_id
, noexpand
);
604 cdmScrollToArticleId(next_id
, true);
607 } else if (next_id
) {
608 correctHeadlinesOffset(next_id
);
609 view(next_id
, getActiveFeedId(), noexpand
);
614 if (mode
== "prev") {
615 if (prev_id
|| getActiveArticleId()) {
618 var article
= $("RROW-" + getActiveArticleId());
619 var prev_article
= $("RROW-" + prev_id
);
620 var ctr
= $("headlines-frame");
622 if (!getInitParam("cdm_expanded")) {
624 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
625 scrollArticle(-ctr
.offsetHeight
/4);
627 cdmExpandArticle(prev_id
, noexpand
);
628 cdmScrollToArticleId(prev_id
, true);
632 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
633 scrollArticle(-ctr
.offsetHeight
/3);
634 } else if (!noscroll
&& prev_article
&&
635 prev_article
.offsetTop
< ctr
.scrollTop
) {
636 cdmExpandArticle(prev_id
, noexpand
);
637 scrollArticle(-ctr
.offsetHeight
/4);
638 } else if (prev_id
) {
639 cdmExpandArticle(prev_id
, noexpand
);
640 cdmScrollToArticleId(prev_id
, noscroll
);
644 } else if (prev_id
) {
645 correctHeadlinesOffset(prev_id
);
646 view(prev_id
, getActiveFeedId(), noexpand
);
652 exception_error("moveToPost", e
);
656 function toggleSelected(id
, force_on
) {
658 var row
= $("RROW-" + id
);
661 var cb
= dijit
.getEnclosingWidget(
662 row
.getElementsByClassName("rchk")[0]);
664 if (row
.hasClassName('Selected') && !force_on
) {
665 row
.removeClassName('Selected');
666 if (cb
) cb
.attr("checked", false);
668 row
.addClassName('Selected');
669 if (cb
) cb
.attr("checked", true);
673 updateSelectedPrompt();
675 exception_error("toggleSelected", e
);
679 function updateSelectedPrompt() {
681 var count
= getSelectedArticleIds2().size();
682 var elem
= $("selected_prompt");
685 elem
.innerHTML
= ngettext("%d article selected",
686 "%d articles selected", count
).replace("%d", count
);
695 exception_error("updateSelectedPrompt", e
);
699 function toggleUnread_afh(effect
) {
702 var elem
= effect
.element
;
703 elem
.style
.backgroundColor
= "";
706 exception_error("toggleUnread_afh", e
);
710 function toggleUnread(id
, cmode
, effect
) {
713 var row
= $("RROW-" + id
);
715 if (cmode
== undefined || cmode
== 2) {
716 if (row
.hasClassName("Unread")) {
717 row
.removeClassName("Unread");
720 row
.addClassName("Unread");
723 } else if (cmode
== 0) {
725 row
.removeClassName("Unread");
727 } else if (cmode
== 1) {
728 row
.addClassName("Unread");
731 if (cmode
== undefined) cmode
= 2;
733 var query
= "?op=rpc&method=catchupSelected" +
734 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
736 // notify_progress("Loading, please wait...");
738 new Ajax
.Request("backend.php", {
740 onComplete: function(transport
) {
741 handle_rpc_json(transport
);
747 exception_error("toggleUnread", e
);
751 function selectionRemoveLabel(id
, ids
) {
754 if (!ids
) ids
= getSelectedArticleIds2();
756 if (ids
.length
== 0) {
757 alert(__("No articles are selected."));
761 var query
= "?op=article&method=removeFromLabel&ids=" +
762 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
766 new Ajax
.Request("backend.php", {
768 onComplete: function(transport
) {
769 handle_rpc_json(transport
);
770 show_labels_in_headlines(transport
);
774 exception_error("selectionAssignLabel", e
);
779 function selectionAssignLabel(id
, ids
) {
782 if (!ids
) ids
= getSelectedArticleIds2();
784 if (ids
.length
== 0) {
785 alert(__("No articles are selected."));
789 var query
= "?op=article&method=assignToLabel&ids=" +
790 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
794 new Ajax
.Request("backend.php", {
796 onComplete: function(transport
) {
797 handle_rpc_json(transport
);
798 show_labels_in_headlines(transport
);
802 exception_error("selectionAssignLabel", e
);
807 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
809 var rows
= ids
? ids
: getSelectedArticleIds2();
811 if (rows
.length
== 0 && !no_error
) {
812 alert(__("No articles are selected."));
816 for (var i
= 0; i
< rows
.length
; i
++) {
817 var row
= $("RROW-" + rows
[i
]);
819 if (set_state
== undefined) {
820 if (row
.hasClassName("Unread")) {
821 row
.removeClassName("Unread");
823 row
.addClassName("Unread");
827 if (set_state
== false) {
828 row
.removeClassName("Unread");
831 if (set_state
== true) {
832 row
.addClassName("Unread");
837 updateFloatingTitle(true);
839 if (rows
.length
> 0) {
843 if (set_state
== undefined) {
845 } else if (set_state
== true) {
847 } else if (set_state
== false) {
851 var query
= "?op=rpc&method=catchupSelected" +
852 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
854 notify_progress("Loading, please wait...");
856 new Ajax
.Request("backend.php", {
858 onComplete: function(transport
) {
859 handle_rpc_json(transport
);
860 if (callback
) callback(transport
);
866 exception_error("selectionToggleUnread", e
);
871 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
874 var rows
= ids
? ids
: getSelectedArticleIds2();
876 if (rows
.length
== 0 && !no_error
) {
877 alert(__("No articles are selected."));
881 for (var i
= 0; i
< rows
.length
; i
++) {
882 toggleMark(rows
[i
], true, true);
885 if (rows
.length
> 0) {
887 var query
= "?op=rpc&method=markSelected&ids=" +
888 param_escape(rows
.toString()) + "&cmode=2";
890 new Ajax
.Request("backend.php", {
892 onComplete: function(transport
) {
893 handle_rpc_json(transport
);
894 if (callback
) callback(transport
);
900 exception_error("selectionToggleMarked", e
);
905 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
908 var rows
= ids
? ids
: getSelectedArticleIds2();
910 if (rows
.length
== 0 && !no_error
) {
911 alert(__("No articles are selected."));
915 for (var i
= 0; i
< rows
.length
; i
++) {
916 togglePub(rows
[i
], true, true);
919 if (rows
.length
> 0) {
921 var query
= "?op=rpc&method=publishSelected&ids=" +
922 param_escape(rows
.toString()) + "&cmode=2";
924 new Ajax
.Request("backend.php", {
926 onComplete: function(transport
) {
927 handle_rpc_json(transport
);
933 exception_error("selectionToggleMarked", e
);
937 function getSelectedArticleIds2() {
941 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
943 rv
.push(child
.id
.replace("RROW-", ""));
949 function getLoadedArticleIds() {
952 var children
= $$("#headlines-frame > div[id*=RROW-]");
954 children
.each(function(child
) {
955 rv
.push(child
.id
.replace("RROW-", ""));
962 // mode = all,none,unread,invert,marked,published
963 function selectArticles(mode
, query
) {
966 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
968 var children
= $$(query
);
970 children
.each(function(child
) {
971 var id
= child
.id
.replace("RROW-", "");
973 var cb
= dijit
.getEnclosingWidget(
974 child
.getElementsByClassName("rchk")[0]);
977 child
.addClassName("Selected");
978 if (cb
) cb
.attr("checked", true);
979 } else if (mode
== "unread") {
980 if (child
.hasClassName("Unread")) {
981 child
.addClassName("Selected");
982 if (cb
) cb
.attr("checked", true);
984 child
.removeClassName("Selected");
985 if (cb
) cb
.attr("checked", false);
987 } else if (mode
== "marked") {
988 if (child
.hasClassName("marked")) {
989 child
.addClassName("Selected");
990 if (cb
) cb
.attr("checked", true);
992 child
.removeClassName("Selected");
993 if (cb
) cb
.attr("checked", false);
995 } else if (mode
== "published") {
996 if (child
.hasClassName("published")) {
997 child
.addClassName("Selected");
998 if (cb
) cb
.attr("checked", true);
1000 child
.removeClassName("Selected");
1001 if (cb
) cb
.attr("checked", false);
1004 } else if (mode
== "invert") {
1005 if (child
.hasClassName("Selected")) {
1006 child
.removeClassName("Selected");
1007 if (cb
) cb
.attr("checked", false);
1009 child
.addClassName("Selected");
1010 if (cb
) cb
.attr("checked", true);
1014 child
.removeClassName("Selected");
1015 if (cb
) cb
.attr("checked", false);
1019 updateSelectedPrompt();
1022 exception_error("selectArticles", e
);
1026 function deleteSelection() {
1030 var rows
= getSelectedArticleIds2();
1032 if (rows
.length
== 0) {
1033 alert(__("No articles are selected."));
1037 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1040 if (getActiveFeedId() != 0) {
1041 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1043 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1046 str
= str
.replace("%d", rows
.length
);
1047 str
= str
.replace("%s", fn
);
1049 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1053 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1057 new Ajax
.Request("backend.php", {
1059 onComplete: function(transport
) {
1060 handle_rpc_json(transport
);
1065 exception_error("deleteSelection", e
);
1069 function archiveSelection() {
1073 var rows
= getSelectedArticleIds2();
1075 if (rows
.length
== 0) {
1076 alert(__("No articles are selected."));
1080 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1084 if (getActiveFeedId() != 0) {
1085 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1088 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1090 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1095 str
= str
.replace("%d", rows
.length
);
1096 str
= str
.replace("%s", fn
);
1098 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1102 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1106 for (var i
= 0; i
< rows
.length
; i
++) {
1107 cache_delete("article:" + rows
[i
]);
1110 new Ajax
.Request("backend.php", {
1112 onComplete: function(transport
) {
1113 handle_rpc_json(transport
);
1118 exception_error("archiveSelection", e
);
1122 function catchupSelection() {
1126 var rows
= getSelectedArticleIds2();
1128 if (rows
.length
== 0) {
1129 alert(__("No articles are selected."));
1133 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1135 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1137 str
= str
.replace("%d", rows
.length
);
1138 str
= str
.replace("%s", fn
);
1140 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1144 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1147 exception_error("catchupSelection", e
);
1151 function editArticleTags(id
) {
1152 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1154 if (dijit
.byId("editTagsDlg"))
1155 dijit
.byId("editTagsDlg").destroyRecursive();
1157 dialog
= new dijit
.Dialog({
1159 title
: __("Edit article Tags"),
1160 style
: "width: 600px",
1161 execute: function() {
1162 if (this.validate()) {
1163 var query
= dojo
.objectToQuery(this.attr('value'));
1165 notify_progress("Saving article tags...", true);
1167 new Ajax
.Request("backend.php", {
1169 onComplete: function(transport
) {
1174 var data
= JSON
.parse(transport
.responseText
);
1181 var tags
= $("ATSTR-" + id
);
1182 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1184 if (tags
) tags
.innerHTML
= data
.content
;
1185 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1188 exception_error("editArticleTags/inner", e
);
1197 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1198 dojo
.disconnect(tmph
);
1200 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1201 "backend.php?op=article&method=completeTags",
1202 { tokens
: ',', paramName
: "search" });
1209 function cdmScrollToArticleId(id
, force
) {
1211 var ctr
= $("headlines-frame");
1212 var e
= $("RROW-" + id
);
1214 if (!e
|| !ctr
) return;
1216 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1217 e
.offsetTop
< ctr
.scrollTop
) {
1219 // expanded cdm has a 4px margin now
1220 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1224 exception_error("cdmScrollToArticleId", e
);
1228 function setActiveArticleId(id
) {
1229 _active_article_id
= id
;
1230 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1233 function getActiveArticleId() {
1234 return _active_article_id
;
1237 function postMouseIn(e
, id
) {
1238 post_under_pointer
= id
;
1241 function postMouseOut(id
) {
1242 post_under_pointer
= false;
1245 function unpackVisibleHeadlines() {
1247 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1249 $$("#headlines-frame > div[id*=RROW]").each(
1251 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1252 $("headlines-frame").offsetHeight
) {
1254 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1257 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1259 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1260 cencw
.setAttribute('id', '');
1261 Element
.show(cencw
);
1268 exception_error("unpackVisibleHeadlines", e
);
1272 function headlines_scroll_handler(e
) {
1274 var hsp
= $("headlines-spacer");
1276 unpackVisibleHeadlines();
1278 // set topmost child in the buffer as active
1279 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1280 getSelectedArticleIds2().length
<= 1 &&
1281 getInitParam("cdm_expanded")) {
1282 var rows
= $$("#headlines-frame > div[id*=RROW]");
1284 for (var i
= 0; i
< rows
.length
; i
++) {
1285 var child
= rows
[i
];
1287 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1288 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1289 child
.id
.replace("RROW-", "") != _active_article_id
) {
1291 if (_active_article_id
) {
1292 var row
= $("RROW-" + _active_article_id
);
1293 if (row
) row
.removeClassName("active");
1296 _active_article_id
= child
.id
.replace("RROW-", "");
1297 showArticleInHeadlines(_active_article_id
, true);
1298 updateSelectedPrompt();
1304 if (!_infscroll_disable
) {
1305 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1306 (e
.scrollHeight
!= 0 &&
1307 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1310 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1311 __("Loading, please wait...");
1313 loadMoreHeadlines();
1318 if (hsp
) hsp
.innerHTML
= "";
1322 updateFloatingTitle();
1325 if (getInitParam("cdm_auto_catchup") == 1) {
1327 // let's get DOM some time to settle down
1328 var ts
= new Date().getTime();
1329 if (ts
- _last_headlines_update
< 100) return;
1331 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1333 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1334 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1336 var id
= child
.id
.replace("RROW-", "");
1338 if (catchup_id_batch
.indexOf(id
) == -1)
1339 catchup_id_batch
.push(id
);
1341 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1346 if (catchup_id_batch
.length
> 0) {
1347 window
.clearTimeout(catchup_timeout_id
);
1349 if (!_infscroll_request_sent
) {
1350 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1353 } else if (_infscroll_disable
) {
1354 var child
= $$("#headlines-frame div[id*=RROW]").last();
1356 if (child
&& $("headlines-frame").scrollTop
>
1357 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1359 console
.log("we seem to be at an end");
1361 if (getInitParam("on_catchup_show_next_feed") == "1") {
1362 var is_cat
= activeFeedIsCat();
1363 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1365 if (nuf
) viewfeed(nuf
, '', is_cat
);
1372 console
.warn("headlines_scroll_handler: " + e
);
1376 function catchupBatchedArticles() {
1378 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1380 // make a copy of the array
1381 var batch
= catchup_id_batch
.slice();
1382 var query
= "?op=rpc&method=catchupSelected" +
1383 "&cmode=0&ids=" + param_escape(batch
.toString());
1387 new Ajax
.Request("backend.php", {
1389 onComplete: function(transport
) {
1390 handle_rpc_json(transport
);
1392 reply
= JSON
.parse(transport
.responseText
);
1393 var batch
= reply
.ids
;
1395 batch
.each(function(id
) {
1397 var elem
= $("RROW-" + id
);
1398 if (elem
) elem
.removeClassName("Unread");
1399 catchup_id_batch
.remove(id
);
1402 updateFloatingTitle(true);
1408 exception_error("catchupBatchedArticles", e
);
1412 function catchupRelativeToArticle(below
, id
) {
1416 if (!id
) id
= getActiveArticleId();
1419 alert(__("No article is selected."));
1423 var visible_ids
= getVisibleArticleIds();
1425 var ids_to_mark
= new Array();
1428 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1429 if (visible_ids
[i
] != id
) {
1430 var e
= $("RROW-" + visible_ids
[i
]);
1432 if (e
&& e
.hasClassName("Unread")) {
1433 ids_to_mark
.push(visible_ids
[i
]);
1440 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1441 if (visible_ids
[i
] != id
) {
1442 var e
= $("RROW-" + visible_ids
[i
]);
1444 if (e
&& e
.hasClassName("Unread")) {
1445 ids_to_mark
.push(visible_ids
[i
]);
1453 if (ids_to_mark
.length
== 0) {
1454 alert(__("No articles found to mark"));
1456 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1458 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1460 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1461 var e
= $("RROW-" + ids_to_mark
[i
]);
1462 e
.removeClassName("Unread");
1465 var query
= "?op=rpc&method=catchupSelected" +
1466 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1468 new Ajax
.Request("backend.php", {
1470 onComplete: function(transport
) {
1471 handle_rpc_json(transport
);
1478 exception_error("catchupRelativeToArticle", e
);
1482 function cdmCollapseArticle(event
, id
, unmark
) {
1484 if (unmark
== undefined) unmark
= true;
1486 var row
= $("RROW-" + id
);
1487 var elem
= $("CICD-" + id
);
1490 var collapse
= $$("div#RROW-" + id
+
1491 " span[class='collapseBtn']")[0];
1494 Element
.show("CEXC-" + id
);
1495 Element
.hide(collapse
);
1498 row
.removeClassName("active");
1500 markHeadline(id
, false);
1502 if (id
== getActiveArticleId()) {
1503 setActiveArticleId(0);
1506 updateSelectedPrompt();
1509 if (event
) Event
.stop(event
);
1511 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1513 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1514 scrollToRowId(row
.id
);
1516 Element
.hide("floatingTitle");
1517 $("floatingTitle").setAttribute("rowid", false);
1521 exception_error("cdmCollapseArticle", e
);
1525 function cdmExpandArticle(id
, noexpand
) {
1527 console
.log("cdmExpandArticle " + id
);
1529 if (!$("RROW-" + id
)) return false;
1531 var oldrow
= $("RROW-" + getActiveArticleId());
1533 var elem
= $("CICD-" + getActiveArticleId());
1535 if (id
== getActiveArticleId() && Element
.visible(elem
))
1538 selectArticles("none");
1540 var old_offset
= $("RROW-" + id
).offsetTop
;
1542 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1543 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1544 " span[class='collapseBtn']")[0];
1547 Element
.show("CEXC-" + getActiveArticleId());
1548 Element
.hide(collapse
);
1551 if (oldrow
) oldrow
.removeClassName("active");
1553 setActiveArticleId(id
);
1555 elem
= $("CICD-" + id
);
1557 var collapse
= $$("div#RROW-" + id
+
1558 " span[class='collapseBtn']")[0];
1560 var cencw
= $("CENCW-" + id
);
1562 if (!Element
.visible(elem
) && !noexpand
) {
1564 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1565 cencw
.setAttribute('id', '');
1566 Element
.show(cencw
);
1570 Element
.hide("CEXC-" + id
);
1571 Element
.show(collapse
);
1574 var new_offset
= $("RROW-" + id
).offsetTop
;
1576 if (old_offset
> new_offset
)
1577 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1580 toggleUnread(id
, 0, true);
1582 $("RROW-" + id
).addClassName("active");
1584 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1587 exception_error("cdmExpandArticle", e
);
1593 function getArticleUnderPointer() {
1594 return post_under_pointer
;
1597 function scrollArticle(offset
) {
1600 var ci
= $("content-insert");
1602 ci
.scrollTop
+= offset
;
1605 var hi
= $("headlines-frame");
1607 hi
.scrollTop
+= offset
;
1612 exception_error("scrollArticle", e
);
1616 function show_labels_in_headlines(transport
) {
1618 var data
= JSON
.parse(transport
.responseText
);
1621 data
['info-for-headlines'].each(function(elem
) {
1622 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1623 ctr
.innerHTML
= elem
.labels
;
1628 exception_error("show_labels_in_headlines", e
);
1632 function dismissArticle(id
) {
1634 var elem
= $("RROW-" + id
);
1638 toggleUnread(id
, 0, true);
1640 new Effect
.Fade(elem
, {duration
: 0.5});
1642 // Remove the content, too
1643 var elem_content
= $("CICD-" + id
);
1645 Element
.remove(elem_content
);
1648 if (id
== getActiveArticleId()) {
1649 setActiveArticleId(0);
1653 exception_error("dismissArticle", e
);
1657 function dismissSelectedArticles() {
1660 var ids
= getVisibleArticleIds();
1664 for (var i
= 0; i
< ids
.length
; i
++) {
1665 var elem
= $("RROW-" + ids
[i
]);
1667 if (elem
.className
&& elem
.hasClassName("Selected") &&
1668 ids
[i
] != getActiveArticleId()) {
1669 new Effect
.Fade(elem
, {duration
: 0.5});
1672 // Remove the content, too
1673 var elem_content
= $("CICD-" + ids
[i
]);
1675 Element
.remove(elem_content
);
1683 selectionToggleUnread(false);
1687 exception_error("dismissSelectedArticles", e
);
1691 function dismissReadArticles() {
1694 var ids
= getVisibleArticleIds();
1697 for (var i
= 0; i
< ids
.length
; i
++) {
1698 var elem
= $("RROW-" + ids
[i
]);
1700 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1701 !elem
.hasClassName("Selected")) {
1703 new Effect
.Fade(elem
, {duration
: 0.5});
1705 // Remove the content, too
1706 var elem_content
= $("CICD-" + ids
[i
]);
1708 Element
.remove(elem_content
);
1716 exception_error("dismissReadArticles", e
);
1720 function getVisibleArticleIds() {
1725 getLoadedArticleIds().each(function(id
) {
1726 var elem
= $("RROW-" + id
);
1727 if (elem
&& Element
.visible(elem
))
1732 exception_error("getVisibleArticleIds", e
);
1738 function cdmClicked(event
, id
) {
1740 //var shift_key = event.shiftKey;
1742 if (!event
.ctrlKey
) {
1744 if (!getInitParam("cdm_expanded")) {
1745 return cdmExpandArticle(id
);
1748 var elem
= $("RROW-" + getActiveArticleId());
1750 if (elem
) elem
.removeClassName("active");
1752 selectArticles("none");
1755 var elem
= $("RROW-" + id
);
1756 var article_is_unread
= elem
.hasClassName("Unread");
1758 elem
.removeClassName("Unread");
1759 elem
.addClassName("active");
1761 setActiveArticleId(id
);
1763 if (article_is_unread
) {
1764 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1765 updateFloatingTitle(true);
1768 var query
= "?op=rpc&method=catchupSelected" +
1769 "&cmode=0&ids=" + param_escape(id
);
1771 new Ajax
.Request("backend.php", {
1773 onComplete: function(transport
) {
1774 handle_rpc_json(transport
);
1777 return !event
.shiftKey
;
1780 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1782 toggleSelected(id
, true);
1784 var elem
= $("RROW-" + id
);
1785 var article_is_unread
= elem
.hasClassName("Unread");
1787 if (article_is_unread
) {
1788 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1791 toggleUnread(id
, 0, false);
1793 openArticleInNewWindow(id
);
1796 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1797 request_counters(unread_in_buffer
== 0);
1800 exception_error("cdmClicked");
1806 function hlClicked(event
, id
) {
1808 if (event
.which
== 2) {
1811 } else if (event
.ctrlKey
) {
1812 toggleSelected(id
, true);
1813 toggleUnread(id
, 0, false);
1814 openArticleInNewWindow(id
);
1822 exception_error("hlClicked");
1826 function getFirstVisibleHeadlineId() {
1827 var rows
= getVisibleArticleIds();
1832 function getLastVisibleHeadlineId() {
1833 var rows
= getVisibleArticleIds();
1834 return rows
[rows
.length
-1];
1837 function openArticleInNewWindow(id
) {
1838 toggleUnread(id
, 0, false);
1839 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1842 function isCdmMode() {
1843 return getInitParam("combined_display_mode");
1846 function markHeadline(id
, marked
) {
1847 if (marked
== undefined) marked
= true;
1849 var row
= $("RROW-" + id
);
1851 var check
= dijit
.getEnclosingWidget(
1852 row
.getElementsByClassName("rchk")[0]);
1855 check
.attr("checked", marked
);
1859 row
.addClassName("Selected");
1861 row
.removeClassName("Selected");
1865 function getRelativePostIds(id
, limit
) {
1871 if (!limit
) limit
= 6; //3
1873 var ids
= getVisibleArticleIds();
1875 for (var i
= 0; i
< ids
.length
; i
++) {
1877 for (var k
= 1; k
<= limit
; k
++) {
1878 //if (i > k-1) tmp.push(ids[i-k]);
1879 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1886 exception_error("getRelativePostIds", e
);
1892 function correctHeadlinesOffset(id
) {
1896 var container
= $("headlines-frame");
1897 var row
= $("RROW-" + id
);
1899 if (!container
|| !row
) return;
1901 var viewport
= container
.offsetHeight
;
1903 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1904 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1906 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1907 //console.log("Vport: " + viewport);
1909 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1910 container
.scrollTop
= row
.offsetTop
;
1911 } else if (rel_offset_bottom
> viewport
) {
1913 /* doesn't properly work with Opera in some cases because
1914 Opera fucks up element scrolling */
1916 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1920 exception_error("correctHeadlinesOffset", e
);
1925 function headlineActionsChange(elem
) {
1928 elem
.attr('value', 'false');
1930 exception_error("headlineActionsChange", e
);
1934 function closeArticlePanel() {
1936 if (dijit
.byId("content-insert"))
1937 dijit
.byId("headlines-wrap-inner").removeChild(
1938 dijit
.byId("content-insert"));
1941 function initFloatingMenu() {
1943 if (dijit
.byId("floatingMenu"))
1944 dijit
.byId("floatingMenu").destroyRecursive();
1946 var menu
= new dijit
.Menu({
1948 targetNodeIds
: ["floatingTitle"]
1951 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1953 headlinesMenuCommon(menu
, id
);
1957 exception_error("initFloatingMenu", e
);
1961 function headlinesMenuCommon(menu
, base_id
) {
1964 menu
.addChild(new dijit
.MenuItem({
1965 label
: __("Open original article"),
1966 onClick: function(event
) {
1967 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1970 menu
.addChild(new dijit
.MenuItem({
1971 label
: __("Display article URL"),
1972 onClick: function(event
) {
1973 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1976 menu
.addChild(new dijit
.MenuSeparator());
1978 menu
.addChild(new dijit
.MenuItem({
1979 label
: __("Toggle unread"),
1980 onClick: function(event
) {
1981 var ids
= getSelectedArticleIds2();
1983 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1984 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1986 selectionToggleUnread(undefined, false, true, ids
);
1989 menu
.addChild(new dijit
.MenuItem({
1990 label
: __("Toggle starred"),
1991 onClick: function(event
) {
1992 var ids
= getSelectedArticleIds2();
1994 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1995 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1997 selectionToggleMarked(undefined, false, true, ids
);
2000 menu
.addChild(new dijit
.MenuItem({
2001 label
: __("Toggle published"),
2002 onClick: function(event
) {
2003 var ids
= getSelectedArticleIds2();
2005 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2006 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2008 selectionTogglePublished(undefined, false, true, ids
);
2011 menu
.addChild(new dijit
.MenuSeparator());
2013 menu
.addChild(new dijit
.MenuItem({
2014 label
: __("Mark above as read"),
2015 onClick: function(event
) {
2016 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2019 menu
.addChild(new dijit
.MenuItem({
2020 label
: __("Mark below as read"),
2021 onClick: function(event
) {
2022 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2026 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2030 menu
.addChild(new dijit
.MenuSeparator());
2032 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2033 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2035 labels
.each(function(label
) {
2036 var id
= label
.id
[0];
2037 var bare_id
= id
.substr(id
.indexOf(":")+1);
2038 var name
= label
.name
[0];
2040 bare_id
= feed_to_label_id(bare_id
);
2042 labelAddMenu
.addChild(new dijit
.MenuItem({
2045 onClick: function(event
) {
2046 var ids
= getSelectedArticleIds2();
2048 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2050 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2052 selectionAssignLabel(this.labelId
, ids
);
2055 labelDelMenu
.addChild(new dijit
.MenuItem({
2058 onClick: function(event
) {
2059 var ids
= getSelectedArticleIds2();
2061 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2063 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2065 selectionRemoveLabel(this.labelId
, ids
);
2070 menu
.addChild(new dijit
.PopupMenuItem({
2071 label
: __("Assign label"),
2072 popup
: labelAddMenu
,
2075 menu
.addChild(new dijit
.PopupMenuItem({
2076 label
: __("Remove label"),
2077 popup
: labelDelMenu
,
2084 exception_error("headlinesMenuCommon", e
);
2088 function initHeadlinesMenu() {
2090 if (dijit
.byId("headlinesMenu"))
2091 dijit
.byId("headlinesMenu").destroyRecursive();
2096 nodes
= $$("#headlines-frame > div[id*=RROW]");
2098 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2101 nodes
.each(function(node
) {
2105 var menu
= new dijit
.Menu({
2106 id
: "headlinesMenu",
2110 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2111 var callerNode
= event
.target
, match
= null, tries
= 0;
2113 while (match
== null && callerNode
&& tries
<= 3) {
2114 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2115 callerNode
= callerNode
.parentNode
;
2119 if (match
) this.callerRowId
= parseInt(match
[1]);
2123 headlinesMenuCommon(menu
, false);
2127 /* vgroup feed title menu */
2129 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2132 nodes
.each(function(node
) {
2136 if (ids
.length
> 0) {
2137 if (dijit
.byId("headlinesFeedTitleMenu"))
2138 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2140 var menu
= new dijit
.Menu({
2141 id
: "headlinesFeedTitleMenu",
2145 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2146 var callerNode
= event
.target
, match
= null, tries
= 0;
2148 while (match
== null && callerNode
&& tries
<= 3) {
2149 console
.log(callerNode
.id
);
2151 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2152 callerNode
= callerNode
.parentNode
;
2155 console
.log(match
[1]);
2158 if (match
) this.callerRowId
= parseInt(match
[1]);
2162 menu
.addChild(new dijit
.MenuItem({
2163 label
: __("Select articles in group"),
2164 onClick: function(event
) {
2165 selectArticles("all",
2166 "#headlines-frame > div[id*=RROW]"+
2167 "[orig-feed-id='"+menu
.callerRowId
+"']");
2171 menu
.addChild(new dijit
.MenuItem({
2172 label
: __("Mark group as read"),
2173 onClick: function(event
) {
2174 selectArticles("none");
2175 selectArticles("all",
2176 "#headlines-frame > div[id*=RROW]"+
2177 "[orig-feed-id='"+menu
.callerRowId
+"']");
2183 menu
.addChild(new dijit
.MenuItem({
2184 label
: __("Mark feed as read"),
2185 onClick: function(event
) {
2186 catchupFeedInGroup(menu
.callerRowId
);
2194 exception_error("initHeadlinesMenu", e
);
2198 function cache_set(id
, obj
) {
2199 //console.log("cache_set: " + id);
2202 sessionStorage
[id
] = obj
;
2204 sessionStorage
.clear();
2208 function cache_get(id
) {
2210 return sessionStorage
[id
];
2213 function cache_clear() {
2215 sessionStorage
.clear();
2218 function cache_delete(id
) {
2220 sessionStorage
.removeItem(id
);
2223 function cancelSearch() {
2228 exception_error("cancelSearch", e
);
2232 function setSelectionScore() {
2234 var ids
= getSelectedArticleIds2();
2236 if (ids
.length
> 0) {
2239 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2241 if (score
!= undefined) {
2242 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2243 "&score=" + param_escape(score
);
2245 new Ajax
.Request("backend.php", {
2247 onComplete: function(transport
) {
2248 var reply
= JSON
.parse(transport
.responseText
);
2252 ids
.each(function(id
) {
2253 var row
= $("RROW-" + id
);
2256 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2259 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2260 reply
["score_pic"]);
2261 pic
.setAttribute("score", score
);
2270 alert(__("No articles are selected."));
2273 exception_error("setSelectionScore", e
);
2277 function changeScore(id
, pic
) {
2279 var score
= pic
.getAttribute("score");
2281 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2283 if (new_score
!= undefined) {
2285 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2286 "&score=" + param_escape(new_score
);
2288 new Ajax
.Request("backend.php", {
2290 onComplete: function(transport
) {
2291 var reply
= JSON
.parse(transport
.responseText
);
2294 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2295 pic
.setAttribute("score", new_score
);
2300 exception_error("changeScore", e
);
2304 function displayArticleUrl(id
) {
2306 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2308 new Ajax
.Request("backend.php", {
2310 onComplete: function(transport
) {
2311 var reply
= JSON
.parse(transport
.responseText
);
2313 if (reply
&& reply
.link
) {
2314 prompt(__("Article URL:"), reply
.link
);
2318 exception_error("changeScore", e
);
2322 function openSelectedAttachment(elem
) {
2324 var url
= elem
[elem
.selectedIndex
].value
;
2328 elem
.selectedIndex
= 0;
2332 exception_error("openSelectedAttachment", e
);
2336 function scrollToRowId(id
) {
2341 $("headlines-frame").scrollTop
= row
.offsetTop
;
2344 exception_error("scrollToRowId", e
);
2348 function updateFloatingTitle(unread_only
) {
2350 if (!isCdmMode()) return;
2352 var hf
= $("headlines-frame");
2354 var elems
= $$("#headlines-frame > div[id*=RROW]");
2356 for (var i
= 0; i
< elems
.length
; i
++) {
2358 var child
= elems
[i
];
2360 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2362 var header
= child
.getElementsByClassName("cdmHeader")[0];
2364 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2365 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2366 $("floatingTitle").setAttribute("rowid", child
.id
);
2367 $("floatingTitle").innerHTML
= header
.innerHTML
;
2368 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2372 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2375 cb
.parentNode
.removeChild(cb
);
2378 if (child
.hasClassName("Unread"))
2379 $("floatingTitle").addClassName("Unread");
2381 $("floatingTitle").removeClassName("Unread");
2383 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2386 if (child
.offsetTop
< hf
.scrollTop
- header
.offsetHeight
&&
2387 child
.offsetTop
+ child
.offsetHeight
- hf
.scrollTop
> header
.offsetHeight
)
2388 Element
.show("floatingTitle");
2390 Element
.hide("floatingTitle");
2398 exception_error("updateFloatingTitle", e
);