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
!= 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 dijit
.byId("headlines-frame").attr("content", "");
95 var tmp
= new Element("div");
97 reply
['headlines']['content'].each(function(row
) {
98 if (loaded_article_ids
.indexOf(row
.id
) == -1) {
99 loaded_article_ids
.push(row
.id
);
102 tmp
.innerHTML
+= row
.html
;
105 dojo
.parser
.parse(tmp
);
106 dijit
.byId("headlines-frame").attr("content", tmp
.innerHTML
);
108 var hsp
= $("headlines-spacer");
109 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
110 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
114 if (_infscroll_disable
)
115 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
116 __("Click to open next unread feed.") + "</a>";
119 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
120 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
126 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
127 console
.log("adding some more headlines: " + headlines_count
);
129 var c
= dijit
.byId("headlines-frame");
130 var ids
= getSelectedArticleIds2();
132 var hsp
= $("headlines-spacer");
135 c
.domNode
.removeChild(hsp
);
137 var tmp
= new Element("div");
139 reply
['headlines']['content'].each(function(row
) {
140 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.kind
== 'feed_title') {
141 loaded_article_ids
.push(row
.id
);
143 tmp
.innerHTML
+= row
.html
;
148 dojo
.parser
.parse(tmp
);
150 while (tmp
.hasChildNodes()) {
151 dijit
.byId("headlines-frame").domNode
.appendChild(tmp
.removeChild(tmp
.firstChild
));
154 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
155 c
.domNode
.appendChild(hsp
);
157 if (reply
['headlines']['content'].size() == 0) _infscroll_disable
= true;
159 console
.log("restore selected ids: " + ids
);
161 for (var i
= 0; i
< ids
.length
; i
++) {
162 markHeadline(ids
[i
]);
167 if (_infscroll_disable
) {
168 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
169 __("Click to open next unread feed.") + "</a>";
173 console
.log("no new headlines received");
175 var first_id_changed
= reply
['headlines']['first_id_changed'];
176 console
.log("first id changed:" + first_id_changed
);
178 var hsp
= $("headlines-spacer");
181 if (first_id_changed
) {
182 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
183 __("New articles found, reload feed to continue.") + "</a>";
185 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
186 __("Click to open next unread feed.") + "</a>";
195 for (var i
= 0; i
< articles
.length
; i
++) {
196 var a_id
= articles
[i
]['id'];
197 cache_set("article:" + a_id
, articles
[i
]['content']);
200 console
.log("no cached articles received");
204 parse_counters(counters
);
206 request_counters(true);
209 console
.error("Invalid object received: " + transport
.responseText
);
210 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
211 __('Could not update headlines (invalid object received - see error console for details)') +
215 _infscroll_request_sent
= 0;
216 _last_headlines_update
= new Date().getTime();
218 unpackVisibleHeadlines();
220 // if we have some more space in the buffer, why not try to fill it
222 if (!_infscroll_disable
&& $("headlines-spacer") &&
223 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
225 window
.setTimeout(function() {
233 exception_error("headlines_callback2", e
, transport
);
237 function render_article(article
) {
239 dijit
.byId("headlines-wrap-inner").addChild(
240 dijit
.byId("content-insert"));
242 var c
= dijit
.byId("content-insert");
245 c
.domNode
.scrollTop
= 0;
248 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
250 c
.attr('content', article
);
252 correctHeadlinesOffset(getActiveArticleId());
259 exception_error("render_article", e
);
263 function showArticleInHeadlines(id
, noexpand
) {
266 selectArticles("none");
268 var crow
= $("RROW-" + id
);
272 var article_is_unread
= crow
.hasClassName("Unread");
275 crow
.removeClassName("Unread");
276 crow
.addClassName("active");
278 selectArticles('none');
280 var view_mode
= false;
283 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
284 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
291 if (article_is_unread
&& !noexpand
)
292 _force_scheduled_update
= true;
295 exception_error("showArticleInHeadlines", e
);
299 function article_callback2(transport
, id
) {
301 console
.log("article_callback2 " + id
);
303 handle_rpc_json(transport
);
308 reply
= JSON
.parse(transport
.responseText
);
315 reply
.each(function(article
) {
316 if (getActiveArticleId() == article
['id']) {
317 render_article(article
['content']);
319 cids_requested
.remove(article
['id']);
321 cache_set("article:" + article
['id'], article
['content']);
324 // if (id != last_requested_article) {
325 // console.log("requested article id is out of sequence, aborting");
330 console
.error("Invalid object received: " + transport
.responseText
);
332 render_article("<div class='whiteBox'>" +
333 __('Could not display article (invalid object received - see error console for details)') + "</div>");
336 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
337 request_counters(unread_in_buffer
== 0);
341 exception_error("article_callback2", e
, transport
);
345 function view(id
, activefeed
, noexpand
) {
347 var oldrow
= $("RROW-" + getActiveArticleId());
348 if (oldrow
) oldrow
.removeClassName("active");
350 var crow
= $("RROW-" + id
);
354 setActiveArticleId(id
);
355 showArticleInHeadlines(id
, noexpand
);
359 console
.log("loading article: " + id
);
361 var cached_article
= cache_get("article:" + id
);
363 console
.log("cache check result: " + (cached_article
!= false));
365 var query
= "?op=article&method=view&id=" + param_escape(id
);
367 var neighbor_ids
= getRelativePostIds(id
);
369 /* only request uncached articles */
371 var cids_to_request
= [];
373 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
374 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
375 if (!cache_get("article:" + neighbor_ids
[i
])) {
376 cids_to_request
.push(neighbor_ids
[i
]);
377 cids_requested
.push(neighbor_ids
[i
]);
381 console
.log("additional ids: " + cids_to_request
.toString());
383 query
= query
+ "&cids=" + cids_to_request
.toString();
385 var article_is_unread
= crow
.hasClassName("Unread");
387 setActiveArticleId(id
);
388 showArticleInHeadlines(id
);
390 if (cached_article
&& article_is_unread
) {
392 query
= query
+ "&mode=prefetch";
394 render_article(cached_article
);
396 } else if (cached_article
) {
398 query
= query
+ "&mode=prefetch_old";
399 render_article(cached_article
);
401 // if we don't need to request any relative ids, we might as well skip
402 // the server roundtrip altogether
403 if (cids_to_request
.length
== 0) {
408 last_requested_article
= id
;
412 if (article_is_unread
) {
413 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
416 new Ajax
.Request("backend.php", {
418 onComplete: function(transport
) {
419 article_callback2(transport
, id
);
425 exception_error("view", e
);
429 function toggleMark(id
, client_only
) {
431 var query
= "?op=rpc&id=" + id
+ "&method=mark";
433 var row
= $("RROW-" + id
);
438 var row_imgs
= row
.getElementsByClassName("markedPic");
440 for (var i
= 0; i
< row_imgs
.length
; i
++)
441 imgs
.push(row_imgs
[i
]);
443 var ft
= $("floatingTitle");
445 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
446 var fte
= ft
.getElementsByClassName("markedPic");
448 for (var i
= 0; i
< fte
.length
; i
++)
452 for (i
= 0; i
< imgs
.length
; i
++) {
455 if (!row
.hasClassName("marked")) {
456 img
.src
= img
.src
.replace("mark_unset", "mark_set");
457 img
.alt
= __("Unstar article");
458 query
= query
+ "&mark=1";
460 img
.src
= img
.src
.replace("mark_set", "mark_unset");
461 img
.alt
= __("Star article");
462 query
= query
+ "&mark=0";
466 row
.toggleClassName("marked");
469 new Ajax
.Request("backend.php", {
471 onComplete: function(transport
) {
472 handle_rpc_json(transport
);
477 exception_error("toggleMark", e
);
481 function togglePub(id
, client_only
, no_effects
, note
) {
483 var query
= "?op=rpc&id=" + id
+ "&method=publ";
485 if (note
!= undefined) {
486 query
= query
+ "¬e=" + param_escape(note
);
488 query
= query
+ "¬e=undefined";
491 var row
= $("RROW-" + id
);
496 var row_imgs
= row
.getElementsByClassName("pubPic");
498 for (var i
= 0; i
< row_imgs
.length
; i
++)
499 imgs
.push(row_imgs
[i
]);
501 var ft
= $("floatingTitle");
503 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
504 var fte
= ft
.getElementsByClassName("pubPic");
506 for (var i
= 0; i
< fte
.length
; i
++)
510 for (i
= 0; i
< imgs
.length
; i
++) {
513 if (!row
.hasClassName("published") || note
!= undefined) {
514 img
.src
= img
.src
.replace("pub_unset", "pub_set");
515 img
.alt
= __("Unpublish article");
516 query
= query
+ "&pub=1";
518 img
.src
= img
.src
.replace("pub_set", "pub_unset");
519 img
.alt
= __("Publish article");
520 query
= query
+ "&pub=0";
524 if (note
!= undefined)
525 row
.addClassName("published");
527 row
.toggleClassName("published");
530 new Ajax
.Request("backend.php", {
532 onComplete: function(transport
) {
533 handle_rpc_json(transport
);
538 exception_error("togglePub", e
);
542 function moveToPost(mode
, noscroll
, noexpand
) {
546 var rows
= getVisibleArticleIds();
551 if (!$('RROW-' + getActiveArticleId())) {
552 setActiveArticleId(0);
555 if (!getActiveArticleId()) {
557 prev_id
= rows
[rows
.length
-1]
559 for (var i
= 0; i
< rows
.length
; i
++) {
560 if (rows
[i
] == getActiveArticleId()) {
562 // Account for adjacent identical article ids.
563 if (i
> 0) prev_id
= rows
[i
-1];
565 for (var j
= i
+1; j
< rows
.length
; j
++) {
566 if (rows
[j
] != getActiveArticleId()) {
576 if (mode
== "next") {
577 if (next_id
|| getActiveArticleId()) {
580 var article
= $("RROW-" + getActiveArticleId());
581 var ctr
= $("headlines-frame");
583 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
584 ctr
.scrollTop
+ ctr
.offsetHeight
) {
586 scrollArticle(ctr
.offsetHeight
/4);
588 } else if (next_id
) {
589 cdmExpandArticle(next_id
, noexpand
);
590 cdmScrollToArticleId(next_id
, true);
593 } else if (next_id
) {
594 correctHeadlinesOffset(next_id
);
595 view(next_id
, getActiveFeedId(), noexpand
);
600 if (mode
== "prev") {
601 if (prev_id
|| getActiveArticleId()) {
604 var article
= $("RROW-" + getActiveArticleId());
605 var prev_article
= $("RROW-" + prev_id
);
606 var ctr
= $("headlines-frame");
608 if (!getInitParam("cdm_expanded")) {
610 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
611 scrollArticle(-ctr
.offsetHeight
/4);
613 cdmExpandArticle(prev_id
, noexpand
);
614 cdmScrollToArticleId(prev_id
, true);
618 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
619 scrollArticle(-ctr
.offsetHeight
/3);
620 } else if (!noscroll
&& prev_article
&&
621 prev_article
.offsetTop
< ctr
.scrollTop
) {
622 cdmExpandArticle(prev_id
, noexpand
);
623 scrollArticle(-ctr
.offsetHeight
/4);
624 } else if (prev_id
) {
625 cdmExpandArticle(prev_id
, noexpand
);
626 cdmScrollToArticleId(prev_id
, noscroll
);
630 } else if (prev_id
) {
631 correctHeadlinesOffset(prev_id
);
632 view(prev_id
, getActiveFeedId(), noexpand
);
638 exception_error("moveToPost", e
);
642 function toggleSelected(id
, force_on
) {
644 var row
= $("RROW-" + id
);
647 var cb
= dijit
.getEnclosingWidget(
648 row
.getElementsByClassName("rchk")[0]);
650 if (row
.hasClassName('Selected') && !force_on
) {
651 row
.removeClassName('Selected');
652 if (cb
) cb
.attr("checked", false);
654 row
.addClassName('Selected');
655 if (cb
) cb
.attr("checked", true);
659 updateSelectedPrompt();
661 exception_error("toggleSelected", e
);
665 function updateSelectedPrompt() {
667 var count
= getSelectedArticleIds2().size();
668 var elem
= $("selected_prompt");
671 elem
.innerHTML
= ngettext("%d article selected",
672 "%d articles selected", count
).replace("%d", count
);
681 exception_error("updateSelectedPrompt", e
);
685 function toggleUnread_afh(effect
) {
688 var elem
= effect
.element
;
689 elem
.style
.backgroundColor
= "";
692 exception_error("toggleUnread_afh", e
);
696 function toggleUnread(id
, cmode
, effect
) {
699 var row
= $("RROW-" + id
);
701 if (cmode
== undefined || cmode
== 2) {
702 if (row
.hasClassName("Unread")) {
703 row
.removeClassName("Unread");
706 row
.addClassName("Unread");
709 } else if (cmode
== 0) {
711 row
.removeClassName("Unread");
713 } else if (cmode
== 1) {
714 row
.addClassName("Unread");
717 if (cmode
== undefined) cmode
= 2;
719 var query
= "?op=rpc&method=catchupSelected" +
720 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
722 // notify_progress("Loading, please wait...");
724 new Ajax
.Request("backend.php", {
726 onComplete: function(transport
) {
727 handle_rpc_json(transport
);
733 exception_error("toggleUnread", e
);
737 function selectionRemoveLabel(id
, ids
) {
740 if (!ids
) ids
= getSelectedArticleIds2();
742 if (ids
.length
== 0) {
743 alert(__("No articles are selected."));
747 var query
= "?op=article&method=removeFromLabel&ids=" +
748 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
752 new Ajax
.Request("backend.php", {
754 onComplete: function(transport
) {
755 handle_rpc_json(transport
);
756 show_labels_in_headlines(transport
);
760 exception_error("selectionAssignLabel", e
);
765 function selectionAssignLabel(id
, ids
) {
768 if (!ids
) ids
= getSelectedArticleIds2();
770 if (ids
.length
== 0) {
771 alert(__("No articles are selected."));
775 var query
= "?op=article&method=assignToLabel&ids=" +
776 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
780 new Ajax
.Request("backend.php", {
782 onComplete: function(transport
) {
783 handle_rpc_json(transport
);
784 show_labels_in_headlines(transport
);
788 exception_error("selectionAssignLabel", e
);
793 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
795 var rows
= ids
? ids
: getSelectedArticleIds2();
797 if (rows
.length
== 0 && !no_error
) {
798 alert(__("No articles are selected."));
802 for (var i
= 0; i
< rows
.length
; i
++) {
803 var row
= $("RROW-" + rows
[i
]);
805 if (set_state
== undefined) {
806 if (row
.hasClassName("Unread")) {
807 row
.removeClassName("Unread");
809 row
.addClassName("Unread");
813 if (set_state
== false) {
814 row
.removeClassName("Unread");
817 if (set_state
== true) {
818 row
.addClassName("Unread");
823 updateFloatingTitle(true);
825 if (rows
.length
> 0) {
829 if (set_state
== undefined) {
831 } else if (set_state
== true) {
833 } else if (set_state
== false) {
837 var query
= "?op=rpc&method=catchupSelected" +
838 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
840 notify_progress("Loading, please wait...");
842 new Ajax
.Request("backend.php", {
844 onComplete: function(transport
) {
845 handle_rpc_json(transport
);
846 if (callback
) callback(transport
);
852 exception_error("selectionToggleUnread", e
);
857 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
860 var rows
= ids
? ids
: getSelectedArticleIds2();
862 if (rows
.length
== 0 && !no_error
) {
863 alert(__("No articles are selected."));
867 for (var i
= 0; i
< rows
.length
; i
++) {
868 toggleMark(rows
[i
], true, true);
871 if (rows
.length
> 0) {
873 var query
= "?op=rpc&method=markSelected&ids=" +
874 param_escape(rows
.toString()) + "&cmode=2";
876 new Ajax
.Request("backend.php", {
878 onComplete: function(transport
) {
879 handle_rpc_json(transport
);
880 if (callback
) callback(transport
);
886 exception_error("selectionToggleMarked", e
);
891 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
894 var rows
= ids
? ids
: getSelectedArticleIds2();
896 if (rows
.length
== 0 && !no_error
) {
897 alert(__("No articles are selected."));
901 for (var i
= 0; i
< rows
.length
; i
++) {
902 togglePub(rows
[i
], true, true);
905 if (rows
.length
> 0) {
907 var query
= "?op=rpc&method=publishSelected&ids=" +
908 param_escape(rows
.toString()) + "&cmode=2";
910 new Ajax
.Request("backend.php", {
912 onComplete: function(transport
) {
913 handle_rpc_json(transport
);
919 exception_error("selectionToggleMarked", e
);
923 function getSelectedArticleIds2() {
927 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
929 rv
.push(child
.id
.replace("RROW-", ""));
935 function getLoadedArticleIds() {
938 var children
= $$("#headlines-frame > div[id*=RROW-]");
940 children
.each(function(child
) {
941 rv
.push(child
.id
.replace("RROW-", ""));
948 // mode = all,none,unread,invert,marked,published
949 function selectArticles(mode
, query
) {
952 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
954 var children
= $$(query
);
956 children
.each(function(child
) {
957 var id
= child
.id
.replace("RROW-", "");
959 var cb
= dijit
.getEnclosingWidget(
960 child
.getElementsByClassName("rchk")[0]);
963 child
.addClassName("Selected");
964 if (cb
) cb
.attr("checked", true);
965 } else if (mode
== "unread") {
966 if (child
.hasClassName("Unread")) {
967 child
.addClassName("Selected");
968 if (cb
) cb
.attr("checked", true);
970 child
.removeClassName("Selected");
971 if (cb
) cb
.attr("checked", false);
973 } else if (mode
== "marked") {
974 if (child
.hasClassName("marked")) {
975 child
.addClassName("Selected");
976 if (cb
) cb
.attr("checked", true);
978 child
.removeClassName("Selected");
979 if (cb
) cb
.attr("checked", false);
981 } else if (mode
== "published") {
982 if (child
.hasClassName("published")) {
983 child
.addClassName("Selected");
984 if (cb
) cb
.attr("checked", true);
986 child
.removeClassName("Selected");
987 if (cb
) cb
.attr("checked", false);
990 } else if (mode
== "invert") {
991 if (child
.hasClassName("Selected")) {
992 child
.removeClassName("Selected");
993 if (cb
) cb
.attr("checked", false);
995 child
.addClassName("Selected");
996 if (cb
) cb
.attr("checked", true);
1000 child
.removeClassName("Selected");
1001 if (cb
) cb
.attr("checked", false);
1005 updateSelectedPrompt();
1008 exception_error("selectArticles", e
);
1012 function deleteSelection() {
1016 var rows
= getSelectedArticleIds2();
1018 if (rows
.length
== 0) {
1019 alert(__("No articles are selected."));
1023 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1026 if (getActiveFeedId() != 0) {
1027 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1029 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1032 str
= str
.replace("%d", rows
.length
);
1033 str
= str
.replace("%s", fn
);
1035 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1039 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1043 new Ajax
.Request("backend.php", {
1045 onComplete: function(transport
) {
1046 handle_rpc_json(transport
);
1051 exception_error("deleteSelection", e
);
1055 function archiveSelection() {
1059 var rows
= getSelectedArticleIds2();
1061 if (rows
.length
== 0) {
1062 alert(__("No articles are selected."));
1066 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1070 if (getActiveFeedId() != 0) {
1071 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1074 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1076 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1081 str
= str
.replace("%d", rows
.length
);
1082 str
= str
.replace("%s", fn
);
1084 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1088 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1092 for (var i
= 0; i
< rows
.length
; i
++) {
1093 cache_delete("article:" + rows
[i
]);
1096 new Ajax
.Request("backend.php", {
1098 onComplete: function(transport
) {
1099 handle_rpc_json(transport
);
1104 exception_error("archiveSelection", e
);
1108 function catchupSelection() {
1112 var rows
= getSelectedArticleIds2();
1114 if (rows
.length
== 0) {
1115 alert(__("No articles are selected."));
1119 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1121 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1123 str
= str
.replace("%d", rows
.length
);
1124 str
= str
.replace("%s", fn
);
1126 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1130 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1133 exception_error("catchupSelection", e
);
1137 function editArticleTags(id
) {
1138 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1140 if (dijit
.byId("editTagsDlg"))
1141 dijit
.byId("editTagsDlg").destroyRecursive();
1143 dialog
= new dijit
.Dialog({
1145 title
: __("Edit article Tags"),
1146 style
: "width: 600px",
1147 execute: function() {
1148 if (this.validate()) {
1149 var query
= dojo
.objectToQuery(this.attr('value'));
1151 notify_progress("Saving article tags...", true);
1153 new Ajax
.Request("backend.php", {
1155 onComplete: function(transport
) {
1160 var data
= JSON
.parse(transport
.responseText
);
1167 var tags
= $("ATSTR-" + id
);
1168 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1170 if (tags
) tags
.innerHTML
= data
.content
;
1171 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1174 exception_error("editArticleTags/inner", e
);
1183 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1184 dojo
.disconnect(tmph
);
1186 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1187 "backend.php?op=article&method=completeTags",
1188 { tokens
: ',', paramName
: "search" });
1195 function cdmScrollToArticleId(id
, force
) {
1197 var ctr
= $("headlines-frame");
1198 var e
= $("RROW-" + id
);
1200 if (!e
|| !ctr
) return;
1202 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1203 e
.offsetTop
< ctr
.scrollTop
) {
1205 // expanded cdm has a 4px margin now
1206 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1210 exception_error("cdmScrollToArticleId", e
);
1214 function setActiveArticleId(id
) {
1215 _active_article_id
= id
;
1216 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1219 function getActiveArticleId() {
1220 return _active_article_id
;
1223 function postMouseIn(e
, id
) {
1224 post_under_pointer
= id
;
1227 function postMouseOut(id
) {
1228 post_under_pointer
= false;
1231 function unpackVisibleHeadlines() {
1233 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1235 $$("#headlines-frame > div[id*=RROW]").each(
1237 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1238 $("headlines-frame").offsetHeight
) {
1240 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1243 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1245 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1246 cencw
.setAttribute('id', '');
1247 Element
.show(cencw
);
1254 exception_error("unpackVisibleHeadlines", e
);
1258 function headlines_scroll_handler(e
) {
1260 var hsp
= $("headlines-spacer");
1262 unpackVisibleHeadlines();
1264 // set topmost child in the buffer as active
1265 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1266 getSelectedArticleIds2().length
<= 1 &&
1267 getInitParam("cdm_expanded")) {
1268 var rows
= $$("#headlines-frame > div[id*=RROW]");
1270 for (var i
= 0; i
< rows
.length
; i
++) {
1271 var child
= rows
[i
];
1273 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1274 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1275 child
.id
.replace("RROW-", "") != _active_article_id
) {
1277 if (_active_article_id
) {
1278 var row
= $("RROW-" + _active_article_id
);
1279 if (row
) row
.removeClassName("active");
1282 _active_article_id
= child
.id
.replace("RROW-", "");
1283 showArticleInHeadlines(_active_article_id
, true);
1284 updateSelectedPrompt();
1290 if (!_infscroll_disable
) {
1291 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1292 (e
.scrollHeight
!= 0 &&
1293 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1296 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1297 __("Loading, please wait...") + "</span>";
1299 loadMoreHeadlines();
1305 if (_infscroll_disable)
1306 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1307 __("Click to open next unread feed.") + "</a>";
1314 updateFloatingTitle();
1317 if (getInitParam("cdm_auto_catchup") == 1) {
1319 // let's get DOM some time to settle down
1320 var ts
= new Date().getTime();
1321 if (ts
- _last_headlines_update
< 100) return;
1323 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1325 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1326 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1328 var id
= child
.id
.replace("RROW-", "");
1330 if (catchup_id_batch
.indexOf(id
) == -1)
1331 catchup_id_batch
.push(id
);
1333 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1338 if (catchup_id_batch
.length
> 0) {
1339 window
.clearTimeout(catchup_timeout_id
);
1341 if (!_infscroll_request_sent
) {
1342 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1347 if (_infscroll_disable
) {
1348 var child
= $$("#headlines-frame div[id*=RROW]").last();
1350 if (child
&& $("headlines-frame").scrollTop
>
1351 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1353 console
.log("we seem to be at an end");
1355 if (getInitParam("on_catchup_show_next_feed") == "1") {
1356 openNextUnreadFeed();
1363 console
.warn("headlines_scroll_handler: " + e
);
1367 function openNextUnreadFeed() {
1369 var is_cat
= activeFeedIsCat();
1370 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1371 if (nuf
) viewfeed(nuf
, '', is_cat
);
1373 exception_error("openNextUnreadFeed", e
);
1377 function catchupBatchedArticles() {
1379 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1381 // make a copy of the array
1382 var batch
= catchup_id_batch
.slice();
1383 var query
= "?op=rpc&method=catchupSelected" +
1384 "&cmode=0&ids=" + param_escape(batch
.toString());
1388 new Ajax
.Request("backend.php", {
1390 onComplete: function(transport
) {
1391 handle_rpc_json(transport
);
1393 reply
= JSON
.parse(transport
.responseText
);
1394 var batch
= reply
.ids
;
1396 batch
.each(function(id
) {
1398 var elem
= $("RROW-" + id
);
1399 if (elem
) elem
.removeClassName("Unread");
1400 catchup_id_batch
.remove(id
);
1403 updateFloatingTitle(true);
1409 exception_error("catchupBatchedArticles", e
);
1413 function catchupRelativeToArticle(below
, id
) {
1417 if (!id
) id
= getActiveArticleId();
1420 alert(__("No article is selected."));
1424 var visible_ids
= getVisibleArticleIds();
1426 var ids_to_mark
= new Array();
1429 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1430 if (visible_ids
[i
] != id
) {
1431 var e
= $("RROW-" + visible_ids
[i
]);
1433 if (e
&& e
.hasClassName("Unread")) {
1434 ids_to_mark
.push(visible_ids
[i
]);
1441 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1442 if (visible_ids
[i
] != id
) {
1443 var e
= $("RROW-" + visible_ids
[i
]);
1445 if (e
&& e
.hasClassName("Unread")) {
1446 ids_to_mark
.push(visible_ids
[i
]);
1454 if (ids_to_mark
.length
== 0) {
1455 alert(__("No articles found to mark"));
1457 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1459 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1461 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1462 var e
= $("RROW-" + ids_to_mark
[i
]);
1463 e
.removeClassName("Unread");
1466 var query
= "?op=rpc&method=catchupSelected" +
1467 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1469 new Ajax
.Request("backend.php", {
1471 onComplete: function(transport
) {
1472 handle_rpc_json(transport
);
1479 exception_error("catchupRelativeToArticle", e
);
1483 function cdmCollapseArticle(event
, id
, unmark
) {
1485 if (unmark
== undefined) unmark
= true;
1487 var row
= $("RROW-" + id
);
1488 var elem
= $("CICD-" + id
);
1491 var collapse
= $$("div#RROW-" + id
+
1492 " span[class='collapseBtn']")[0];
1495 Element
.show("CEXC-" + id
);
1496 Element
.hide(collapse
);
1499 row
.removeClassName("active");
1501 markHeadline(id
, false);
1503 if (id
== getActiveArticleId()) {
1504 setActiveArticleId(0);
1507 updateSelectedPrompt();
1510 if (event
) Event
.stop(event
);
1512 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1514 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1515 scrollToRowId(row
.id
);
1517 $("floatingTitle").style
.visibility
= "hidden";
1518 $("floatingTitle").setAttribute("rowid", false);
1522 exception_error("cdmCollapseArticle", e
);
1526 function cdmExpandArticle(id
, noexpand
) {
1528 console
.log("cdmExpandArticle " + id
);
1530 if (!$("RROW-" + id
)) return false;
1532 var oldrow
= $("RROW-" + getActiveArticleId());
1534 var elem
= $("CICD-" + getActiveArticleId());
1536 if (id
== getActiveArticleId() && Element
.visible(elem
))
1539 selectArticles("none");
1541 var old_offset
= $("RROW-" + id
).offsetTop
;
1543 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1544 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1545 " span[class='collapseBtn']")[0];
1548 Element
.show("CEXC-" + getActiveArticleId());
1549 Element
.hide(collapse
);
1552 if (oldrow
) oldrow
.removeClassName("active");
1554 setActiveArticleId(id
);
1556 elem
= $("CICD-" + id
);
1558 var collapse
= $$("div#RROW-" + id
+
1559 " span[class='collapseBtn']")[0];
1561 var cencw
= $("CENCW-" + id
);
1563 if (!Element
.visible(elem
) && !noexpand
) {
1565 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1566 cencw
.setAttribute('id', '');
1567 Element
.show(cencw
);
1571 Element
.hide("CEXC-" + id
);
1572 Element
.show(collapse
);
1575 var new_offset
= $("RROW-" + id
).offsetTop
;
1577 if (old_offset
> new_offset
)
1578 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1581 toggleUnread(id
, 0, true);
1583 $("RROW-" + id
).addClassName("active");
1585 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1588 exception_error("cdmExpandArticle", e
);
1594 function getArticleUnderPointer() {
1595 return post_under_pointer
;
1598 function scrollArticle(offset
) {
1601 var ci
= $("content-insert");
1603 ci
.scrollTop
+= offset
;
1606 var hi
= $("headlines-frame");
1608 hi
.scrollTop
+= offset
;
1613 exception_error("scrollArticle", e
);
1617 function show_labels_in_headlines(transport
) {
1619 var data
= JSON
.parse(transport
.responseText
);
1622 data
['info-for-headlines'].each(function(elem
) {
1623 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1624 ctr
.innerHTML
= elem
.labels
;
1629 exception_error("show_labels_in_headlines", e
);
1633 function dismissArticle(id
) {
1635 var elem
= $("RROW-" + id
);
1639 toggleUnread(id
, 0, true);
1641 new Effect
.Fade(elem
, {duration
: 0.5});
1643 // Remove the content, too
1644 var elem_content
= $("CICD-" + id
);
1646 Element
.remove(elem_content
);
1649 if (id
== getActiveArticleId()) {
1650 setActiveArticleId(0);
1654 exception_error("dismissArticle", e
);
1658 function dismissSelectedArticles() {
1661 var ids
= getVisibleArticleIds();
1665 for (var i
= 0; i
< ids
.length
; i
++) {
1666 var elem
= $("RROW-" + ids
[i
]);
1668 if (elem
.className
&& elem
.hasClassName("Selected") &&
1669 ids
[i
] != getActiveArticleId()) {
1670 new Effect
.Fade(elem
, {duration
: 0.5});
1673 // Remove the content, too
1674 var elem_content
= $("CICD-" + ids
[i
]);
1676 Element
.remove(elem_content
);
1684 selectionToggleUnread(false);
1688 exception_error("dismissSelectedArticles", e
);
1692 function dismissReadArticles() {
1695 var ids
= getVisibleArticleIds();
1698 for (var i
= 0; i
< ids
.length
; i
++) {
1699 var elem
= $("RROW-" + ids
[i
]);
1701 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1702 !elem
.hasClassName("Selected")) {
1704 new Effect
.Fade(elem
, {duration
: 0.5});
1706 // Remove the content, too
1707 var elem_content
= $("CICD-" + ids
[i
]);
1709 Element
.remove(elem_content
);
1717 exception_error("dismissReadArticles", e
);
1721 function getVisibleArticleIds() {
1726 getLoadedArticleIds().each(function(id
) {
1727 var elem
= $("RROW-" + id
);
1728 if (elem
&& Element
.visible(elem
))
1733 exception_error("getVisibleArticleIds", e
);
1739 function cdmClicked(event
, id
) {
1741 //var shift_key = event.shiftKey;
1743 if (!event
.ctrlKey
) {
1745 if (!getInitParam("cdm_expanded")) {
1746 return cdmExpandArticle(id
);
1749 var elem
= $("RROW-" + getActiveArticleId());
1751 if (elem
) elem
.removeClassName("active");
1753 selectArticles("none");
1756 var elem
= $("RROW-" + id
);
1757 var article_is_unread
= elem
.hasClassName("Unread");
1759 elem
.removeClassName("Unread");
1760 elem
.addClassName("active");
1762 setActiveArticleId(id
);
1764 if (article_is_unread
) {
1765 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1766 updateFloatingTitle(true);
1769 var query
= "?op=rpc&method=catchupSelected" +
1770 "&cmode=0&ids=" + param_escape(id
);
1772 new Ajax
.Request("backend.php", {
1774 onComplete: function(transport
) {
1775 handle_rpc_json(transport
);
1778 return !event
.shiftKey
;
1781 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1783 toggleSelected(id
, true);
1785 var elem
= $("RROW-" + id
);
1786 var article_is_unread
= elem
.hasClassName("Unread");
1788 if (article_is_unread
) {
1789 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1792 toggleUnread(id
, 0, false);
1794 openArticleInNewWindow(id
);
1797 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1798 request_counters(unread_in_buffer
== 0);
1801 exception_error("cdmClicked");
1807 function hlClicked(event
, id
) {
1809 if (event
.which
== 2) {
1812 } else if (event
.ctrlKey
) {
1813 toggleSelected(id
, true);
1814 toggleUnread(id
, 0, false);
1815 openArticleInNewWindow(id
);
1823 exception_error("hlClicked");
1827 function getFirstVisibleHeadlineId() {
1828 var rows
= getVisibleArticleIds();
1833 function getLastVisibleHeadlineId() {
1834 var rows
= getVisibleArticleIds();
1835 return rows
[rows
.length
-1];
1838 function openArticleInNewWindow(id
) {
1839 toggleUnread(id
, 0, false);
1840 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1843 function isCdmMode() {
1844 return getInitParam("combined_display_mode");
1847 function markHeadline(id
, marked
) {
1848 if (marked
== undefined) marked
= true;
1850 var row
= $("RROW-" + id
);
1852 var check
= dijit
.getEnclosingWidget(
1853 row
.getElementsByClassName("rchk")[0]);
1856 check
.attr("checked", marked
);
1860 row
.addClassName("Selected");
1862 row
.removeClassName("Selected");
1866 function getRelativePostIds(id
, limit
) {
1872 if (!limit
) limit
= 6; //3
1874 var ids
= getVisibleArticleIds();
1876 for (var i
= 0; i
< ids
.length
; i
++) {
1878 for (var k
= 1; k
<= limit
; k
++) {
1879 //if (i > k-1) tmp.push(ids[i-k]);
1880 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1887 exception_error("getRelativePostIds", e
);
1893 function correctHeadlinesOffset(id
) {
1897 var container
= $("headlines-frame");
1898 var row
= $("RROW-" + id
);
1900 if (!container
|| !row
) return;
1902 var viewport
= container
.offsetHeight
;
1904 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1905 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1907 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1908 //console.log("Vport: " + viewport);
1910 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1911 container
.scrollTop
= row
.offsetTop
;
1912 } else if (rel_offset_bottom
> viewport
) {
1914 /* doesn't properly work with Opera in some cases because
1915 Opera fucks up element scrolling */
1917 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1921 exception_error("correctHeadlinesOffset", e
);
1926 function headlineActionsChange(elem
) {
1929 elem
.attr('value', 'false');
1931 exception_error("headlineActionsChange", e
);
1935 function closeArticlePanel() {
1937 if (dijit
.byId("content-insert"))
1938 dijit
.byId("headlines-wrap-inner").removeChild(
1939 dijit
.byId("content-insert"));
1942 function initFloatingMenu() {
1944 if (dijit
.byId("floatingMenu"))
1945 dijit
.byId("floatingMenu").destroyRecursive();
1947 var menu
= new dijit
.Menu({
1949 targetNodeIds
: ["floatingTitle"]
1952 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1954 headlinesMenuCommon(menu
, id
);
1958 exception_error("initFloatingMenu", e
);
1962 function headlinesMenuCommon(menu
, base_id
) {
1965 menu
.addChild(new dijit
.MenuItem({
1966 label
: __("Open original article"),
1967 onClick: function(event
) {
1968 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1971 menu
.addChild(new dijit
.MenuItem({
1972 label
: __("Display article URL"),
1973 onClick: function(event
) {
1974 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1977 menu
.addChild(new dijit
.MenuSeparator());
1979 menu
.addChild(new dijit
.MenuItem({
1980 label
: __("Toggle unread"),
1981 onClick: function(event
) {
1982 var ids
= getSelectedArticleIds2();
1984 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1985 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1987 selectionToggleUnread(undefined, false, true, ids
);
1990 menu
.addChild(new dijit
.MenuItem({
1991 label
: __("Toggle starred"),
1992 onClick: function(event
) {
1993 var ids
= getSelectedArticleIds2();
1995 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1996 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1998 selectionToggleMarked(undefined, false, true, ids
);
2001 menu
.addChild(new dijit
.MenuItem({
2002 label
: __("Toggle published"),
2003 onClick: function(event
) {
2004 var ids
= getSelectedArticleIds2();
2006 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2007 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2009 selectionTogglePublished(undefined, false, true, ids
);
2012 menu
.addChild(new dijit
.MenuSeparator());
2014 menu
.addChild(new dijit
.MenuItem({
2015 label
: __("Mark above as read"),
2016 onClick: function(event
) {
2017 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2020 menu
.addChild(new dijit
.MenuItem({
2021 label
: __("Mark below as read"),
2022 onClick: function(event
) {
2023 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2027 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2031 menu
.addChild(new dijit
.MenuSeparator());
2033 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2034 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2036 labels
.each(function(label
) {
2037 var id
= label
.id
[0];
2038 var bare_id
= id
.substr(id
.indexOf(":")+1);
2039 var name
= label
.name
[0];
2041 bare_id
= feed_to_label_id(bare_id
);
2043 labelAddMenu
.addChild(new dijit
.MenuItem({
2046 onClick: function(event
) {
2047 var ids
= getSelectedArticleIds2();
2049 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2051 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2053 selectionAssignLabel(this.labelId
, ids
);
2056 labelDelMenu
.addChild(new dijit
.MenuItem({
2059 onClick: function(event
) {
2060 var ids
= getSelectedArticleIds2();
2062 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2064 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2066 selectionRemoveLabel(this.labelId
, ids
);
2071 menu
.addChild(new dijit
.PopupMenuItem({
2072 label
: __("Assign label"),
2076 menu
.addChild(new dijit
.PopupMenuItem({
2077 label
: __("Remove label"),
2085 exception_error("headlinesMenuCommon", e
);
2089 function initHeadlinesMenu() {
2091 if (dijit
.byId("headlinesMenu"))
2092 dijit
.byId("headlinesMenu").destroyRecursive();
2097 nodes
= $$("#headlines-frame > div[id*=RROW]");
2099 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2102 nodes
.each(function(node
) {
2106 var menu
= new dijit
.Menu({
2107 id
: "headlinesMenu",
2111 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2112 var callerNode
= event
.target
, match
= null, tries
= 0;
2114 while (match
== null && callerNode
&& tries
<= 3) {
2115 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2116 callerNode
= callerNode
.parentNode
;
2120 if (match
) this.callerRowId
= parseInt(match
[1]);
2124 headlinesMenuCommon(menu
, false);
2128 /* vgroup feed title menu */
2130 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2133 nodes
.each(function(node
) {
2137 if (ids
.length
> 0) {
2138 if (dijit
.byId("headlinesFeedTitleMenu"))
2139 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2141 var menu
= new dijit
.Menu({
2142 id
: "headlinesFeedTitleMenu",
2146 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2147 var callerNode
= event
.target
, match
= null, tries
= 0;
2149 while (match
== null && callerNode
&& tries
<= 3) {
2150 console
.log(callerNode
.id
);
2152 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2153 callerNode
= callerNode
.parentNode
;
2156 console
.log(match
[1]);
2159 if (match
) this.callerRowId
= parseInt(match
[1]);
2163 menu
.addChild(new dijit
.MenuItem({
2164 label
: __("Select articles in group"),
2165 onClick: function(event
) {
2166 selectArticles("all",
2167 "#headlines-frame > div[id*=RROW]"+
2168 "[orig-feed-id='"+menu
.callerRowId
+"']");
2172 menu
.addChild(new dijit
.MenuItem({
2173 label
: __("Mark group as read"),
2174 onClick: function(event
) {
2175 selectArticles("none");
2176 selectArticles("all",
2177 "#headlines-frame > div[id*=RROW]"+
2178 "[orig-feed-id='"+menu
.callerRowId
+"']");
2184 menu
.addChild(new dijit
.MenuItem({
2185 label
: __("Mark feed as read"),
2186 onClick: function(event
) {
2187 catchupFeedInGroup(menu
.callerRowId
);
2195 exception_error("initHeadlinesMenu", e
);
2199 function cache_set(id
, obj
) {
2200 //console.log("cache_set: " + id);
2203 sessionStorage
[id
] = obj
;
2205 sessionStorage
.clear();
2209 function cache_get(id
) {
2211 return sessionStorage
[id
];
2214 function cache_clear() {
2216 sessionStorage
.clear();
2219 function cache_delete(id
) {
2221 sessionStorage
.removeItem(id
);
2224 function cancelSearch() {
2229 exception_error("cancelSearch", e
);
2233 function setSelectionScore() {
2235 var ids
= getSelectedArticleIds2();
2237 if (ids
.length
> 0) {
2240 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2242 if (score
!= undefined) {
2243 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2244 "&score=" + param_escape(score
);
2246 new Ajax
.Request("backend.php", {
2248 onComplete: function(transport
) {
2249 var reply
= JSON
.parse(transport
.responseText
);
2253 ids
.each(function(id
) {
2254 var row
= $("RROW-" + id
);
2257 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2260 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2261 reply
["score_pic"]);
2262 pic
.setAttribute("score", score
);
2271 alert(__("No articles are selected."));
2274 exception_error("setSelectionScore", e
);
2278 function updateScore(id
) {
2280 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2284 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2286 new Ajax
.Request("backend.php", {
2288 onComplete: function(transport
) {
2289 console
.log(transport
.responseText
);
2291 var reply
= JSON
.parse(transport
.responseText
);
2294 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2295 pic
.setAttribute("score", reply
["score"]);
2296 pic
.setAttribute("title", reply
["score"]);
2302 exception_error("updateScore", e
);
2306 function changeScore(id
, pic
) {
2308 var score
= pic
.getAttribute("score");
2310 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2312 if (new_score
!= undefined) {
2314 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2315 "&score=" + param_escape(new_score
);
2317 new Ajax
.Request("backend.php", {
2319 onComplete: function(transport
) {
2320 var reply
= JSON
.parse(transport
.responseText
);
2323 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2324 pic
.setAttribute("score", new_score
);
2325 pic
.setAttribute("title", new_score
);
2330 exception_error("changeScore", e
);
2334 function displayArticleUrl(id
) {
2336 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2338 new Ajax
.Request("backend.php", {
2340 onComplete: function(transport
) {
2341 var reply
= JSON
.parse(transport
.responseText
);
2343 if (reply
&& reply
.link
) {
2344 prompt(__("Article URL:"), reply
.link
);
2348 exception_error("changeScore", e
);
2352 function openSelectedAttachment(elem
) {
2354 var url
= elem
[elem
.selectedIndex
].value
;
2358 elem
.selectedIndex
= 0;
2362 exception_error("openSelectedAttachment", e
);
2366 function scrollToRowId(id
) {
2371 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2374 exception_error("scrollToRowId", e
);
2378 function updateFloatingTitle(unread_only
) {
2380 if (!isCdmMode()) return;
2382 var hf
= $("headlines-frame");
2384 var elems
= $$("#headlines-frame > div[id*=RROW]");
2386 for (var i
= 0; i
< elems
.length
; i
++) {
2388 var child
= elems
[i
];
2390 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2392 var header
= child
.getElementsByClassName("cdmHeader")[0];
2394 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2395 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2396 $("floatingTitle").setAttribute("rowid", child
.id
);
2397 $("floatingTitle").innerHTML
= header
.innerHTML
;
2398 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2402 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2405 cb
.parentNode
.removeChild(cb
);
2408 if (child
.hasClassName("Unread"))
2409 $("floatingTitle").addClassName("Unread");
2411 $("floatingTitle").removeClassName("Unread");
2413 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2416 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2417 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2418 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2419 $("floatingTitle").style
.visibility
= "visible";
2421 $("floatingTitle").style
.visibility
= "hidden";
2429 exception_error("updateFloatingTitle", e
);
2433 function cdmFooterClick(event
) {
2434 event
.stopPropagation();