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_first_id
= 0;
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
!= -7 && (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 current_first_id
= reply
['headlines']['first_id'];
82 var counters
= reply
['counters'];
83 var articles
= reply
['articles'];
84 //var runtime_info = reply['runtime-info'];
86 if (infscroll_req
== false) {
87 loaded_article_ids
= [];
89 dojo
.html
.set($("headlines-toolbar"),
90 reply
['headlines']['toolbar'],
91 {parseContent
: true});
93 dojo
.html
.set($("headlines-frame"),
94 reply
['headlines']['content'],
95 {parseContent
: true});
97 $$("#headlines-frame div[id*='RROW']").each(function(row
) {
98 loaded_article_ids
.push(row
.id
);
101 var hsp
= $("headlines-spacer");
102 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
103 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
107 if (_infscroll_disable
)
108 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
109 __("Click to open next unread feed.") + "</a>";
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();
125 var hsp
= $("headlines-spacer");
128 c
.domNode
.removeChild(hsp
);
130 var tmp
= new Element("div");
131 tmp
.innerHTML
= reply
['headlines']['content'];
132 dojo
.parser
.parse(tmp
);
134 while (tmp
.hasChildNodes()) {
135 var row
= tmp
.removeChild(tmp
.firstChild
);
137 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
138 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
140 new Effect
.Appear(row
, {duration
:0.5});
141 loaded_article_ids
.push(row
.id
);
145 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
146 c
.domNode
.appendChild(hsp
);
148 if (headlines_count
< 30) _infscroll_disable
= true;
150 console
.log("restore selected ids: " + ids
);
152 for (var i
= 0; i
< ids
.length
; i
++) {
153 markHeadline(ids
[i
]);
158 if (_infscroll_disable
) {
159 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
160 __("Click to open next unread feed.") + "</a>";
164 console
.log("no new headlines received");
166 var first_id_changed
= reply
['headlines']['first_id_changed'];
167 console
.log("first id changed:" + first_id_changed
);
169 var hsp
= $("headlines-spacer");
172 if (first_id_changed
) {
173 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
174 __("New articles found, reload feed to continue.") + "</a>";
176 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
177 __("Click to open next unread feed.") + "</a>";
186 for (var i
= 0; i
< articles
.length
; i
++) {
187 var a_id
= articles
[i
]['id'];
188 cache_set("article:" + a_id
, articles
[i
]['content']);
191 console
.log("no cached articles received");
195 parse_counters(counters
);
197 request_counters(true);
200 console
.error("Invalid object received: " + transport
.responseText
);
201 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
202 __('Could not update headlines (invalid object received - see error console for details)') +
206 _infscroll_request_sent
= 0;
207 _last_headlines_update
= new Date().getTime();
209 unpackVisibleHeadlines();
211 // if we have some more space in the buffer, why not try to fill it
213 if (!_infscroll_disable
&& $("headlines-spacer") &&
214 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
216 window
.setTimeout(function() {
224 exception_error("headlines_callback2", e
, transport
);
228 function render_article(article
) {
230 dijit
.byId("headlines-wrap-inner").addChild(
231 dijit
.byId("content-insert"));
233 var c
= dijit
.byId("content-insert");
236 c
.domNode
.scrollTop
= 0;
239 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
241 c
.attr('content', article
);
243 correctHeadlinesOffset(getActiveArticleId());
250 exception_error("render_article", e
);
254 function showArticleInHeadlines(id
, noexpand
) {
257 selectArticles("none");
259 var crow
= $("RROW-" + id
);
263 var article_is_unread
= crow
.hasClassName("Unread");
266 crow
.removeClassName("Unread");
267 crow
.addClassName("active");
269 selectArticles('none');
271 var view_mode
= false;
274 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
275 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
282 if (article_is_unread
&& !noexpand
)
283 _force_scheduled_update
= true;
286 exception_error("showArticleInHeadlines", e
);
290 function article_callback2(transport
, id
) {
292 console
.log("article_callback2 " + id
);
294 handle_rpc_json(transport
);
299 reply
= JSON
.parse(transport
.responseText
);
306 reply
.each(function(article
) {
307 if (getActiveArticleId() == article
['id']) {
308 render_article(article
['content']);
310 cids_requested
.remove(article
['id']);
312 cache_set("article:" + article
['id'], article
['content']);
315 // if (id != last_requested_article) {
316 // console.log("requested article id is out of sequence, aborting");
321 console
.error("Invalid object received: " + transport
.responseText
);
323 render_article("<div class='whiteBox'>" +
324 __('Could not display article (invalid object received - see error console for details)') + "</div>");
327 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
328 request_counters(unread_in_buffer
== 0);
332 exception_error("article_callback2", e
, transport
);
336 function view(id
, activefeed
, noexpand
) {
338 var oldrow
= $("RROW-" + getActiveArticleId());
339 if (oldrow
) oldrow
.removeClassName("active");
341 var crow
= $("RROW-" + id
);
345 setActiveArticleId(id
);
346 showArticleInHeadlines(id
, noexpand
);
350 console
.log("loading article: " + id
);
352 var cached_article
= cache_get("article:" + id
);
354 console
.log("cache check result: " + (cached_article
!= false));
356 var query
= "?op=article&method=view&id=" + param_escape(id
);
358 var neighbor_ids
= getRelativePostIds(id
);
360 /* only request uncached articles */
362 var cids_to_request
= [];
364 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
365 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
366 if (!cache_get("article:" + neighbor_ids
[i
])) {
367 cids_to_request
.push(neighbor_ids
[i
]);
368 cids_requested
.push(neighbor_ids
[i
]);
372 console
.log("additional ids: " + cids_to_request
.toString());
374 query
= query
+ "&cids=" + cids_to_request
.toString();
376 var article_is_unread
= crow
.hasClassName("Unread");
378 setActiveArticleId(id
);
379 showArticleInHeadlines(id
);
381 if (cached_article
&& article_is_unread
) {
383 query
= query
+ "&mode=prefetch";
385 render_article(cached_article
);
387 } else if (cached_article
) {
389 query
= query
+ "&mode=prefetch_old";
390 render_article(cached_article
);
392 // if we don't need to request any relative ids, we might as well skip
393 // the server roundtrip altogether
394 if (cids_to_request
.length
== 0) {
399 last_requested_article
= id
;
403 if (article_is_unread
) {
404 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
407 new Ajax
.Request("backend.php", {
409 onComplete: function(transport
) {
410 article_callback2(transport
, id
);
416 exception_error("view", e
);
420 function toggleMark(id
, client_only
) {
422 var query
= "?op=rpc&id=" + id
+ "&method=mark";
424 var row
= $("RROW-" + id
);
429 var row_imgs
= row
.getElementsByClassName("markedPic");
431 for (var i
= 0; i
< row_imgs
.length
; i
++)
432 imgs
.push(row_imgs
[i
]);
434 var ft
= $("floatingTitle");
436 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
437 var fte
= ft
.getElementsByClassName("markedPic");
439 for (var i
= 0; i
< fte
.length
; i
++)
443 for (i
= 0; i
< imgs
.length
; i
++) {
446 if (!row
.hasClassName("marked")) {
447 img
.src
= img
.src
.replace("mark_unset", "mark_set");
448 img
.alt
= __("Unstar article");
449 query
= query
+ "&mark=1";
451 img
.src
= img
.src
.replace("mark_set", "mark_unset");
452 img
.alt
= __("Star article");
453 query
= query
+ "&mark=0";
457 row
.toggleClassName("marked");
460 new Ajax
.Request("backend.php", {
462 onComplete: function(transport
) {
463 handle_rpc_json(transport
);
468 exception_error("toggleMark", e
);
472 function togglePub(id
, client_only
, no_effects
, note
) {
474 var query
= "?op=rpc&id=" + id
+ "&method=publ";
476 if (note
!= undefined) {
477 query
= query
+ "¬e=" + param_escape(note
);
479 query
= query
+ "¬e=undefined";
482 var row
= $("RROW-" + id
);
487 var row_imgs
= row
.getElementsByClassName("pubPic");
489 for (var i
= 0; i
< row_imgs
.length
; i
++)
490 imgs
.push(row_imgs
[i
]);
492 var ft
= $("floatingTitle");
494 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
495 var fte
= ft
.getElementsByClassName("pubPic");
497 for (var i
= 0; i
< fte
.length
; i
++)
501 for (i
= 0; i
< imgs
.length
; i
++) {
504 if (!row
.hasClassName("published") || note
!= undefined) {
505 img
.src
= img
.src
.replace("pub_unset", "pub_set");
506 img
.alt
= __("Unpublish article");
507 query
= query
+ "&pub=1";
509 img
.src
= img
.src
.replace("pub_set", "pub_unset");
510 img
.alt
= __("Publish article");
511 query
= query
+ "&pub=0";
515 if (note
!= undefined)
516 row
.addClassName("published");
518 row
.toggleClassName("published");
521 new Ajax
.Request("backend.php", {
523 onComplete: function(transport
) {
524 handle_rpc_json(transport
);
529 exception_error("togglePub", e
);
533 function moveToPost(mode
, noscroll
, noexpand
) {
537 var rows
= getVisibleArticleIds();
542 if (!$('RROW-' + getActiveArticleId())) {
543 setActiveArticleId(0);
546 if (!getActiveArticleId()) {
548 prev_id
= rows
[rows
.length
-1]
550 for (var i
= 0; i
< rows
.length
; i
++) {
551 if (rows
[i
] == getActiveArticleId()) {
553 // Account for adjacent identical article ids.
554 if (i
> 0) prev_id
= rows
[i
-1];
556 for (var j
= i
+1; j
< rows
.length
; j
++) {
557 if (rows
[j
] != getActiveArticleId()) {
567 if (mode
== "next") {
568 if (next_id
|| getActiveArticleId()) {
571 var article
= $("RROW-" + getActiveArticleId());
572 var ctr
= $("headlines-frame");
574 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
575 ctr
.scrollTop
+ ctr
.offsetHeight
) {
577 scrollArticle(ctr
.offsetHeight
/4);
579 } else if (next_id
) {
580 cdmExpandArticle(next_id
, noexpand
);
581 cdmScrollToArticleId(next_id
, true);
584 } else if (next_id
) {
585 correctHeadlinesOffset(next_id
);
586 view(next_id
, getActiveFeedId(), noexpand
);
591 if (mode
== "prev") {
592 if (prev_id
|| getActiveArticleId()) {
595 var article
= $("RROW-" + getActiveArticleId());
596 var prev_article
= $("RROW-" + prev_id
);
597 var ctr
= $("headlines-frame");
599 if (!getInitParam("cdm_expanded")) {
601 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
602 scrollArticle(-ctr
.offsetHeight
/4);
604 cdmExpandArticle(prev_id
, noexpand
);
605 cdmScrollToArticleId(prev_id
, true);
609 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
610 scrollArticle(-ctr
.offsetHeight
/3);
611 } else if (!noscroll
&& prev_article
&&
612 prev_article
.offsetTop
< ctr
.scrollTop
) {
613 cdmExpandArticle(prev_id
, noexpand
);
614 scrollArticle(-ctr
.offsetHeight
/4);
615 } else if (prev_id
) {
616 cdmExpandArticle(prev_id
, noexpand
);
617 cdmScrollToArticleId(prev_id
, noscroll
);
621 } else if (prev_id
) {
622 correctHeadlinesOffset(prev_id
);
623 view(prev_id
, getActiveFeedId(), noexpand
);
629 exception_error("moveToPost", e
);
633 function toggleSelected(id
, force_on
) {
635 var row
= $("RROW-" + id
);
638 var cb
= dijit
.getEnclosingWidget(
639 row
.getElementsByClassName("rchk")[0]);
641 if (row
.hasClassName('Selected') && !force_on
) {
642 row
.removeClassName('Selected');
643 if (cb
) cb
.attr("checked", false);
645 row
.addClassName('Selected');
646 if (cb
) cb
.attr("checked", true);
650 updateSelectedPrompt();
652 exception_error("toggleSelected", e
);
656 function updateSelectedPrompt() {
658 var count
= getSelectedArticleIds2().size();
659 var elem
= $("selected_prompt");
662 elem
.innerHTML
= ngettext("%d article selected",
663 "%d articles selected", count
).replace("%d", count
);
672 exception_error("updateSelectedPrompt", e
);
676 function toggleUnread_afh(effect
) {
679 var elem
= effect
.element
;
680 elem
.style
.backgroundColor
= "";
683 exception_error("toggleUnread_afh", e
);
687 function toggleUnread(id
, cmode
, effect
) {
690 var row
= $("RROW-" + id
);
692 if (cmode
== undefined || cmode
== 2) {
693 if (row
.hasClassName("Unread")) {
694 row
.removeClassName("Unread");
697 row
.addClassName("Unread");
700 } else if (cmode
== 0) {
702 row
.removeClassName("Unread");
704 } else if (cmode
== 1) {
705 row
.addClassName("Unread");
708 if (cmode
== undefined) cmode
= 2;
710 var query
= "?op=rpc&method=catchupSelected" +
711 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
713 // notify_progress("Loading, please wait...");
715 new Ajax
.Request("backend.php", {
717 onComplete: function(transport
) {
718 handle_rpc_json(transport
);
724 exception_error("toggleUnread", e
);
728 function selectionRemoveLabel(id
, ids
) {
731 if (!ids
) ids
= getSelectedArticleIds2();
733 if (ids
.length
== 0) {
734 alert(__("No articles are selected."));
738 var query
= "?op=article&method=removeFromLabel&ids=" +
739 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
743 new Ajax
.Request("backend.php", {
745 onComplete: function(transport
) {
746 handle_rpc_json(transport
);
747 show_labels_in_headlines(transport
);
751 exception_error("selectionAssignLabel", e
);
756 function selectionAssignLabel(id
, ids
) {
759 if (!ids
) ids
= getSelectedArticleIds2();
761 if (ids
.length
== 0) {
762 alert(__("No articles are selected."));
766 var query
= "?op=article&method=assignToLabel&ids=" +
767 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
771 new Ajax
.Request("backend.php", {
773 onComplete: function(transport
) {
774 handle_rpc_json(transport
);
775 show_labels_in_headlines(transport
);
779 exception_error("selectionAssignLabel", e
);
784 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
786 var rows
= ids
? ids
: getSelectedArticleIds2();
788 if (rows
.length
== 0 && !no_error
) {
789 alert(__("No articles are selected."));
793 for (var i
= 0; i
< rows
.length
; i
++) {
794 var row
= $("RROW-" + rows
[i
]);
796 if (set_state
== undefined) {
797 if (row
.hasClassName("Unread")) {
798 row
.removeClassName("Unread");
800 row
.addClassName("Unread");
804 if (set_state
== false) {
805 row
.removeClassName("Unread");
808 if (set_state
== true) {
809 row
.addClassName("Unread");
814 updateFloatingTitle(true);
816 if (rows
.length
> 0) {
820 if (set_state
== undefined) {
822 } else if (set_state
== true) {
824 } else if (set_state
== false) {
828 var query
= "?op=rpc&method=catchupSelected" +
829 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
831 notify_progress("Loading, please wait...");
833 new Ajax
.Request("backend.php", {
835 onComplete: function(transport
) {
836 handle_rpc_json(transport
);
837 if (callback
) callback(transport
);
843 exception_error("selectionToggleUnread", e
);
848 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
851 var rows
= ids
? ids
: getSelectedArticleIds2();
853 if (rows
.length
== 0 && !no_error
) {
854 alert(__("No articles are selected."));
858 for (var i
= 0; i
< rows
.length
; i
++) {
859 toggleMark(rows
[i
], true, true);
862 if (rows
.length
> 0) {
864 var query
= "?op=rpc&method=markSelected&ids=" +
865 param_escape(rows
.toString()) + "&cmode=2";
867 new Ajax
.Request("backend.php", {
869 onComplete: function(transport
) {
870 handle_rpc_json(transport
);
871 if (callback
) callback(transport
);
877 exception_error("selectionToggleMarked", e
);
882 function selectionTogglePublished(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 togglePub(rows
[i
], true, true);
896 if (rows
.length
> 0) {
898 var query
= "?op=rpc&method=publishSelected&ids=" +
899 param_escape(rows
.toString()) + "&cmode=2";
901 new Ajax
.Request("backend.php", {
903 onComplete: function(transport
) {
904 handle_rpc_json(transport
);
910 exception_error("selectionToggleMarked", e
);
914 function getSelectedArticleIds2() {
918 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
920 rv
.push(child
.id
.replace("RROW-", ""));
926 function getLoadedArticleIds() {
929 var children
= $$("#headlines-frame > div[id*=RROW-]");
931 children
.each(function(child
) {
932 rv
.push(child
.id
.replace("RROW-", ""));
939 // mode = all,none,unread,invert,marked,published
940 function selectArticles(mode
, query
) {
943 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
945 var children
= $$(query
);
947 children
.each(function(child
) {
948 var id
= child
.id
.replace("RROW-", "");
950 var cb
= dijit
.getEnclosingWidget(
951 child
.getElementsByClassName("rchk")[0]);
954 child
.addClassName("Selected");
955 if (cb
) cb
.attr("checked", true);
956 } else if (mode
== "unread") {
957 if (child
.hasClassName("Unread")) {
958 child
.addClassName("Selected");
959 if (cb
) cb
.attr("checked", true);
961 child
.removeClassName("Selected");
962 if (cb
) cb
.attr("checked", false);
964 } else if (mode
== "marked") {
965 if (child
.hasClassName("marked")) {
966 child
.addClassName("Selected");
967 if (cb
) cb
.attr("checked", true);
969 child
.removeClassName("Selected");
970 if (cb
) cb
.attr("checked", false);
972 } else if (mode
== "published") {
973 if (child
.hasClassName("published")) {
974 child
.addClassName("Selected");
975 if (cb
) cb
.attr("checked", true);
977 child
.removeClassName("Selected");
978 if (cb
) cb
.attr("checked", false);
981 } else if (mode
== "invert") {
982 if (child
.hasClassName("Selected")) {
983 child
.removeClassName("Selected");
984 if (cb
) cb
.attr("checked", false);
986 child
.addClassName("Selected");
987 if (cb
) cb
.attr("checked", true);
991 child
.removeClassName("Selected");
992 if (cb
) cb
.attr("checked", false);
996 updateSelectedPrompt();
999 exception_error("selectArticles", e
);
1003 function deleteSelection() {
1007 var rows
= getSelectedArticleIds2();
1009 if (rows
.length
== 0) {
1010 alert(__("No articles are selected."));
1014 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1017 if (getActiveFeedId() != 0) {
1018 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1020 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1023 str
= str
.replace("%d", rows
.length
);
1024 str
= str
.replace("%s", fn
);
1026 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1030 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1034 new Ajax
.Request("backend.php", {
1036 onComplete: function(transport
) {
1037 handle_rpc_json(transport
);
1042 exception_error("deleteSelection", e
);
1046 function archiveSelection() {
1050 var rows
= getSelectedArticleIds2();
1052 if (rows
.length
== 0) {
1053 alert(__("No articles are selected."));
1057 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1061 if (getActiveFeedId() != 0) {
1062 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1065 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1067 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1072 str
= str
.replace("%d", rows
.length
);
1073 str
= str
.replace("%s", fn
);
1075 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1079 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1083 for (var i
= 0; i
< rows
.length
; i
++) {
1084 cache_delete("article:" + rows
[i
]);
1087 new Ajax
.Request("backend.php", {
1089 onComplete: function(transport
) {
1090 handle_rpc_json(transport
);
1095 exception_error("archiveSelection", e
);
1099 function catchupSelection() {
1103 var rows
= getSelectedArticleIds2();
1105 if (rows
.length
== 0) {
1106 alert(__("No articles are selected."));
1110 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1112 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1114 str
= str
.replace("%d", rows
.length
);
1115 str
= str
.replace("%s", fn
);
1117 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1121 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1124 exception_error("catchupSelection", e
);
1128 function editArticleTags(id
) {
1129 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1131 if (dijit
.byId("editTagsDlg"))
1132 dijit
.byId("editTagsDlg").destroyRecursive();
1134 dialog
= new dijit
.Dialog({
1136 title
: __("Edit article Tags"),
1137 style
: "width: 600px",
1138 execute: function() {
1139 if (this.validate()) {
1140 var query
= dojo
.objectToQuery(this.attr('value'));
1142 notify_progress("Saving article tags...", true);
1144 new Ajax
.Request("backend.php", {
1146 onComplete: function(transport
) {
1151 var data
= JSON
.parse(transport
.responseText
);
1158 var tags
= $("ATSTR-" + id
);
1159 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1161 if (tags
) tags
.innerHTML
= data
.content
;
1162 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1165 exception_error("editArticleTags/inner", e
);
1174 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1175 dojo
.disconnect(tmph
);
1177 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1178 "backend.php?op=article&method=completeTags",
1179 { tokens
: ',', paramName
: "search" });
1186 function cdmScrollToArticleId(id
, force
) {
1188 var ctr
= $("headlines-frame");
1189 var e
= $("RROW-" + id
);
1191 if (!e
|| !ctr
) return;
1193 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1194 e
.offsetTop
< ctr
.scrollTop
) {
1196 // expanded cdm has a 4px margin now
1197 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1201 exception_error("cdmScrollToArticleId", e
);
1205 function setActiveArticleId(id
) {
1206 _active_article_id
= id
;
1207 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1210 function getActiveArticleId() {
1211 return _active_article_id
;
1214 function postMouseIn(e
, id
) {
1215 post_under_pointer
= id
;
1218 function postMouseOut(id
) {
1219 post_under_pointer
= false;
1222 function unpackVisibleHeadlines() {
1224 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1226 $$("#headlines-frame > div[id*=RROW]").each(
1228 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1229 $("headlines-frame").offsetHeight
) {
1231 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1234 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1236 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1237 cencw
.setAttribute('id', '');
1238 Element
.show(cencw
);
1245 exception_error("unpackVisibleHeadlines", e
);
1249 function headlines_scroll_handler(e
) {
1251 var hsp
= $("headlines-spacer");
1253 unpackVisibleHeadlines();
1255 // set topmost child in the buffer as active
1256 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1257 getSelectedArticleIds2().length
<= 1 &&
1258 getInitParam("cdm_expanded")) {
1259 var rows
= $$("#headlines-frame > div[id*=RROW]");
1261 for (var i
= 0; i
< rows
.length
; i
++) {
1262 var child
= rows
[i
];
1264 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1265 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1266 child
.id
.replace("RROW-", "") != _active_article_id
) {
1268 if (_active_article_id
) {
1269 var row
= $("RROW-" + _active_article_id
);
1270 if (row
) row
.removeClassName("active");
1273 _active_article_id
= child
.id
.replace("RROW-", "");
1274 showArticleInHeadlines(_active_article_id
, true);
1275 updateSelectedPrompt();
1281 if (!_infscroll_disable
) {
1282 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1283 (e
.scrollHeight
!= 0 &&
1284 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1287 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1288 __("Loading, please wait...") + "</span>";
1290 loadMoreHeadlines();
1296 if (_infscroll_disable)
1297 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1298 __("Click to open next unread feed.") + "</a>";
1305 updateFloatingTitle();
1308 if (getInitParam("cdm_auto_catchup") == 1) {
1310 // let's get DOM some time to settle down
1311 var ts
= new Date().getTime();
1312 if (ts
- _last_headlines_update
< 100) return;
1314 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1316 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1317 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1319 var id
= child
.id
.replace("RROW-", "");
1321 if (catchup_id_batch
.indexOf(id
) == -1)
1322 catchup_id_batch
.push(id
);
1324 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1329 if (catchup_id_batch
.length
> 0) {
1330 window
.clearTimeout(catchup_timeout_id
);
1332 if (!_infscroll_request_sent
) {
1333 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1338 if (_infscroll_disable
) {
1339 var child
= $$("#headlines-frame div[id*=RROW]").last();
1341 if (child
&& $("headlines-frame").scrollTop
>
1342 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1344 console
.log("we seem to be at an end");
1346 if (getInitParam("on_catchup_show_next_feed") == "1") {
1347 openNextUnreadFeed();
1354 console
.warn("headlines_scroll_handler: " + e
);
1358 function openNextUnreadFeed() {
1360 var is_cat
= activeFeedIsCat();
1361 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1362 if (nuf
) viewfeed(nuf
, '', is_cat
);
1364 exception_error("openNextUnreadFeed", e
);
1368 function catchupBatchedArticles() {
1370 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1372 // make a copy of the array
1373 var batch
= catchup_id_batch
.slice();
1374 var query
= "?op=rpc&method=catchupSelected" +
1375 "&cmode=0&ids=" + param_escape(batch
.toString());
1379 new Ajax
.Request("backend.php", {
1381 onComplete: function(transport
) {
1382 handle_rpc_json(transport
);
1384 reply
= JSON
.parse(transport
.responseText
);
1385 var batch
= reply
.ids
;
1387 batch
.each(function(id
) {
1389 var elem
= $("RROW-" + id
);
1390 if (elem
) elem
.removeClassName("Unread");
1391 catchup_id_batch
.remove(id
);
1394 updateFloatingTitle(true);
1400 exception_error("catchupBatchedArticles", e
);
1404 function catchupRelativeToArticle(below
, id
) {
1408 if (!id
) id
= getActiveArticleId();
1411 alert(__("No article is selected."));
1415 var visible_ids
= getVisibleArticleIds();
1417 var ids_to_mark
= new Array();
1420 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1421 if (visible_ids
[i
] != id
) {
1422 var e
= $("RROW-" + visible_ids
[i
]);
1424 if (e
&& e
.hasClassName("Unread")) {
1425 ids_to_mark
.push(visible_ids
[i
]);
1432 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1433 if (visible_ids
[i
] != id
) {
1434 var e
= $("RROW-" + visible_ids
[i
]);
1436 if (e
&& e
.hasClassName("Unread")) {
1437 ids_to_mark
.push(visible_ids
[i
]);
1445 if (ids_to_mark
.length
== 0) {
1446 alert(__("No articles found to mark"));
1448 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1450 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1452 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1453 var e
= $("RROW-" + ids_to_mark
[i
]);
1454 e
.removeClassName("Unread");
1457 var query
= "?op=rpc&method=catchupSelected" +
1458 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1460 new Ajax
.Request("backend.php", {
1462 onComplete: function(transport
) {
1463 handle_rpc_json(transport
);
1470 exception_error("catchupRelativeToArticle", e
);
1474 function cdmCollapseArticle(event
, id
, unmark
) {
1476 if (unmark
== undefined) unmark
= true;
1478 var row
= $("RROW-" + id
);
1479 var elem
= $("CICD-" + id
);
1482 var collapse
= $$("div#RROW-" + id
+
1483 " span[class='collapseBtn']")[0];
1486 Element
.show("CEXC-" + id
);
1487 Element
.hide(collapse
);
1490 row
.removeClassName("active");
1492 markHeadline(id
, false);
1494 if (id
== getActiveArticleId()) {
1495 setActiveArticleId(0);
1498 updateSelectedPrompt();
1501 if (event
) Event
.stop(event
);
1503 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1505 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1506 scrollToRowId(row
.id
);
1508 $("floatingTitle").style
.visibility
= "hidden";
1509 $("floatingTitle").setAttribute("rowid", false);
1513 exception_error("cdmCollapseArticle", e
);
1517 function cdmExpandArticle(id
, noexpand
) {
1519 console
.log("cdmExpandArticle " + id
);
1521 if (!$("RROW-" + id
)) return false;
1523 var oldrow
= $("RROW-" + getActiveArticleId());
1525 var elem
= $("CICD-" + getActiveArticleId());
1527 if (id
== getActiveArticleId() && Element
.visible(elem
))
1530 selectArticles("none");
1532 var old_offset
= $("RROW-" + id
).offsetTop
;
1534 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1535 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1536 " span[class='collapseBtn']")[0];
1539 Element
.show("CEXC-" + getActiveArticleId());
1540 Element
.hide(collapse
);
1543 if (oldrow
) oldrow
.removeClassName("active");
1545 setActiveArticleId(id
);
1547 elem
= $("CICD-" + id
);
1549 var collapse
= $$("div#RROW-" + id
+
1550 " span[class='collapseBtn']")[0];
1552 var cencw
= $("CENCW-" + id
);
1554 if (!Element
.visible(elem
) && !noexpand
) {
1556 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1557 cencw
.setAttribute('id', '');
1558 Element
.show(cencw
);
1562 Element
.hide("CEXC-" + id
);
1563 Element
.show(collapse
);
1566 var new_offset
= $("RROW-" + id
).offsetTop
;
1568 if (old_offset
> new_offset
)
1569 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1572 toggleUnread(id
, 0, true);
1574 $("RROW-" + id
).addClassName("active");
1576 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1579 exception_error("cdmExpandArticle", e
);
1585 function getArticleUnderPointer() {
1586 return post_under_pointer
;
1589 function scrollArticle(offset
) {
1592 var ci
= $("content-insert");
1594 ci
.scrollTop
+= offset
;
1597 var hi
= $("headlines-frame");
1599 hi
.scrollTop
+= offset
;
1604 exception_error("scrollArticle", e
);
1608 function show_labels_in_headlines(transport
) {
1610 var data
= JSON
.parse(transport
.responseText
);
1613 data
['info-for-headlines'].each(function(elem
) {
1614 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1615 ctr
.innerHTML
= elem
.labels
;
1620 exception_error("show_labels_in_headlines", e
);
1624 function dismissArticle(id
) {
1626 var elem
= $("RROW-" + id
);
1630 toggleUnread(id
, 0, true);
1632 new Effect
.Fade(elem
, {duration
: 0.5});
1634 // Remove the content, too
1635 var elem_content
= $("CICD-" + id
);
1637 Element
.remove(elem_content
);
1640 if (id
== getActiveArticleId()) {
1641 setActiveArticleId(0);
1645 exception_error("dismissArticle", e
);
1649 function dismissSelectedArticles() {
1652 var ids
= getVisibleArticleIds();
1656 for (var i
= 0; i
< ids
.length
; i
++) {
1657 var elem
= $("RROW-" + ids
[i
]);
1659 if (elem
.className
&& elem
.hasClassName("Selected") &&
1660 ids
[i
] != getActiveArticleId()) {
1661 new Effect
.Fade(elem
, {duration
: 0.5});
1664 // Remove the content, too
1665 var elem_content
= $("CICD-" + ids
[i
]);
1667 Element
.remove(elem_content
);
1675 selectionToggleUnread(false);
1679 exception_error("dismissSelectedArticles", e
);
1683 function dismissReadArticles() {
1686 var ids
= getVisibleArticleIds();
1689 for (var i
= 0; i
< ids
.length
; i
++) {
1690 var elem
= $("RROW-" + ids
[i
]);
1692 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1693 !elem
.hasClassName("Selected")) {
1695 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 exception_error("dismissReadArticles", e
);
1712 function getVisibleArticleIds() {
1717 getLoadedArticleIds().each(function(id
) {
1718 var elem
= $("RROW-" + id
);
1719 if (elem
&& Element
.visible(elem
))
1724 exception_error("getVisibleArticleIds", e
);
1730 function cdmClicked(event
, id
) {
1732 //var shift_key = event.shiftKey;
1734 if (!event
.ctrlKey
) {
1736 if (!getInitParam("cdm_expanded")) {
1737 return cdmExpandArticle(id
);
1740 var elem
= $("RROW-" + getActiveArticleId());
1742 if (elem
) elem
.removeClassName("active");
1744 selectArticles("none");
1747 var elem
= $("RROW-" + id
);
1748 var article_is_unread
= elem
.hasClassName("Unread");
1750 elem
.removeClassName("Unread");
1751 elem
.addClassName("active");
1753 setActiveArticleId(id
);
1755 if (article_is_unread
) {
1756 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1757 updateFloatingTitle(true);
1760 var query
= "?op=rpc&method=catchupSelected" +
1761 "&cmode=0&ids=" + param_escape(id
);
1763 new Ajax
.Request("backend.php", {
1765 onComplete: function(transport
) {
1766 handle_rpc_json(transport
);
1769 return !event
.shiftKey
;
1772 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1774 toggleSelected(id
, true);
1776 var elem
= $("RROW-" + id
);
1777 var article_is_unread
= elem
.hasClassName("Unread");
1779 if (article_is_unread
) {
1780 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1783 toggleUnread(id
, 0, false);
1785 openArticleInNewWindow(id
);
1788 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1789 request_counters(unread_in_buffer
== 0);
1792 exception_error("cdmClicked");
1798 function hlClicked(event
, id
) {
1800 if (event
.which
== 2) {
1803 } else if (event
.ctrlKey
) {
1804 toggleSelected(id
, true);
1805 toggleUnread(id
, 0, false);
1806 openArticleInNewWindow(id
);
1814 exception_error("hlClicked");
1818 function getFirstVisibleHeadlineId() {
1819 var rows
= getVisibleArticleIds();
1824 function getLastVisibleHeadlineId() {
1825 var rows
= getVisibleArticleIds();
1826 return rows
[rows
.length
-1];
1829 function openArticleInNewWindow(id
) {
1830 toggleUnread(id
, 0, false);
1831 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1834 function isCdmMode() {
1835 return getInitParam("combined_display_mode");
1838 function markHeadline(id
, marked
) {
1839 if (marked
== undefined) marked
= true;
1841 var row
= $("RROW-" + id
);
1843 var check
= dijit
.getEnclosingWidget(
1844 row
.getElementsByClassName("rchk")[0]);
1847 check
.attr("checked", marked
);
1851 row
.addClassName("Selected");
1853 row
.removeClassName("Selected");
1857 function getRelativePostIds(id
, limit
) {
1863 if (!limit
) limit
= 6; //3
1865 var ids
= getVisibleArticleIds();
1867 for (var i
= 0; i
< ids
.length
; i
++) {
1869 for (var k
= 1; k
<= limit
; k
++) {
1870 //if (i > k-1) tmp.push(ids[i-k]);
1871 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1878 exception_error("getRelativePostIds", e
);
1884 function correctHeadlinesOffset(id
) {
1888 var container
= $("headlines-frame");
1889 var row
= $("RROW-" + id
);
1891 if (!container
|| !row
) return;
1893 var viewport
= container
.offsetHeight
;
1895 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1896 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1898 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1899 //console.log("Vport: " + viewport);
1901 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1902 container
.scrollTop
= row
.offsetTop
;
1903 } else if (rel_offset_bottom
> viewport
) {
1905 /* doesn't properly work with Opera in some cases because
1906 Opera fucks up element scrolling */
1908 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1912 exception_error("correctHeadlinesOffset", e
);
1917 function headlineActionsChange(elem
) {
1920 elem
.attr('value', 'false');
1922 exception_error("headlineActionsChange", e
);
1926 function closeArticlePanel() {
1928 if (dijit
.byId("content-insert"))
1929 dijit
.byId("headlines-wrap-inner").removeChild(
1930 dijit
.byId("content-insert"));
1933 function initFloatingMenu() {
1935 if (dijit
.byId("floatingMenu"))
1936 dijit
.byId("floatingMenu").destroyRecursive();
1938 var menu
= new dijit
.Menu({
1940 targetNodeIds
: ["floatingTitle"]
1943 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1945 headlinesMenuCommon(menu
, id
);
1949 exception_error("initFloatingMenu", e
);
1953 function headlinesMenuCommon(menu
, base_id
) {
1956 menu
.addChild(new dijit
.MenuItem({
1957 label
: __("Open original article"),
1958 onClick: function(event
) {
1959 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1962 menu
.addChild(new dijit
.MenuItem({
1963 label
: __("Display article URL"),
1964 onClick: function(event
) {
1965 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1968 menu
.addChild(new dijit
.MenuSeparator());
1970 menu
.addChild(new dijit
.MenuItem({
1971 label
: __("Toggle unread"),
1972 onClick: function(event
) {
1973 var ids
= getSelectedArticleIds2();
1975 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1976 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1978 selectionToggleUnread(undefined, false, true, ids
);
1981 menu
.addChild(new dijit
.MenuItem({
1982 label
: __("Toggle starred"),
1983 onClick: function(event
) {
1984 var ids
= getSelectedArticleIds2();
1986 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1987 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1989 selectionToggleMarked(undefined, false, true, ids
);
1992 menu
.addChild(new dijit
.MenuItem({
1993 label
: __("Toggle published"),
1994 onClick: function(event
) {
1995 var ids
= getSelectedArticleIds2();
1997 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1998 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2000 selectionTogglePublished(undefined, false, true, ids
);
2003 menu
.addChild(new dijit
.MenuSeparator());
2005 menu
.addChild(new dijit
.MenuItem({
2006 label
: __("Mark above as read"),
2007 onClick: function(event
) {
2008 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2011 menu
.addChild(new dijit
.MenuItem({
2012 label
: __("Mark below as read"),
2013 onClick: function(event
) {
2014 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2018 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2022 menu
.addChild(new dijit
.MenuSeparator());
2024 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2025 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2027 labels
.each(function(label
) {
2028 var id
= label
.id
[0];
2029 var bare_id
= id
.substr(id
.indexOf(":")+1);
2030 var name
= label
.name
[0];
2032 bare_id
= feed_to_label_id(bare_id
);
2034 labelAddMenu
.addChild(new dijit
.MenuItem({
2037 onClick: function(event
) {
2038 var ids
= getSelectedArticleIds2();
2040 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2042 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2044 selectionAssignLabel(this.labelId
, ids
);
2047 labelDelMenu
.addChild(new dijit
.MenuItem({
2050 onClick: function(event
) {
2051 var ids
= getSelectedArticleIds2();
2053 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2055 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2057 selectionRemoveLabel(this.labelId
, ids
);
2062 menu
.addChild(new dijit
.PopupMenuItem({
2063 label
: __("Assign label"),
2067 menu
.addChild(new dijit
.PopupMenuItem({
2068 label
: __("Remove label"),
2076 exception_error("headlinesMenuCommon", e
);
2080 function initHeadlinesMenu() {
2082 if (dijit
.byId("headlinesMenu"))
2083 dijit
.byId("headlinesMenu").destroyRecursive();
2088 nodes
= $$("#headlines-frame > div[id*=RROW]");
2090 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2093 nodes
.each(function(node
) {
2097 var menu
= new dijit
.Menu({
2098 id
: "headlinesMenu",
2102 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2103 var callerNode
= event
.target
, match
= null, tries
= 0;
2105 while (match
== null && callerNode
&& tries
<= 3) {
2106 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2107 callerNode
= callerNode
.parentNode
;
2111 if (match
) this.callerRowId
= parseInt(match
[1]);
2115 headlinesMenuCommon(menu
, false);
2119 /* vgroup feed title menu */
2121 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2124 nodes
.each(function(node
) {
2128 if (ids
.length
> 0) {
2129 if (dijit
.byId("headlinesFeedTitleMenu"))
2130 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2132 var menu
= new dijit
.Menu({
2133 id
: "headlinesFeedTitleMenu",
2137 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2138 var callerNode
= event
.target
, match
= null, tries
= 0;
2140 while (match
== null && callerNode
&& tries
<= 3) {
2141 console
.log(callerNode
.id
);
2143 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2144 callerNode
= callerNode
.parentNode
;
2147 console
.log(match
[1]);
2150 if (match
) this.callerRowId
= parseInt(match
[1]);
2154 menu
.addChild(new dijit
.MenuItem({
2155 label
: __("Select articles in group"),
2156 onClick: function(event
) {
2157 selectArticles("all",
2158 "#headlines-frame > div[id*=RROW]"+
2159 "[orig-feed-id='"+menu
.callerRowId
+"']");
2163 menu
.addChild(new dijit
.MenuItem({
2164 label
: __("Mark group as read"),
2165 onClick: function(event
) {
2166 selectArticles("none");
2167 selectArticles("all",
2168 "#headlines-frame > div[id*=RROW]"+
2169 "[orig-feed-id='"+menu
.callerRowId
+"']");
2175 menu
.addChild(new dijit
.MenuItem({
2176 label
: __("Mark feed as read"),
2177 onClick: function(event
) {
2178 catchupFeedInGroup(menu
.callerRowId
);
2186 exception_error("initHeadlinesMenu", e
);
2190 function cache_set(id
, obj
) {
2191 //console.log("cache_set: " + id);
2194 sessionStorage
[id
] = obj
;
2196 sessionStorage
.clear();
2200 function cache_get(id
) {
2202 return sessionStorage
[id
];
2205 function cache_clear() {
2207 sessionStorage
.clear();
2210 function cache_delete(id
) {
2212 sessionStorage
.removeItem(id
);
2215 function cancelSearch() {
2220 exception_error("cancelSearch", e
);
2224 function setSelectionScore() {
2226 var ids
= getSelectedArticleIds2();
2228 if (ids
.length
> 0) {
2231 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2233 if (score
!= undefined) {
2234 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2235 "&score=" + param_escape(score
);
2237 new Ajax
.Request("backend.php", {
2239 onComplete: function(transport
) {
2240 var reply
= JSON
.parse(transport
.responseText
);
2244 ids
.each(function(id
) {
2245 var row
= $("RROW-" + id
);
2248 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2251 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2252 reply
["score_pic"]);
2253 pic
.setAttribute("score", score
);
2262 alert(__("No articles are selected."));
2265 exception_error("setSelectionScore", e
);
2269 function updateScore(id
) {
2271 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2275 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2277 new Ajax
.Request("backend.php", {
2279 onComplete: function(transport
) {
2280 console
.log(transport
.responseText
);
2282 var reply
= JSON
.parse(transport
.responseText
);
2285 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2286 pic
.setAttribute("score", reply
["score"]);
2287 pic
.setAttribute("title", reply
["score"]);
2293 exception_error("updateScore", e
);
2297 function changeScore(id
, pic
) {
2299 var score
= pic
.getAttribute("score");
2301 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2303 if (new_score
!= undefined) {
2305 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2306 "&score=" + param_escape(new_score
);
2308 new Ajax
.Request("backend.php", {
2310 onComplete: function(transport
) {
2311 var reply
= JSON
.parse(transport
.responseText
);
2314 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2315 pic
.setAttribute("score", new_score
);
2316 pic
.setAttribute("title", new_score
);
2321 exception_error("changeScore", e
);
2325 function displayArticleUrl(id
) {
2327 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2329 new Ajax
.Request("backend.php", {
2331 onComplete: function(transport
) {
2332 var reply
= JSON
.parse(transport
.responseText
);
2334 if (reply
&& reply
.link
) {
2335 prompt(__("Article URL:"), reply
.link
);
2339 exception_error("changeScore", e
);
2343 function openSelectedAttachment(elem
) {
2345 var url
= elem
[elem
.selectedIndex
].value
;
2349 elem
.selectedIndex
= 0;
2353 exception_error("openSelectedAttachment", e
);
2357 function scrollToRowId(id
) {
2362 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2365 exception_error("scrollToRowId", e
);
2369 function updateFloatingTitle(unread_only
) {
2371 if (!isCdmMode()) return;
2373 var hf
= $("headlines-frame");
2375 var elems
= $$("#headlines-frame > div[id*=RROW]");
2377 for (var i
= 0; i
< elems
.length
; i
++) {
2379 var child
= elems
[i
];
2381 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2383 var header
= child
.getElementsByClassName("cdmHeader")[0];
2385 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2386 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2387 $("floatingTitle").setAttribute("rowid", child
.id
);
2388 $("floatingTitle").innerHTML
= header
.innerHTML
;
2389 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2393 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2396 cb
.parentNode
.removeChild(cb
);
2399 if (child
.hasClassName("Unread"))
2400 $("floatingTitle").addClassName("Unread");
2402 $("floatingTitle").removeClassName("Unread");
2404 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2407 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2408 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2409 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2410 $("floatingTitle").style
.visibility
= "visible";
2412 $("floatingTitle").style
.visibility
= "hidden";
2420 exception_error("updateFloatingTitle", e
);
2424 function cdmFooterClick(event
) {
2425 event
.stopPropagation();