1 var article_cache
= new Array();
3 var _active_article_id
= 0;
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
13 var cids_requested
= [];
14 var loaded_article_ids
= [];
15 var _last_headlines_update
= 0;
16 var current_top_article_id
= false;
18 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
20 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
22 handle_rpc_json(transport
);
24 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
32 reply
= JSON
.parse(transport
.responseText
);
39 is_cat
= reply
['headlines']['is_cat'];
40 feed_id
= reply
['headlines']['id'];
43 var content
= reply
['headlines']['content'];
45 content
= content
+ "<div id='headlines-spacer'></div>";
49 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
52 /* dijit.getEnclosingWidget(
53 document.forms["main_toolbar_form"].update).attr('disabled',
54 is_cat || feed_id <= 0); */
57 if (infscroll_req
== false) {
58 $("headlines-frame").scrollTop
= 0;
60 $("floatingTitle").style
.visibility
= "hidden";
61 $("floatingTitle").setAttribute("rowid", 0);
62 $("floatingTitle").innerHTML
= "";
66 $("headlines-frame").removeClassName("cdm");
67 $("headlines-frame").removeClassName("normal");
69 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
71 var headlines_count
= reply
['headlines-info']['count'];
73 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
75 if (parseInt(headlines_count
) < 30) {
76 _infscroll_disable
= 1;
78 _infscroll_disable
= 0;
81 var counters
= reply
['counters'];
82 var articles
= reply
['articles'];
83 //var runtime_info = reply['runtime-info'];
85 if (infscroll_req
== false) {
86 loaded_article_ids
= [];
87 current_top_article_id
= false;
89 dijit
.byId("headlines-frame").attr('content',
90 reply
['headlines']['content']);
92 //dijit.byId("headlines-toolbar").attr('content',
93 // reply['headlines']['toolbar']);
95 dojo
.html
.set($("headlines-toolbar"),
96 reply
['headlines']['toolbar'],
97 {parseContent
: true});
99 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
100 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
101 row
.parentNode
.removeChild(row
);
103 loaded_article_ids
.push(row
.id
);
107 if (loaded_article_ids
.size() > 0) {
108 current_top_article_id
= parseInt(loaded_article_ids
[0].replace("RROW-", ""));
111 var hsp
= $("headlines-spacer");
112 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
113 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
117 if (_infscroll_disable
)
118 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
119 __("Click to open next unread feed.") + "</a>";
122 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
123 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
129 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
130 console
.log("adding some more headlines: " + headlines_count
);
132 var c
= dijit
.byId("headlines-frame");
133 var ids
= getSelectedArticleIds2();
136 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
138 var hsp
= $("headlines-spacer");
141 c
.domNode
.removeChild(hsp
);
143 $$("#headlines-tmp > div").each(function(row
) {
144 if (row
.className
== 'cdmFeedTitle') {
145 row
.style
.display
= 'none';
146 c
.domNode
.appendChild(row
);
148 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
149 row
.style
.display
= 'none';
150 c
.domNode
.appendChild(row
);
152 loaded_article_ids
.push(row
.id
);
154 row
.parentNode
.removeChild(row
);
158 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
160 // if (getInitParam("cdm_auto_catchup") == 1) {
161 c
.domNode
.appendChild(hsp
);
164 console
.log("added " + new_elems
.size() + " headlines");
166 if (new_elems
.size() == 0)
167 _infscroll_disable
= true;
169 console
.log("restore selected ids: " + ids
);
171 for (var i
= 0; i
< ids
.length
; i
++) {
172 markHeadline(ids
[i
]);
177 new_elems
.each(function(child
) {
178 dojo
.parser
.parse(child
);
180 if (!Element
.visible(child
))
181 new Effect
.Appear(child
, { duration
: 0.5 });
185 console
.log("no new headlines received");
187 var top_id_changed
= reply
['headlines']['top_id_changed'];
188 console
.log("top id changed:" + top_id_changed
);
190 var hsp
= $("headlines-spacer");
193 if (top_id_changed
) {
194 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
195 __("New articles found, reload feed to continue.") + "</a>";
197 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
198 __("Click to open next unread feed.") + "</a>";
207 for (var i
= 0; i
< articles
.length
; i
++) {
208 var a_id
= articles
[i
]['id'];
209 cache_set("article:" + a_id
, articles
[i
]['content']);
212 console
.log("no cached articles received");
216 parse_counters(counters
);
218 request_counters(true);
221 console
.error("Invalid object received: " + transport
.responseText
);
222 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
223 __('Could not update headlines (invalid object received - see error console for details)') +
227 _infscroll_request_sent
= 0;
228 _last_headlines_update
= new Date().getTime();
230 unpackVisibleHeadlines();
232 // if we have some more space in the buffer, why not try to fill it
234 if (!_infscroll_disable
&& $("headlines-spacer") &&
235 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
237 window
.setTimeout(function() {
245 exception_error("headlines_callback2", e
, transport
);
249 function render_article(article
) {
251 dijit
.byId("headlines-wrap-inner").addChild(
252 dijit
.byId("content-insert"));
254 var c
= dijit
.byId("content-insert");
257 c
.domNode
.scrollTop
= 0;
260 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
262 c
.attr('content', article
);
264 correctHeadlinesOffset(getActiveArticleId());
271 exception_error("render_article", e
);
275 function showArticleInHeadlines(id
, noexpand
) {
278 selectArticles("none");
280 var crow
= $("RROW-" + id
);
284 var article_is_unread
= crow
.hasClassName("Unread");
287 crow
.removeClassName("Unread");
288 crow
.addClassName("active");
290 selectArticles('none');
292 var view_mode
= false;
295 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
296 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
303 if (article_is_unread
&& !noexpand
)
304 _force_scheduled_update
= true;
307 exception_error("showArticleInHeadlines", e
);
311 function article_callback2(transport
, id
) {
313 console
.log("article_callback2 " + id
);
315 handle_rpc_json(transport
);
320 reply
= JSON
.parse(transport
.responseText
);
327 reply
.each(function(article
) {
328 if (getActiveArticleId() == article
['id']) {
329 render_article(article
['content']);
331 cids_requested
.remove(article
['id']);
333 cache_set("article:" + article
['id'], article
['content']);
336 // if (id != last_requested_article) {
337 // console.log("requested article id is out of sequence, aborting");
342 console
.error("Invalid object received: " + transport
.responseText
);
344 render_article("<div class='whiteBox'>" +
345 __('Could not display article (invalid object received - see error console for details)') + "</div>");
348 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
349 request_counters(unread_in_buffer
== 0);
351 //headlines_scroll_handler($("headlines-frame"));
354 if (!_infscroll_disable &&
355 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
365 exception_error("article_callback2", e
, transport
);
369 function view(id
, activefeed
, noexpand
) {
371 var oldrow
= $("RROW-" + getActiveArticleId());
372 if (oldrow
) oldrow
.removeClassName("active");
374 var crow
= $("RROW-" + id
);
378 setActiveArticleId(id
);
379 showArticleInHeadlines(id
, noexpand
);
383 console
.log("loading article: " + id
);
385 var cached_article
= cache_get("article:" + id
);
387 console
.log("cache check result: " + (cached_article
!= false));
389 var query
= "?op=article&method=view&id=" + param_escape(id
);
391 var neighbor_ids
= getRelativePostIds(id
);
393 /* only request uncached articles */
395 var cids_to_request
= [];
397 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
398 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
399 if (!cache_get("article:" + neighbor_ids
[i
])) {
400 cids_to_request
.push(neighbor_ids
[i
]);
401 cids_requested
.push(neighbor_ids
[i
]);
405 console
.log("additional ids: " + cids_to_request
.toString());
407 query
= query
+ "&cids=" + cids_to_request
.toString();
409 var article_is_unread
= crow
.hasClassName("Unread");
411 setActiveArticleId(id
);
412 showArticleInHeadlines(id
);
414 if (cached_article
&& article_is_unread
) {
416 query
= query
+ "&mode=prefetch";
418 render_article(cached_article
);
420 } else if (cached_article
) {
422 query
= query
+ "&mode=prefetch_old";
423 render_article(cached_article
);
425 // if we don't need to request any relative ids, we might as well skip
426 // the server roundtrip altogether
427 if (cids_to_request
.length
== 0) {
430 if (!_infscroll_disable &&
431 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
439 //headlines_scroll_handler($("headlines-frame"));
445 last_requested_article
= id
;
449 if (article_is_unread
) {
450 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
453 new Ajax
.Request("backend.php", {
455 onComplete: function(transport
) {
456 article_callback2(transport
, id
);
462 exception_error("view", e
);
466 function toggleMark(id
, client_only
) {
468 var query
= "?op=rpc&id=" + id
+ "&method=mark";
470 var row
= $("RROW-" + id
);
475 var row_imgs
= row
.getElementsByClassName("markedPic");
477 for (var i
= 0; i
< row_imgs
.length
; i
++)
478 imgs
.push(row_imgs
[i
]);
480 var ft
= $("floatingTitle");
482 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
483 var fte
= ft
.getElementsByClassName("markedPic");
485 for (var i
= 0; i
< fte
.length
; i
++)
489 for (i
= 0; i
< imgs
.length
; i
++) {
492 if (!row
.hasClassName("marked")) {
493 img
.src
= img
.src
.replace("mark_unset", "mark_set");
494 img
.alt
= __("Unstar article");
495 query
= query
+ "&mark=1";
497 img
.src
= img
.src
.replace("mark_set", "mark_unset");
498 img
.alt
= __("Star article");
499 query
= query
+ "&mark=0";
503 row
.toggleClassName("marked");
506 new Ajax
.Request("backend.php", {
508 onComplete: function(transport
) {
509 handle_rpc_json(transport
);
514 exception_error("toggleMark", e
);
518 function togglePub(id
, client_only
, no_effects
, note
) {
520 var query
= "?op=rpc&id=" + id
+ "&method=publ";
522 if (note
!= undefined) {
523 query
= query
+ "¬e=" + param_escape(note
);
525 query
= query
+ "¬e=undefined";
528 var row
= $("RROW-" + id
);
533 var row_imgs
= row
.getElementsByClassName("pubPic");
535 for (var i
= 0; i
< row_imgs
.length
; i
++)
536 imgs
.push(row_imgs
[i
]);
538 var ft
= $("floatingTitle");
540 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
541 var fte
= ft
.getElementsByClassName("pubPic");
543 for (var i
= 0; i
< fte
.length
; i
++)
547 for (i
= 0; i
< imgs
.length
; i
++) {
550 if (!row
.hasClassName("published") || note
!= undefined) {
551 img
.src
= img
.src
.replace("pub_unset", "pub_set");
552 img
.alt
= __("Unpublish article");
553 query
= query
+ "&pub=1";
555 img
.src
= img
.src
.replace("pub_set", "pub_unset");
556 img
.alt
= __("Publish article");
557 query
= query
+ "&pub=0";
561 if (note
!= undefined)
562 row
.addClassName("published");
564 row
.toggleClassName("published");
567 new Ajax
.Request("backend.php", {
569 onComplete: function(transport
) {
570 handle_rpc_json(transport
);
575 exception_error("togglePub", e
);
579 function moveToPost(mode
, noscroll
, noexpand
) {
583 var rows
= getVisibleArticleIds();
588 if (!$('RROW-' + getActiveArticleId())) {
589 setActiveArticleId(0);
592 if (!getActiveArticleId()) {
594 prev_id
= rows
[rows
.length
-1]
596 for (var i
= 0; i
< rows
.length
; i
++) {
597 if (rows
[i
] == getActiveArticleId()) {
599 // Account for adjacent identical article ids.
600 if (i
> 0) prev_id
= rows
[i
-1];
602 for (var j
= i
+1; j
< rows
.length
; j
++) {
603 if (rows
[j
] != getActiveArticleId()) {
613 if (mode
== "next") {
614 if (next_id
|| getActiveArticleId()) {
617 var article
= $("RROW-" + getActiveArticleId());
618 var ctr
= $("headlines-frame");
620 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
621 ctr
.scrollTop
+ ctr
.offsetHeight
) {
623 scrollArticle(ctr
.offsetHeight
/4);
625 } else if (next_id
) {
626 cdmExpandArticle(next_id
, noexpand
);
627 cdmScrollToArticleId(next_id
, true);
630 } else if (next_id
) {
631 correctHeadlinesOffset(next_id
);
632 view(next_id
, getActiveFeedId(), noexpand
);
637 if (mode
== "prev") {
638 if (prev_id
|| getActiveArticleId()) {
641 var article
= $("RROW-" + getActiveArticleId());
642 var prev_article
= $("RROW-" + prev_id
);
643 var ctr
= $("headlines-frame");
645 if (!getInitParam("cdm_expanded")) {
647 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
648 scrollArticle(-ctr
.offsetHeight
/4);
650 cdmExpandArticle(prev_id
, noexpand
);
651 cdmScrollToArticleId(prev_id
, true);
655 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
656 scrollArticle(-ctr
.offsetHeight
/3);
657 } else if (!noscroll
&& prev_article
&&
658 prev_article
.offsetTop
< ctr
.scrollTop
) {
659 cdmExpandArticle(prev_id
, noexpand
);
660 scrollArticle(-ctr
.offsetHeight
/4);
661 } else if (prev_id
) {
662 cdmExpandArticle(prev_id
, noexpand
);
663 cdmScrollToArticleId(prev_id
, noscroll
);
667 } else if (prev_id
) {
668 correctHeadlinesOffset(prev_id
);
669 view(prev_id
, getActiveFeedId(), noexpand
);
675 exception_error("moveToPost", e
);
679 function toggleSelected(id
, force_on
) {
681 var row
= $("RROW-" + id
);
684 var cb
= dijit
.getEnclosingWidget(
685 row
.getElementsByClassName("rchk")[0]);
687 if (row
.hasClassName('Selected') && !force_on
) {
688 row
.removeClassName('Selected');
689 if (cb
) cb
.attr("checked", false);
691 row
.addClassName('Selected');
692 if (cb
) cb
.attr("checked", true);
696 updateSelectedPrompt();
698 exception_error("toggleSelected", e
);
702 function updateSelectedPrompt() {
704 var count
= getSelectedArticleIds2().size();
705 var elem
= $("selected_prompt");
708 elem
.innerHTML
= ngettext("%d article selected",
709 "%d articles selected", count
).replace("%d", count
);
718 exception_error("updateSelectedPrompt", e
);
722 function toggleUnread_afh(effect
) {
725 var elem
= effect
.element
;
726 elem
.style
.backgroundColor
= "";
729 exception_error("toggleUnread_afh", e
);
733 function toggleUnread(id
, cmode
, effect
) {
736 var row
= $("RROW-" + id
);
738 if (cmode
== undefined || cmode
== 2) {
739 if (row
.hasClassName("Unread")) {
740 row
.removeClassName("Unread");
743 row
.addClassName("Unread");
746 } else if (cmode
== 0) {
748 row
.removeClassName("Unread");
750 } else if (cmode
== 1) {
751 row
.addClassName("Unread");
754 if (cmode
== undefined) cmode
= 2;
756 var query
= "?op=rpc&method=catchupSelected" +
757 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
759 // notify_progress("Loading, please wait...");
761 new Ajax
.Request("backend.php", {
763 onComplete: function(transport
) {
764 handle_rpc_json(transport
);
770 exception_error("toggleUnread", e
);
774 function selectionRemoveLabel(id
, ids
) {
777 if (!ids
) ids
= getSelectedArticleIds2();
779 if (ids
.length
== 0) {
780 alert(__("No articles are selected."));
784 var query
= "?op=article&method=removeFromLabel&ids=" +
785 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
789 new Ajax
.Request("backend.php", {
791 onComplete: function(transport
) {
792 handle_rpc_json(transport
);
793 show_labels_in_headlines(transport
);
797 exception_error("selectionAssignLabel", e
);
802 function selectionAssignLabel(id
, ids
) {
805 if (!ids
) ids
= getSelectedArticleIds2();
807 if (ids
.length
== 0) {
808 alert(__("No articles are selected."));
812 var query
= "?op=article&method=assignToLabel&ids=" +
813 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
817 new Ajax
.Request("backend.php", {
819 onComplete: function(transport
) {
820 handle_rpc_json(transport
);
821 show_labels_in_headlines(transport
);
825 exception_error("selectionAssignLabel", e
);
830 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
832 var rows
= ids
? ids
: getSelectedArticleIds2();
834 if (rows
.length
== 0 && !no_error
) {
835 alert(__("No articles are selected."));
839 for (var i
= 0; i
< rows
.length
; i
++) {
840 var row
= $("RROW-" + rows
[i
]);
842 if (set_state
== undefined) {
843 if (row
.hasClassName("Unread")) {
844 row
.removeClassName("Unread");
846 row
.addClassName("Unread");
850 if (set_state
== false) {
851 row
.removeClassName("Unread");
854 if (set_state
== true) {
855 row
.addClassName("Unread");
860 updateFloatingTitle(true);
862 if (rows
.length
> 0) {
866 if (set_state
== undefined) {
868 } else if (set_state
== true) {
870 } else if (set_state
== false) {
874 var query
= "?op=rpc&method=catchupSelected" +
875 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
877 notify_progress("Loading, please wait...");
879 new Ajax
.Request("backend.php", {
881 onComplete: function(transport
) {
882 handle_rpc_json(transport
);
883 if (callback
) callback(transport
);
889 exception_error("selectionToggleUnread", e
);
894 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
897 var rows
= ids
? ids
: getSelectedArticleIds2();
899 if (rows
.length
== 0 && !no_error
) {
900 alert(__("No articles are selected."));
904 for (var i
= 0; i
< rows
.length
; i
++) {
905 toggleMark(rows
[i
], true, true);
908 if (rows
.length
> 0) {
910 var query
= "?op=rpc&method=markSelected&ids=" +
911 param_escape(rows
.toString()) + "&cmode=2";
913 new Ajax
.Request("backend.php", {
915 onComplete: function(transport
) {
916 handle_rpc_json(transport
);
917 if (callback
) callback(transport
);
923 exception_error("selectionToggleMarked", e
);
928 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
931 var rows
= ids
? ids
: getSelectedArticleIds2();
933 if (rows
.length
== 0 && !no_error
) {
934 alert(__("No articles are selected."));
938 for (var i
= 0; i
< rows
.length
; i
++) {
939 togglePub(rows
[i
], true, true);
942 if (rows
.length
> 0) {
944 var query
= "?op=rpc&method=publishSelected&ids=" +
945 param_escape(rows
.toString()) + "&cmode=2";
947 new Ajax
.Request("backend.php", {
949 onComplete: function(transport
) {
950 handle_rpc_json(transport
);
956 exception_error("selectionToggleMarked", e
);
960 function getSelectedArticleIds2() {
964 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
966 rv
.push(child
.id
.replace("RROW-", ""));
972 function getLoadedArticleIds() {
975 var children
= $$("#headlines-frame > div[id*=RROW-]");
977 children
.each(function(child
) {
978 rv
.push(child
.id
.replace("RROW-", ""));
985 // mode = all,none,unread,invert,marked,published
986 function selectArticles(mode
, query
) {
989 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
991 var children
= $$(query
);
993 children
.each(function(child
) {
994 var id
= child
.id
.replace("RROW-", "");
996 var cb
= dijit
.getEnclosingWidget(
997 child
.getElementsByClassName("rchk")[0]);
1000 child
.addClassName("Selected");
1001 if (cb
) cb
.attr("checked", true);
1002 } else if (mode
== "unread") {
1003 if (child
.hasClassName("Unread")) {
1004 child
.addClassName("Selected");
1005 if (cb
) cb
.attr("checked", true);
1007 child
.removeClassName("Selected");
1008 if (cb
) cb
.attr("checked", false);
1010 } else if (mode
== "marked") {
1011 if (child
.hasClassName("marked")) {
1012 child
.addClassName("Selected");
1013 if (cb
) cb
.attr("checked", true);
1015 child
.removeClassName("Selected");
1016 if (cb
) cb
.attr("checked", false);
1018 } else if (mode
== "published") {
1019 if (child
.hasClassName("published")) {
1020 child
.addClassName("Selected");
1021 if (cb
) cb
.attr("checked", true);
1023 child
.removeClassName("Selected");
1024 if (cb
) cb
.attr("checked", false);
1027 } else if (mode
== "invert") {
1028 if (child
.hasClassName("Selected")) {
1029 child
.removeClassName("Selected");
1030 if (cb
) cb
.attr("checked", false);
1032 child
.addClassName("Selected");
1033 if (cb
) cb
.attr("checked", true);
1037 child
.removeClassName("Selected");
1038 if (cb
) cb
.attr("checked", false);
1042 updateSelectedPrompt();
1045 exception_error("selectArticles", e
);
1049 function deleteSelection() {
1053 var rows
= getSelectedArticleIds2();
1055 if (rows
.length
== 0) {
1056 alert(__("No articles are selected."));
1060 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1063 if (getActiveFeedId() != 0) {
1064 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1066 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1069 str
= str
.replace("%d", rows
.length
);
1070 str
= str
.replace("%s", fn
);
1072 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1076 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1080 new Ajax
.Request("backend.php", {
1082 onComplete: function(transport
) {
1083 handle_rpc_json(transport
);
1088 exception_error("deleteSelection", e
);
1092 function archiveSelection() {
1096 var rows
= getSelectedArticleIds2();
1098 if (rows
.length
== 0) {
1099 alert(__("No articles are selected."));
1103 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1107 if (getActiveFeedId() != 0) {
1108 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1111 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1113 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1118 str
= str
.replace("%d", rows
.length
);
1119 str
= str
.replace("%s", fn
);
1121 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1125 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1129 for (var i
= 0; i
< rows
.length
; i
++) {
1130 cache_delete("article:" + rows
[i
]);
1133 new Ajax
.Request("backend.php", {
1135 onComplete: function(transport
) {
1136 handle_rpc_json(transport
);
1141 exception_error("archiveSelection", e
);
1145 function catchupSelection() {
1149 var rows
= getSelectedArticleIds2();
1151 if (rows
.length
== 0) {
1152 alert(__("No articles are selected."));
1156 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1158 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1160 str
= str
.replace("%d", rows
.length
);
1161 str
= str
.replace("%s", fn
);
1163 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1167 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1170 exception_error("catchupSelection", e
);
1174 function editArticleTags(id
) {
1175 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1177 if (dijit
.byId("editTagsDlg"))
1178 dijit
.byId("editTagsDlg").destroyRecursive();
1180 dialog
= new dijit
.Dialog({
1182 title
: __("Edit article Tags"),
1183 style
: "width: 600px",
1184 execute: function() {
1185 if (this.validate()) {
1186 var query
= dojo
.objectToQuery(this.attr('value'));
1188 notify_progress("Saving article tags...", true);
1190 new Ajax
.Request("backend.php", {
1192 onComplete: function(transport
) {
1197 var data
= JSON
.parse(transport
.responseText
);
1204 var tags
= $("ATSTR-" + id
);
1205 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1207 if (tags
) tags
.innerHTML
= data
.content
;
1208 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1211 exception_error("editArticleTags/inner", e
);
1220 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1221 dojo
.disconnect(tmph
);
1223 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1224 "backend.php?op=article&method=completeTags",
1225 { tokens
: ',', paramName
: "search" });
1232 function cdmScrollToArticleId(id
, force
) {
1234 var ctr
= $("headlines-frame");
1235 var e
= $("RROW-" + id
);
1237 if (!e
|| !ctr
) return;
1239 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1240 e
.offsetTop
< ctr
.scrollTop
) {
1242 // expanded cdm has a 4px margin now
1243 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1247 exception_error("cdmScrollToArticleId", e
);
1251 function setActiveArticleId(id
) {
1252 _active_article_id
= id
;
1253 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1256 function getActiveArticleId() {
1257 return _active_article_id
;
1260 function postMouseIn(e
, id
) {
1261 post_under_pointer
= id
;
1264 function postMouseOut(id
) {
1265 post_under_pointer
= false;
1268 function unpackVisibleHeadlines() {
1270 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1272 $$("#headlines-frame > div[id*=RROW]").each(
1274 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1275 $("headlines-frame").offsetHeight
) {
1277 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1280 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1282 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1283 cencw
.setAttribute('id', '');
1284 Element
.show(cencw
);
1291 exception_error("unpackVisibleHeadlines", e
);
1295 function headlines_scroll_handler(e
) {
1297 var hsp
= $("headlines-spacer");
1299 unpackVisibleHeadlines();
1301 // set topmost child in the buffer as active
1302 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1303 getSelectedArticleIds2().length
<= 1 &&
1304 getInitParam("cdm_expanded")) {
1305 var rows
= $$("#headlines-frame > div[id*=RROW]");
1307 for (var i
= 0; i
< rows
.length
; i
++) {
1308 var child
= rows
[i
];
1310 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1311 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1312 child
.id
.replace("RROW-", "") != _active_article_id
) {
1314 if (_active_article_id
) {
1315 var row
= $("RROW-" + _active_article_id
);
1316 if (row
) row
.removeClassName("active");
1319 _active_article_id
= child
.id
.replace("RROW-", "");
1320 showArticleInHeadlines(_active_article_id
, true);
1321 updateSelectedPrompt();
1327 if (!_infscroll_disable
) {
1328 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1329 (e
.scrollHeight
!= 0 &&
1330 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1333 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1334 __("Loading, please wait...") + "</span>";
1336 loadMoreHeadlines();
1342 if (_infscroll_disable)
1343 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1344 __("Click to open next unread feed.") + "</a>";
1351 updateFloatingTitle();
1354 if (getInitParam("cdm_auto_catchup") == 1) {
1356 // let's get DOM some time to settle down
1357 var ts
= new Date().getTime();
1358 if (ts
- _last_headlines_update
< 100) return;
1360 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1362 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1363 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1365 var id
= child
.id
.replace("RROW-", "");
1367 if (catchup_id_batch
.indexOf(id
) == -1)
1368 catchup_id_batch
.push(id
);
1370 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1375 if (catchup_id_batch
.length
> 0) {
1376 window
.clearTimeout(catchup_timeout_id
);
1378 if (!_infscroll_request_sent
) {
1379 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1384 if (_infscroll_disable
) {
1385 var child
= $$("#headlines-frame div[id*=RROW]").last();
1387 if (child
&& $("headlines-frame").scrollTop
>
1388 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1390 console
.log("we seem to be at an end");
1392 if (getInitParam("on_catchup_show_next_feed") == "1") {
1393 openNextUnreadFeed();
1400 console
.warn("headlines_scroll_handler: " + e
);
1404 function openNextUnreadFeed() {
1406 var is_cat
= activeFeedIsCat();
1407 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1408 if (nuf
) viewfeed(nuf
, '', is_cat
);
1410 exception_error("openNextUnreadFeed", e
);
1414 function catchupBatchedArticles() {
1416 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1418 // make a copy of the array
1419 var batch
= catchup_id_batch
.slice();
1420 var query
= "?op=rpc&method=catchupSelected" +
1421 "&cmode=0&ids=" + param_escape(batch
.toString());
1425 new Ajax
.Request("backend.php", {
1427 onComplete: function(transport
) {
1428 handle_rpc_json(transport
);
1430 reply
= JSON
.parse(transport
.responseText
);
1431 var batch
= reply
.ids
;
1433 batch
.each(function(id
) {
1435 var elem
= $("RROW-" + id
);
1436 if (elem
) elem
.removeClassName("Unread");
1437 catchup_id_batch
.remove(id
);
1440 updateFloatingTitle(true);
1446 exception_error("catchupBatchedArticles", e
);
1450 function catchupRelativeToArticle(below
, id
) {
1454 if (!id
) id
= getActiveArticleId();
1457 alert(__("No article is selected."));
1461 var visible_ids
= getVisibleArticleIds();
1463 var ids_to_mark
= new Array();
1466 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1467 if (visible_ids
[i
] != id
) {
1468 var e
= $("RROW-" + visible_ids
[i
]);
1470 if (e
&& e
.hasClassName("Unread")) {
1471 ids_to_mark
.push(visible_ids
[i
]);
1478 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1479 if (visible_ids
[i
] != id
) {
1480 var e
= $("RROW-" + visible_ids
[i
]);
1482 if (e
&& e
.hasClassName("Unread")) {
1483 ids_to_mark
.push(visible_ids
[i
]);
1491 if (ids_to_mark
.length
== 0) {
1492 alert(__("No articles found to mark"));
1494 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1496 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1498 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1499 var e
= $("RROW-" + ids_to_mark
[i
]);
1500 e
.removeClassName("Unread");
1503 var query
= "?op=rpc&method=catchupSelected" +
1504 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1506 new Ajax
.Request("backend.php", {
1508 onComplete: function(transport
) {
1509 handle_rpc_json(transport
);
1516 exception_error("catchupRelativeToArticle", e
);
1520 function cdmCollapseArticle(event
, id
, unmark
) {
1522 if (unmark
== undefined) unmark
= true;
1524 var row
= $("RROW-" + id
);
1525 var elem
= $("CICD-" + id
);
1528 var collapse
= $$("div#RROW-" + id
+
1529 " span[class='collapseBtn']")[0];
1532 Element
.show("CEXC-" + id
);
1533 Element
.hide(collapse
);
1536 row
.removeClassName("active");
1538 markHeadline(id
, false);
1540 if (id
== getActiveArticleId()) {
1541 setActiveArticleId(0);
1544 updateSelectedPrompt();
1547 if (event
) Event
.stop(event
);
1549 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1551 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1552 scrollToRowId(row
.id
);
1554 $("floatingTitle").style
.visibility
= "hidden";
1555 $("floatingTitle").setAttribute("rowid", false);
1559 exception_error("cdmCollapseArticle", e
);
1563 function cdmExpandArticle(id
, noexpand
) {
1565 console
.log("cdmExpandArticle " + id
);
1567 if (!$("RROW-" + id
)) return false;
1569 var oldrow
= $("RROW-" + getActiveArticleId());
1571 var elem
= $("CICD-" + getActiveArticleId());
1573 if (id
== getActiveArticleId() && Element
.visible(elem
))
1576 selectArticles("none");
1578 var old_offset
= $("RROW-" + id
).offsetTop
;
1580 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1581 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1582 " span[class='collapseBtn']")[0];
1585 Element
.show("CEXC-" + getActiveArticleId());
1586 Element
.hide(collapse
);
1589 if (oldrow
) oldrow
.removeClassName("active");
1591 setActiveArticleId(id
);
1593 elem
= $("CICD-" + id
);
1595 var collapse
= $$("div#RROW-" + id
+
1596 " span[class='collapseBtn']")[0];
1598 var cencw
= $("CENCW-" + id
);
1600 if (!Element
.visible(elem
) && !noexpand
) {
1602 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1603 cencw
.setAttribute('id', '');
1604 Element
.show(cencw
);
1608 Element
.hide("CEXC-" + id
);
1609 Element
.show(collapse
);
1612 var new_offset
= $("RROW-" + id
).offsetTop
;
1614 if (old_offset
> new_offset
)
1615 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1618 toggleUnread(id
, 0, true);
1620 $("RROW-" + id
).addClassName("active");
1622 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1625 exception_error("cdmExpandArticle", e
);
1631 function getArticleUnderPointer() {
1632 return post_under_pointer
;
1635 function scrollArticle(offset
) {
1638 var ci
= $("content-insert");
1640 ci
.scrollTop
+= offset
;
1643 var hi
= $("headlines-frame");
1645 hi
.scrollTop
+= offset
;
1650 exception_error("scrollArticle", e
);
1654 function show_labels_in_headlines(transport
) {
1656 var data
= JSON
.parse(transport
.responseText
);
1659 data
['info-for-headlines'].each(function(elem
) {
1660 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1661 ctr
.innerHTML
= elem
.labels
;
1666 exception_error("show_labels_in_headlines", e
);
1670 function dismissArticle(id
) {
1672 var elem
= $("RROW-" + id
);
1676 toggleUnread(id
, 0, true);
1678 new Effect
.Fade(elem
, {duration
: 0.5});
1680 // Remove the content, too
1681 var elem_content
= $("CICD-" + id
);
1683 Element
.remove(elem_content
);
1686 if (id
== getActiveArticleId()) {
1687 setActiveArticleId(0);
1691 exception_error("dismissArticle", e
);
1695 function dismissSelectedArticles() {
1698 var ids
= getVisibleArticleIds();
1702 for (var i
= 0; i
< ids
.length
; i
++) {
1703 var elem
= $("RROW-" + ids
[i
]);
1705 if (elem
.className
&& elem
.hasClassName("Selected") &&
1706 ids
[i
] != getActiveArticleId()) {
1707 new Effect
.Fade(elem
, {duration
: 0.5});
1710 // Remove the content, too
1711 var elem_content
= $("CICD-" + ids
[i
]);
1713 Element
.remove(elem_content
);
1721 selectionToggleUnread(false);
1725 exception_error("dismissSelectedArticles", e
);
1729 function dismissReadArticles() {
1732 var ids
= getVisibleArticleIds();
1735 for (var i
= 0; i
< ids
.length
; i
++) {
1736 var elem
= $("RROW-" + ids
[i
]);
1738 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1739 !elem
.hasClassName("Selected")) {
1741 new Effect
.Fade(elem
, {duration
: 0.5});
1743 // Remove the content, too
1744 var elem_content
= $("CICD-" + ids
[i
]);
1746 Element
.remove(elem_content
);
1754 exception_error("dismissReadArticles", e
);
1758 function getVisibleArticleIds() {
1763 getLoadedArticleIds().each(function(id
) {
1764 var elem
= $("RROW-" + id
);
1765 if (elem
&& Element
.visible(elem
))
1770 exception_error("getVisibleArticleIds", e
);
1776 function cdmClicked(event
, id
) {
1778 //var shift_key = event.shiftKey;
1780 if (!event
.ctrlKey
) {
1782 if (!getInitParam("cdm_expanded")) {
1783 return cdmExpandArticle(id
);
1786 var elem
= $("RROW-" + getActiveArticleId());
1788 if (elem
) elem
.removeClassName("active");
1790 selectArticles("none");
1793 var elem
= $("RROW-" + id
);
1794 var article_is_unread
= elem
.hasClassName("Unread");
1796 elem
.removeClassName("Unread");
1797 elem
.addClassName("active");
1799 setActiveArticleId(id
);
1801 if (article_is_unread
) {
1802 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1803 updateFloatingTitle(true);
1806 var query
= "?op=rpc&method=catchupSelected" +
1807 "&cmode=0&ids=" + param_escape(id
);
1809 new Ajax
.Request("backend.php", {
1811 onComplete: function(transport
) {
1812 handle_rpc_json(transport
);
1815 return !event
.shiftKey
;
1818 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1820 toggleSelected(id
, true);
1822 var elem
= $("RROW-" + id
);
1823 var article_is_unread
= elem
.hasClassName("Unread");
1825 if (article_is_unread
) {
1826 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1829 toggleUnread(id
, 0, false);
1831 openArticleInNewWindow(id
);
1834 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1835 request_counters(unread_in_buffer
== 0);
1838 exception_error("cdmClicked");
1844 function hlClicked(event
, id
) {
1846 if (event
.which
== 2) {
1849 } else if (event
.ctrlKey
) {
1850 toggleSelected(id
, true);
1851 toggleUnread(id
, 0, false);
1852 openArticleInNewWindow(id
);
1860 exception_error("hlClicked");
1864 function getFirstVisibleHeadlineId() {
1865 var rows
= getVisibleArticleIds();
1870 function getLastVisibleHeadlineId() {
1871 var rows
= getVisibleArticleIds();
1872 return rows
[rows
.length
-1];
1875 function openArticleInNewWindow(id
) {
1876 toggleUnread(id
, 0, false);
1877 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1880 function isCdmMode() {
1881 return getInitParam("combined_display_mode");
1884 function markHeadline(id
, marked
) {
1885 if (marked
== undefined) marked
= true;
1887 var row
= $("RROW-" + id
);
1889 var check
= dijit
.getEnclosingWidget(
1890 row
.getElementsByClassName("rchk")[0]);
1893 check
.attr("checked", marked
);
1897 row
.addClassName("Selected");
1899 row
.removeClassName("Selected");
1903 function getRelativePostIds(id
, limit
) {
1909 if (!limit
) limit
= 6; //3
1911 var ids
= getVisibleArticleIds();
1913 for (var i
= 0; i
< ids
.length
; i
++) {
1915 for (var k
= 1; k
<= limit
; k
++) {
1916 //if (i > k-1) tmp.push(ids[i-k]);
1917 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1924 exception_error("getRelativePostIds", e
);
1930 function correctHeadlinesOffset(id
) {
1934 var container
= $("headlines-frame");
1935 var row
= $("RROW-" + id
);
1937 if (!container
|| !row
) return;
1939 var viewport
= container
.offsetHeight
;
1941 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1942 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1944 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1945 //console.log("Vport: " + viewport);
1947 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1948 container
.scrollTop
= row
.offsetTop
;
1949 } else if (rel_offset_bottom
> viewport
) {
1951 /* doesn't properly work with Opera in some cases because
1952 Opera fucks up element scrolling */
1954 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1958 exception_error("correctHeadlinesOffset", e
);
1963 function headlineActionsChange(elem
) {
1966 elem
.attr('value', 'false');
1968 exception_error("headlineActionsChange", e
);
1972 function closeArticlePanel() {
1974 if (dijit
.byId("content-insert"))
1975 dijit
.byId("headlines-wrap-inner").removeChild(
1976 dijit
.byId("content-insert"));
1979 function initFloatingMenu() {
1981 if (dijit
.byId("floatingMenu"))
1982 dijit
.byId("floatingMenu").destroyRecursive();
1984 var menu
= new dijit
.Menu({
1986 targetNodeIds
: ["floatingTitle"]
1989 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1991 headlinesMenuCommon(menu
, id
);
1995 exception_error("initFloatingMenu", e
);
1999 function headlinesMenuCommon(menu
, base_id
) {
2002 menu
.addChild(new dijit
.MenuItem({
2003 label
: __("Open original article"),
2004 onClick: function(event
) {
2005 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
2008 menu
.addChild(new dijit
.MenuItem({
2009 label
: __("Display article URL"),
2010 onClick: function(event
) {
2011 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
2014 menu
.addChild(new dijit
.MenuSeparator());
2016 menu
.addChild(new dijit
.MenuItem({
2017 label
: __("Toggle unread"),
2018 onClick: function(event
) {
2019 var ids
= getSelectedArticleIds2();
2021 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2022 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2024 selectionToggleUnread(undefined, false, true, ids
);
2027 menu
.addChild(new dijit
.MenuItem({
2028 label
: __("Toggle starred"),
2029 onClick: function(event
) {
2030 var ids
= getSelectedArticleIds2();
2032 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2033 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2035 selectionToggleMarked(undefined, false, true, ids
);
2038 menu
.addChild(new dijit
.MenuItem({
2039 label
: __("Toggle published"),
2040 onClick: function(event
) {
2041 var ids
= getSelectedArticleIds2();
2043 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2044 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2046 selectionTogglePublished(undefined, false, true, ids
);
2049 menu
.addChild(new dijit
.MenuSeparator());
2051 menu
.addChild(new dijit
.MenuItem({
2052 label
: __("Mark above as read"),
2053 onClick: function(event
) {
2054 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2057 menu
.addChild(new dijit
.MenuItem({
2058 label
: __("Mark below as read"),
2059 onClick: function(event
) {
2060 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2064 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2068 menu
.addChild(new dijit
.MenuSeparator());
2070 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2071 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2073 labels
.each(function(label
) {
2074 var id
= label
.id
[0];
2075 var bare_id
= id
.substr(id
.indexOf(":")+1);
2076 var name
= label
.name
[0];
2078 bare_id
= feed_to_label_id(bare_id
);
2080 labelAddMenu
.addChild(new dijit
.MenuItem({
2083 onClick: function(event
) {
2084 var ids
= getSelectedArticleIds2();
2086 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2088 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2090 selectionAssignLabel(this.labelId
, ids
);
2093 labelDelMenu
.addChild(new dijit
.MenuItem({
2096 onClick: function(event
) {
2097 var ids
= getSelectedArticleIds2();
2099 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2101 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2103 selectionRemoveLabel(this.labelId
, ids
);
2108 menu
.addChild(new dijit
.PopupMenuItem({
2109 label
: __("Assign label"),
2110 popup
: labelAddMenu
,
2113 menu
.addChild(new dijit
.PopupMenuItem({
2114 label
: __("Remove label"),
2115 popup
: labelDelMenu
,
2122 exception_error("headlinesMenuCommon", e
);
2126 function initHeadlinesMenu() {
2128 if (dijit
.byId("headlinesMenu"))
2129 dijit
.byId("headlinesMenu").destroyRecursive();
2134 nodes
= $$("#headlines-frame > div[id*=RROW]");
2136 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2139 nodes
.each(function(node
) {
2143 var menu
= new dijit
.Menu({
2144 id
: "headlinesMenu",
2148 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2149 var callerNode
= event
.target
, match
= null, tries
= 0;
2151 while (match
== null && callerNode
&& tries
<= 3) {
2152 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2153 callerNode
= callerNode
.parentNode
;
2157 if (match
) this.callerRowId
= parseInt(match
[1]);
2161 headlinesMenuCommon(menu
, false);
2165 /* vgroup feed title menu */
2167 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2170 nodes
.each(function(node
) {
2174 if (ids
.length
> 0) {
2175 if (dijit
.byId("headlinesFeedTitleMenu"))
2176 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2178 var menu
= new dijit
.Menu({
2179 id
: "headlinesFeedTitleMenu",
2183 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2184 var callerNode
= event
.target
, match
= null, tries
= 0;
2186 while (match
== null && callerNode
&& tries
<= 3) {
2187 console
.log(callerNode
.id
);
2189 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2190 callerNode
= callerNode
.parentNode
;
2193 console
.log(match
[1]);
2196 if (match
) this.callerRowId
= parseInt(match
[1]);
2200 menu
.addChild(new dijit
.MenuItem({
2201 label
: __("Select articles in group"),
2202 onClick: function(event
) {
2203 selectArticles("all",
2204 "#headlines-frame > div[id*=RROW]"+
2205 "[orig-feed-id='"+menu
.callerRowId
+"']");
2209 menu
.addChild(new dijit
.MenuItem({
2210 label
: __("Mark group as read"),
2211 onClick: function(event
) {
2212 selectArticles("none");
2213 selectArticles("all",
2214 "#headlines-frame > div[id*=RROW]"+
2215 "[orig-feed-id='"+menu
.callerRowId
+"']");
2221 menu
.addChild(new dijit
.MenuItem({
2222 label
: __("Mark feed as read"),
2223 onClick: function(event
) {
2224 catchupFeedInGroup(menu
.callerRowId
);
2232 exception_error("initHeadlinesMenu", e
);
2236 function cache_set(id
, obj
) {
2237 //console.log("cache_set: " + id);
2240 sessionStorage
[id
] = obj
;
2242 sessionStorage
.clear();
2246 function cache_get(id
) {
2248 return sessionStorage
[id
];
2251 function cache_clear() {
2253 sessionStorage
.clear();
2256 function cache_delete(id
) {
2258 sessionStorage
.removeItem(id
);
2261 function cancelSearch() {
2266 exception_error("cancelSearch", e
);
2270 function setSelectionScore() {
2272 var ids
= getSelectedArticleIds2();
2274 if (ids
.length
> 0) {
2277 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2279 if (score
!= undefined) {
2280 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2281 "&score=" + param_escape(score
);
2283 new Ajax
.Request("backend.php", {
2285 onComplete: function(transport
) {
2286 var reply
= JSON
.parse(transport
.responseText
);
2290 ids
.each(function(id
) {
2291 var row
= $("RROW-" + id
);
2294 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2297 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2298 reply
["score_pic"]);
2299 pic
.setAttribute("score", score
);
2308 alert(__("No articles are selected."));
2311 exception_error("setSelectionScore", e
);
2315 function updateScore(id
) {
2317 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2321 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2323 new Ajax
.Request("backend.php", {
2325 onComplete: function(transport
) {
2326 console
.log(transport
.responseText
);
2328 var reply
= JSON
.parse(transport
.responseText
);
2331 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2332 pic
.setAttribute("score", reply
["score"]);
2333 pic
.setAttribute("title", reply
["score"]);
2339 exception_error("updateScore", e
);
2343 function changeScore(id
, pic
) {
2345 var score
= pic
.getAttribute("score");
2347 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2349 if (new_score
!= undefined) {
2351 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2352 "&score=" + param_escape(new_score
);
2354 new Ajax
.Request("backend.php", {
2356 onComplete: function(transport
) {
2357 var reply
= JSON
.parse(transport
.responseText
);
2360 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2361 pic
.setAttribute("score", new_score
);
2362 pic
.setAttribute("title", new_score
);
2367 exception_error("changeScore", e
);
2371 function displayArticleUrl(id
) {
2373 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2375 new Ajax
.Request("backend.php", {
2377 onComplete: function(transport
) {
2378 var reply
= JSON
.parse(transport
.responseText
);
2380 if (reply
&& reply
.link
) {
2381 prompt(__("Article URL:"), reply
.link
);
2385 exception_error("changeScore", e
);
2389 function openSelectedAttachment(elem
) {
2391 var url
= elem
[elem
.selectedIndex
].value
;
2395 elem
.selectedIndex
= 0;
2399 exception_error("openSelectedAttachment", e
);
2403 function scrollToRowId(id
) {
2408 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2411 exception_error("scrollToRowId", e
);
2415 function updateFloatingTitle(unread_only
) {
2417 if (!isCdmMode()) return;
2419 var hf
= $("headlines-frame");
2421 var elems
= $$("#headlines-frame > div[id*=RROW]");
2423 for (var i
= 0; i
< elems
.length
; i
++) {
2425 var child
= elems
[i
];
2427 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2429 var header
= child
.getElementsByClassName("cdmHeader")[0];
2431 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2432 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2433 $("floatingTitle").setAttribute("rowid", child
.id
);
2434 $("floatingTitle").innerHTML
= header
.innerHTML
;
2435 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2439 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2442 cb
.parentNode
.removeChild(cb
);
2445 if (child
.hasClassName("Unread"))
2446 $("floatingTitle").addClassName("Unread");
2448 $("floatingTitle").removeClassName("Unread");
2450 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2453 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2454 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2455 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2456 $("floatingTitle").style
.visibility
= "visible";
2458 $("floatingTitle").style
.visibility
= "hidden";
2466 exception_error("updateFloatingTitle", e
);
2470 function cdmFooterClick(event
) {
2471 event
.stopPropagation();