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 _catchup_request_sent
= false;
20 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
22 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
24 handle_rpc_json(transport
);
26 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
34 reply
= JSON
.parse(transport
.responseText
);
41 is_cat
= reply
['headlines']['is_cat'];
42 feed_id
= reply
['headlines']['id'];
45 var content
= reply
['headlines']['content'];
47 content
= content
+ "<div id='headlines-spacer'></div>";
51 if (feed_id
!= -7 && (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat()))
54 /* dijit.getEnclosingWidget(
55 document.forms["main_toolbar_form"].update).attr('disabled',
56 is_cat || feed_id <= 0); */
59 if (infscroll_req
== false) {
60 $("headlines-frame").scrollTop
= 0;
62 $("floatingTitle").style
.visibility
= "hidden";
63 $("floatingTitle").setAttribute("rowid", 0);
64 $("floatingTitle").innerHTML
= "";
68 $("headlines-frame").removeClassName("cdm");
69 $("headlines-frame").removeClassName("normal");
71 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
73 var headlines_count
= reply
['headlines-info']['count'];
75 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
77 if (parseInt(headlines_count
) < 30) {
78 _infscroll_disable
= 1;
80 _infscroll_disable
= 0;
83 current_first_id
= reply
['headlines']['first_id'];
84 var counters
= reply
['counters'];
85 var articles
= reply
['articles'];
86 //var runtime_info = reply['runtime-info'];
88 if (infscroll_req
== false) {
89 loaded_article_ids
= [];
91 dojo
.html
.set($("headlines-toolbar"),
92 reply
['headlines']['toolbar'],
93 {parseContent
: true});
95 dojo
.html
.set($("headlines-frame"),
96 reply
['headlines']['content'],
97 {parseContent
: true});
99 $$("#headlines-frame div[id*='RROW']").each(function(row
) {
100 loaded_article_ids
.push(row
.id
);
103 var hsp
= $("headlines-spacer");
104 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
105 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
109 if (_infscroll_disable
)
110 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
111 __("Click to open next unread feed.") + "</a>";
114 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
115 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
121 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
122 console
.log("adding some more headlines: " + headlines_count
);
124 var c
= dijit
.byId("headlines-frame");
125 var ids
= getSelectedArticleIds2();
127 var hsp
= $("headlines-spacer");
130 c
.domNode
.removeChild(hsp
);
132 var tmp
= new Element("div");
133 tmp
.innerHTML
= reply
['headlines']['content'];
134 dojo
.parser
.parse(tmp
);
136 while (tmp
.hasChildNodes()) {
137 var row
= tmp
.removeChild(tmp
.firstChild
);
139 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
140 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
142 //new Effect.Appear(row, {duration:0.5});
143 loaded_article_ids
.push(row
.id
);
147 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
148 c
.domNode
.appendChild(hsp
);
150 if (headlines_count
< 30) _infscroll_disable
= true;
152 console
.log("restore selected ids: " + ids
);
154 for (var i
= 0; i
< ids
.length
; i
++) {
155 markHeadline(ids
[i
]);
160 if (_infscroll_disable
) {
161 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
162 __("Click to open next unread feed.") + "</a>";
166 console
.log("no new headlines received");
168 var first_id_changed
= reply
['headlines']['first_id_changed'];
169 console
.log("first id changed:" + first_id_changed
);
171 var hsp
= $("headlines-spacer");
174 if (first_id_changed
) {
175 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
176 __("New articles found, reload feed to continue.") + "</a>";
178 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
179 __("Click to open next unread feed.") + "</a>";
188 for (var i
= 0; i
< articles
.length
; i
++) {
189 var a_id
= articles
[i
]['id'];
190 cache_set("article:" + a_id
, articles
[i
]['content']);
193 console
.log("no cached articles received");
197 parse_counters(counters
);
199 request_counters(true);
202 console
.error("Invalid object received: " + transport
.responseText
);
203 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
204 __('Could not update headlines (invalid object received - see error console for details)') +
208 _infscroll_request_sent
= 0;
209 _last_headlines_update
= new Date().getTime();
211 unpackVisibleHeadlines();
213 // if we have some more space in the buffer, why not try to fill it
215 if (!_infscroll_disable
&& $("headlines-spacer") &&
216 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
218 window
.setTimeout(function() {
226 exception_error("headlines_callback2", e
, transport
);
230 function render_article(article
) {
232 dijit
.byId("headlines-wrap-inner").addChild(
233 dijit
.byId("content-insert"));
235 var c
= dijit
.byId("content-insert");
238 c
.domNode
.scrollTop
= 0;
241 c
.attr('content', article
);
242 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
244 correctHeadlinesOffset(getActiveArticleId());
251 exception_error("render_article", e
);
255 function showArticleInHeadlines(id
, noexpand
) {
258 selectArticles("none");
260 var crow
= $("RROW-" + id
);
264 var article_is_unread
= crow
.hasClassName("Unread");
267 crow
.removeClassName("Unread");
268 crow
.addClassName("active");
270 selectArticles('none');
272 var view_mode
= false;
275 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
276 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
283 if (article_is_unread
&& !noexpand
)
284 _force_scheduled_update
= true;
287 exception_error("showArticleInHeadlines", e
);
291 function article_callback2(transport
, id
) {
293 console
.log("article_callback2 " + id
);
295 handle_rpc_json(transport
);
300 reply
= JSON
.parse(transport
.responseText
);
307 reply
.each(function(article
) {
308 if (getActiveArticleId() == article
['id']) {
309 render_article(article
['content']);
311 cids_requested
.remove(article
['id']);
313 cache_set("article:" + article
['id'], article
['content']);
316 // if (id != last_requested_article) {
317 // console.log("requested article id is out of sequence, aborting");
322 console
.error("Invalid object received: " + transport
.responseText
);
324 render_article("<div class='whiteBox'>" +
325 __('Could not display article (invalid object received - see error console for details)') + "</div>");
328 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
329 request_counters(unread_in_buffer
== 0);
333 exception_error("article_callback2", e
, transport
);
337 function view(id
, activefeed
, noexpand
) {
339 var oldrow
= $("RROW-" + getActiveArticleId());
340 if (oldrow
) oldrow
.removeClassName("active");
342 var crow
= $("RROW-" + id
);
346 setActiveArticleId(id
);
347 showArticleInHeadlines(id
, noexpand
);
351 console
.log("loading article: " + id
);
353 var cached_article
= cache_get("article:" + id
);
355 console
.log("cache check result: " + (cached_article
!= false));
357 var query
= "?op=article&method=view&id=" + param_escape(id
);
359 var neighbor_ids
= getRelativePostIds(id
);
361 /* only request uncached articles */
363 var cids_to_request
= [];
365 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
366 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
367 if (!cache_get("article:" + neighbor_ids
[i
])) {
368 cids_to_request
.push(neighbor_ids
[i
]);
369 cids_requested
.push(neighbor_ids
[i
]);
373 console
.log("additional ids: " + cids_to_request
.toString());
375 query
= query
+ "&cids=" + cids_to_request
.toString();
377 var article_is_unread
= crow
.hasClassName("Unread");
379 setActiveArticleId(id
);
380 showArticleInHeadlines(id
);
382 if (cached_article
&& article_is_unread
) {
384 query
= query
+ "&mode=prefetch";
386 render_article(cached_article
);
388 } else if (cached_article
) {
390 query
= query
+ "&mode=prefetch_old";
391 render_article(cached_article
);
393 // if we don't need to request any relative ids, we might as well skip
394 // the server roundtrip altogether
395 if (cids_to_request
.length
== 0) {
400 last_requested_article
= id
;
404 if (article_is_unread
) {
405 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
408 new Ajax
.Request("backend.php", {
410 onComplete: function(transport
) {
411 article_callback2(transport
, id
);
417 exception_error("view", e
);
421 function toggleMark(id
, client_only
) {
423 var query
= "?op=rpc&id=" + id
+ "&method=mark";
425 var row
= $("RROW-" + id
);
430 var row_imgs
= row
.getElementsByClassName("markedPic");
432 for (var i
= 0; i
< row_imgs
.length
; i
++)
433 imgs
.push(row_imgs
[i
]);
435 var ft
= $("floatingTitle");
437 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
438 var fte
= ft
.getElementsByClassName("markedPic");
440 for (var i
= 0; i
< fte
.length
; i
++)
444 for (i
= 0; i
< imgs
.length
; i
++) {
447 if (!row
.hasClassName("marked")) {
448 img
.src
= img
.src
.replace("mark_unset", "mark_set");
449 img
.alt
= __("Unstar article");
450 query
= query
+ "&mark=1";
452 img
.src
= img
.src
.replace("mark_set", "mark_unset");
453 img
.alt
= __("Star article");
454 query
= query
+ "&mark=0";
458 row
.toggleClassName("marked");
461 new Ajax
.Request("backend.php", {
463 onComplete: function(transport
) {
464 handle_rpc_json(transport
);
469 exception_error("toggleMark", e
);
473 function togglePub(id
, client_only
, no_effects
, note
) {
475 var query
= "?op=rpc&id=" + id
+ "&method=publ";
477 if (note
!= undefined) {
478 query
= query
+ "¬e=" + param_escape(note
);
480 query
= query
+ "¬e=undefined";
483 var row
= $("RROW-" + id
);
488 var row_imgs
= row
.getElementsByClassName("pubPic");
490 for (var i
= 0; i
< row_imgs
.length
; i
++)
491 imgs
.push(row_imgs
[i
]);
493 var ft
= $("floatingTitle");
495 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
496 var fte
= ft
.getElementsByClassName("pubPic");
498 for (var i
= 0; i
< fte
.length
; i
++)
502 for (i
= 0; i
< imgs
.length
; i
++) {
505 if (!row
.hasClassName("published") || note
!= undefined) {
506 img
.src
= img
.src
.replace("pub_unset", "pub_set");
507 img
.alt
= __("Unpublish article");
508 query
= query
+ "&pub=1";
510 img
.src
= img
.src
.replace("pub_set", "pub_unset");
511 img
.alt
= __("Publish article");
512 query
= query
+ "&pub=0";
516 if (note
!= undefined)
517 row
.addClassName("published");
519 row
.toggleClassName("published");
522 new Ajax
.Request("backend.php", {
524 onComplete: function(transport
) {
525 handle_rpc_json(transport
);
530 exception_error("togglePub", e
);
534 function moveToPost(mode
, noscroll
, noexpand
) {
538 var rows
= getVisibleArticleIds();
543 if (!$('RROW-' + getActiveArticleId())) {
544 setActiveArticleId(0);
547 if (!getActiveArticleId()) {
549 prev_id
= rows
[rows
.length
-1]
551 for (var i
= 0; i
< rows
.length
; i
++) {
552 if (rows
[i
] == getActiveArticleId()) {
554 // Account for adjacent identical article ids.
555 if (i
> 0) prev_id
= rows
[i
-1];
557 for (var j
= i
+1; j
< rows
.length
; j
++) {
558 if (rows
[j
] != getActiveArticleId()) {
568 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
570 if (mode
== "next") {
571 if (next_id
|| getActiveArticleId()) {
574 var article
= $("RROW-" + getActiveArticleId());
575 var ctr
= $("headlines-frame");
577 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
578 ctr
.scrollTop
+ ctr
.offsetHeight
) {
580 scrollArticle(ctr
.offsetHeight
/4);
582 } else if (next_id
) {
583 cdmExpandArticle(next_id
, noexpand
);
584 cdmScrollToArticleId(next_id
, true);
587 } else if (next_id
) {
588 correctHeadlinesOffset(next_id
);
589 view(next_id
, getActiveFeedId(), noexpand
);
594 if (mode
== "prev") {
595 if (prev_id
|| getActiveArticleId()) {
598 var article
= $("RROW-" + getActiveArticleId());
599 var prev_article
= $("RROW-" + prev_id
);
600 var ctr
= $("headlines-frame");
602 if (!getInitParam("cdm_expanded")) {
604 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
605 scrollArticle(-ctr
.offsetHeight
/4);
607 cdmExpandArticle(prev_id
, noexpand
);
608 cdmScrollToArticleId(prev_id
, true);
612 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
613 scrollArticle(-ctr
.offsetHeight
/3);
614 } else if (!noscroll
&& prev_article
&&
615 prev_article
.offsetTop
< ctr
.scrollTop
) {
616 cdmExpandArticle(prev_id
, noexpand
);
617 scrollArticle(-ctr
.offsetHeight
/4);
618 } else if (prev_id
) {
619 cdmExpandArticle(prev_id
, noexpand
);
620 cdmScrollToArticleId(prev_id
, noscroll
);
624 } else if (prev_id
) {
625 correctHeadlinesOffset(prev_id
);
626 view(prev_id
, getActiveFeedId(), noexpand
);
632 exception_error("moveToPost", e
);
636 function toggleSelected(id
, force_on
) {
638 var row
= $("RROW-" + id
);
641 var cb
= dijit
.getEnclosingWidget(
642 row
.getElementsByClassName("rchk")[0]);
644 if (row
.hasClassName('Selected') && !force_on
) {
645 row
.removeClassName('Selected');
646 if (cb
) cb
.attr("checked", false);
648 row
.addClassName('Selected');
649 if (cb
) cb
.attr("checked", true);
653 updateSelectedPrompt();
655 exception_error("toggleSelected", e
);
659 function updateSelectedPrompt() {
661 var count
= getSelectedArticleIds2().size();
662 var elem
= $("selected_prompt");
665 elem
.innerHTML
= ngettext("%d article selected",
666 "%d articles selected", count
).replace("%d", count
);
675 exception_error("updateSelectedPrompt", e
);
679 function toggleUnread_afh(effect
) {
682 var elem
= effect
.element
;
683 elem
.style
.backgroundColor
= "";
686 exception_error("toggleUnread_afh", e
);
690 function toggleUnread(id
, cmode
, effect
) {
693 var row
= $("RROW-" + id
);
695 var tmpClassName
= row
.className
;
697 if (cmode
== undefined || cmode
== 2) {
698 if (row
.hasClassName("Unread")) {
699 row
.removeClassName("Unread");
702 row
.addClassName("Unread");
705 } else if (cmode
== 0) {
707 row
.removeClassName("Unread");
709 } else if (cmode
== 1) {
710 row
.addClassName("Unread");
713 if (cmode
== undefined) cmode
= 2;
715 var query
= "?op=rpc&method=catchupSelected" +
716 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
718 // notify_progress("Loading, please wait...");
720 if (tmpClassName
!= row
.className
) {
721 new Ajax
.Request("backend.php", {
723 onComplete: function (transport
) {
724 handle_rpc_json(transport
);
732 exception_error("toggleUnread", e
);
736 function selectionRemoveLabel(id
, ids
) {
739 if (!ids
) ids
= getSelectedArticleIds2();
741 if (ids
.length
== 0) {
742 alert(__("No articles are selected."));
746 var query
= "?op=article&method=removeFromLabel&ids=" +
747 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
751 new Ajax
.Request("backend.php", {
753 onComplete: function(transport
) {
754 handle_rpc_json(transport
);
755 show_labels_in_headlines(transport
);
759 exception_error("selectionAssignLabel", e
);
764 function selectionAssignLabel(id
, ids
) {
767 if (!ids
) ids
= getSelectedArticleIds2();
769 if (ids
.length
== 0) {
770 alert(__("No articles are selected."));
774 var query
= "?op=article&method=assignToLabel&ids=" +
775 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
779 new Ajax
.Request("backend.php", {
781 onComplete: function(transport
) {
782 handle_rpc_json(transport
);
783 show_labels_in_headlines(transport
);
787 exception_error("selectionAssignLabel", e
);
792 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
794 var rows
= ids
? ids
: getSelectedArticleIds2();
796 if (rows
.length
== 0 && !no_error
) {
797 alert(__("No articles are selected."));
801 for (var i
= 0; i
< rows
.length
; i
++) {
802 var row
= $("RROW-" + rows
[i
]);
804 if (set_state
== undefined) {
805 if (row
.hasClassName("Unread")) {
806 row
.removeClassName("Unread");
808 row
.addClassName("Unread");
812 if (set_state
== false) {
813 row
.removeClassName("Unread");
816 if (set_state
== true) {
817 row
.addClassName("Unread");
822 updateFloatingTitle(true);
824 if (rows
.length
> 0) {
828 if (set_state
== undefined) {
830 } else if (set_state
== true) {
832 } else if (set_state
== false) {
836 var query
= "?op=rpc&method=catchupSelected" +
837 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
839 notify_progress("Loading, please wait...");
841 new Ajax
.Request("backend.php", {
843 onComplete: function(transport
) {
844 handle_rpc_json(transport
);
845 if (callback
) callback(transport
);
851 exception_error("selectionToggleUnread", e
);
856 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
859 var rows
= ids
? ids
: getSelectedArticleIds2();
861 if (rows
.length
== 0 && !no_error
) {
862 alert(__("No articles are selected."));
866 for (var i
= 0; i
< rows
.length
; i
++) {
867 toggleMark(rows
[i
], true, true);
870 if (rows
.length
> 0) {
872 var query
= "?op=rpc&method=markSelected&ids=" +
873 param_escape(rows
.toString()) + "&cmode=2";
875 new Ajax
.Request("backend.php", {
877 onComplete: function(transport
) {
878 handle_rpc_json(transport
);
879 if (callback
) callback(transport
);
885 exception_error("selectionToggleMarked", e
);
890 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
893 var rows
= ids
? ids
: getSelectedArticleIds2();
895 if (rows
.length
== 0 && !no_error
) {
896 alert(__("No articles are selected."));
900 for (var i
= 0; i
< rows
.length
; i
++) {
901 togglePub(rows
[i
], true, true);
904 if (rows
.length
> 0) {
906 var query
= "?op=rpc&method=publishSelected&ids=" +
907 param_escape(rows
.toString()) + "&cmode=2";
909 new Ajax
.Request("backend.php", {
911 onComplete: function(transport
) {
912 handle_rpc_json(transport
);
918 exception_error("selectionToggleMarked", e
);
922 function getSelectedArticleIds2() {
926 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
928 rv
.push(child
.id
.replace("RROW-", ""));
934 function getLoadedArticleIds() {
937 var children
= $$("#headlines-frame > div[id*=RROW-]");
939 children
.each(function(child
) {
940 rv
.push(child
.id
.replace("RROW-", ""));
947 // mode = all,none,unread,invert,marked,published
948 function selectArticles(mode
, query
) {
951 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
953 var children
= $$(query
);
955 children
.each(function(child
) {
956 var id
= child
.id
.replace("RROW-", "");
958 var cb
= dijit
.getEnclosingWidget(
959 child
.getElementsByClassName("rchk")[0]);
962 child
.addClassName("Selected");
963 if (cb
) cb
.attr("checked", true);
964 } else if (mode
== "unread") {
965 if (child
.hasClassName("Unread")) {
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
== "marked") {
973 if (child
.hasClassName("marked")) {
974 child
.addClassName("Selected");
975 if (cb
) cb
.attr("checked", true);
977 child
.removeClassName("Selected");
978 if (cb
) cb
.attr("checked", false);
980 } else if (mode
== "published") {
981 if (child
.hasClassName("published")) {
982 child
.addClassName("Selected");
983 if (cb
) cb
.attr("checked", true);
985 child
.removeClassName("Selected");
986 if (cb
) cb
.attr("checked", false);
989 } else if (mode
== "invert") {
990 if (child
.hasClassName("Selected")) {
991 child
.removeClassName("Selected");
992 if (cb
) cb
.attr("checked", false);
994 child
.addClassName("Selected");
995 if (cb
) cb
.attr("checked", true);
999 child
.removeClassName("Selected");
1000 if (cb
) cb
.attr("checked", false);
1004 updateSelectedPrompt();
1007 exception_error("selectArticles", e
);
1011 function deleteSelection() {
1015 var rows
= getSelectedArticleIds2();
1017 if (rows
.length
== 0) {
1018 alert(__("No articles are selected."));
1022 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1025 if (getActiveFeedId() != 0) {
1026 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1028 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1031 str
= str
.replace("%d", rows
.length
);
1032 str
= str
.replace("%s", fn
);
1034 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1038 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1045 handle_rpc_json(transport
);
1050 exception_error("deleteSelection", e
);
1054 function archiveSelection() {
1058 var rows
= getSelectedArticleIds2();
1060 if (rows
.length
== 0) {
1061 alert(__("No articles are selected."));
1065 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1069 if (getActiveFeedId() != 0) {
1070 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1073 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1075 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1080 str
= str
.replace("%d", rows
.length
);
1081 str
= str
.replace("%s", fn
);
1083 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1087 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1091 for (var i
= 0; i
< rows
.length
; i
++) {
1092 cache_delete("article:" + rows
[i
]);
1095 new Ajax
.Request("backend.php", {
1097 onComplete: function(transport
) {
1098 handle_rpc_json(transport
);
1103 exception_error("archiveSelection", e
);
1107 function catchupSelection() {
1111 var rows
= getSelectedArticleIds2();
1113 if (rows
.length
== 0) {
1114 alert(__("No articles are selected."));
1118 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1120 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1122 str
= str
.replace("%d", rows
.length
);
1123 str
= str
.replace("%s", fn
);
1125 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1129 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1132 exception_error("catchupSelection", e
);
1136 function editArticleTags(id
) {
1137 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1139 if (dijit
.byId("editTagsDlg"))
1140 dijit
.byId("editTagsDlg").destroyRecursive();
1142 dialog
= new dijit
.Dialog({
1144 title
: __("Edit article Tags"),
1145 style
: "width: 600px",
1146 execute: function() {
1147 if (this.validate()) {
1148 var query
= dojo
.objectToQuery(this.attr('value'));
1150 notify_progress("Saving article tags...", true);
1152 new Ajax
.Request("backend.php", {
1154 onComplete: function(transport
) {
1159 var data
= JSON
.parse(transport
.responseText
);
1166 var tags
= $("ATSTR-" + id
);
1167 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1169 if (tags
) tags
.innerHTML
= data
.content
;
1170 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1173 exception_error("editArticleTags/inner", e
);
1182 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1183 dojo
.disconnect(tmph
);
1185 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1186 "backend.php?op=article&method=completeTags",
1187 { tokens
: ',', paramName
: "search" });
1194 function cdmScrollToArticleId(id
, force
) {
1196 var ctr
= $("headlines-frame");
1197 var e
= $("RROW-" + id
);
1199 if (!e
|| !ctr
) return;
1201 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1202 e
.offsetTop
< ctr
.scrollTop
) {
1204 // expanded cdm has a 4px margin now
1205 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1209 exception_error("cdmScrollToArticleId", e
);
1213 function setActiveArticleId(id
) {
1214 console
.log("setActiveArticleId:" + id
);
1216 _active_article_id
= id
;
1217 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1220 function getActiveArticleId() {
1221 return _active_article_id
;
1224 function postMouseIn(e
, id
) {
1225 post_under_pointer
= id
;
1228 function postMouseOut(id
) {
1229 post_under_pointer
= false;
1232 function unpackVisibleHeadlines() {
1234 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1236 $$("#headlines-frame > div[id*=RROW]").each(
1238 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1239 $("headlines-frame").offsetHeight
) {
1241 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1244 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1245 cencw
.setAttribute('id', '');
1247 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1249 Element
.show(cencw
);
1256 exception_error("unpackVisibleHeadlines", e
);
1260 function headlines_scroll_handler(e
) {
1262 var hsp
= $("headlines-spacer");
1264 unpackVisibleHeadlines();
1266 // set topmost child in the buffer as active
1267 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1268 getSelectedArticleIds2().length
<= 1 &&
1269 getInitParam("cdm_expanded")) {
1270 var rows
= $$("#headlines-frame > div[id*=RROW]");
1272 for (var i
= 0; i
< rows
.length
; i
++) {
1273 var child
= rows
[i
];
1275 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1276 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1277 child
.id
.replace("RROW-", "") != _active_article_id
) {
1279 if (_active_article_id
) {
1280 var row
= $("RROW-" + _active_article_id
);
1281 if (row
) row
.removeClassName("active");
1284 _active_article_id
= child
.id
.replace("RROW-", "");
1285 showArticleInHeadlines(_active_article_id
, true);
1286 updateSelectedPrompt();
1292 if (!_infscroll_disable
) {
1293 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1295 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1296 __("Loading, please wait...") + "</span>";
1298 loadMoreHeadlines();
1305 updateFloatingTitle();
1308 catchupCurrentBatchIfNeeded();
1310 if (getInitParam("cdm_auto_catchup") == 1) {
1312 // let's get DOM some time to settle down
1313 var ts
= new Date().getTime();
1314 if (ts
- _last_headlines_update
< 100) return;
1316 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1318 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1319 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1321 var id
= child
.id
.replace("RROW-", "");
1323 if (catchup_id_batch
.indexOf(id
) == -1)
1324 catchup_id_batch
.push(id
);
1326 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1331 if (_infscroll_disable
) {
1332 var child
= $$("#headlines-frame div[id*=RROW]").last();
1334 if (child
&& $("headlines-frame").scrollTop
>
1335 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1337 console
.log("we seem to be at an end");
1339 if (getInitParam("on_catchup_show_next_feed") == "1") {
1340 openNextUnreadFeed();
1347 console
.warn("headlines_scroll_handler: " + e
);
1351 function openNextUnreadFeed() {
1353 var is_cat
= activeFeedIsCat();
1354 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1355 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1357 exception_error("openNextUnreadFeed", e
);
1361 function catchupBatchedArticles() {
1363 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1365 console
.log("catchupBatchedArticles: working");
1367 // make a copy of the array
1368 var batch
= catchup_id_batch
.slice();
1369 var query
= "?op=rpc&method=catchupSelected" +
1370 "&cmode=0&ids=" + param_escape(batch
.toString());
1374 _catchup_request_sent
= true;
1376 new Ajax
.Request("backend.php", {
1378 onComplete: function(transport
) {
1379 handle_rpc_json(transport
);
1381 _catchup_request_sent
= false;
1383 reply
= JSON
.parse(transport
.responseText
);
1384 var batch
= reply
.ids
;
1386 batch
.each(function(id
) {
1388 var elem
= $("RROW-" + id
);
1389 if (elem
) elem
.removeClassName("Unread");
1390 catchup_id_batch
.remove(id
);
1393 updateFloatingTitle(true);
1399 exception_error("catchupBatchedArticles", e
);
1403 function catchupRelativeToArticle(below
, id
) {
1407 if (!id
) id
= getActiveArticleId();
1410 alert(__("No article is selected."));
1414 var visible_ids
= getVisibleArticleIds();
1416 var ids_to_mark
= new Array();
1419 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1420 if (visible_ids
[i
] != id
) {
1421 var e
= $("RROW-" + visible_ids
[i
]);
1423 if (e
&& e
.hasClassName("Unread")) {
1424 ids_to_mark
.push(visible_ids
[i
]);
1431 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1432 if (visible_ids
[i
] != id
) {
1433 var e
= $("RROW-" + visible_ids
[i
]);
1435 if (e
&& e
.hasClassName("Unread")) {
1436 ids_to_mark
.push(visible_ids
[i
]);
1444 if (ids_to_mark
.length
== 0) {
1445 alert(__("No articles found to mark"));
1447 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1449 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1451 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1452 var e
= $("RROW-" + ids_to_mark
[i
]);
1453 e
.removeClassName("Unread");
1456 var query
= "?op=rpc&method=catchupSelected" +
1457 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1459 new Ajax
.Request("backend.php", {
1461 onComplete: function(transport
) {
1462 handle_rpc_json(transport
);
1469 exception_error("catchupRelativeToArticle", e
);
1473 function cdmCollapseArticle(event
, id
, unmark
) {
1475 if (unmark
== undefined) unmark
= true;
1477 var row
= $("RROW-" + id
);
1478 var elem
= $("CICD-" + id
);
1481 var collapse
= $$("div#RROW-" + id
+
1482 " span[class='collapseBtn']")[0];
1485 Element
.show("CEXC-" + id
);
1486 Element
.hide(collapse
);
1489 row
.removeClassName("active");
1491 markHeadline(id
, false);
1493 if (id
== getActiveArticleId()) {
1494 setActiveArticleId(0);
1497 updateSelectedPrompt();
1500 if (event
) Event
.stop(event
);
1502 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1504 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1505 scrollToRowId(row
.id
);
1507 $("floatingTitle").style
.visibility
= "hidden";
1508 $("floatingTitle").setAttribute("rowid", false);
1512 exception_error("cdmCollapseArticle", e
);
1516 function cdmExpandArticle(id
, noexpand
) {
1518 console
.log("cdmExpandArticle " + id
);
1520 if (!$("RROW-" + id
)) return false;
1522 var oldrow
= $("RROW-" + getActiveArticleId());
1524 var elem
= $("CICD-" + getActiveArticleId());
1526 if (id
== getActiveArticleId() && Element
.visible(elem
))
1529 selectArticles("none");
1531 var old_offset
= $("RROW-" + id
).offsetTop
;
1533 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1534 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1535 " span[class='collapseBtn']")[0];
1538 Element
.show("CEXC-" + getActiveArticleId());
1539 Element
.hide(collapse
);
1542 if (oldrow
) oldrow
.removeClassName("active");
1544 setActiveArticleId(id
);
1546 elem
= $("CICD-" + id
);
1548 var collapse
= $$("div#RROW-" + id
+
1549 " span[class='collapseBtn']")[0];
1551 var cencw
= $("CENCW-" + id
);
1553 if (!Element
.visible(elem
) && !noexpand
) {
1555 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1556 cencw
.setAttribute('id', '');
1557 Element
.show(cencw
);
1561 Element
.hide("CEXC-" + id
);
1562 Element
.show(collapse
);
1565 var new_offset
= $("RROW-" + id
).offsetTop
;
1567 if (old_offset
> new_offset
)
1568 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1571 if (catchup_id_batch
.indexOf(id
) == -1)
1572 catchup_id_batch
.push(id
);
1574 catchupCurrentBatchIfNeeded();
1578 $("RROW-" + id
).addClassName("active");
1580 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1583 exception_error("cdmExpandArticle", e
);
1589 function getArticleUnderPointer() {
1590 return post_under_pointer
;
1593 function scrollArticle(offset
) {
1596 var ci
= $("content-insert");
1598 ci
.scrollTop
+= offset
;
1601 var hi
= $("headlines-frame");
1603 hi
.scrollTop
+= offset
;
1608 exception_error("scrollArticle", e
);
1612 function show_labels_in_headlines(transport
) {
1614 var data
= JSON
.parse(transport
.responseText
);
1617 data
['info-for-headlines'].each(function(elem
) {
1618 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1619 ctr
.innerHTML
= elem
.labels
;
1624 exception_error("show_labels_in_headlines", e
);
1628 function dismissArticle(id
) {
1630 var elem
= $("RROW-" + id
);
1634 toggleUnread(id
, 0, true);
1636 new Effect
.Fade(elem
, {duration
: 0.5});
1638 // Remove the content, too
1639 var elem_content
= $("CICD-" + id
);
1641 Element
.remove(elem_content
);
1644 if (id
== getActiveArticleId()) {
1645 setActiveArticleId(0);
1649 exception_error("dismissArticle", e
);
1653 function dismissSelectedArticles() {
1656 var ids
= getVisibleArticleIds();
1660 for (var i
= 0; i
< ids
.length
; i
++) {
1661 var elem
= $("RROW-" + ids
[i
]);
1663 if (elem
.className
&& elem
.hasClassName("Selected") &&
1664 ids
[i
] != getActiveArticleId()) {
1665 new Effect
.Fade(elem
, {duration
: 0.5});
1668 // Remove the content, too
1669 var elem_content
= $("CICD-" + ids
[i
]);
1671 Element
.remove(elem_content
);
1679 selectionToggleUnread(false);
1683 exception_error("dismissSelectedArticles", e
);
1687 function dismissReadArticles() {
1690 var ids
= getVisibleArticleIds();
1693 for (var i
= 0; i
< ids
.length
; i
++) {
1694 var elem
= $("RROW-" + ids
[i
]);
1696 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1697 !elem
.hasClassName("Selected")) {
1699 new Effect
.Fade(elem
, {duration
: 0.5});
1701 // Remove the content, too
1702 var elem_content
= $("CICD-" + ids
[i
]);
1704 Element
.remove(elem_content
);
1712 exception_error("dismissReadArticles", e
);
1716 // we don't really hide rows anymore
1717 function getVisibleArticleIds() {
1718 return getLoadedArticleIds();
1724 getLoadedArticleIds().each(function(id) {
1725 var elem = $("RROW-" + id);
1726 if (elem && Element.visible(elem))
1731 exception_error("getVisibleArticleIds", e);
1737 function cdmClicked(event
, id
) {
1739 //var shift_key = event.shiftKey;
1741 if (!event
.ctrlKey
) {
1743 if (!getInitParam("cdm_expanded")) {
1744 return cdmExpandArticle(id
);
1747 var elem
= $("RROW-" + getActiveArticleId());
1749 if (elem
) elem
.removeClassName("active");
1751 selectArticles("none");
1754 var elem
= $("RROW-" + id
);
1755 var article_is_unread
= elem
.hasClassName("Unread");
1757 elem
.removeClassName("Unread");
1758 elem
.addClassName("active");
1760 setActiveArticleId(id
);
1762 if (article_is_unread
) {
1763 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1764 updateFloatingTitle(true);
1767 var query
= "?op=rpc&method=catchupSelected" +
1768 "&cmode=0&ids=" + param_escape(id
);
1770 new Ajax
.Request("backend.php", {
1772 onComplete: function(transport
) {
1773 handle_rpc_json(transport
);
1776 return !event
.shiftKey
;
1779 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1781 toggleSelected(id
, true);
1783 var elem
= $("RROW-" + id
);
1784 var article_is_unread
= elem
.hasClassName("Unread");
1786 if (article_is_unread
) {
1787 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1790 toggleUnread(id
, 0, false);
1792 openArticleInNewWindow(id
);
1795 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1796 request_counters(unread_in_buffer
== 0);
1799 exception_error("cdmClicked");
1805 function hlClicked(event
, id
) {
1807 if (event
.which
== 2) {
1810 } else if (event
.ctrlKey
) {
1811 toggleSelected(id
, true);
1812 toggleUnread(id
, 0, false);
1813 openArticleInNewWindow(id
);
1821 exception_error("hlClicked");
1825 function getFirstVisibleHeadlineId() {
1826 var rows
= getVisibleArticleIds();
1831 function getLastVisibleHeadlineId() {
1832 var rows
= getVisibleArticleIds();
1833 return rows
[rows
.length
-1];
1836 function openArticleInNewWindow(id
) {
1837 toggleUnread(id
, 0, false);
1838 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1841 function isCdmMode() {
1842 return getInitParam("combined_display_mode");
1845 function markHeadline(id
, marked
) {
1846 if (marked
== undefined) marked
= true;
1848 var row
= $("RROW-" + id
);
1850 var check
= dijit
.getEnclosingWidget(
1851 row
.getElementsByClassName("rchk")[0]);
1854 check
.attr("checked", marked
);
1858 row
.addClassName("Selected");
1860 row
.removeClassName("Selected");
1864 function getRelativePostIds(id
, limit
) {
1870 if (!limit
) limit
= 6; //3
1872 var ids
= getVisibleArticleIds();
1874 for (var i
= 0; i
< ids
.length
; i
++) {
1876 for (var k
= 1; k
<= limit
; k
++) {
1877 //if (i > k-1) tmp.push(ids[i-k]);
1878 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1885 exception_error("getRelativePostIds", e
);
1891 function correctHeadlinesOffset(id
) {
1895 var container
= $("headlines-frame");
1896 var row
= $("RROW-" + id
);
1898 if (!container
|| !row
) return;
1900 var viewport
= container
.offsetHeight
;
1902 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1903 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1905 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1906 //console.log("Vport: " + viewport);
1908 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1909 container
.scrollTop
= row
.offsetTop
;
1910 } else if (rel_offset_bottom
> viewport
) {
1912 /* doesn't properly work with Opera in some cases because
1913 Opera fucks up element scrolling */
1915 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1919 exception_error("correctHeadlinesOffset", e
);
1924 function headlineActionsChange(elem
) {
1927 elem
.attr('value', 'false');
1929 exception_error("headlineActionsChange", e
);
1933 function closeArticlePanel() {
1935 if (dijit
.byId("content-insert"))
1936 dijit
.byId("headlines-wrap-inner").removeChild(
1937 dijit
.byId("content-insert"));
1940 function initFloatingMenu() {
1942 if (dijit
.byId("floatingMenu"))
1943 dijit
.byId("floatingMenu").destroyRecursive();
1945 var menu
= new dijit
.Menu({
1947 targetNodeIds
: ["floatingTitle"]
1950 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1952 headlinesMenuCommon(menu
, id
);
1956 exception_error("initFloatingMenu", e
);
1960 function headlinesMenuCommon(menu
, base_id
) {
1963 menu
.addChild(new dijit
.MenuItem({
1964 label
: __("Open original article"),
1965 onClick: function(event
) {
1966 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1969 menu
.addChild(new dijit
.MenuItem({
1970 label
: __("Display article URL"),
1971 onClick: function(event
) {
1972 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1975 menu
.addChild(new dijit
.MenuSeparator());
1977 menu
.addChild(new dijit
.MenuItem({
1978 label
: __("Toggle unread"),
1979 onClick: function(event
) {
1980 var ids
= getSelectedArticleIds2();
1982 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1983 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1985 selectionToggleUnread(undefined, false, true, ids
);
1988 menu
.addChild(new dijit
.MenuItem({
1989 label
: __("Toggle starred"),
1990 onClick: function(event
) {
1991 var ids
= getSelectedArticleIds2();
1993 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1994 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1996 selectionToggleMarked(undefined, false, true, ids
);
1999 menu
.addChild(new dijit
.MenuItem({
2000 label
: __("Toggle published"),
2001 onClick: function(event
) {
2002 var ids
= getSelectedArticleIds2();
2004 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2005 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2007 selectionTogglePublished(undefined, false, true, ids
);
2010 menu
.addChild(new dijit
.MenuSeparator());
2012 menu
.addChild(new dijit
.MenuItem({
2013 label
: __("Mark above as read"),
2014 onClick: function(event
) {
2015 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2018 menu
.addChild(new dijit
.MenuItem({
2019 label
: __("Mark below as read"),
2020 onClick: function(event
) {
2021 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2025 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2029 menu
.addChild(new dijit
.MenuSeparator());
2031 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2032 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2034 labels
.each(function(label
) {
2035 var id
= label
.id
[0];
2036 var bare_id
= id
.substr(id
.indexOf(":")+1);
2037 var name
= label
.name
[0];
2039 bare_id
= feed_to_label_id(bare_id
);
2041 labelAddMenu
.addChild(new dijit
.MenuItem({
2044 onClick: function(event
) {
2045 var ids
= getSelectedArticleIds2();
2047 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2049 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2051 selectionAssignLabel(this.labelId
, ids
);
2054 labelDelMenu
.addChild(new dijit
.MenuItem({
2057 onClick: function(event
) {
2058 var ids
= getSelectedArticleIds2();
2060 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2062 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2064 selectionRemoveLabel(this.labelId
, ids
);
2069 menu
.addChild(new dijit
.PopupMenuItem({
2070 label
: __("Assign label"),
2074 menu
.addChild(new dijit
.PopupMenuItem({
2075 label
: __("Remove label"),
2083 exception_error("headlinesMenuCommon", e
);
2087 function initHeadlinesMenu() {
2089 if (dijit
.byId("headlinesMenu"))
2090 dijit
.byId("headlinesMenu").destroyRecursive();
2095 nodes
= $$("#headlines-frame > div[id*=RROW]");
2097 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2100 nodes
.each(function(node
) {
2104 var menu
= new dijit
.Menu({
2105 id
: "headlinesMenu",
2109 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2110 var callerNode
= event
.target
, match
= null, tries
= 0;
2112 while (match
== null && callerNode
&& tries
<= 3) {
2113 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2114 callerNode
= callerNode
.parentNode
;
2118 if (match
) this.callerRowId
= parseInt(match
[1]);
2122 headlinesMenuCommon(menu
, false);
2126 /* vgroup feed title menu */
2128 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2131 nodes
.each(function(node
) {
2135 if (ids
.length
> 0) {
2136 if (dijit
.byId("headlinesFeedTitleMenu"))
2137 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2139 var menu
= new dijit
.Menu({
2140 id
: "headlinesFeedTitleMenu",
2144 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2145 var callerNode
= event
.target
, match
= null, tries
= 0;
2147 while (match
== null && callerNode
&& tries
<= 3) {
2148 console
.log(callerNode
.id
);
2150 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2151 callerNode
= callerNode
.parentNode
;
2154 console
.log(match
[1]);
2157 if (match
) this.callerRowId
= parseInt(match
[1]);
2161 menu
.addChild(new dijit
.MenuItem({
2162 label
: __("Select articles in group"),
2163 onClick: function(event
) {
2164 selectArticles("all",
2165 "#headlines-frame > div[id*=RROW]"+
2166 "[orig-feed-id='"+menu
.callerRowId
+"']");
2170 menu
.addChild(new dijit
.MenuItem({
2171 label
: __("Mark group as read"),
2172 onClick: function(event
) {
2173 selectArticles("none");
2174 selectArticles("all",
2175 "#headlines-frame > div[id*=RROW]"+
2176 "[orig-feed-id='"+menu
.callerRowId
+"']");
2182 menu
.addChild(new dijit
.MenuItem({
2183 label
: __("Mark feed as read"),
2184 onClick: function(event
) {
2185 catchupFeedInGroup(menu
.callerRowId
);
2188 menu
.addChild(new dijit
.MenuItem({
2189 label
: __("Edit feed"),
2190 onClick: function(event
) {
2191 editFeed(menu
.callerRowId
);
2199 exception_error("initHeadlinesMenu", e
);
2203 function cache_set(id
, obj
) {
2204 //console.log("cache_set: " + id);
2207 sessionStorage
[id
] = obj
;
2209 sessionStorage
.clear();
2213 function cache_get(id
) {
2215 return sessionStorage
[id
];
2218 function cache_clear() {
2220 sessionStorage
.clear();
2223 function cache_delete(id
) {
2225 sessionStorage
.removeItem(id
);
2228 function cancelSearch() {
2233 exception_error("cancelSearch", e
);
2237 function setSelectionScore() {
2239 var ids
= getSelectedArticleIds2();
2241 if (ids
.length
> 0) {
2244 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2246 if (score
!= undefined) {
2247 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2248 "&score=" + param_escape(score
);
2250 new Ajax
.Request("backend.php", {
2252 onComplete: function(transport
) {
2253 var reply
= JSON
.parse(transport
.responseText
);
2257 ids
.each(function(id
) {
2258 var row
= $("RROW-" + id
);
2261 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2264 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2265 reply
["score_pic"]);
2266 pic
.setAttribute("score", score
);
2275 alert(__("No articles are selected."));
2278 exception_error("setSelectionScore", e
);
2282 function updateScore(id
) {
2284 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2288 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2290 new Ajax
.Request("backend.php", {
2292 onComplete: function(transport
) {
2293 console
.log(transport
.responseText
);
2295 var reply
= JSON
.parse(transport
.responseText
);
2298 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2299 pic
.setAttribute("score", reply
["score"]);
2300 pic
.setAttribute("title", reply
["score"]);
2306 exception_error("updateScore", e
);
2310 function changeScore(id
, pic
) {
2312 var score
= pic
.getAttribute("score");
2314 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2316 if (new_score
!= undefined) {
2318 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2319 "&score=" + param_escape(new_score
);
2321 new Ajax
.Request("backend.php", {
2323 onComplete: function(transport
) {
2324 var reply
= JSON
.parse(transport
.responseText
);
2327 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2328 pic
.setAttribute("score", new_score
);
2329 pic
.setAttribute("title", new_score
);
2334 exception_error("changeScore", e
);
2338 function displayArticleUrl(id
) {
2340 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2342 new Ajax
.Request("backend.php", {
2344 onComplete: function(transport
) {
2345 var reply
= JSON
.parse(transport
.responseText
);
2347 if (reply
&& reply
.link
) {
2348 prompt(__("Article URL:"), reply
.link
);
2352 exception_error("changeScore", e
);
2356 function scrollToRowId(id
) {
2361 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2364 exception_error("scrollToRowId", e
);
2368 function updateFloatingTitle(unread_only
) {
2370 if (!isCdmMode()) return;
2372 var hf
= $("headlines-frame");
2374 var elems
= $$("#headlines-frame > div[id*=RROW]");
2376 for (var i
= 0; i
< elems
.length
; i
++) {
2378 var child
= elems
[i
];
2380 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2382 var header
= child
.getElementsByClassName("cdmHeader")[0];
2384 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2385 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2386 $("floatingTitle").setAttribute("rowid", child
.id
);
2387 $("floatingTitle").innerHTML
= header
.innerHTML
;
2388 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2392 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2395 cb
.parentNode
.removeChild(cb
);
2398 if (child
.hasClassName("Unread"))
2399 $("floatingTitle").addClassName("Unread");
2401 $("floatingTitle").removeClassName("Unread");
2403 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2406 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2407 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2408 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2409 $("floatingTitle").style
.visibility
= "visible";
2411 $("floatingTitle").style
.visibility
= "hidden";
2419 exception_error("updateFloatingTitle", e
);
2423 function catchupCurrentBatchIfNeeded() {
2424 if (catchup_id_batch
.length
> 0) {
2425 window
.clearTimeout(catchup_timeout_id
);
2426 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2428 if (catchup_id_batch
.length
>= 10) {
2429 catchupBatchedArticles();
2434 function cdmFooterClick(event
) {
2435 event
.stopPropagation();