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 $("floatingTitle").style
.visibility
= "hidden";
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
);
111 if (_infscroll_disable
)
112 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
113 __("Click to open next unread feed.") + "</a>";
116 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
117 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
123 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
124 console
.log("adding some more headlines: " + headlines_count
);
126 var c
= dijit
.byId("headlines-frame");
127 var ids
= getSelectedArticleIds2();
130 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
132 var hsp
= $("headlines-spacer");
135 c
.domNode
.removeChild(hsp
);
137 $$("#headlines-tmp > div").each(function(row
) {
138 if (row
.className
== 'cdmFeedTitle') {
139 row
.style
.display
= 'none';
140 c
.domNode
.appendChild(row
);
142 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
143 row
.style
.display
= 'none';
144 c
.domNode
.appendChild(row
);
146 loaded_article_ids
.push(row
.id
);
148 row
.parentNode
.removeChild(row
);
152 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
154 // if (getInitParam("cdm_auto_catchup") == 1) {
155 c
.domNode
.appendChild(hsp
);
158 console
.log("added " + new_elems
.size() + " headlines");
160 if (new_elems
.size() == 0)
161 _infscroll_disable
= true;
163 console
.log("restore selected ids: " + ids
);
165 for (var i
= 0; i
< ids
.length
; i
++) {
166 markHeadline(ids
[i
]);
171 new_elems
.each(function(child
) {
172 dojo
.parser
.parse(child
);
174 if (!Element
.visible(child
))
175 new Effect
.Appear(child
, { duration
: 0.5 });
179 console
.log("no new headlines received");
181 var hsp
= $("headlines-spacer");
183 if (hsp
) hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
184 __("Click to open next unread feed.") + "</a>";
189 for (var i
= 0; i
< articles
.length
; i
++) {
190 var a_id
= articles
[i
]['id'];
191 cache_set("article:" + a_id
, articles
[i
]['content']);
194 console
.log("no cached articles received");
198 parse_counters(counters
);
200 request_counters(true);
203 console
.error("Invalid object received: " + transport
.responseText
);
204 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
205 __('Could not update headlines (invalid object received - see error console for details)') +
209 _infscroll_request_sent
= 0;
210 _last_headlines_update
= new Date().getTime();
212 unpackVisibleHeadlines();
214 // if we have some more space in the buffer, why not try to fill it
216 if (!_infscroll_disable
&& $("headlines-spacer") &&
217 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
219 window
.setTimeout(function() {
227 exception_error("headlines_callback2", e
, transport
);
231 function render_article(article
) {
233 dijit
.byId("headlines-wrap-inner").addChild(
234 dijit
.byId("content-insert"));
236 var c
= dijit
.byId("content-insert");
239 c
.domNode
.scrollTop
= 0;
242 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
244 c
.attr('content', article
);
246 correctHeadlinesOffset(getActiveArticleId());
253 exception_error("render_article", e
);
257 function showArticleInHeadlines(id
, noexpand
) {
260 selectArticles("none");
262 var crow
= $("RROW-" + id
);
266 var article_is_unread
= crow
.hasClassName("Unread");
269 crow
.removeClassName("Unread");
270 crow
.addClassName("active");
272 selectArticles('none');
274 var view_mode
= false;
277 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
278 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
285 if (article_is_unread
&& !noexpand
)
286 _force_scheduled_update
= true;
289 exception_error("showArticleInHeadlines", e
);
293 function article_callback2(transport
, id
) {
295 console
.log("article_callback2 " + id
);
297 handle_rpc_json(transport
);
302 reply
= JSON
.parse(transport
.responseText
);
309 reply
.each(function(article
) {
310 if (getActiveArticleId() == article
['id']) {
311 render_article(article
['content']);
313 cids_requested
.remove(article
['id']);
315 cache_set("article:" + article
['id'], article
['content']);
318 // if (id != last_requested_article) {
319 // console.log("requested article id is out of sequence, aborting");
324 console
.error("Invalid object received: " + transport
.responseText
);
326 render_article("<div class='whiteBox'>" +
327 __('Could not display article (invalid object received - see error console for details)') + "</div>");
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
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1316 __("Loading, please wait...") + "</span>";
1318 loadMoreHeadlines();
1324 if (_infscroll_disable
)
1325 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
1326 __("Click to open next unread feed.") + "</a>";
1332 updateFloatingTitle();
1335 if (getInitParam("cdm_auto_catchup") == 1) {
1337 // let's get DOM some time to settle down
1338 var ts
= new Date().getTime();
1339 if (ts
- _last_headlines_update
< 100) return;
1341 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1343 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1344 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1346 var id
= child
.id
.replace("RROW-", "");
1348 if (catchup_id_batch
.indexOf(id
) == -1)
1349 catchup_id_batch
.push(id
);
1351 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1356 if (catchup_id_batch
.length
> 0) {
1357 window
.clearTimeout(catchup_timeout_id
);
1359 if (!_infscroll_request_sent
) {
1360 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1365 if (_infscroll_disable
) {
1366 var child
= $$("#headlines-frame div[id*=RROW]").last();
1368 if (child
&& $("headlines-frame").scrollTop
>
1369 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1371 console
.log("we seem to be at an end");
1373 if (getInitParam("on_catchup_show_next_feed") == "1") {
1374 openNextUnreadFeed();
1381 console
.warn("headlines_scroll_handler: " + e
);
1385 function openNextUnreadFeed() {
1387 var is_cat
= activeFeedIsCat();
1388 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1389 if (nuf
) viewfeed(nuf
, '', is_cat
);
1391 exception_error("openNextUnreadFeed", e
);
1395 function catchupBatchedArticles() {
1397 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1399 // make a copy of the array
1400 var batch
= catchup_id_batch
.slice();
1401 var query
= "?op=rpc&method=catchupSelected" +
1402 "&cmode=0&ids=" + param_escape(batch
.toString());
1406 new Ajax
.Request("backend.php", {
1408 onComplete: function(transport
) {
1409 handle_rpc_json(transport
);
1411 reply
= JSON
.parse(transport
.responseText
);
1412 var batch
= reply
.ids
;
1414 batch
.each(function(id
) {
1416 var elem
= $("RROW-" + id
);
1417 if (elem
) elem
.removeClassName("Unread");
1418 catchup_id_batch
.remove(id
);
1421 updateFloatingTitle(true);
1427 exception_error("catchupBatchedArticles", e
);
1431 function catchupRelativeToArticle(below
, id
) {
1435 if (!id
) id
= getActiveArticleId();
1438 alert(__("No article is selected."));
1442 var visible_ids
= getVisibleArticleIds();
1444 var ids_to_mark
= new Array();
1447 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1448 if (visible_ids
[i
] != id
) {
1449 var e
= $("RROW-" + visible_ids
[i
]);
1451 if (e
&& e
.hasClassName("Unread")) {
1452 ids_to_mark
.push(visible_ids
[i
]);
1459 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1460 if (visible_ids
[i
] != id
) {
1461 var e
= $("RROW-" + visible_ids
[i
]);
1463 if (e
&& e
.hasClassName("Unread")) {
1464 ids_to_mark
.push(visible_ids
[i
]);
1472 if (ids_to_mark
.length
== 0) {
1473 alert(__("No articles found to mark"));
1475 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1477 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1479 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1480 var e
= $("RROW-" + ids_to_mark
[i
]);
1481 e
.removeClassName("Unread");
1484 var query
= "?op=rpc&method=catchupSelected" +
1485 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1487 new Ajax
.Request("backend.php", {
1489 onComplete: function(transport
) {
1490 handle_rpc_json(transport
);
1497 exception_error("catchupRelativeToArticle", e
);
1501 function cdmCollapseArticle(event
, id
, unmark
) {
1503 if (unmark
== undefined) unmark
= true;
1505 var row
= $("RROW-" + id
);
1506 var elem
= $("CICD-" + id
);
1509 var collapse
= $$("div#RROW-" + id
+
1510 " span[class='collapseBtn']")[0];
1513 Element
.show("CEXC-" + id
);
1514 Element
.hide(collapse
);
1517 row
.removeClassName("active");
1519 markHeadline(id
, false);
1521 if (id
== getActiveArticleId()) {
1522 setActiveArticleId(0);
1525 updateSelectedPrompt();
1528 if (event
) Event
.stop(event
);
1530 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1532 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1533 scrollToRowId(row
.id
);
1535 $("floatingTitle").style
.visibility
= "hidden";
1536 $("floatingTitle").setAttribute("rowid", false);
1540 exception_error("cdmCollapseArticle", e
);
1544 function cdmExpandArticle(id
, noexpand
) {
1546 console
.log("cdmExpandArticle " + id
);
1548 if (!$("RROW-" + id
)) return false;
1550 var oldrow
= $("RROW-" + getActiveArticleId());
1552 var elem
= $("CICD-" + getActiveArticleId());
1554 if (id
== getActiveArticleId() && Element
.visible(elem
))
1557 selectArticles("none");
1559 var old_offset
= $("RROW-" + id
).offsetTop
;
1561 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1562 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1563 " span[class='collapseBtn']")[0];
1566 Element
.show("CEXC-" + getActiveArticleId());
1567 Element
.hide(collapse
);
1570 if (oldrow
) oldrow
.removeClassName("active");
1572 setActiveArticleId(id
);
1574 elem
= $("CICD-" + id
);
1576 var collapse
= $$("div#RROW-" + id
+
1577 " span[class='collapseBtn']")[0];
1579 var cencw
= $("CENCW-" + id
);
1581 if (!Element
.visible(elem
) && !noexpand
) {
1583 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1584 cencw
.setAttribute('id', '');
1585 Element
.show(cencw
);
1589 Element
.hide("CEXC-" + id
);
1590 Element
.show(collapse
);
1593 var new_offset
= $("RROW-" + id
).offsetTop
;
1595 if (old_offset
> new_offset
)
1596 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1599 toggleUnread(id
, 0, true);
1601 $("RROW-" + id
).addClassName("active");
1603 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1606 exception_error("cdmExpandArticle", e
);
1612 function getArticleUnderPointer() {
1613 return post_under_pointer
;
1616 function scrollArticle(offset
) {
1619 var ci
= $("content-insert");
1621 ci
.scrollTop
+= offset
;
1624 var hi
= $("headlines-frame");
1626 hi
.scrollTop
+= offset
;
1631 exception_error("scrollArticle", e
);
1635 function show_labels_in_headlines(transport
) {
1637 var data
= JSON
.parse(transport
.responseText
);
1640 data
['info-for-headlines'].each(function(elem
) {
1641 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1642 ctr
.innerHTML
= elem
.labels
;
1647 exception_error("show_labels_in_headlines", e
);
1651 function dismissArticle(id
) {
1653 var elem
= $("RROW-" + id
);
1657 toggleUnread(id
, 0, true);
1659 new Effect
.Fade(elem
, {duration
: 0.5});
1661 // Remove the content, too
1662 var elem_content
= $("CICD-" + id
);
1664 Element
.remove(elem_content
);
1667 if (id
== getActiveArticleId()) {
1668 setActiveArticleId(0);
1672 exception_error("dismissArticle", e
);
1676 function dismissSelectedArticles() {
1679 var ids
= getVisibleArticleIds();
1683 for (var i
= 0; i
< ids
.length
; i
++) {
1684 var elem
= $("RROW-" + ids
[i
]);
1686 if (elem
.className
&& elem
.hasClassName("Selected") &&
1687 ids
[i
] != getActiveArticleId()) {
1688 new Effect
.Fade(elem
, {duration
: 0.5});
1691 // Remove the content, too
1692 var elem_content
= $("CICD-" + ids
[i
]);
1694 Element
.remove(elem_content
);
1702 selectionToggleUnread(false);
1706 exception_error("dismissSelectedArticles", e
);
1710 function dismissReadArticles() {
1713 var ids
= getVisibleArticleIds();
1716 for (var i
= 0; i
< ids
.length
; i
++) {
1717 var elem
= $("RROW-" + ids
[i
]);
1719 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1720 !elem
.hasClassName("Selected")) {
1722 new Effect
.Fade(elem
, {duration
: 0.5});
1724 // Remove the content, too
1725 var elem_content
= $("CICD-" + ids
[i
]);
1727 Element
.remove(elem_content
);
1735 exception_error("dismissReadArticles", e
);
1739 function getVisibleArticleIds() {
1744 getLoadedArticleIds().each(function(id
) {
1745 var elem
= $("RROW-" + id
);
1746 if (elem
&& Element
.visible(elem
))
1751 exception_error("getVisibleArticleIds", e
);
1757 function cdmClicked(event
, id
) {
1759 //var shift_key = event.shiftKey;
1761 if (!event
.ctrlKey
) {
1763 if (!getInitParam("cdm_expanded")) {
1764 return cdmExpandArticle(id
);
1767 var elem
= $("RROW-" + getActiveArticleId());
1769 if (elem
) elem
.removeClassName("active");
1771 selectArticles("none");
1774 var elem
= $("RROW-" + id
);
1775 var article_is_unread
= elem
.hasClassName("Unread");
1777 elem
.removeClassName("Unread");
1778 elem
.addClassName("active");
1780 setActiveArticleId(id
);
1782 if (article_is_unread
) {
1783 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1784 updateFloatingTitle(true);
1787 var query
= "?op=rpc&method=catchupSelected" +
1788 "&cmode=0&ids=" + param_escape(id
);
1790 new Ajax
.Request("backend.php", {
1792 onComplete: function(transport
) {
1793 handle_rpc_json(transport
);
1796 return !event
.shiftKey
;
1799 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1801 toggleSelected(id
, true);
1803 var elem
= $("RROW-" + id
);
1804 var article_is_unread
= elem
.hasClassName("Unread");
1806 if (article_is_unread
) {
1807 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1810 toggleUnread(id
, 0, false);
1812 openArticleInNewWindow(id
);
1815 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1816 request_counters(unread_in_buffer
== 0);
1819 exception_error("cdmClicked");
1825 function hlClicked(event
, id
) {
1827 if (event
.which
== 2) {
1830 } else if (event
.ctrlKey
) {
1831 toggleSelected(id
, true);
1832 toggleUnread(id
, 0, false);
1833 openArticleInNewWindow(id
);
1841 exception_error("hlClicked");
1845 function getFirstVisibleHeadlineId() {
1846 var rows
= getVisibleArticleIds();
1851 function getLastVisibleHeadlineId() {
1852 var rows
= getVisibleArticleIds();
1853 return rows
[rows
.length
-1];
1856 function openArticleInNewWindow(id
) {
1857 toggleUnread(id
, 0, false);
1858 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1861 function isCdmMode() {
1862 return getInitParam("combined_display_mode");
1865 function markHeadline(id
, marked
) {
1866 if (marked
== undefined) marked
= true;
1868 var row
= $("RROW-" + id
);
1870 var check
= dijit
.getEnclosingWidget(
1871 row
.getElementsByClassName("rchk")[0]);
1874 check
.attr("checked", marked
);
1878 row
.addClassName("Selected");
1880 row
.removeClassName("Selected");
1884 function getRelativePostIds(id
, limit
) {
1890 if (!limit
) limit
= 6; //3
1892 var ids
= getVisibleArticleIds();
1894 for (var i
= 0; i
< ids
.length
; i
++) {
1896 for (var k
= 1; k
<= limit
; k
++) {
1897 //if (i > k-1) tmp.push(ids[i-k]);
1898 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1905 exception_error("getRelativePostIds", e
);
1911 function correctHeadlinesOffset(id
) {
1915 var container
= $("headlines-frame");
1916 var row
= $("RROW-" + id
);
1918 if (!container
|| !row
) return;
1920 var viewport
= container
.offsetHeight
;
1922 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1923 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1925 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1926 //console.log("Vport: " + viewport);
1928 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1929 container
.scrollTop
= row
.offsetTop
;
1930 } else if (rel_offset_bottom
> viewport
) {
1932 /* doesn't properly work with Opera in some cases because
1933 Opera fucks up element scrolling */
1935 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1939 exception_error("correctHeadlinesOffset", e
);
1944 function headlineActionsChange(elem
) {
1947 elem
.attr('value', 'false');
1949 exception_error("headlineActionsChange", e
);
1953 function closeArticlePanel() {
1955 if (dijit
.byId("content-insert"))
1956 dijit
.byId("headlines-wrap-inner").removeChild(
1957 dijit
.byId("content-insert"));
1960 function initFloatingMenu() {
1962 if (dijit
.byId("floatingMenu"))
1963 dijit
.byId("floatingMenu").destroyRecursive();
1965 var menu
= new dijit
.Menu({
1967 targetNodeIds
: ["floatingTitle"]
1970 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1972 headlinesMenuCommon(menu
, id
);
1976 exception_error("initFloatingMenu", e
);
1980 function headlinesMenuCommon(menu
, base_id
) {
1983 menu
.addChild(new dijit
.MenuItem({
1984 label
: __("Open original article"),
1985 onClick: function(event
) {
1986 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1989 menu
.addChild(new dijit
.MenuItem({
1990 label
: __("Display article URL"),
1991 onClick: function(event
) {
1992 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1995 menu
.addChild(new dijit
.MenuSeparator());
1997 menu
.addChild(new dijit
.MenuItem({
1998 label
: __("Toggle unread"),
1999 onClick: function(event
) {
2000 var ids
= getSelectedArticleIds2();
2002 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2003 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2005 selectionToggleUnread(undefined, false, true, ids
);
2008 menu
.addChild(new dijit
.MenuItem({
2009 label
: __("Toggle starred"),
2010 onClick: function(event
) {
2011 var ids
= getSelectedArticleIds2();
2013 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2014 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2016 selectionToggleMarked(undefined, false, true, ids
);
2019 menu
.addChild(new dijit
.MenuItem({
2020 label
: __("Toggle published"),
2021 onClick: function(event
) {
2022 var ids
= getSelectedArticleIds2();
2024 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2025 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2027 selectionTogglePublished(undefined, false, true, ids
);
2030 menu
.addChild(new dijit
.MenuSeparator());
2032 menu
.addChild(new dijit
.MenuItem({
2033 label
: __("Mark above as read"),
2034 onClick: function(event
) {
2035 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2038 menu
.addChild(new dijit
.MenuItem({
2039 label
: __("Mark below as read"),
2040 onClick: function(event
) {
2041 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2045 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2049 menu
.addChild(new dijit
.MenuSeparator());
2051 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2052 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2054 labels
.each(function(label
) {
2055 var id
= label
.id
[0];
2056 var bare_id
= id
.substr(id
.indexOf(":")+1);
2057 var name
= label
.name
[0];
2059 bare_id
= feed_to_label_id(bare_id
);
2061 labelAddMenu
.addChild(new dijit
.MenuItem({
2064 onClick: function(event
) {
2065 var ids
= getSelectedArticleIds2();
2067 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2069 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2071 selectionAssignLabel(this.labelId
, ids
);
2074 labelDelMenu
.addChild(new dijit
.MenuItem({
2077 onClick: function(event
) {
2078 var ids
= getSelectedArticleIds2();
2080 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2082 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2084 selectionRemoveLabel(this.labelId
, ids
);
2089 menu
.addChild(new dijit
.PopupMenuItem({
2090 label
: __("Assign label"),
2091 popup
: labelAddMenu
,
2094 menu
.addChild(new dijit
.PopupMenuItem({
2095 label
: __("Remove label"),
2096 popup
: labelDelMenu
,
2103 exception_error("headlinesMenuCommon", e
);
2107 function initHeadlinesMenu() {
2109 if (dijit
.byId("headlinesMenu"))
2110 dijit
.byId("headlinesMenu").destroyRecursive();
2115 nodes
= $$("#headlines-frame > div[id*=RROW]");
2117 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2120 nodes
.each(function(node
) {
2124 var menu
= new dijit
.Menu({
2125 id
: "headlinesMenu",
2129 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2130 var callerNode
= event
.target
, match
= null, tries
= 0;
2132 while (match
== null && callerNode
&& tries
<= 3) {
2133 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2134 callerNode
= callerNode
.parentNode
;
2138 if (match
) this.callerRowId
= parseInt(match
[1]);
2142 headlinesMenuCommon(menu
, false);
2146 /* vgroup feed title menu */
2148 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2151 nodes
.each(function(node
) {
2155 if (ids
.length
> 0) {
2156 if (dijit
.byId("headlinesFeedTitleMenu"))
2157 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2159 var menu
= new dijit
.Menu({
2160 id
: "headlinesFeedTitleMenu",
2164 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2165 var callerNode
= event
.target
, match
= null, tries
= 0;
2167 while (match
== null && callerNode
&& tries
<= 3) {
2168 console
.log(callerNode
.id
);
2170 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2171 callerNode
= callerNode
.parentNode
;
2174 console
.log(match
[1]);
2177 if (match
) this.callerRowId
= parseInt(match
[1]);
2181 menu
.addChild(new dijit
.MenuItem({
2182 label
: __("Select articles in group"),
2183 onClick: function(event
) {
2184 selectArticles("all",
2185 "#headlines-frame > div[id*=RROW]"+
2186 "[orig-feed-id='"+menu
.callerRowId
+"']");
2190 menu
.addChild(new dijit
.MenuItem({
2191 label
: __("Mark group as read"),
2192 onClick: function(event
) {
2193 selectArticles("none");
2194 selectArticles("all",
2195 "#headlines-frame > div[id*=RROW]"+
2196 "[orig-feed-id='"+menu
.callerRowId
+"']");
2202 menu
.addChild(new dijit
.MenuItem({
2203 label
: __("Mark feed as read"),
2204 onClick: function(event
) {
2205 catchupFeedInGroup(menu
.callerRowId
);
2213 exception_error("initHeadlinesMenu", e
);
2217 function cache_set(id
, obj
) {
2218 //console.log("cache_set: " + id);
2221 sessionStorage
[id
] = obj
;
2223 sessionStorage
.clear();
2227 function cache_get(id
) {
2229 return sessionStorage
[id
];
2232 function cache_clear() {
2234 sessionStorage
.clear();
2237 function cache_delete(id
) {
2239 sessionStorage
.removeItem(id
);
2242 function cancelSearch() {
2247 exception_error("cancelSearch", e
);
2251 function setSelectionScore() {
2253 var ids
= getSelectedArticleIds2();
2255 if (ids
.length
> 0) {
2258 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2260 if (score
!= undefined) {
2261 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2262 "&score=" + param_escape(score
);
2264 new Ajax
.Request("backend.php", {
2266 onComplete: function(transport
) {
2267 var reply
= JSON
.parse(transport
.responseText
);
2271 ids
.each(function(id
) {
2272 var row
= $("RROW-" + id
);
2275 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2278 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2279 reply
["score_pic"]);
2280 pic
.setAttribute("score", score
);
2289 alert(__("No articles are selected."));
2292 exception_error("setSelectionScore", e
);
2296 function changeScore(id
, pic
) {
2298 var score
= pic
.getAttribute("score");
2300 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2302 if (new_score
!= undefined) {
2304 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2305 "&score=" + param_escape(new_score
);
2307 new Ajax
.Request("backend.php", {
2309 onComplete: function(transport
) {
2310 var reply
= JSON
.parse(transport
.responseText
);
2313 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2314 pic
.setAttribute("score", new_score
);
2319 exception_error("changeScore", e
);
2323 function displayArticleUrl(id
) {
2325 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2327 new Ajax
.Request("backend.php", {
2329 onComplete: function(transport
) {
2330 var reply
= JSON
.parse(transport
.responseText
);
2332 if (reply
&& reply
.link
) {
2333 prompt(__("Article URL:"), reply
.link
);
2337 exception_error("changeScore", e
);
2341 function openSelectedAttachment(elem
) {
2343 var url
= elem
[elem
.selectedIndex
].value
;
2347 elem
.selectedIndex
= 0;
2351 exception_error("openSelectedAttachment", e
);
2355 function scrollToRowId(id
) {
2360 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2363 exception_error("scrollToRowId", e
);
2367 function updateFloatingTitle(unread_only
) {
2369 if (!isCdmMode()) return;
2371 var hf
= $("headlines-frame");
2373 var elems
= $$("#headlines-frame > div[id*=RROW]");
2375 for (var i
= 0; i
< elems
.length
; i
++) {
2377 var child
= elems
[i
];
2379 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2381 var header
= child
.getElementsByClassName("cdmHeader")[0];
2383 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2384 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2385 $("floatingTitle").setAttribute("rowid", child
.id
);
2386 $("floatingTitle").innerHTML
= header
.innerHTML
;
2387 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2391 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2394 cb
.parentNode
.removeChild(cb
);
2397 if (child
.hasClassName("Unread"))
2398 $("floatingTitle").addClassName("Unread");
2400 $("floatingTitle").removeClassName("Unread");
2402 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2405 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2406 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2407 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2408 $("floatingTitle").style
.visibility
= "visible";
2410 $("floatingTitle").style
.visibility
= "hidden";
2418 exception_error("updateFloatingTitle", e
);