1 var article_cache
= new Array();
3 var _active_article_id
= 0;
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
13 var cids_requested
= [];
14 var loaded_article_ids
= [];
15 var _last_headlines_update
= 0;
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
21 handle_rpc_json(transport
);
23 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
31 reply
= JSON
.parse(transport
.responseText
);
38 is_cat
= reply
['headlines']['is_cat'];
39 feed_id
= reply
['headlines']['id'];
42 var content
= reply
['headlines']['content'];
44 content
= content
+ "<div id='headlines-spacer'></div>";
48 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
51 /* dijit.getEnclosingWidget(
52 document.forms["main_toolbar_form"].update).attr('disabled',
53 is_cat || feed_id <= 0); */
56 if (infscroll_req
== false) {
57 $("headlines-frame").scrollTop
= 0;
59 Element
.hide("floatingTitle");
60 $("floatingTitle").setAttribute("rowid", 0);
61 $("floatingTitle").innerHTML
= "";
65 $("headlines-frame").removeClassName("cdm");
66 $("headlines-frame").removeClassName("normal");
68 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
70 var headlines_count
= reply
['headlines-info']['count'];
72 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
74 if (parseInt(headlines_count
) < 30) {
75 _infscroll_disable
= 1;
77 _infscroll_disable
= 0;
80 var counters
= reply
['counters'];
81 var articles
= reply
['articles'];
82 //var runtime_info = reply['runtime-info'];
84 if (infscroll_req
== false) {
85 loaded_article_ids
= [];
87 dijit
.byId("headlines-frame").attr('content',
88 reply
['headlines']['content']);
90 //dijit.byId("headlines-toolbar").attr('content',
91 // reply['headlines']['toolbar']);
93 dojo
.html
.set($("headlines-toolbar"),
94 reply
['headlines']['toolbar'],
95 {parseContent
: true});
97 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
98 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
99 row
.parentNode
.removeChild(row
);
101 loaded_article_ids
.push(row
.id
);
105 var hsp
= $("headlines-spacer");
106 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
107 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
112 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
113 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
119 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
120 console
.log("adding some more headlines: " + headlines_count
);
122 var c
= dijit
.byId("headlines-frame");
123 var ids
= getSelectedArticleIds2();
126 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
128 var hsp
= $("headlines-spacer");
131 c
.domNode
.removeChild(hsp
);
133 $$("#headlines-tmp > div").each(function(row
) {
134 if (row
.className
== 'cdmFeedTitle') {
135 row
.style
.display
= 'none';
136 c
.domNode
.appendChild(row
);
138 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
139 row
.style
.display
= 'none';
140 c
.domNode
.appendChild(row
);
142 loaded_article_ids
.push(row
.id
);
144 row
.parentNode
.removeChild(row
);
148 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
150 if (getInitParam("cdm_auto_catchup") == 1) {
151 c
.domNode
.appendChild(hsp
);
154 console
.log("added " + new_elems
.size() + " headlines");
156 if (new_elems
.size() == 0)
157 _infscroll_disable
= true;
159 console
.log("restore selected ids: " + ids
);
161 for (var i
= 0; i
< ids
.length
; i
++) {
162 markHeadline(ids
[i
]);
167 new_elems
.each(function(child
) {
168 dojo
.parser
.parse(child
);
170 if (!Element
.visible(child
))
171 new Effect
.Appear(child
, { duration
: 0.5 });
175 console
.log("no new headlines received");
177 var hsp
= $("headlines-spacer");
179 if (hsp
) hsp
.innerHTML
= "";
184 for (var i
= 0; i
< articles
.length
; i
++) {
185 var a_id
= articles
[i
]['id'];
186 cache_set("article:" + a_id
, articles
[i
]['content']);
189 console
.log("no cached articles received");
193 parse_counters(counters
);
195 request_counters(true);
197 } else if (transport
.responseText
) {
198 console
.error("Invalid object received: " + transport
.responseText
);
199 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
200 __('Could not update headlines (invalid object received - see error console for details)') +
203 //notify_error("Error communicating with server.");
204 Element
.show(dijit
.byId("net-alert").domNode
);
207 _infscroll_request_sent
= 0;
208 _last_headlines_update
= new Date().getTime();
210 unpackVisibleHeadlines();
212 // if we have some more space in the buffer, why not try to fill it
214 if (!_infscroll_disable
&& $("headlines-spacer") &&
215 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
217 window
.setTimeout(function() {
225 exception_error("headlines_callback2", e
, transport
);
229 function render_article(article
) {
231 dijit
.byId("headlines-wrap-inner").addChild(
232 dijit
.byId("content-insert"));
234 var c
= dijit
.byId("content-insert");
237 c
.domNode
.scrollTop
= 0;
240 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
242 c
.attr('content', article
);
244 correctHeadlinesOffset(getActiveArticleId());
251 exception_error("render_article", e
);
255 function showArticleInHeadlines(id
, noexpand
) {
258 selectArticles("none");
260 var crow
= $("RROW-" + id
);
264 var article_is_unread
= crow
.hasClassName("Unread");
267 crow
.removeClassName("Unread");
268 crow
.addClassName("active");
270 selectArticles('none');
272 var view_mode
= false;
275 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
276 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
283 if (article_is_unread
&& !noexpand
)
284 _force_scheduled_update
= true;
287 exception_error("showArticleInHeadlines", e
);
291 function article_callback2(transport
, id
) {
293 console
.log("article_callback2 " + id
);
295 handle_rpc_json(transport
);
300 reply
= JSON
.parse(transport
.responseText
);
307 reply
.each(function(article
) {
308 if (getActiveArticleId() == article
['id']) {
309 render_article(article
['content']);
311 cids_requested
.remove(article
['id']);
313 cache_set("article:" + article
['id'], article
['content']);
316 // if (id != last_requested_article) {
317 // console.log("requested article id is out of sequence, aborting");
321 } else if (transport
.responseText
) {
322 console
.error("Invalid object received: " + transport
.responseText
);
324 render_article("<div class='whiteBox'>" +
325 __('Could not display article (invalid object received - see error console for details)') + "</div>");
327 Element
.show(dijit
.byId("net-alert").domNode
);
330 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
331 request_counters(unread_in_buffer
== 0);
333 //headlines_scroll_handler($("headlines-frame"));
336 if (!_infscroll_disable &&
337 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
347 exception_error("article_callback2", e
, transport
);
351 function view(id
, activefeed
, noexpand
) {
353 var oldrow
= $("RROW-" + getActiveArticleId());
354 if (oldrow
) oldrow
.removeClassName("active");
356 var crow
= $("RROW-" + id
);
360 setActiveArticleId(id
);
361 showArticleInHeadlines(id
, noexpand
);
365 console
.log("loading article: " + id
);
367 var cached_article
= cache_get("article:" + id
);
369 console
.log("cache check result: " + (cached_article
!= false));
371 var query
= "?op=article&method=view&id=" + param_escape(id
);
373 var neighbor_ids
= getRelativePostIds(id
);
375 /* only request uncached articles */
377 var cids_to_request
= [];
379 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
380 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
381 if (!cache_get("article:" + neighbor_ids
[i
])) {
382 cids_to_request
.push(neighbor_ids
[i
]);
383 cids_requested
.push(neighbor_ids
[i
]);
387 console
.log("additional ids: " + cids_to_request
.toString());
389 query
= query
+ "&cids=" + cids_to_request
.toString();
391 var article_is_unread
= crow
.hasClassName("Unread");
393 setActiveArticleId(id
);
394 showArticleInHeadlines(id
);
396 if (cached_article
&& article_is_unread
) {
398 query
= query
+ "&mode=prefetch";
400 render_article(cached_article
);
402 } else if (cached_article
) {
404 query
= query
+ "&mode=prefetch_old";
405 render_article(cached_article
);
407 // if we don't need to request any relative ids, we might as well skip
408 // the server roundtrip altogether
409 if (cids_to_request
.length
== 0) {
412 if (!_infscroll_disable &&
413 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
421 //headlines_scroll_handler($("headlines-frame"));
427 last_requested_article
= id
;
431 if (article_is_unread
) {
432 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
435 new Ajax
.Request("backend.php", {
437 onComplete: function(transport
) {
438 article_callback2(transport
, id
);
444 exception_error("view", e
);
448 function toggleMark(id
, client_only
) {
450 var query
= "?op=rpc&id=" + id
+ "&method=mark";
452 var row
= $("RROW-" + id
);
457 var row_imgs
= row
.getElementsByClassName("markedPic");
459 for (var i
= 0; i
< row_imgs
.length
; i
++)
460 imgs
.push(row_imgs
[i
]);
462 var ft
= $("floatingTitle");
464 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
465 var fte
= ft
.getElementsByClassName("markedPic");
467 for (var i
= 0; i
< fte
.length
; i
++)
471 for (i
= 0; i
< imgs
.length
; i
++) {
474 if (!row
.hasClassName("marked")) {
475 img
.src
= img
.src
.replace("mark_unset", "mark_set");
476 img
.alt
= __("Unstar article");
477 query
= query
+ "&mark=1";
479 img
.src
= img
.src
.replace("mark_set", "mark_unset");
480 img
.alt
= __("Star article");
481 query
= query
+ "&mark=0";
485 row
.toggleClassName("marked");
488 new Ajax
.Request("backend.php", {
490 onComplete: function(transport
) {
491 handle_rpc_json(transport
);
496 exception_error("toggleMark", e
);
500 function togglePub(id
, client_only
, no_effects
, note
) {
502 var query
= "?op=rpc&id=" + id
+ "&method=publ";
504 if (note
!= undefined) {
505 query
= query
+ "¬e=" + param_escape(note
);
507 query
= query
+ "¬e=undefined";
510 var row
= $("RROW-" + id
);
515 var row_imgs
= row
.getElementsByClassName("pubPic");
517 for (var i
= 0; i
< row_imgs
.length
; i
++)
518 imgs
.push(row_imgs
[i
]);
520 var ft
= $("floatingTitle");
522 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
523 var fte
= ft
.getElementsByClassName("pubPic");
525 for (var i
= 0; i
< fte
.length
; i
++)
529 for (i
= 0; i
< imgs
.length
; i
++) {
532 if (!row
.hasClassName("published") || note
!= undefined) {
533 img
.src
= img
.src
.replace("pub_unset", "pub_set");
534 img
.alt
= __("Unpublish article");
535 query
= query
+ "&pub=1";
537 img
.src
= img
.src
.replace("pub_set", "pub_unset");
538 img
.alt
= __("Publish article");
539 query
= query
+ "&pub=0";
543 if (note
!= undefined)
544 row
.addClassName("published");
546 row
.toggleClassName("published");
549 new Ajax
.Request("backend.php", {
551 onComplete: function(transport
) {
552 handle_rpc_json(transport
);
557 exception_error("togglePub", e
);
561 function moveToPost(mode
, noscroll
, noexpand
) {
565 var rows
= getVisibleArticleIds();
570 if (!$('RROW-' + getActiveArticleId())) {
571 setActiveArticleId(0);
574 if (!getActiveArticleId()) {
576 prev_id
= rows
[rows
.length
-1]
578 for (var i
= 0; i
< rows
.length
; i
++) {
579 if (rows
[i
] == getActiveArticleId()) {
581 // Account for adjacent identical article ids.
582 if (i
> 0) prev_id
= rows
[i
-1];
584 for (var j
= i
+1; j
< rows
.length
; j
++) {
585 if (rows
[j
] != getActiveArticleId()) {
595 if (mode
== "next") {
596 if (next_id
|| getActiveArticleId()) {
599 var article
= $("RROW-" + getActiveArticleId());
600 var ctr
= $("headlines-frame");
602 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
603 ctr
.scrollTop
+ ctr
.offsetHeight
) {
605 scrollArticle(ctr
.offsetHeight
/4);
607 } else if (next_id
) {
608 cdmExpandArticle(next_id
, noexpand
);
609 cdmScrollToArticleId(next_id
, true);
612 } else if (next_id
) {
613 correctHeadlinesOffset(next_id
);
614 view(next_id
, getActiveFeedId(), noexpand
);
619 if (mode
== "prev") {
620 if (prev_id
|| getActiveArticleId()) {
623 var article
= $("RROW-" + getActiveArticleId());
624 var prev_article
= $("RROW-" + prev_id
);
625 var ctr
= $("headlines-frame");
627 if (!getInitParam("cdm_expanded")) {
629 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
630 scrollArticle(-ctr
.offsetHeight
/4);
632 cdmExpandArticle(prev_id
, noexpand
);
633 cdmScrollToArticleId(prev_id
, true);
637 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
638 scrollArticle(-ctr
.offsetHeight
/3);
639 } else if (!noscroll
&& prev_article
&&
640 prev_article
.offsetTop
< ctr
.scrollTop
) {
641 cdmExpandArticle(prev_id
, noexpand
);
642 scrollArticle(-ctr
.offsetHeight
/4);
643 } else if (prev_id
) {
644 cdmExpandArticle(prev_id
, noexpand
);
645 cdmScrollToArticleId(prev_id
, noscroll
);
649 } else if (prev_id
) {
650 correctHeadlinesOffset(prev_id
);
651 view(prev_id
, getActiveFeedId(), noexpand
);
657 exception_error("moveToPost", e
);
661 function toggleSelected(id
, force_on
) {
663 var row
= $("RROW-" + id
);
666 var cb
= dijit
.getEnclosingWidget(
667 row
.getElementsByClassName("rchk")[0]);
669 if (row
.hasClassName('Selected') && !force_on
) {
670 row
.removeClassName('Selected');
671 if (cb
) cb
.attr("checked", false);
673 row
.addClassName('Selected');
674 if (cb
) cb
.attr("checked", true);
678 updateSelectedPrompt();
680 exception_error("toggleSelected", e
);
684 function updateSelectedPrompt() {
686 var count
= getSelectedArticleIds2().size();
687 var elem
= $("selected_prompt");
690 elem
.innerHTML
= ngettext("%d article selected",
691 "%d articles selected", count
).replace("%d", count
);
700 exception_error("updateSelectedPrompt", e
);
704 function toggleUnread_afh(effect
) {
707 var elem
= effect
.element
;
708 elem
.style
.backgroundColor
= "";
711 exception_error("toggleUnread_afh", e
);
715 function toggleUnread(id
, cmode
, effect
) {
718 var row
= $("RROW-" + id
);
720 if (cmode
== undefined || cmode
== 2) {
721 if (row
.hasClassName("Unread")) {
722 row
.removeClassName("Unread");
725 row
.addClassName("Unread");
728 } else if (cmode
== 0) {
730 row
.removeClassName("Unread");
732 } else if (cmode
== 1) {
733 row
.addClassName("Unread");
736 if (cmode
== undefined) cmode
= 2;
738 var query
= "?op=rpc&method=catchupSelected" +
739 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
741 // notify_progress("Loading, please wait...");
743 new Ajax
.Request("backend.php", {
745 onComplete: function(transport
) {
746 handle_rpc_json(transport
);
752 exception_error("toggleUnread", e
);
756 function selectionRemoveLabel(id
, ids
) {
759 if (!ids
) ids
= getSelectedArticleIds2();
761 if (ids
.length
== 0) {
762 alert(__("No articles are selected."));
766 var query
= "?op=article&method=removeFromLabel&ids=" +
767 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
771 new Ajax
.Request("backend.php", {
773 onComplete: function(transport
) {
774 handle_rpc_json(transport
);
775 show_labels_in_headlines(transport
);
779 exception_error("selectionAssignLabel", e
);
784 function selectionAssignLabel(id
, ids
) {
787 if (!ids
) ids
= getSelectedArticleIds2();
789 if (ids
.length
== 0) {
790 alert(__("No articles are selected."));
794 var query
= "?op=article&method=assignToLabel&ids=" +
795 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
799 new Ajax
.Request("backend.php", {
801 onComplete: function(transport
) {
802 handle_rpc_json(transport
);
803 show_labels_in_headlines(transport
);
807 exception_error("selectionAssignLabel", e
);
812 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
814 var rows
= ids
? ids
: getSelectedArticleIds2();
816 if (rows
.length
== 0 && !no_error
) {
817 alert(__("No articles are selected."));
821 for (var i
= 0; i
< rows
.length
; i
++) {
822 var row
= $("RROW-" + rows
[i
]);
824 if (set_state
== undefined) {
825 if (row
.hasClassName("Unread")) {
826 row
.removeClassName("Unread");
828 row
.addClassName("Unread");
832 if (set_state
== false) {
833 row
.removeClassName("Unread");
836 if (set_state
== true) {
837 row
.addClassName("Unread");
842 updateFloatingTitle(true);
844 if (rows
.length
> 0) {
848 if (set_state
== undefined) {
850 } else if (set_state
== true) {
852 } else if (set_state
== false) {
856 var query
= "?op=rpc&method=catchupSelected" +
857 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
859 notify_progress("Loading, please wait...");
861 new Ajax
.Request("backend.php", {
863 onComplete: function(transport
) {
864 handle_rpc_json(transport
);
865 if (callback
) callback(transport
);
871 exception_error("selectionToggleUnread", e
);
876 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
879 var rows
= ids
? ids
: getSelectedArticleIds2();
881 if (rows
.length
== 0 && !no_error
) {
882 alert(__("No articles are selected."));
886 for (var i
= 0; i
< rows
.length
; i
++) {
887 toggleMark(rows
[i
], true, true);
890 if (rows
.length
> 0) {
892 var query
= "?op=rpc&method=markSelected&ids=" +
893 param_escape(rows
.toString()) + "&cmode=2";
895 new Ajax
.Request("backend.php", {
897 onComplete: function(transport
) {
898 handle_rpc_json(transport
);
899 if (callback
) callback(transport
);
905 exception_error("selectionToggleMarked", e
);
910 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
913 var rows
= ids
? ids
: getSelectedArticleIds2();
915 if (rows
.length
== 0 && !no_error
) {
916 alert(__("No articles are selected."));
920 for (var i
= 0; i
< rows
.length
; i
++) {
921 togglePub(rows
[i
], true, true);
924 if (rows
.length
> 0) {
926 var query
= "?op=rpc&method=publishSelected&ids=" +
927 param_escape(rows
.toString()) + "&cmode=2";
929 new Ajax
.Request("backend.php", {
931 onComplete: function(transport
) {
932 handle_rpc_json(transport
);
938 exception_error("selectionToggleMarked", e
);
942 function getSelectedArticleIds2() {
946 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
948 rv
.push(child
.id
.replace("RROW-", ""));
954 function getLoadedArticleIds() {
957 var children
= $$("#headlines-frame > div[id*=RROW-]");
959 children
.each(function(child
) {
960 rv
.push(child
.id
.replace("RROW-", ""));
967 // mode = all,none,unread,invert,marked,published
968 function selectArticles(mode
, query
) {
971 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
973 var children
= $$(query
);
975 children
.each(function(child
) {
976 var id
= child
.id
.replace("RROW-", "");
978 var cb
= dijit
.getEnclosingWidget(
979 child
.getElementsByClassName("rchk")[0]);
982 child
.addClassName("Selected");
983 if (cb
) cb
.attr("checked", true);
984 } else if (mode
== "unread") {
985 if (child
.hasClassName("Unread")) {
986 child
.addClassName("Selected");
987 if (cb
) cb
.attr("checked", true);
989 child
.removeClassName("Selected");
990 if (cb
) cb
.attr("checked", false);
992 } else if (mode
== "marked") {
993 if (child
.hasClassName("marked")) {
994 child
.addClassName("Selected");
995 if (cb
) cb
.attr("checked", true);
997 child
.removeClassName("Selected");
998 if (cb
) cb
.attr("checked", false);
1000 } else if (mode
== "published") {
1001 if (child
.hasClassName("published")) {
1002 child
.addClassName("Selected");
1003 if (cb
) cb
.attr("checked", true);
1005 child
.removeClassName("Selected");
1006 if (cb
) cb
.attr("checked", false);
1009 } else if (mode
== "invert") {
1010 if (child
.hasClassName("Selected")) {
1011 child
.removeClassName("Selected");
1012 if (cb
) cb
.attr("checked", false);
1014 child
.addClassName("Selected");
1015 if (cb
) cb
.attr("checked", true);
1019 child
.removeClassName("Selected");
1020 if (cb
) cb
.attr("checked", false);
1024 updateSelectedPrompt();
1027 exception_error("selectArticles", e
);
1031 function deleteSelection() {
1035 var rows
= getSelectedArticleIds2();
1037 if (rows
.length
== 0) {
1038 alert(__("No articles are selected."));
1042 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1045 if (getActiveFeedId() != 0) {
1046 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1048 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1051 str
= str
.replace("%d", rows
.length
);
1052 str
= str
.replace("%s", fn
);
1054 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1058 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1062 new Ajax
.Request("backend.php", {
1064 onComplete: function(transport
) {
1065 handle_rpc_json(transport
);
1070 exception_error("deleteSelection", e
);
1074 function archiveSelection() {
1078 var rows
= getSelectedArticleIds2();
1080 if (rows
.length
== 0) {
1081 alert(__("No articles are selected."));
1085 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1089 if (getActiveFeedId() != 0) {
1090 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1093 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1095 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1100 str
= str
.replace("%d", rows
.length
);
1101 str
= str
.replace("%s", fn
);
1103 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1107 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1111 for (var i
= 0; i
< rows
.length
; i
++) {
1112 cache_delete("article:" + rows
[i
]);
1115 new Ajax
.Request("backend.php", {
1117 onComplete: function(transport
) {
1118 handle_rpc_json(transport
);
1123 exception_error("archiveSelection", e
);
1127 function catchupSelection() {
1131 var rows
= getSelectedArticleIds2();
1133 if (rows
.length
== 0) {
1134 alert(__("No articles are selected."));
1138 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1140 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1142 str
= str
.replace("%d", rows
.length
);
1143 str
= str
.replace("%s", fn
);
1145 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1149 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1152 exception_error("catchupSelection", e
);
1156 function editArticleTags(id
) {
1157 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1159 if (dijit
.byId("editTagsDlg"))
1160 dijit
.byId("editTagsDlg").destroyRecursive();
1162 dialog
= new dijit
.Dialog({
1164 title
: __("Edit article Tags"),
1165 style
: "width: 600px",
1166 execute: function() {
1167 if (this.validate()) {
1168 var query
= dojo
.objectToQuery(this.attr('value'));
1170 notify_progress("Saving article tags...", true);
1172 new Ajax
.Request("backend.php", {
1174 onComplete: function(transport
) {
1179 var data
= JSON
.parse(transport
.responseText
);
1186 var tags
= $("ATSTR-" + id
);
1187 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1189 if (tags
) tags
.innerHTML
= data
.content
;
1190 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1193 exception_error("editArticleTags/inner", e
);
1202 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1203 dojo
.disconnect(tmph
);
1205 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1206 "backend.php?op=article&method=completeTags",
1207 { tokens
: ',', paramName
: "search" });
1214 function cdmScrollToArticleId(id
, force
) {
1216 var ctr
= $("headlines-frame");
1217 var e
= $("RROW-" + id
);
1219 if (!e
|| !ctr
) return;
1221 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1222 e
.offsetTop
< ctr
.scrollTop
) {
1224 // expanded cdm has a 4px margin now
1225 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1229 exception_error("cdmScrollToArticleId", e
);
1233 function setActiveArticleId(id
) {
1234 _active_article_id
= id
;
1235 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1238 function getActiveArticleId() {
1239 return _active_article_id
;
1242 function postMouseIn(e
, id
) {
1243 post_under_pointer
= id
;
1246 function postMouseOut(id
) {
1247 post_under_pointer
= false;
1250 function unpackVisibleHeadlines() {
1252 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1254 $$("#headlines-frame > div[id*=RROW]").each(
1256 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1257 $("headlines-frame").offsetHeight
) {
1259 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1262 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1264 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1265 cencw
.setAttribute('id', '');
1266 Element
.show(cencw
);
1273 exception_error("unpackVisibleHeadlines", e
);
1277 function headlines_scroll_handler(e
) {
1279 var hsp
= $("headlines-spacer");
1281 unpackVisibleHeadlines();
1283 // set topmost child in the buffer as active
1284 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1285 getSelectedArticleIds2().length
<= 1 &&
1286 getInitParam("cdm_expanded")) {
1287 var rows
= $$("#headlines-frame > div[id*=RROW]");
1289 for (var i
= 0; i
< rows
.length
; i
++) {
1290 var child
= rows
[i
];
1292 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1293 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1294 child
.id
.replace("RROW-", "") != _active_article_id
) {
1296 if (_active_article_id
) {
1297 var row
= $("RROW-" + _active_article_id
);
1298 if (row
) row
.removeClassName("active");
1301 _active_article_id
= child
.id
.replace("RROW-", "");
1302 showArticleInHeadlines(_active_article_id
, true);
1303 updateSelectedPrompt();
1309 if (!_infscroll_disable
) {
1310 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1311 (e
.scrollHeight
!= 0 &&
1312 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1315 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1316 __("Loading, please wait...");
1318 loadMoreHeadlines();
1323 if (hsp
) hsp
.innerHTML
= "";
1327 updateFloatingTitle();
1330 if (getInitParam("cdm_auto_catchup") == 1) {
1332 // let's get DOM some time to settle down
1333 var ts
= new Date().getTime();
1334 if (ts
- _last_headlines_update
< 100) return;
1336 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1338 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1339 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1341 var id
= child
.id
.replace("RROW-", "");
1343 if (catchup_id_batch
.indexOf(id
) == -1)
1344 catchup_id_batch
.push(id
);
1346 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1351 if (catchup_id_batch
.length
> 0) {
1352 window
.clearTimeout(catchup_timeout_id
);
1354 if (!_infscroll_request_sent
) {
1355 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1362 console
.warn("headlines_scroll_handler: " + e
);
1366 function catchupBatchedArticles() {
1368 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1370 // make a copy of the array
1371 var batch
= catchup_id_batch
.slice();
1372 var query
= "?op=rpc&method=catchupSelected" +
1373 "&cmode=0&ids=" + param_escape(batch
.toString());
1377 new Ajax
.Request("backend.php", {
1379 onComplete: function(transport
) {
1380 handle_rpc_json(transport
);
1382 reply
= JSON
.parse(transport
.responseText
);
1383 var batch
= reply
.ids
;
1385 batch
.each(function(id
) {
1387 var elem
= $("RROW-" + id
);
1388 if (elem
) elem
.removeClassName("Unread");
1389 catchup_id_batch
.remove(id
);
1392 updateFloatingTitle(true);
1398 exception_error("catchupBatchedArticles", e
);
1402 function catchupRelativeToArticle(below
, id
) {
1406 if (!id
) id
= getActiveArticleId();
1409 alert(__("No article is selected."));
1413 var visible_ids
= getVisibleArticleIds();
1415 var ids_to_mark
= new Array();
1418 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1419 if (visible_ids
[i
] != id
) {
1420 var e
= $("RROW-" + visible_ids
[i
]);
1422 if (e
&& e
.hasClassName("Unread")) {
1423 ids_to_mark
.push(visible_ids
[i
]);
1430 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1431 if (visible_ids
[i
] != id
) {
1432 var e
= $("RROW-" + visible_ids
[i
]);
1434 if (e
&& e
.hasClassName("Unread")) {
1435 ids_to_mark
.push(visible_ids
[i
]);
1443 if (ids_to_mark
.length
== 0) {
1444 alert(__("No articles found to mark"));
1446 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1448 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1450 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1451 var e
= $("RROW-" + ids_to_mark
[i
]);
1452 e
.removeClassName("Unread");
1455 var query
= "?op=rpc&method=catchupSelected" +
1456 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1458 new Ajax
.Request("backend.php", {
1460 onComplete: function(transport
) {
1461 handle_rpc_json(transport
);
1468 exception_error("catchupRelativeToArticle", e
);
1472 function cdmCollapseArticle(event
, id
, unmark
) {
1474 if (unmark
== undefined) unmark
= true;
1476 var row
= $("RROW-" + id
);
1477 var elem
= $("CICD-" + id
);
1480 var collapse
= $$("div#RROW-" + id
+
1481 " span[class='collapseBtn']")[0];
1484 Element
.show("CEXC-" + id
);
1485 Element
.hide(collapse
);
1488 row
.removeClassName("active");
1490 markHeadline(id
, false);
1492 if (id
== getActiveArticleId()) {
1493 setActiveArticleId(0);
1496 updateSelectedPrompt();
1499 if (event
) Event
.stop(event
);
1501 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1503 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1504 scrollToRowId(row
.id
);
1506 Element
.hide("floatingTitle");
1507 $("floatingTitle").setAttribute("rowid", false);
1511 exception_error("cdmCollapseArticle", e
);
1515 function cdmExpandArticle(id
, noexpand
) {
1517 console
.log("cdmExpandArticle " + id
);
1519 if (!$("RROW-" + id
)) return false;
1521 var oldrow
= $("RROW-" + getActiveArticleId());
1523 var elem
= $("CICD-" + getActiveArticleId());
1525 if (id
== getActiveArticleId() && Element
.visible(elem
))
1528 selectArticles("none");
1530 var old_offset
= $("RROW-" + id
).offsetTop
;
1532 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1533 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1534 " span[class='collapseBtn']")[0];
1537 Element
.show("CEXC-" + getActiveArticleId());
1538 Element
.hide(collapse
);
1541 if (oldrow
) oldrow
.removeClassName("active");
1543 setActiveArticleId(id
);
1545 elem
= $("CICD-" + id
);
1547 var collapse
= $$("div#RROW-" + id
+
1548 " span[class='collapseBtn']")[0];
1550 var cencw
= $("CENCW-" + id
);
1552 if (!Element
.visible(elem
) && !noexpand
) {
1554 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1555 cencw
.setAttribute('id', '');
1556 Element
.show(cencw
);
1560 Element
.hide("CEXC-" + id
);
1561 Element
.show(collapse
);
1564 var new_offset
= $("RROW-" + id
).offsetTop
;
1566 if (old_offset
> new_offset
)
1567 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1570 toggleUnread(id
, 0, true);
1572 $("RROW-" + id
).addClassName("active");
1574 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1577 exception_error("cdmExpandArticle", e
);
1583 function getArticleUnderPointer() {
1584 return post_under_pointer
;
1587 function scrollArticle(offset
) {
1590 var ci
= $("content-insert");
1592 ci
.scrollTop
+= offset
;
1595 var hi
= $("headlines-frame");
1597 hi
.scrollTop
+= offset
;
1602 exception_error("scrollArticle", e
);
1606 function show_labels_in_headlines(transport
) {
1608 var data
= JSON
.parse(transport
.responseText
);
1611 data
['info-for-headlines'].each(function(elem
) {
1612 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1613 ctr
.innerHTML
= elem
.labels
;
1618 exception_error("show_labels_in_headlines", e
);
1622 function dismissArticle(id
) {
1624 var elem
= $("RROW-" + id
);
1628 toggleUnread(id
, 0, true);
1630 new Effect
.Fade(elem
, {duration
: 0.5});
1632 // Remove the content, too
1633 var elem_content
= $("CICD-" + id
);
1635 Element
.remove(elem_content
);
1638 if (id
== getActiveArticleId()) {
1639 setActiveArticleId(0);
1643 exception_error("dismissArticle", e
);
1647 function dismissSelectedArticles() {
1650 var ids
= getVisibleArticleIds();
1654 for (var i
= 0; i
< ids
.length
; i
++) {
1655 var elem
= $("RROW-" + ids
[i
]);
1657 if (elem
.className
&& elem
.hasClassName("Selected") &&
1658 ids
[i
] != getActiveArticleId()) {
1659 new Effect
.Fade(elem
, {duration
: 0.5});
1662 // Remove the content, too
1663 var elem_content
= $("CICD-" + ids
[i
]);
1665 Element
.remove(elem_content
);
1673 selectionToggleUnread(false);
1677 exception_error("dismissSelectedArticles", e
);
1681 function dismissReadArticles() {
1684 var ids
= getVisibleArticleIds();
1687 for (var i
= 0; i
< ids
.length
; i
++) {
1688 var elem
= $("RROW-" + ids
[i
]);
1690 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1691 !elem
.hasClassName("Selected")) {
1693 new Effect
.Fade(elem
, {duration
: 0.5});
1695 // Remove the content, too
1696 var elem_content
= $("CICD-" + ids
[i
]);
1698 Element
.remove(elem_content
);
1706 exception_error("dismissReadArticles", e
);
1710 function getVisibleArticleIds() {
1715 getLoadedArticleIds().each(function(id
) {
1716 var elem
= $("RROW-" + id
);
1717 if (elem
&& Element
.visible(elem
))
1722 exception_error("getVisibleArticleIds", e
);
1728 function cdmClicked(event
, id
) {
1730 //var shift_key = event.shiftKey;
1732 if (!event
.ctrlKey
) {
1734 if (!getInitParam("cdm_expanded")) {
1735 return cdmExpandArticle(id
);
1738 var elem
= $("RROW-" + getActiveArticleId());
1740 if (elem
) elem
.removeClassName("active");
1742 selectArticles("none");
1745 var elem
= $("RROW-" + id
);
1746 var article_is_unread
= elem
.hasClassName("Unread");
1748 elem
.removeClassName("Unread");
1749 elem
.addClassName("active");
1751 setActiveArticleId(id
);
1753 if (article_is_unread
) {
1754 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1755 updateFloatingTitle(true);
1758 var query
= "?op=rpc&method=catchupSelected" +
1759 "&cmode=0&ids=" + param_escape(id
);
1761 new Ajax
.Request("backend.php", {
1763 onComplete: function(transport
) {
1764 handle_rpc_json(transport
);
1767 return !event
.shiftKey
;
1771 toggleSelected(id
, true);
1773 var elem
= $("RROW-" + id
);
1774 var article_is_unread
= elem
.hasClassName("Unread");
1776 if (article_is_unread
) {
1777 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1780 toggleUnread(id
, 0, false);
1782 openArticleInNewWindow(id
);
1785 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1786 request_counters(unread_in_buffer
== 0);
1789 exception_error("cdmClicked");
1795 function hlClicked(event
, id
) {
1797 if (event
.which
== 2) {
1800 } else if (event
.ctrlKey
) {
1801 toggleSelected(id
, true);
1802 toggleUnread(id
, 0, false);
1803 openArticleInNewWindow(id
);
1811 exception_error("hlClicked");
1815 function getFirstVisibleHeadlineId() {
1816 var rows
= getVisibleArticleIds();
1821 function getLastVisibleHeadlineId() {
1822 var rows
= getVisibleArticleIds();
1823 return rows
[rows
.length
-1];
1826 function openArticleInNewWindow(id
) {
1827 toggleUnread(id
, 0, false);
1828 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1831 function isCdmMode() {
1832 return getInitParam("combined_display_mode");
1835 function markHeadline(id
, marked
) {
1836 if (marked
== undefined) marked
= true;
1838 var row
= $("RROW-" + id
);
1840 var check
= dijit
.getEnclosingWidget(
1841 row
.getElementsByClassName("rchk")[0]);
1844 check
.attr("checked", marked
);
1848 row
.addClassName("Selected");
1850 row
.removeClassName("Selected");
1854 function getRelativePostIds(id
, limit
) {
1860 if (!limit
) limit
= 6; //3
1862 var ids
= getVisibleArticleIds();
1864 for (var i
= 0; i
< ids
.length
; i
++) {
1866 for (var k
= 1; k
<= limit
; k
++) {
1867 //if (i > k-1) tmp.push(ids[i-k]);
1868 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1875 exception_error("getRelativePostIds", e
);
1881 function correctHeadlinesOffset(id
) {
1885 var container
= $("headlines-frame");
1886 var row
= $("RROW-" + id
);
1888 if (!container
|| !row
) return;
1890 var viewport
= container
.offsetHeight
;
1892 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1893 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1895 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1896 //console.log("Vport: " + viewport);
1898 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1899 container
.scrollTop
= row
.offsetTop
;
1900 } else if (rel_offset_bottom
> viewport
) {
1902 /* doesn't properly work with Opera in some cases because
1903 Opera fucks up element scrolling */
1905 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1909 exception_error("correctHeadlinesOffset", e
);
1914 function headlineActionsChange(elem
) {
1917 elem
.attr('value', 'false');
1919 exception_error("headlineActionsChange", e
);
1923 function closeArticlePanel() {
1925 if (dijit
.byId("content-insert"))
1926 dijit
.byId("headlines-wrap-inner").removeChild(
1927 dijit
.byId("content-insert"));
1930 function initFloatingMenu() {
1932 if (dijit
.byId("floatingMenu"))
1933 dijit
.byId("floatingMenu").destroyRecursive();
1935 var menu
= new dijit
.Menu({
1937 targetNodeIds
: ["floatingTitle"]
1940 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1942 headlinesMenuCommon(menu
, id
);
1946 exception_error("initFloatingMenu", e
);
1950 function headlinesMenuCommon(menu
, base_id
) {
1953 menu
.addChild(new dijit
.MenuItem({
1954 label
: __("Open original article"),
1955 onClick: function(event
) {
1956 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1959 menu
.addChild(new dijit
.MenuItem({
1960 label
: __("Display article URL"),
1961 onClick: function(event
) {
1962 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1965 menu
.addChild(new dijit
.MenuSeparator());
1967 menu
.addChild(new dijit
.MenuItem({
1968 label
: __("Toggle unread"),
1969 onClick: function(event
) {
1970 var ids
= getSelectedArticleIds2();
1972 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1973 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1975 selectionToggleUnread(undefined, false, true, ids
);
1978 menu
.addChild(new dijit
.MenuItem({
1979 label
: __("Toggle starred"),
1980 onClick: function(event
) {
1981 var ids
= getSelectedArticleIds2();
1983 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1984 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1986 selectionToggleMarked(undefined, false, true, ids
);
1989 menu
.addChild(new dijit
.MenuItem({
1990 label
: __("Toggle published"),
1991 onClick: function(event
) {
1992 var ids
= getSelectedArticleIds2();
1994 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1995 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1997 selectionTogglePublished(undefined, false, true, ids
);
2000 menu
.addChild(new dijit
.MenuSeparator());
2002 menu
.addChild(new dijit
.MenuItem({
2003 label
: __("Mark above as read"),
2004 onClick: function(event
) {
2005 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2008 menu
.addChild(new dijit
.MenuItem({
2009 label
: __("Mark below as read"),
2010 onClick: function(event
) {
2011 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2015 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2019 menu
.addChild(new dijit
.MenuSeparator());
2021 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2022 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2024 labels
.each(function(label
) {
2025 var id
= label
.id
[0];
2026 var bare_id
= id
.substr(id
.indexOf(":")+1);
2027 var name
= label
.name
[0];
2029 bare_id
= feed_to_label_id(bare_id
);
2031 labelAddMenu
.addChild(new dijit
.MenuItem({
2034 onClick: function(event
) {
2035 var ids
= getSelectedArticleIds2();
2037 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2039 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2041 selectionAssignLabel(this.labelId
, ids
);
2044 labelDelMenu
.addChild(new dijit
.MenuItem({
2047 onClick: function(event
) {
2048 var ids
= getSelectedArticleIds2();
2050 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2052 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2054 selectionRemoveLabel(this.labelId
, ids
);
2059 menu
.addChild(new dijit
.PopupMenuItem({
2060 label
: __("Assign label"),
2061 popup
: labelAddMenu
,
2064 menu
.addChild(new dijit
.PopupMenuItem({
2065 label
: __("Remove label"),
2066 popup
: labelDelMenu
,
2073 exception_error("headlinesMenuCommon", e
);
2077 function initHeadlinesMenu() {
2079 if (dijit
.byId("headlinesMenu"))
2080 dijit
.byId("headlinesMenu").destroyRecursive();
2085 nodes
= $$("#headlines-frame > div[id*=RROW]");
2087 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2090 nodes
.each(function(node
) {
2094 var menu
= new dijit
.Menu({
2095 id
: "headlinesMenu",
2099 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2100 var callerNode
= event
.target
, match
= null, tries
= 0;
2102 while (match
== null && callerNode
&& tries
<= 3) {
2103 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2104 callerNode
= callerNode
.parentNode
;
2108 if (match
) this.callerRowId
= parseInt(match
[1]);
2112 headlinesMenuCommon(menu
, false);
2116 /* vgroup feed title menu */
2118 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2121 nodes
.each(function(node
) {
2125 if (ids
.length
> 0) {
2126 if (dijit
.byId("headlinesFeedTitleMenu"))
2127 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2129 var menu
= new dijit
.Menu({
2130 id
: "headlinesFeedTitleMenu",
2134 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2135 var callerNode
= event
.target
, match
= null, tries
= 0;
2137 while (match
== null && callerNode
&& tries
<= 3) {
2138 console
.log(callerNode
.id
);
2140 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2141 callerNode
= callerNode
.parentNode
;
2144 console
.log(match
[1]);
2147 if (match
) this.callerRowId
= parseInt(match
[1]);
2151 menu
.addChild(new dijit
.MenuItem({
2152 label
: __("Select articles in group"),
2153 onClick: function(event
) {
2154 selectArticles("all",
2155 "#headlines-frame > div[id*=RROW]"+
2156 "[orig-feed-id='"+menu
.callerRowId
+"']");
2160 menu
.addChild(new dijit
.MenuItem({
2161 label
: __("Mark group as read"),
2162 onClick: function(event
) {
2163 selectArticles("none");
2164 selectArticles("all",
2165 "#headlines-frame > div[id*=RROW]"+
2166 "[orig-feed-id='"+menu
.callerRowId
+"']");
2172 menu
.addChild(new dijit
.MenuItem({
2173 label
: __("Mark feed as read"),
2174 onClick: function(event
) {
2175 catchupFeedInGroup(menu
.callerRowId
);
2183 exception_error("initHeadlinesMenu", e
);
2187 function cache_set(id
, obj
) {
2188 //console.log("cache_set: " + id);
2191 sessionStorage
[id
] = obj
;
2193 sessionStorage
.clear();
2197 function cache_get(id
) {
2199 return sessionStorage
[id
];
2202 function cache_clear() {
2204 sessionStorage
.clear();
2207 function cache_delete(id
) {
2209 sessionStorage
.removeItem(id
);
2212 function cancelSearch() {
2217 exception_error("cancelSearch", e
);
2221 function setSelectionScore() {
2223 var ids
= getSelectedArticleIds2();
2225 if (ids
.length
> 0) {
2228 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2230 if (score
!= undefined) {
2231 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2232 "&score=" + param_escape(score
);
2234 new Ajax
.Request("backend.php", {
2236 onComplete: function(transport
) {
2237 var reply
= JSON
.parse(transport
.responseText
);
2241 ids
.each(function(id
) {
2242 var row
= $("RROW-" + id
);
2245 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2248 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2249 reply
["score_pic"]);
2250 pic
.setAttribute("score", score
);
2259 alert(__("No articles are selected."));
2262 exception_error("setSelectionScore", e
);
2266 function changeScore(id
, pic
) {
2268 var score
= pic
.getAttribute("score");
2270 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2272 if (new_score
!= undefined) {
2274 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2275 "&score=" + param_escape(new_score
);
2277 new Ajax
.Request("backend.php", {
2279 onComplete: function(transport
) {
2280 var reply
= JSON
.parse(transport
.responseText
);
2283 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2284 pic
.setAttribute("score", new_score
);
2289 exception_error("changeScore", e
);
2293 function displayArticleUrl(id
) {
2295 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2297 new Ajax
.Request("backend.php", {
2299 onComplete: function(transport
) {
2300 var reply
= JSON
.parse(transport
.responseText
);
2302 if (reply
&& reply
.link
) {
2303 prompt(__("Article URL:"), reply
.link
);
2307 exception_error("changeScore", e
);
2311 function openSelectedAttachment(elem
) {
2313 var url
= elem
[elem
.selectedIndex
].value
;
2317 elem
.selectedIndex
= 0;
2321 exception_error("openSelectedAttachment", e
);
2325 function scrollToRowId(id
) {
2330 $("headlines-frame").scrollTop
= row
.offsetTop
;
2333 exception_error("scrollToRowId", e
);
2337 function updateFloatingTitle(unread_only
) {
2339 if (!isCdmMode()) return;
2341 var hf
= $("headlines-frame");
2343 var elems
= $$("#headlines-frame > div[id*=RROW]");
2345 for (var i
= 0; i
< elems
.length
; i
++) {
2347 var child
= elems
[i
];
2349 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2351 var header
= child
.getElementsByClassName("cdmHeader")[0];
2353 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2354 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2355 $("floatingTitle").setAttribute("rowid", child
.id
);
2356 $("floatingTitle").innerHTML
= header
.innerHTML
;
2357 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2361 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2364 cb
.parentNode
.removeChild(cb
);
2367 if (child
.hasClassName("Unread"))
2368 $("floatingTitle").addClassName("Unread");
2370 $("floatingTitle").removeClassName("Unread");
2372 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2375 if (child
.offsetTop
< hf
.scrollTop
- header
.offsetHeight
&&
2376 child
.offsetTop
+ child
.offsetHeight
- hf
.scrollTop
> header
.offsetHeight
)
2377 Element
.show("floatingTitle");
2379 Element
.hide("floatingTitle");
2387 exception_error("updateFloatingTitle", e
);