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 /*dijit.byId("headlines-frame").attr('content',
90 reply['headlines']['content']);*/
92 //dijit.byId("headlines-toolbar").attr('content',
93 // reply['headlines']['toolbar']);
95 dojo
.html
.set($("headlines-toolbar"),
96 reply
['headlines']['toolbar'],
97 {parseContent
: true});
99 /*$$("#headlines-frame > div[id*=RROW]").each(function(row) {
100 if (loaded_article_ids.indexOf(row.id) != -1) {
101 row.parentNode.removeChild(row);
103 loaded_article_ids.push(row.id);
108 dijit
.byId("headlines-frame").attr("content", "");
110 reply
['headlines']['content'].each(function(row
) {
111 if (loaded_article_ids
.indexOf(row
.id
) == -1) {
112 loaded_article_ids
.push(row
.id
);
115 var tmp
= new Element("div");
116 tmp
.innerHTML
= row
.html
;
118 dojo
.parser
.parse(tmp
.firstChild
);
119 dijit
.byId("headlines-frame").domNode
.appendChild(tmp
.firstChild
);
123 var hsp
= $("headlines-spacer");
124 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
125 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
129 if (_infscroll_disable
)
130 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
131 __("Click to open next unread feed.") + "</a>";
134 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
135 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
141 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
142 console
.log("adding some more headlines: " + headlines_count
);
144 var c
= dijit
.byId("headlines-frame");
145 var ids
= getSelectedArticleIds2();
146 //var new_elems = [];
148 //$("headlines-tmp").innerHTML = reply['headlines']['content'];
150 var hsp
= $("headlines-spacer");
153 c
.domNode
.removeChild(hsp
);
155 /*$$("#headlines-tmp > div").each(function(row) {
156 if (row.className == 'cdmFeedTitle') {
157 row.style.display = 'none';
158 c.domNode.appendChild(row);
160 } else if (loaded_article_ids.indexOf(row.id) == -1) {
161 row.style.display = 'none';
162 c.domNode.appendChild(row);
164 loaded_article_ids.push(row.id);
166 row.parentNode.removeChild(row);
170 reply
['headlines']['content'].each(function(row
) {
171 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.kind
== 'feed_title') {
172 loaded_article_ids
.push(row
.id
);
174 var tmp
= new Element("div");
175 tmp
.innerHTML
= row
.html
;
177 dojo
.parser
.parse(tmp
.firstChild
);
178 dijit
.byId("headlines-frame").domNode
.appendChild(tmp
.firstChild
);
184 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
186 // if (getInitParam("cdm_auto_catchup") == 1) {
187 c
.domNode
.appendChild(hsp
);
190 console
.log("added " + reply
['headlines']['content'].size() + " headlines");
192 if (reply
['headlines']['content'].size() == 0) _infscroll_disable
= true;
194 console
.log("restore selected ids: " + ids
);
196 for (var i
= 0; i
< ids
.length
; i
++) {
197 markHeadline(ids
[i
]);
202 /*new_elems.each(function(child) {
203 dojo.parser.parse(child);
205 if (!Element.visible(child))
206 new Effect.Appear(child, { duration : 0.5 });
209 if (_infscroll_disable
) {
210 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
211 __("Click to open next unread feed.") + "</a>";
215 console
.log("no new headlines received");
217 var first_id_changed
= reply
['headlines']['first_id_changed'];
218 console
.log("first id changed:" + first_id_changed
);
220 var hsp
= $("headlines-spacer");
223 if (first_id_changed
) {
224 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
225 __("New articles found, reload feed to continue.") + "</a>";
227 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
228 __("Click to open next unread feed.") + "</a>";
237 for (var i
= 0; i
< articles
.length
; i
++) {
238 var a_id
= articles
[i
]['id'];
239 cache_set("article:" + a_id
, articles
[i
]['content']);
242 console
.log("no cached articles received");
246 parse_counters(counters
);
248 request_counters(true);
251 console
.error("Invalid object received: " + transport
.responseText
);
252 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
253 __('Could not update headlines (invalid object received - see error console for details)') +
257 _infscroll_request_sent
= 0;
258 _last_headlines_update
= new Date().getTime();
260 unpackVisibleHeadlines();
262 // if we have some more space in the buffer, why not try to fill it
264 if (!_infscroll_disable
&& $("headlines-spacer") &&
265 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
267 window
.setTimeout(function() {
275 exception_error("headlines_callback2", e
, transport
);
279 function render_article(article
) {
281 dijit
.byId("headlines-wrap-inner").addChild(
282 dijit
.byId("content-insert"));
284 var c
= dijit
.byId("content-insert");
287 c
.domNode
.scrollTop
= 0;
290 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
292 c
.attr('content', article
);
294 correctHeadlinesOffset(getActiveArticleId());
301 exception_error("render_article", e
);
305 function showArticleInHeadlines(id
, noexpand
) {
308 selectArticles("none");
310 var crow
= $("RROW-" + id
);
314 var article_is_unread
= crow
.hasClassName("Unread");
317 crow
.removeClassName("Unread");
318 crow
.addClassName("active");
320 selectArticles('none');
322 var view_mode
= false;
325 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
326 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
333 if (article_is_unread
&& !noexpand
)
334 _force_scheduled_update
= true;
337 exception_error("showArticleInHeadlines", e
);
341 function article_callback2(transport
, id
) {
343 console
.log("article_callback2 " + id
);
345 handle_rpc_json(transport
);
350 reply
= JSON
.parse(transport
.responseText
);
357 reply
.each(function(article
) {
358 if (getActiveArticleId() == article
['id']) {
359 render_article(article
['content']);
361 cids_requested
.remove(article
['id']);
363 cache_set("article:" + article
['id'], article
['content']);
366 // if (id != last_requested_article) {
367 // console.log("requested article id is out of sequence, aborting");
372 console
.error("Invalid object received: " + transport
.responseText
);
374 render_article("<div class='whiteBox'>" +
375 __('Could not display article (invalid object received - see error console for details)') + "</div>");
378 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
379 request_counters(unread_in_buffer
== 0);
381 //headlines_scroll_handler($("headlines-frame"));
384 if (!_infscroll_disable &&
385 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
395 exception_error("article_callback2", e
, transport
);
399 function view(id
, activefeed
, noexpand
) {
401 var oldrow
= $("RROW-" + getActiveArticleId());
402 if (oldrow
) oldrow
.removeClassName("active");
404 var crow
= $("RROW-" + id
);
408 setActiveArticleId(id
);
409 showArticleInHeadlines(id
, noexpand
);
413 console
.log("loading article: " + id
);
415 var cached_article
= cache_get("article:" + id
);
417 console
.log("cache check result: " + (cached_article
!= false));
419 var query
= "?op=article&method=view&id=" + param_escape(id
);
421 var neighbor_ids
= getRelativePostIds(id
);
423 /* only request uncached articles */
425 var cids_to_request
= [];
427 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
428 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
429 if (!cache_get("article:" + neighbor_ids
[i
])) {
430 cids_to_request
.push(neighbor_ids
[i
]);
431 cids_requested
.push(neighbor_ids
[i
]);
435 console
.log("additional ids: " + cids_to_request
.toString());
437 query
= query
+ "&cids=" + cids_to_request
.toString();
439 var article_is_unread
= crow
.hasClassName("Unread");
441 setActiveArticleId(id
);
442 showArticleInHeadlines(id
);
444 if (cached_article
&& article_is_unread
) {
446 query
= query
+ "&mode=prefetch";
448 render_article(cached_article
);
450 } else if (cached_article
) {
452 query
= query
+ "&mode=prefetch_old";
453 render_article(cached_article
);
455 // if we don't need to request any relative ids, we might as well skip
456 // the server roundtrip altogether
457 if (cids_to_request
.length
== 0) {
460 if (!_infscroll_disable &&
461 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
469 //headlines_scroll_handler($("headlines-frame"));
475 last_requested_article
= id
;
479 if (article_is_unread
) {
480 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
483 new Ajax
.Request("backend.php", {
485 onComplete: function(transport
) {
486 article_callback2(transport
, id
);
492 exception_error("view", e
);
496 function toggleMark(id
, client_only
) {
498 var query
= "?op=rpc&id=" + id
+ "&method=mark";
500 var row
= $("RROW-" + id
);
505 var row_imgs
= row
.getElementsByClassName("markedPic");
507 for (var i
= 0; i
< row_imgs
.length
; i
++)
508 imgs
.push(row_imgs
[i
]);
510 var ft
= $("floatingTitle");
512 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
513 var fte
= ft
.getElementsByClassName("markedPic");
515 for (var i
= 0; i
< fte
.length
; i
++)
519 for (i
= 0; i
< imgs
.length
; i
++) {
522 if (!row
.hasClassName("marked")) {
523 img
.src
= img
.src
.replace("mark_unset", "mark_set");
524 img
.alt
= __("Unstar article");
525 query
= query
+ "&mark=1";
527 img
.src
= img
.src
.replace("mark_set", "mark_unset");
528 img
.alt
= __("Star article");
529 query
= query
+ "&mark=0";
533 row
.toggleClassName("marked");
536 new Ajax
.Request("backend.php", {
538 onComplete: function(transport
) {
539 handle_rpc_json(transport
);
544 exception_error("toggleMark", e
);
548 function togglePub(id
, client_only
, no_effects
, note
) {
550 var query
= "?op=rpc&id=" + id
+ "&method=publ";
552 if (note
!= undefined) {
553 query
= query
+ "¬e=" + param_escape(note
);
555 query
= query
+ "¬e=undefined";
558 var row
= $("RROW-" + id
);
563 var row_imgs
= row
.getElementsByClassName("pubPic");
565 for (var i
= 0; i
< row_imgs
.length
; i
++)
566 imgs
.push(row_imgs
[i
]);
568 var ft
= $("floatingTitle");
570 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
571 var fte
= ft
.getElementsByClassName("pubPic");
573 for (var i
= 0; i
< fte
.length
; i
++)
577 for (i
= 0; i
< imgs
.length
; i
++) {
580 if (!row
.hasClassName("published") || note
!= undefined) {
581 img
.src
= img
.src
.replace("pub_unset", "pub_set");
582 img
.alt
= __("Unpublish article");
583 query
= query
+ "&pub=1";
585 img
.src
= img
.src
.replace("pub_set", "pub_unset");
586 img
.alt
= __("Publish article");
587 query
= query
+ "&pub=0";
591 if (note
!= undefined)
592 row
.addClassName("published");
594 row
.toggleClassName("published");
597 new Ajax
.Request("backend.php", {
599 onComplete: function(transport
) {
600 handle_rpc_json(transport
);
605 exception_error("togglePub", e
);
609 function moveToPost(mode
, noscroll
, noexpand
) {
613 var rows
= getVisibleArticleIds();
618 if (!$('RROW-' + getActiveArticleId())) {
619 setActiveArticleId(0);
622 if (!getActiveArticleId()) {
624 prev_id
= rows
[rows
.length
-1]
626 for (var i
= 0; i
< rows
.length
; i
++) {
627 if (rows
[i
] == getActiveArticleId()) {
629 // Account for adjacent identical article ids.
630 if (i
> 0) prev_id
= rows
[i
-1];
632 for (var j
= i
+1; j
< rows
.length
; j
++) {
633 if (rows
[j
] != getActiveArticleId()) {
643 if (mode
== "next") {
644 if (next_id
|| getActiveArticleId()) {
647 var article
= $("RROW-" + getActiveArticleId());
648 var ctr
= $("headlines-frame");
650 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
651 ctr
.scrollTop
+ ctr
.offsetHeight
) {
653 scrollArticle(ctr
.offsetHeight
/4);
655 } else if (next_id
) {
656 cdmExpandArticle(next_id
, noexpand
);
657 cdmScrollToArticleId(next_id
, true);
660 } else if (next_id
) {
661 correctHeadlinesOffset(next_id
);
662 view(next_id
, getActiveFeedId(), noexpand
);
667 if (mode
== "prev") {
668 if (prev_id
|| getActiveArticleId()) {
671 var article
= $("RROW-" + getActiveArticleId());
672 var prev_article
= $("RROW-" + prev_id
);
673 var ctr
= $("headlines-frame");
675 if (!getInitParam("cdm_expanded")) {
677 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
678 scrollArticle(-ctr
.offsetHeight
/4);
680 cdmExpandArticle(prev_id
, noexpand
);
681 cdmScrollToArticleId(prev_id
, true);
685 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
686 scrollArticle(-ctr
.offsetHeight
/3);
687 } else if (!noscroll
&& prev_article
&&
688 prev_article
.offsetTop
< ctr
.scrollTop
) {
689 cdmExpandArticle(prev_id
, noexpand
);
690 scrollArticle(-ctr
.offsetHeight
/4);
691 } else if (prev_id
) {
692 cdmExpandArticle(prev_id
, noexpand
);
693 cdmScrollToArticleId(prev_id
, noscroll
);
697 } else if (prev_id
) {
698 correctHeadlinesOffset(prev_id
);
699 view(prev_id
, getActiveFeedId(), noexpand
);
705 exception_error("moveToPost", e
);
709 function toggleSelected(id
, force_on
) {
711 var row
= $("RROW-" + id
);
714 var cb
= dijit
.getEnclosingWidget(
715 row
.getElementsByClassName("rchk")[0]);
717 if (row
.hasClassName('Selected') && !force_on
) {
718 row
.removeClassName('Selected');
719 if (cb
) cb
.attr("checked", false);
721 row
.addClassName('Selected');
722 if (cb
) cb
.attr("checked", true);
726 updateSelectedPrompt();
728 exception_error("toggleSelected", e
);
732 function updateSelectedPrompt() {
734 var count
= getSelectedArticleIds2().size();
735 var elem
= $("selected_prompt");
738 elem
.innerHTML
= ngettext("%d article selected",
739 "%d articles selected", count
).replace("%d", count
);
748 exception_error("updateSelectedPrompt", e
);
752 function toggleUnread_afh(effect
) {
755 var elem
= effect
.element
;
756 elem
.style
.backgroundColor
= "";
759 exception_error("toggleUnread_afh", e
);
763 function toggleUnread(id
, cmode
, effect
) {
766 var row
= $("RROW-" + id
);
768 if (cmode
== undefined || cmode
== 2) {
769 if (row
.hasClassName("Unread")) {
770 row
.removeClassName("Unread");
773 row
.addClassName("Unread");
776 } else if (cmode
== 0) {
778 row
.removeClassName("Unread");
780 } else if (cmode
== 1) {
781 row
.addClassName("Unread");
784 if (cmode
== undefined) cmode
= 2;
786 var query
= "?op=rpc&method=catchupSelected" +
787 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
789 // notify_progress("Loading, please wait...");
791 new Ajax
.Request("backend.php", {
793 onComplete: function(transport
) {
794 handle_rpc_json(transport
);
800 exception_error("toggleUnread", e
);
804 function selectionRemoveLabel(id
, ids
) {
807 if (!ids
) ids
= getSelectedArticleIds2();
809 if (ids
.length
== 0) {
810 alert(__("No articles are selected."));
814 var query
= "?op=article&method=removeFromLabel&ids=" +
815 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
819 new Ajax
.Request("backend.php", {
821 onComplete: function(transport
) {
822 handle_rpc_json(transport
);
823 show_labels_in_headlines(transport
);
827 exception_error("selectionAssignLabel", e
);
832 function selectionAssignLabel(id
, ids
) {
835 if (!ids
) ids
= getSelectedArticleIds2();
837 if (ids
.length
== 0) {
838 alert(__("No articles are selected."));
842 var query
= "?op=article&method=assignToLabel&ids=" +
843 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
847 new Ajax
.Request("backend.php", {
849 onComplete: function(transport
) {
850 handle_rpc_json(transport
);
851 show_labels_in_headlines(transport
);
855 exception_error("selectionAssignLabel", e
);
860 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
862 var rows
= ids
? ids
: getSelectedArticleIds2();
864 if (rows
.length
== 0 && !no_error
) {
865 alert(__("No articles are selected."));
869 for (var i
= 0; i
< rows
.length
; i
++) {
870 var row
= $("RROW-" + rows
[i
]);
872 if (set_state
== undefined) {
873 if (row
.hasClassName("Unread")) {
874 row
.removeClassName("Unread");
876 row
.addClassName("Unread");
880 if (set_state
== false) {
881 row
.removeClassName("Unread");
884 if (set_state
== true) {
885 row
.addClassName("Unread");
890 updateFloatingTitle(true);
892 if (rows
.length
> 0) {
896 if (set_state
== undefined) {
898 } else if (set_state
== true) {
900 } else if (set_state
== false) {
904 var query
= "?op=rpc&method=catchupSelected" +
905 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
907 notify_progress("Loading, please wait...");
909 new Ajax
.Request("backend.php", {
911 onComplete: function(transport
) {
912 handle_rpc_json(transport
);
913 if (callback
) callback(transport
);
919 exception_error("selectionToggleUnread", e
);
924 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
927 var rows
= ids
? ids
: getSelectedArticleIds2();
929 if (rows
.length
== 0 && !no_error
) {
930 alert(__("No articles are selected."));
934 for (var i
= 0; i
< rows
.length
; i
++) {
935 toggleMark(rows
[i
], true, true);
938 if (rows
.length
> 0) {
940 var query
= "?op=rpc&method=markSelected&ids=" +
941 param_escape(rows
.toString()) + "&cmode=2";
943 new Ajax
.Request("backend.php", {
945 onComplete: function(transport
) {
946 handle_rpc_json(transport
);
947 if (callback
) callback(transport
);
953 exception_error("selectionToggleMarked", e
);
958 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
961 var rows
= ids
? ids
: getSelectedArticleIds2();
963 if (rows
.length
== 0 && !no_error
) {
964 alert(__("No articles are selected."));
968 for (var i
= 0; i
< rows
.length
; i
++) {
969 togglePub(rows
[i
], true, true);
972 if (rows
.length
> 0) {
974 var query
= "?op=rpc&method=publishSelected&ids=" +
975 param_escape(rows
.toString()) + "&cmode=2";
977 new Ajax
.Request("backend.php", {
979 onComplete: function(transport
) {
980 handle_rpc_json(transport
);
986 exception_error("selectionToggleMarked", e
);
990 function getSelectedArticleIds2() {
994 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
996 rv
.push(child
.id
.replace("RROW-", ""));
1002 function getLoadedArticleIds() {
1005 var children
= $$("#headlines-frame > div[id*=RROW-]");
1007 children
.each(function(child
) {
1008 rv
.push(child
.id
.replace("RROW-", ""));
1015 // mode = all,none,unread,invert,marked,published
1016 function selectArticles(mode
, query
) {
1019 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
1021 var children
= $$(query
);
1023 children
.each(function(child
) {
1024 var id
= child
.id
.replace("RROW-", "");
1026 var cb
= dijit
.getEnclosingWidget(
1027 child
.getElementsByClassName("rchk")[0]);
1029 if (mode
== "all") {
1030 child
.addClassName("Selected");
1031 if (cb
) cb
.attr("checked", true);
1032 } else if (mode
== "unread") {
1033 if (child
.hasClassName("Unread")) {
1034 child
.addClassName("Selected");
1035 if (cb
) cb
.attr("checked", true);
1037 child
.removeClassName("Selected");
1038 if (cb
) cb
.attr("checked", false);
1040 } else if (mode
== "marked") {
1041 if (child
.hasClassName("marked")) {
1042 child
.addClassName("Selected");
1043 if (cb
) cb
.attr("checked", true);
1045 child
.removeClassName("Selected");
1046 if (cb
) cb
.attr("checked", false);
1048 } else if (mode
== "published") {
1049 if (child
.hasClassName("published")) {
1050 child
.addClassName("Selected");
1051 if (cb
) cb
.attr("checked", true);
1053 child
.removeClassName("Selected");
1054 if (cb
) cb
.attr("checked", false);
1057 } else if (mode
== "invert") {
1058 if (child
.hasClassName("Selected")) {
1059 child
.removeClassName("Selected");
1060 if (cb
) cb
.attr("checked", false);
1062 child
.addClassName("Selected");
1063 if (cb
) cb
.attr("checked", true);
1067 child
.removeClassName("Selected");
1068 if (cb
) cb
.attr("checked", false);
1072 updateSelectedPrompt();
1075 exception_error("selectArticles", e
);
1079 function deleteSelection() {
1083 var rows
= getSelectedArticleIds2();
1085 if (rows
.length
== 0) {
1086 alert(__("No articles are selected."));
1090 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1093 if (getActiveFeedId() != 0) {
1094 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1096 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1099 str
= str
.replace("%d", rows
.length
);
1100 str
= str
.replace("%s", fn
);
1102 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1106 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1110 new Ajax
.Request("backend.php", {
1112 onComplete: function(transport
) {
1113 handle_rpc_json(transport
);
1118 exception_error("deleteSelection", e
);
1122 function archiveSelection() {
1126 var rows
= getSelectedArticleIds2();
1128 if (rows
.length
== 0) {
1129 alert(__("No articles are selected."));
1133 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1137 if (getActiveFeedId() != 0) {
1138 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1141 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1143 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1148 str
= str
.replace("%d", rows
.length
);
1149 str
= str
.replace("%s", fn
);
1151 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1155 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1159 for (var i
= 0; i
< rows
.length
; i
++) {
1160 cache_delete("article:" + rows
[i
]);
1163 new Ajax
.Request("backend.php", {
1165 onComplete: function(transport
) {
1166 handle_rpc_json(transport
);
1171 exception_error("archiveSelection", e
);
1175 function catchupSelection() {
1179 var rows
= getSelectedArticleIds2();
1181 if (rows
.length
== 0) {
1182 alert(__("No articles are selected."));
1186 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1188 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1190 str
= str
.replace("%d", rows
.length
);
1191 str
= str
.replace("%s", fn
);
1193 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1197 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1200 exception_error("catchupSelection", e
);
1204 function editArticleTags(id
) {
1205 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1207 if (dijit
.byId("editTagsDlg"))
1208 dijit
.byId("editTagsDlg").destroyRecursive();
1210 dialog
= new dijit
.Dialog({
1212 title
: __("Edit article Tags"),
1213 style
: "width: 600px",
1214 execute: function() {
1215 if (this.validate()) {
1216 var query
= dojo
.objectToQuery(this.attr('value'));
1218 notify_progress("Saving article tags...", true);
1220 new Ajax
.Request("backend.php", {
1222 onComplete: function(transport
) {
1227 var data
= JSON
.parse(transport
.responseText
);
1234 var tags
= $("ATSTR-" + id
);
1235 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1237 if (tags
) tags
.innerHTML
= data
.content
;
1238 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1241 exception_error("editArticleTags/inner", e
);
1250 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1251 dojo
.disconnect(tmph
);
1253 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1254 "backend.php?op=article&method=completeTags",
1255 { tokens
: ',', paramName
: "search" });
1262 function cdmScrollToArticleId(id
, force
) {
1264 var ctr
= $("headlines-frame");
1265 var e
= $("RROW-" + id
);
1267 if (!e
|| !ctr
) return;
1269 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1270 e
.offsetTop
< ctr
.scrollTop
) {
1272 // expanded cdm has a 4px margin now
1273 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1277 exception_error("cdmScrollToArticleId", e
);
1281 function setActiveArticleId(id
) {
1282 _active_article_id
= id
;
1283 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1286 function getActiveArticleId() {
1287 return _active_article_id
;
1290 function postMouseIn(e
, id
) {
1291 post_under_pointer
= id
;
1294 function postMouseOut(id
) {
1295 post_under_pointer
= false;
1298 function unpackVisibleHeadlines() {
1300 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1302 $$("#headlines-frame > div[id*=RROW]").each(
1304 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1305 $("headlines-frame").offsetHeight
) {
1307 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1310 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1312 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1313 cencw
.setAttribute('id', '');
1314 Element
.show(cencw
);
1321 exception_error("unpackVisibleHeadlines", e
);
1325 function headlines_scroll_handler(e
) {
1327 var hsp
= $("headlines-spacer");
1329 unpackVisibleHeadlines();
1331 // set topmost child in the buffer as active
1332 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1333 getSelectedArticleIds2().length
<= 1 &&
1334 getInitParam("cdm_expanded")) {
1335 var rows
= $$("#headlines-frame > div[id*=RROW]");
1337 for (var i
= 0; i
< rows
.length
; i
++) {
1338 var child
= rows
[i
];
1340 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1341 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1342 child
.id
.replace("RROW-", "") != _active_article_id
) {
1344 if (_active_article_id
) {
1345 var row
= $("RROW-" + _active_article_id
);
1346 if (row
) row
.removeClassName("active");
1349 _active_article_id
= child
.id
.replace("RROW-", "");
1350 showArticleInHeadlines(_active_article_id
, true);
1351 updateSelectedPrompt();
1357 if (!_infscroll_disable
) {
1358 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1359 (e
.scrollHeight
!= 0 &&
1360 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1363 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1364 __("Loading, please wait...") + "</span>";
1366 loadMoreHeadlines();
1372 if (_infscroll_disable)
1373 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1374 __("Click to open next unread feed.") + "</a>";
1381 updateFloatingTitle();
1384 if (getInitParam("cdm_auto_catchup") == 1) {
1386 // let's get DOM some time to settle down
1387 var ts
= new Date().getTime();
1388 if (ts
- _last_headlines_update
< 100) return;
1390 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1392 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1393 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1395 var id
= child
.id
.replace("RROW-", "");
1397 if (catchup_id_batch
.indexOf(id
) == -1)
1398 catchup_id_batch
.push(id
);
1400 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1405 if (catchup_id_batch
.length
> 0) {
1406 window
.clearTimeout(catchup_timeout_id
);
1408 if (!_infscroll_request_sent
) {
1409 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1414 if (_infscroll_disable
) {
1415 var child
= $$("#headlines-frame div[id*=RROW]").last();
1417 if (child
&& $("headlines-frame").scrollTop
>
1418 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1420 console
.log("we seem to be at an end");
1422 if (getInitParam("on_catchup_show_next_feed") == "1") {
1423 openNextUnreadFeed();
1430 console
.warn("headlines_scroll_handler: " + e
);
1434 function openNextUnreadFeed() {
1436 var is_cat
= activeFeedIsCat();
1437 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1438 if (nuf
) viewfeed(nuf
, '', is_cat
);
1440 exception_error("openNextUnreadFeed", e
);
1444 function catchupBatchedArticles() {
1446 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1448 // make a copy of the array
1449 var batch
= catchup_id_batch
.slice();
1450 var query
= "?op=rpc&method=catchupSelected" +
1451 "&cmode=0&ids=" + param_escape(batch
.toString());
1455 new Ajax
.Request("backend.php", {
1457 onComplete: function(transport
) {
1458 handle_rpc_json(transport
);
1460 reply
= JSON
.parse(transport
.responseText
);
1461 var batch
= reply
.ids
;
1463 batch
.each(function(id
) {
1465 var elem
= $("RROW-" + id
);
1466 if (elem
) elem
.removeClassName("Unread");
1467 catchup_id_batch
.remove(id
);
1470 updateFloatingTitle(true);
1476 exception_error("catchupBatchedArticles", e
);
1480 function catchupRelativeToArticle(below
, id
) {
1484 if (!id
) id
= getActiveArticleId();
1487 alert(__("No article is selected."));
1491 var visible_ids
= getVisibleArticleIds();
1493 var ids_to_mark
= new Array();
1496 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1497 if (visible_ids
[i
] != id
) {
1498 var e
= $("RROW-" + visible_ids
[i
]);
1500 if (e
&& e
.hasClassName("Unread")) {
1501 ids_to_mark
.push(visible_ids
[i
]);
1508 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1509 if (visible_ids
[i
] != id
) {
1510 var e
= $("RROW-" + visible_ids
[i
]);
1512 if (e
&& e
.hasClassName("Unread")) {
1513 ids_to_mark
.push(visible_ids
[i
]);
1521 if (ids_to_mark
.length
== 0) {
1522 alert(__("No articles found to mark"));
1524 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1526 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1528 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1529 var e
= $("RROW-" + ids_to_mark
[i
]);
1530 e
.removeClassName("Unread");
1533 var query
= "?op=rpc&method=catchupSelected" +
1534 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1536 new Ajax
.Request("backend.php", {
1538 onComplete: function(transport
) {
1539 handle_rpc_json(transport
);
1546 exception_error("catchupRelativeToArticle", e
);
1550 function cdmCollapseArticle(event
, id
, unmark
) {
1552 if (unmark
== undefined) unmark
= true;
1554 var row
= $("RROW-" + id
);
1555 var elem
= $("CICD-" + id
);
1558 var collapse
= $$("div#RROW-" + id
+
1559 " span[class='collapseBtn']")[0];
1562 Element
.show("CEXC-" + id
);
1563 Element
.hide(collapse
);
1566 row
.removeClassName("active");
1568 markHeadline(id
, false);
1570 if (id
== getActiveArticleId()) {
1571 setActiveArticleId(0);
1574 updateSelectedPrompt();
1577 if (event
) Event
.stop(event
);
1579 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1581 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1582 scrollToRowId(row
.id
);
1584 $("floatingTitle").style
.visibility
= "hidden";
1585 $("floatingTitle").setAttribute("rowid", false);
1589 exception_error("cdmCollapseArticle", e
);
1593 function cdmExpandArticle(id
, noexpand
) {
1595 console
.log("cdmExpandArticle " + id
);
1597 if (!$("RROW-" + id
)) return false;
1599 var oldrow
= $("RROW-" + getActiveArticleId());
1601 var elem
= $("CICD-" + getActiveArticleId());
1603 if (id
== getActiveArticleId() && Element
.visible(elem
))
1606 selectArticles("none");
1608 var old_offset
= $("RROW-" + id
).offsetTop
;
1610 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1611 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1612 " span[class='collapseBtn']")[0];
1615 Element
.show("CEXC-" + getActiveArticleId());
1616 Element
.hide(collapse
);
1619 if (oldrow
) oldrow
.removeClassName("active");
1621 setActiveArticleId(id
);
1623 elem
= $("CICD-" + id
);
1625 var collapse
= $$("div#RROW-" + id
+
1626 " span[class='collapseBtn']")[0];
1628 var cencw
= $("CENCW-" + id
);
1630 if (!Element
.visible(elem
) && !noexpand
) {
1632 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1633 cencw
.setAttribute('id', '');
1634 Element
.show(cencw
);
1638 Element
.hide("CEXC-" + id
);
1639 Element
.show(collapse
);
1642 var new_offset
= $("RROW-" + id
).offsetTop
;
1644 if (old_offset
> new_offset
)
1645 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1648 toggleUnread(id
, 0, true);
1650 $("RROW-" + id
).addClassName("active");
1652 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1655 exception_error("cdmExpandArticle", e
);
1661 function getArticleUnderPointer() {
1662 return post_under_pointer
;
1665 function scrollArticle(offset
) {
1668 var ci
= $("content-insert");
1670 ci
.scrollTop
+= offset
;
1673 var hi
= $("headlines-frame");
1675 hi
.scrollTop
+= offset
;
1680 exception_error("scrollArticle", e
);
1684 function show_labels_in_headlines(transport
) {
1686 var data
= JSON
.parse(transport
.responseText
);
1689 data
['info-for-headlines'].each(function(elem
) {
1690 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1691 ctr
.innerHTML
= elem
.labels
;
1696 exception_error("show_labels_in_headlines", e
);
1700 function dismissArticle(id
) {
1702 var elem
= $("RROW-" + id
);
1706 toggleUnread(id
, 0, true);
1708 new Effect
.Fade(elem
, {duration
: 0.5});
1710 // Remove the content, too
1711 var elem_content
= $("CICD-" + id
);
1713 Element
.remove(elem_content
);
1716 if (id
== getActiveArticleId()) {
1717 setActiveArticleId(0);
1721 exception_error("dismissArticle", e
);
1725 function dismissSelectedArticles() {
1728 var ids
= getVisibleArticleIds();
1732 for (var i
= 0; i
< ids
.length
; i
++) {
1733 var elem
= $("RROW-" + ids
[i
]);
1735 if (elem
.className
&& elem
.hasClassName("Selected") &&
1736 ids
[i
] != getActiveArticleId()) {
1737 new Effect
.Fade(elem
, {duration
: 0.5});
1740 // Remove the content, too
1741 var elem_content
= $("CICD-" + ids
[i
]);
1743 Element
.remove(elem_content
);
1751 selectionToggleUnread(false);
1755 exception_error("dismissSelectedArticles", e
);
1759 function dismissReadArticles() {
1762 var ids
= getVisibleArticleIds();
1765 for (var i
= 0; i
< ids
.length
; i
++) {
1766 var elem
= $("RROW-" + ids
[i
]);
1768 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1769 !elem
.hasClassName("Selected")) {
1771 new Effect
.Fade(elem
, {duration
: 0.5});
1773 // Remove the content, too
1774 var elem_content
= $("CICD-" + ids
[i
]);
1776 Element
.remove(elem_content
);
1784 exception_error("dismissReadArticles", e
);
1788 function getVisibleArticleIds() {
1793 getLoadedArticleIds().each(function(id
) {
1794 var elem
= $("RROW-" + id
);
1795 if (elem
&& Element
.visible(elem
))
1800 exception_error("getVisibleArticleIds", e
);
1806 function cdmClicked(event
, id
) {
1808 //var shift_key = event.shiftKey;
1810 if (!event
.ctrlKey
) {
1812 if (!getInitParam("cdm_expanded")) {
1813 return cdmExpandArticle(id
);
1816 var elem
= $("RROW-" + getActiveArticleId());
1818 if (elem
) elem
.removeClassName("active");
1820 selectArticles("none");
1823 var elem
= $("RROW-" + id
);
1824 var article_is_unread
= elem
.hasClassName("Unread");
1826 elem
.removeClassName("Unread");
1827 elem
.addClassName("active");
1829 setActiveArticleId(id
);
1831 if (article_is_unread
) {
1832 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1833 updateFloatingTitle(true);
1836 var query
= "?op=rpc&method=catchupSelected" +
1837 "&cmode=0&ids=" + param_escape(id
);
1839 new Ajax
.Request("backend.php", {
1841 onComplete: function(transport
) {
1842 handle_rpc_json(transport
);
1845 return !event
.shiftKey
;
1848 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1850 toggleSelected(id
, true);
1852 var elem
= $("RROW-" + id
);
1853 var article_is_unread
= elem
.hasClassName("Unread");
1855 if (article_is_unread
) {
1856 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1859 toggleUnread(id
, 0, false);
1861 openArticleInNewWindow(id
);
1864 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1865 request_counters(unread_in_buffer
== 0);
1868 exception_error("cdmClicked");
1874 function hlClicked(event
, id
) {
1876 if (event
.which
== 2) {
1879 } else if (event
.ctrlKey
) {
1880 toggleSelected(id
, true);
1881 toggleUnread(id
, 0, false);
1882 openArticleInNewWindow(id
);
1890 exception_error("hlClicked");
1894 function getFirstVisibleHeadlineId() {
1895 var rows
= getVisibleArticleIds();
1900 function getLastVisibleHeadlineId() {
1901 var rows
= getVisibleArticleIds();
1902 return rows
[rows
.length
-1];
1905 function openArticleInNewWindow(id
) {
1906 toggleUnread(id
, 0, false);
1907 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1910 function isCdmMode() {
1911 return getInitParam("combined_display_mode");
1914 function markHeadline(id
, marked
) {
1915 if (marked
== undefined) marked
= true;
1917 var row
= $("RROW-" + id
);
1919 var check
= dijit
.getEnclosingWidget(
1920 row
.getElementsByClassName("rchk")[0]);
1923 check
.attr("checked", marked
);
1927 row
.addClassName("Selected");
1929 row
.removeClassName("Selected");
1933 function getRelativePostIds(id
, limit
) {
1939 if (!limit
) limit
= 6; //3
1941 var ids
= getVisibleArticleIds();
1943 for (var i
= 0; i
< ids
.length
; i
++) {
1945 for (var k
= 1; k
<= limit
; k
++) {
1946 //if (i > k-1) tmp.push(ids[i-k]);
1947 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1954 exception_error("getRelativePostIds", e
);
1960 function correctHeadlinesOffset(id
) {
1964 var container
= $("headlines-frame");
1965 var row
= $("RROW-" + id
);
1967 if (!container
|| !row
) return;
1969 var viewport
= container
.offsetHeight
;
1971 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1972 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1974 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1975 //console.log("Vport: " + viewport);
1977 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1978 container
.scrollTop
= row
.offsetTop
;
1979 } else if (rel_offset_bottom
> viewport
) {
1981 /* doesn't properly work with Opera in some cases because
1982 Opera fucks up element scrolling */
1984 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1988 exception_error("correctHeadlinesOffset", e
);
1993 function headlineActionsChange(elem
) {
1996 elem
.attr('value', 'false');
1998 exception_error("headlineActionsChange", e
);
2002 function closeArticlePanel() {
2004 if (dijit
.byId("content-insert"))
2005 dijit
.byId("headlines-wrap-inner").removeChild(
2006 dijit
.byId("content-insert"));
2009 function initFloatingMenu() {
2011 if (dijit
.byId("floatingMenu"))
2012 dijit
.byId("floatingMenu").destroyRecursive();
2014 var menu
= new dijit
.Menu({
2016 targetNodeIds
: ["floatingTitle"]
2019 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
2021 headlinesMenuCommon(menu
, id
);
2025 exception_error("initFloatingMenu", e
);
2029 function headlinesMenuCommon(menu
, base_id
) {
2032 menu
.addChild(new dijit
.MenuItem({
2033 label
: __("Open original article"),
2034 onClick: function(event
) {
2035 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
2038 menu
.addChild(new dijit
.MenuItem({
2039 label
: __("Display article URL"),
2040 onClick: function(event
) {
2041 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
2044 menu
.addChild(new dijit
.MenuSeparator());
2046 menu
.addChild(new dijit
.MenuItem({
2047 label
: __("Toggle unread"),
2048 onClick: function(event
) {
2049 var ids
= getSelectedArticleIds2();
2051 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2052 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2054 selectionToggleUnread(undefined, false, true, ids
);
2057 menu
.addChild(new dijit
.MenuItem({
2058 label
: __("Toggle starred"),
2059 onClick: function(event
) {
2060 var ids
= getSelectedArticleIds2();
2062 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2063 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2065 selectionToggleMarked(undefined, false, true, ids
);
2068 menu
.addChild(new dijit
.MenuItem({
2069 label
: __("Toggle published"),
2070 onClick: function(event
) {
2071 var ids
= getSelectedArticleIds2();
2073 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2074 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2076 selectionTogglePublished(undefined, false, true, ids
);
2079 menu
.addChild(new dijit
.MenuSeparator());
2081 menu
.addChild(new dijit
.MenuItem({
2082 label
: __("Mark above as read"),
2083 onClick: function(event
) {
2084 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2087 menu
.addChild(new dijit
.MenuItem({
2088 label
: __("Mark below as read"),
2089 onClick: function(event
) {
2090 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2094 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2098 menu
.addChild(new dijit
.MenuSeparator());
2100 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2101 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2103 labels
.each(function(label
) {
2104 var id
= label
.id
[0];
2105 var bare_id
= id
.substr(id
.indexOf(":")+1);
2106 var name
= label
.name
[0];
2108 bare_id
= feed_to_label_id(bare_id
);
2110 labelAddMenu
.addChild(new dijit
.MenuItem({
2113 onClick: function(event
) {
2114 var ids
= getSelectedArticleIds2();
2116 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2118 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2120 selectionAssignLabel(this.labelId
, ids
);
2123 labelDelMenu
.addChild(new dijit
.MenuItem({
2126 onClick: function(event
) {
2127 var ids
= getSelectedArticleIds2();
2129 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2131 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2133 selectionRemoveLabel(this.labelId
, ids
);
2138 menu
.addChild(new dijit
.PopupMenuItem({
2139 label
: __("Assign label"),
2140 popup
: labelAddMenu
,
2143 menu
.addChild(new dijit
.PopupMenuItem({
2144 label
: __("Remove label"),
2145 popup
: labelDelMenu
,
2152 exception_error("headlinesMenuCommon", e
);
2156 function initHeadlinesMenu() {
2158 if (dijit
.byId("headlinesMenu"))
2159 dijit
.byId("headlinesMenu").destroyRecursive();
2164 nodes
= $$("#headlines-frame > div[id*=RROW]");
2166 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2169 nodes
.each(function(node
) {
2173 var menu
= new dijit
.Menu({
2174 id
: "headlinesMenu",
2178 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2179 var callerNode
= event
.target
, match
= null, tries
= 0;
2181 while (match
== null && callerNode
&& tries
<= 3) {
2182 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2183 callerNode
= callerNode
.parentNode
;
2187 if (match
) this.callerRowId
= parseInt(match
[1]);
2191 headlinesMenuCommon(menu
, false);
2195 /* vgroup feed title menu */
2197 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2200 nodes
.each(function(node
) {
2204 if (ids
.length
> 0) {
2205 if (dijit
.byId("headlinesFeedTitleMenu"))
2206 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2208 var menu
= new dijit
.Menu({
2209 id
: "headlinesFeedTitleMenu",
2213 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2214 var callerNode
= event
.target
, match
= null, tries
= 0;
2216 while (match
== null && callerNode
&& tries
<= 3) {
2217 console
.log(callerNode
.id
);
2219 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2220 callerNode
= callerNode
.parentNode
;
2223 console
.log(match
[1]);
2226 if (match
) this.callerRowId
= parseInt(match
[1]);
2230 menu
.addChild(new dijit
.MenuItem({
2231 label
: __("Select articles in group"),
2232 onClick: function(event
) {
2233 selectArticles("all",
2234 "#headlines-frame > div[id*=RROW]"+
2235 "[orig-feed-id='"+menu
.callerRowId
+"']");
2239 menu
.addChild(new dijit
.MenuItem({
2240 label
: __("Mark group as read"),
2241 onClick: function(event
) {
2242 selectArticles("none");
2243 selectArticles("all",
2244 "#headlines-frame > div[id*=RROW]"+
2245 "[orig-feed-id='"+menu
.callerRowId
+"']");
2251 menu
.addChild(new dijit
.MenuItem({
2252 label
: __("Mark feed as read"),
2253 onClick: function(event
) {
2254 catchupFeedInGroup(menu
.callerRowId
);
2262 exception_error("initHeadlinesMenu", e
);
2266 function cache_set(id
, obj
) {
2267 //console.log("cache_set: " + id);
2270 sessionStorage
[id
] = obj
;
2272 sessionStorage
.clear();
2276 function cache_get(id
) {
2278 return sessionStorage
[id
];
2281 function cache_clear() {
2283 sessionStorage
.clear();
2286 function cache_delete(id
) {
2288 sessionStorage
.removeItem(id
);
2291 function cancelSearch() {
2296 exception_error("cancelSearch", e
);
2300 function setSelectionScore() {
2302 var ids
= getSelectedArticleIds2();
2304 if (ids
.length
> 0) {
2307 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2309 if (score
!= undefined) {
2310 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2311 "&score=" + param_escape(score
);
2313 new Ajax
.Request("backend.php", {
2315 onComplete: function(transport
) {
2316 var reply
= JSON
.parse(transport
.responseText
);
2320 ids
.each(function(id
) {
2321 var row
= $("RROW-" + id
);
2324 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2327 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2328 reply
["score_pic"]);
2329 pic
.setAttribute("score", score
);
2338 alert(__("No articles are selected."));
2341 exception_error("setSelectionScore", e
);
2345 function updateScore(id
) {
2347 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2351 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2353 new Ajax
.Request("backend.php", {
2355 onComplete: function(transport
) {
2356 console
.log(transport
.responseText
);
2358 var reply
= JSON
.parse(transport
.responseText
);
2361 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2362 pic
.setAttribute("score", reply
["score"]);
2363 pic
.setAttribute("title", reply
["score"]);
2369 exception_error("updateScore", e
);
2373 function changeScore(id
, pic
) {
2375 var score
= pic
.getAttribute("score");
2377 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2379 if (new_score
!= undefined) {
2381 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2382 "&score=" + param_escape(new_score
);
2384 new Ajax
.Request("backend.php", {
2386 onComplete: function(transport
) {
2387 var reply
= JSON
.parse(transport
.responseText
);
2390 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2391 pic
.setAttribute("score", new_score
);
2392 pic
.setAttribute("title", new_score
);
2397 exception_error("changeScore", e
);
2401 function displayArticleUrl(id
) {
2403 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2405 new Ajax
.Request("backend.php", {
2407 onComplete: function(transport
) {
2408 var reply
= JSON
.parse(transport
.responseText
);
2410 if (reply
&& reply
.link
) {
2411 prompt(__("Article URL:"), reply
.link
);
2415 exception_error("changeScore", e
);
2419 function openSelectedAttachment(elem
) {
2421 var url
= elem
[elem
.selectedIndex
].value
;
2425 elem
.selectedIndex
= 0;
2429 exception_error("openSelectedAttachment", e
);
2433 function scrollToRowId(id
) {
2438 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2441 exception_error("scrollToRowId", e
);
2445 function updateFloatingTitle(unread_only
) {
2447 if (!isCdmMode()) return;
2449 var hf
= $("headlines-frame");
2451 var elems
= $$("#headlines-frame > div[id*=RROW]");
2453 for (var i
= 0; i
< elems
.length
; i
++) {
2455 var child
= elems
[i
];
2457 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2459 var header
= child
.getElementsByClassName("cdmHeader")[0];
2461 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2462 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2463 $("floatingTitle").setAttribute("rowid", child
.id
);
2464 $("floatingTitle").innerHTML
= header
.innerHTML
;
2465 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2469 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2472 cb
.parentNode
.removeChild(cb
);
2475 if (child
.hasClassName("Unread"))
2476 $("floatingTitle").addClassName("Unread");
2478 $("floatingTitle").removeClassName("Unread");
2480 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2483 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2484 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2485 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2486 $("floatingTitle").style
.visibility
= "visible";
2488 $("floatingTitle").style
.visibility
= "hidden";
2496 exception_error("updateFloatingTitle", e
);
2500 function cdmFooterClick(event
) {
2501 event
.stopPropagation();