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 top_id_changed
= reply
['headlines']['top_id_changed'];
182 console
.log("top id changed:" + top_id_changed
);
184 var hsp
= $("headlines-spacer");
187 if (top_id_changed
) {
188 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
189 __("New articles found, reload feed to continue.") + "</a>";
191 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
192 __("Click to open next unread feed.") + "</a>";
201 for (var i
= 0; i
< articles
.length
; i
++) {
202 var a_id
= articles
[i
]['id'];
203 cache_set("article:" + a_id
, articles
[i
]['content']);
206 console
.log("no cached articles received");
210 parse_counters(counters
);
212 request_counters(true);
215 console
.error("Invalid object received: " + transport
.responseText
);
216 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
217 __('Could not update headlines (invalid object received - see error console for details)') +
221 _infscroll_request_sent
= 0;
222 _last_headlines_update
= new Date().getTime();
224 unpackVisibleHeadlines();
226 // if we have some more space in the buffer, why not try to fill it
228 if (!_infscroll_disable
&& $("headlines-spacer") &&
229 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
231 window
.setTimeout(function() {
239 exception_error("headlines_callback2", e
, transport
);
243 function render_article(article
) {
245 dijit
.byId("headlines-wrap-inner").addChild(
246 dijit
.byId("content-insert"));
248 var c
= dijit
.byId("content-insert");
251 c
.domNode
.scrollTop
= 0;
254 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
256 c
.attr('content', article
);
258 correctHeadlinesOffset(getActiveArticleId());
265 exception_error("render_article", e
);
269 function showArticleInHeadlines(id
, noexpand
) {
272 selectArticles("none");
274 var crow
= $("RROW-" + id
);
278 var article_is_unread
= crow
.hasClassName("Unread");
281 crow
.removeClassName("Unread");
282 crow
.addClassName("active");
284 selectArticles('none');
286 var view_mode
= false;
289 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
290 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
297 if (article_is_unread
&& !noexpand
)
298 _force_scheduled_update
= true;
301 exception_error("showArticleInHeadlines", e
);
305 function article_callback2(transport
, id
) {
307 console
.log("article_callback2 " + id
);
309 handle_rpc_json(transport
);
314 reply
= JSON
.parse(transport
.responseText
);
321 reply
.each(function(article
) {
322 if (getActiveArticleId() == article
['id']) {
323 render_article(article
['content']);
325 cids_requested
.remove(article
['id']);
327 cache_set("article:" + article
['id'], article
['content']);
330 // if (id != last_requested_article) {
331 // console.log("requested article id is out of sequence, aborting");
336 console
.error("Invalid object received: " + transport
.responseText
);
338 render_article("<div class='whiteBox'>" +
339 __('Could not display article (invalid object received - see error console for details)') + "</div>");
342 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
343 request_counters(unread_in_buffer
== 0);
345 //headlines_scroll_handler($("headlines-frame"));
348 if (!_infscroll_disable &&
349 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
359 exception_error("article_callback2", e
, transport
);
363 function view(id
, activefeed
, noexpand
) {
365 var oldrow
= $("RROW-" + getActiveArticleId());
366 if (oldrow
) oldrow
.removeClassName("active");
368 var crow
= $("RROW-" + id
);
372 setActiveArticleId(id
);
373 showArticleInHeadlines(id
, noexpand
);
377 console
.log("loading article: " + id
);
379 var cached_article
= cache_get("article:" + id
);
381 console
.log("cache check result: " + (cached_article
!= false));
383 var query
= "?op=article&method=view&id=" + param_escape(id
);
385 var neighbor_ids
= getRelativePostIds(id
);
387 /* only request uncached articles */
389 var cids_to_request
= [];
391 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
392 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
393 if (!cache_get("article:" + neighbor_ids
[i
])) {
394 cids_to_request
.push(neighbor_ids
[i
]);
395 cids_requested
.push(neighbor_ids
[i
]);
399 console
.log("additional ids: " + cids_to_request
.toString());
401 query
= query
+ "&cids=" + cids_to_request
.toString();
403 var article_is_unread
= crow
.hasClassName("Unread");
405 setActiveArticleId(id
);
406 showArticleInHeadlines(id
);
408 if (cached_article
&& article_is_unread
) {
410 query
= query
+ "&mode=prefetch";
412 render_article(cached_article
);
414 } else if (cached_article
) {
416 query
= query
+ "&mode=prefetch_old";
417 render_article(cached_article
);
419 // if we don't need to request any relative ids, we might as well skip
420 // the server roundtrip altogether
421 if (cids_to_request
.length
== 0) {
424 if (!_infscroll_disable &&
425 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
433 //headlines_scroll_handler($("headlines-frame"));
439 last_requested_article
= id
;
443 if (article_is_unread
) {
444 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
447 new Ajax
.Request("backend.php", {
449 onComplete: function(transport
) {
450 article_callback2(transport
, id
);
456 exception_error("view", e
);
460 function toggleMark(id
, client_only
) {
462 var query
= "?op=rpc&id=" + id
+ "&method=mark";
464 var row
= $("RROW-" + id
);
469 var row_imgs
= row
.getElementsByClassName("markedPic");
471 for (var i
= 0; i
< row_imgs
.length
; i
++)
472 imgs
.push(row_imgs
[i
]);
474 var ft
= $("floatingTitle");
476 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
477 var fte
= ft
.getElementsByClassName("markedPic");
479 for (var i
= 0; i
< fte
.length
; i
++)
483 for (i
= 0; i
< imgs
.length
; i
++) {
486 if (!row
.hasClassName("marked")) {
487 img
.src
= img
.src
.replace("mark_unset", "mark_set");
488 img
.alt
= __("Unstar article");
489 query
= query
+ "&mark=1";
491 img
.src
= img
.src
.replace("mark_set", "mark_unset");
492 img
.alt
= __("Star article");
493 query
= query
+ "&mark=0";
497 row
.toggleClassName("marked");
500 new Ajax
.Request("backend.php", {
502 onComplete: function(transport
) {
503 handle_rpc_json(transport
);
508 exception_error("toggleMark", e
);
512 function togglePub(id
, client_only
, no_effects
, note
) {
514 var query
= "?op=rpc&id=" + id
+ "&method=publ";
516 if (note
!= undefined) {
517 query
= query
+ "¬e=" + param_escape(note
);
519 query
= query
+ "¬e=undefined";
522 var row
= $("RROW-" + id
);
527 var row_imgs
= row
.getElementsByClassName("pubPic");
529 for (var i
= 0; i
< row_imgs
.length
; i
++)
530 imgs
.push(row_imgs
[i
]);
532 var ft
= $("floatingTitle");
534 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
535 var fte
= ft
.getElementsByClassName("pubPic");
537 for (var i
= 0; i
< fte
.length
; i
++)
541 for (i
= 0; i
< imgs
.length
; i
++) {
544 if (!row
.hasClassName("published") || note
!= undefined) {
545 img
.src
= img
.src
.replace("pub_unset", "pub_set");
546 img
.alt
= __("Unpublish article");
547 query
= query
+ "&pub=1";
549 img
.src
= img
.src
.replace("pub_set", "pub_unset");
550 img
.alt
= __("Publish article");
551 query
= query
+ "&pub=0";
555 if (note
!= undefined)
556 row
.addClassName("published");
558 row
.toggleClassName("published");
561 new Ajax
.Request("backend.php", {
563 onComplete: function(transport
) {
564 handle_rpc_json(transport
);
569 exception_error("togglePub", e
);
573 function moveToPost(mode
, noscroll
, noexpand
) {
577 var rows
= getVisibleArticleIds();
582 if (!$('RROW-' + getActiveArticleId())) {
583 setActiveArticleId(0);
586 if (!getActiveArticleId()) {
588 prev_id
= rows
[rows
.length
-1]
590 for (var i
= 0; i
< rows
.length
; i
++) {
591 if (rows
[i
] == getActiveArticleId()) {
593 // Account for adjacent identical article ids.
594 if (i
> 0) prev_id
= rows
[i
-1];
596 for (var j
= i
+1; j
< rows
.length
; j
++) {
597 if (rows
[j
] != getActiveArticleId()) {
607 if (mode
== "next") {
608 if (next_id
|| getActiveArticleId()) {
611 var article
= $("RROW-" + getActiveArticleId());
612 var ctr
= $("headlines-frame");
614 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
615 ctr
.scrollTop
+ ctr
.offsetHeight
) {
617 scrollArticle(ctr
.offsetHeight
/4);
619 } else if (next_id
) {
620 cdmExpandArticle(next_id
, noexpand
);
621 cdmScrollToArticleId(next_id
, true);
624 } else if (next_id
) {
625 correctHeadlinesOffset(next_id
);
626 view(next_id
, getActiveFeedId(), noexpand
);
631 if (mode
== "prev") {
632 if (prev_id
|| getActiveArticleId()) {
635 var article
= $("RROW-" + getActiveArticleId());
636 var prev_article
= $("RROW-" + prev_id
);
637 var ctr
= $("headlines-frame");
639 if (!getInitParam("cdm_expanded")) {
641 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
642 scrollArticle(-ctr
.offsetHeight
/4);
644 cdmExpandArticle(prev_id
, noexpand
);
645 cdmScrollToArticleId(prev_id
, true);
649 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
650 scrollArticle(-ctr
.offsetHeight
/3);
651 } else if (!noscroll
&& prev_article
&&
652 prev_article
.offsetTop
< ctr
.scrollTop
) {
653 cdmExpandArticle(prev_id
, noexpand
);
654 scrollArticle(-ctr
.offsetHeight
/4);
655 } else if (prev_id
) {
656 cdmExpandArticle(prev_id
, noexpand
);
657 cdmScrollToArticleId(prev_id
, noscroll
);
661 } else if (prev_id
) {
662 correctHeadlinesOffset(prev_id
);
663 view(prev_id
, getActiveFeedId(), noexpand
);
669 exception_error("moveToPost", e
);
673 function toggleSelected(id
, force_on
) {
675 var row
= $("RROW-" + id
);
678 var cb
= dijit
.getEnclosingWidget(
679 row
.getElementsByClassName("rchk")[0]);
681 if (row
.hasClassName('Selected') && !force_on
) {
682 row
.removeClassName('Selected');
683 if (cb
) cb
.attr("checked", false);
685 row
.addClassName('Selected');
686 if (cb
) cb
.attr("checked", true);
690 updateSelectedPrompt();
692 exception_error("toggleSelected", e
);
696 function updateSelectedPrompt() {
698 var count
= getSelectedArticleIds2().size();
699 var elem
= $("selected_prompt");
702 elem
.innerHTML
= ngettext("%d article selected",
703 "%d articles selected", count
).replace("%d", count
);
712 exception_error("updateSelectedPrompt", e
);
716 function toggleUnread_afh(effect
) {
719 var elem
= effect
.element
;
720 elem
.style
.backgroundColor
= "";
723 exception_error("toggleUnread_afh", e
);
727 function toggleUnread(id
, cmode
, effect
) {
730 var row
= $("RROW-" + id
);
732 if (cmode
== undefined || cmode
== 2) {
733 if (row
.hasClassName("Unread")) {
734 row
.removeClassName("Unread");
737 row
.addClassName("Unread");
740 } else if (cmode
== 0) {
742 row
.removeClassName("Unread");
744 } else if (cmode
== 1) {
745 row
.addClassName("Unread");
748 if (cmode
== undefined) cmode
= 2;
750 var query
= "?op=rpc&method=catchupSelected" +
751 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
753 // notify_progress("Loading, please wait...");
755 new Ajax
.Request("backend.php", {
757 onComplete: function(transport
) {
758 handle_rpc_json(transport
);
764 exception_error("toggleUnread", e
);
768 function selectionRemoveLabel(id
, ids
) {
771 if (!ids
) ids
= getSelectedArticleIds2();
773 if (ids
.length
== 0) {
774 alert(__("No articles are selected."));
778 var query
= "?op=article&method=removeFromLabel&ids=" +
779 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
783 new Ajax
.Request("backend.php", {
785 onComplete: function(transport
) {
786 handle_rpc_json(transport
);
787 show_labels_in_headlines(transport
);
791 exception_error("selectionAssignLabel", e
);
796 function selectionAssignLabel(id
, ids
) {
799 if (!ids
) ids
= getSelectedArticleIds2();
801 if (ids
.length
== 0) {
802 alert(__("No articles are selected."));
806 var query
= "?op=article&method=assignToLabel&ids=" +
807 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
811 new Ajax
.Request("backend.php", {
813 onComplete: function(transport
) {
814 handle_rpc_json(transport
);
815 show_labels_in_headlines(transport
);
819 exception_error("selectionAssignLabel", e
);
824 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
826 var rows
= ids
? ids
: getSelectedArticleIds2();
828 if (rows
.length
== 0 && !no_error
) {
829 alert(__("No articles are selected."));
833 for (var i
= 0; i
< rows
.length
; i
++) {
834 var row
= $("RROW-" + rows
[i
]);
836 if (set_state
== undefined) {
837 if (row
.hasClassName("Unread")) {
838 row
.removeClassName("Unread");
840 row
.addClassName("Unread");
844 if (set_state
== false) {
845 row
.removeClassName("Unread");
848 if (set_state
== true) {
849 row
.addClassName("Unread");
854 updateFloatingTitle(true);
856 if (rows
.length
> 0) {
860 if (set_state
== undefined) {
862 } else if (set_state
== true) {
864 } else if (set_state
== false) {
868 var query
= "?op=rpc&method=catchupSelected" +
869 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
871 notify_progress("Loading, please wait...");
873 new Ajax
.Request("backend.php", {
875 onComplete: function(transport
) {
876 handle_rpc_json(transport
);
877 if (callback
) callback(transport
);
883 exception_error("selectionToggleUnread", e
);
888 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
891 var rows
= ids
? ids
: getSelectedArticleIds2();
893 if (rows
.length
== 0 && !no_error
) {
894 alert(__("No articles are selected."));
898 for (var i
= 0; i
< rows
.length
; i
++) {
899 toggleMark(rows
[i
], true, true);
902 if (rows
.length
> 0) {
904 var query
= "?op=rpc&method=markSelected&ids=" +
905 param_escape(rows
.toString()) + "&cmode=2";
907 new Ajax
.Request("backend.php", {
909 onComplete: function(transport
) {
910 handle_rpc_json(transport
);
911 if (callback
) callback(transport
);
917 exception_error("selectionToggleMarked", e
);
922 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
925 var rows
= ids
? ids
: getSelectedArticleIds2();
927 if (rows
.length
== 0 && !no_error
) {
928 alert(__("No articles are selected."));
932 for (var i
= 0; i
< rows
.length
; i
++) {
933 togglePub(rows
[i
], true, true);
936 if (rows
.length
> 0) {
938 var query
= "?op=rpc&method=publishSelected&ids=" +
939 param_escape(rows
.toString()) + "&cmode=2";
941 new Ajax
.Request("backend.php", {
943 onComplete: function(transport
) {
944 handle_rpc_json(transport
);
950 exception_error("selectionToggleMarked", e
);
954 function getSelectedArticleIds2() {
958 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
960 rv
.push(child
.id
.replace("RROW-", ""));
966 function getLoadedArticleIds() {
969 var children
= $$("#headlines-frame > div[id*=RROW-]");
971 children
.each(function(child
) {
972 rv
.push(child
.id
.replace("RROW-", ""));
979 // mode = all,none,unread,invert,marked,published
980 function selectArticles(mode
, query
) {
983 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
985 var children
= $$(query
);
987 children
.each(function(child
) {
988 var id
= child
.id
.replace("RROW-", "");
990 var cb
= dijit
.getEnclosingWidget(
991 child
.getElementsByClassName("rchk")[0]);
994 child
.addClassName("Selected");
995 if (cb
) cb
.attr("checked", true);
996 } else if (mode
== "unread") {
997 if (child
.hasClassName("Unread")) {
998 child
.addClassName("Selected");
999 if (cb
) cb
.attr("checked", true);
1001 child
.removeClassName("Selected");
1002 if (cb
) cb
.attr("checked", false);
1004 } else if (mode
== "marked") {
1005 if (child
.hasClassName("marked")) {
1006 child
.addClassName("Selected");
1007 if (cb
) cb
.attr("checked", true);
1009 child
.removeClassName("Selected");
1010 if (cb
) cb
.attr("checked", false);
1012 } else if (mode
== "published") {
1013 if (child
.hasClassName("published")) {
1014 child
.addClassName("Selected");
1015 if (cb
) cb
.attr("checked", true);
1017 child
.removeClassName("Selected");
1018 if (cb
) cb
.attr("checked", false);
1021 } else if (mode
== "invert") {
1022 if (child
.hasClassName("Selected")) {
1023 child
.removeClassName("Selected");
1024 if (cb
) cb
.attr("checked", false);
1026 child
.addClassName("Selected");
1027 if (cb
) cb
.attr("checked", true);
1031 child
.removeClassName("Selected");
1032 if (cb
) cb
.attr("checked", false);
1036 updateSelectedPrompt();
1039 exception_error("selectArticles", e
);
1043 function deleteSelection() {
1047 var rows
= getSelectedArticleIds2();
1049 if (rows
.length
== 0) {
1050 alert(__("No articles are selected."));
1054 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1057 if (getActiveFeedId() != 0) {
1058 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1060 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1063 str
= str
.replace("%d", rows
.length
);
1064 str
= str
.replace("%s", fn
);
1066 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1070 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1074 new Ajax
.Request("backend.php", {
1076 onComplete: function(transport
) {
1077 handle_rpc_json(transport
);
1082 exception_error("deleteSelection", e
);
1086 function archiveSelection() {
1090 var rows
= getSelectedArticleIds2();
1092 if (rows
.length
== 0) {
1093 alert(__("No articles are selected."));
1097 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1101 if (getActiveFeedId() != 0) {
1102 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1105 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1107 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1112 str
= str
.replace("%d", rows
.length
);
1113 str
= str
.replace("%s", fn
);
1115 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1119 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1123 for (var i
= 0; i
< rows
.length
; i
++) {
1124 cache_delete("article:" + rows
[i
]);
1127 new Ajax
.Request("backend.php", {
1129 onComplete: function(transport
) {
1130 handle_rpc_json(transport
);
1135 exception_error("archiveSelection", e
);
1139 function catchupSelection() {
1143 var rows
= getSelectedArticleIds2();
1145 if (rows
.length
== 0) {
1146 alert(__("No articles are selected."));
1150 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1152 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1154 str
= str
.replace("%d", rows
.length
);
1155 str
= str
.replace("%s", fn
);
1157 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1161 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1164 exception_error("catchupSelection", e
);
1168 function editArticleTags(id
) {
1169 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1171 if (dijit
.byId("editTagsDlg"))
1172 dijit
.byId("editTagsDlg").destroyRecursive();
1174 dialog
= new dijit
.Dialog({
1176 title
: __("Edit article Tags"),
1177 style
: "width: 600px",
1178 execute: function() {
1179 if (this.validate()) {
1180 var query
= dojo
.objectToQuery(this.attr('value'));
1182 notify_progress("Saving article tags...", true);
1184 new Ajax
.Request("backend.php", {
1186 onComplete: function(transport
) {
1191 var data
= JSON
.parse(transport
.responseText
);
1198 var tags
= $("ATSTR-" + id
);
1199 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1201 if (tags
) tags
.innerHTML
= data
.content
;
1202 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1205 exception_error("editArticleTags/inner", e
);
1214 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1215 dojo
.disconnect(tmph
);
1217 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1218 "backend.php?op=article&method=completeTags",
1219 { tokens
: ',', paramName
: "search" });
1226 function cdmScrollToArticleId(id
, force
) {
1228 var ctr
= $("headlines-frame");
1229 var e
= $("RROW-" + id
);
1231 if (!e
|| !ctr
) return;
1233 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1234 e
.offsetTop
< ctr
.scrollTop
) {
1236 // expanded cdm has a 4px margin now
1237 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1241 exception_error("cdmScrollToArticleId", e
);
1245 function setActiveArticleId(id
) {
1246 _active_article_id
= id
;
1247 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1250 function getActiveArticleId() {
1251 return _active_article_id
;
1254 function postMouseIn(e
, id
) {
1255 post_under_pointer
= id
;
1258 function postMouseOut(id
) {
1259 post_under_pointer
= false;
1262 function unpackVisibleHeadlines() {
1264 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1266 $$("#headlines-frame > div[id*=RROW]").each(
1268 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1269 $("headlines-frame").offsetHeight
) {
1271 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1274 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1276 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1277 cencw
.setAttribute('id', '');
1278 Element
.show(cencw
);
1285 exception_error("unpackVisibleHeadlines", e
);
1289 function headlines_scroll_handler(e
) {
1291 var hsp
= $("headlines-spacer");
1293 unpackVisibleHeadlines();
1295 // set topmost child in the buffer as active
1296 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1297 getSelectedArticleIds2().length
<= 1 &&
1298 getInitParam("cdm_expanded")) {
1299 var rows
= $$("#headlines-frame > div[id*=RROW]");
1301 for (var i
= 0; i
< rows
.length
; i
++) {
1302 var child
= rows
[i
];
1304 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1305 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1306 child
.id
.replace("RROW-", "") != _active_article_id
) {
1308 if (_active_article_id
) {
1309 var row
= $("RROW-" + _active_article_id
);
1310 if (row
) row
.removeClassName("active");
1313 _active_article_id
= child
.id
.replace("RROW-", "");
1314 showArticleInHeadlines(_active_article_id
, true);
1315 updateSelectedPrompt();
1321 if (!_infscroll_disable
) {
1322 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1323 (e
.scrollHeight
!= 0 &&
1324 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1327 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1328 __("Loading, please wait...") + "</span>";
1330 loadMoreHeadlines();
1336 if (_infscroll_disable)
1337 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1338 __("Click to open next unread feed.") + "</a>";
1345 updateFloatingTitle();
1348 if (getInitParam("cdm_auto_catchup") == 1) {
1350 // let's get DOM some time to settle down
1351 var ts
= new Date().getTime();
1352 if (ts
- _last_headlines_update
< 100) return;
1354 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1356 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1357 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1359 var id
= child
.id
.replace("RROW-", "");
1361 if (catchup_id_batch
.indexOf(id
) == -1)
1362 catchup_id_batch
.push(id
);
1364 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1369 if (catchup_id_batch
.length
> 0) {
1370 window
.clearTimeout(catchup_timeout_id
);
1372 if (!_infscroll_request_sent
) {
1373 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1378 if (_infscroll_disable
) {
1379 var child
= $$("#headlines-frame div[id*=RROW]").last();
1381 if (child
&& $("headlines-frame").scrollTop
>
1382 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1384 console
.log("we seem to be at an end");
1386 if (getInitParam("on_catchup_show_next_feed") == "1") {
1387 openNextUnreadFeed();
1394 console
.warn("headlines_scroll_handler: " + e
);
1398 function openNextUnreadFeed() {
1400 var is_cat
= activeFeedIsCat();
1401 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1402 if (nuf
) viewfeed(nuf
, '', is_cat
);
1404 exception_error("openNextUnreadFeed", e
);
1408 function catchupBatchedArticles() {
1410 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1412 // make a copy of the array
1413 var batch
= catchup_id_batch
.slice();
1414 var query
= "?op=rpc&method=catchupSelected" +
1415 "&cmode=0&ids=" + param_escape(batch
.toString());
1419 new Ajax
.Request("backend.php", {
1421 onComplete: function(transport
) {
1422 handle_rpc_json(transport
);
1424 reply
= JSON
.parse(transport
.responseText
);
1425 var batch
= reply
.ids
;
1427 batch
.each(function(id
) {
1429 var elem
= $("RROW-" + id
);
1430 if (elem
) elem
.removeClassName("Unread");
1431 catchup_id_batch
.remove(id
);
1434 updateFloatingTitle(true);
1440 exception_error("catchupBatchedArticles", e
);
1444 function catchupRelativeToArticle(below
, id
) {
1448 if (!id
) id
= getActiveArticleId();
1451 alert(__("No article is selected."));
1455 var visible_ids
= getVisibleArticleIds();
1457 var ids_to_mark
= new Array();
1460 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1461 if (visible_ids
[i
] != id
) {
1462 var e
= $("RROW-" + visible_ids
[i
]);
1464 if (e
&& e
.hasClassName("Unread")) {
1465 ids_to_mark
.push(visible_ids
[i
]);
1472 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1473 if (visible_ids
[i
] != id
) {
1474 var e
= $("RROW-" + visible_ids
[i
]);
1476 if (e
&& e
.hasClassName("Unread")) {
1477 ids_to_mark
.push(visible_ids
[i
]);
1485 if (ids_to_mark
.length
== 0) {
1486 alert(__("No articles found to mark"));
1488 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1490 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1492 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1493 var e
= $("RROW-" + ids_to_mark
[i
]);
1494 e
.removeClassName("Unread");
1497 var query
= "?op=rpc&method=catchupSelected" +
1498 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1500 new Ajax
.Request("backend.php", {
1502 onComplete: function(transport
) {
1503 handle_rpc_json(transport
);
1510 exception_error("catchupRelativeToArticle", e
);
1514 function cdmCollapseArticle(event
, id
, unmark
) {
1516 if (unmark
== undefined) unmark
= true;
1518 var row
= $("RROW-" + id
);
1519 var elem
= $("CICD-" + id
);
1522 var collapse
= $$("div#RROW-" + id
+
1523 " span[class='collapseBtn']")[0];
1526 Element
.show("CEXC-" + id
);
1527 Element
.hide(collapse
);
1530 row
.removeClassName("active");
1532 markHeadline(id
, false);
1534 if (id
== getActiveArticleId()) {
1535 setActiveArticleId(0);
1538 updateSelectedPrompt();
1541 if (event
) Event
.stop(event
);
1543 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1545 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1546 scrollToRowId(row
.id
);
1548 $("floatingTitle").style
.visibility
= "hidden";
1549 $("floatingTitle").setAttribute("rowid", false);
1553 exception_error("cdmCollapseArticle", e
);
1557 function cdmExpandArticle(id
, noexpand
) {
1559 console
.log("cdmExpandArticle " + id
);
1561 if (!$("RROW-" + id
)) return false;
1563 var oldrow
= $("RROW-" + getActiveArticleId());
1565 var elem
= $("CICD-" + getActiveArticleId());
1567 if (id
== getActiveArticleId() && Element
.visible(elem
))
1570 selectArticles("none");
1572 var old_offset
= $("RROW-" + id
).offsetTop
;
1574 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1575 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1576 " span[class='collapseBtn']")[0];
1579 Element
.show("CEXC-" + getActiveArticleId());
1580 Element
.hide(collapse
);
1583 if (oldrow
) oldrow
.removeClassName("active");
1585 setActiveArticleId(id
);
1587 elem
= $("CICD-" + id
);
1589 var collapse
= $$("div#RROW-" + id
+
1590 " span[class='collapseBtn']")[0];
1592 var cencw
= $("CENCW-" + id
);
1594 if (!Element
.visible(elem
) && !noexpand
) {
1596 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1597 cencw
.setAttribute('id', '');
1598 Element
.show(cencw
);
1602 Element
.hide("CEXC-" + id
);
1603 Element
.show(collapse
);
1606 var new_offset
= $("RROW-" + id
).offsetTop
;
1608 if (old_offset
> new_offset
)
1609 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1612 toggleUnread(id
, 0, true);
1614 $("RROW-" + id
).addClassName("active");
1616 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1619 exception_error("cdmExpandArticle", e
);
1625 function getArticleUnderPointer() {
1626 return post_under_pointer
;
1629 function scrollArticle(offset
) {
1632 var ci
= $("content-insert");
1634 ci
.scrollTop
+= offset
;
1637 var hi
= $("headlines-frame");
1639 hi
.scrollTop
+= offset
;
1644 exception_error("scrollArticle", e
);
1648 function show_labels_in_headlines(transport
) {
1650 var data
= JSON
.parse(transport
.responseText
);
1653 data
['info-for-headlines'].each(function(elem
) {
1654 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1655 ctr
.innerHTML
= elem
.labels
;
1660 exception_error("show_labels_in_headlines", e
);
1664 function dismissArticle(id
) {
1666 var elem
= $("RROW-" + id
);
1670 toggleUnread(id
, 0, true);
1672 new Effect
.Fade(elem
, {duration
: 0.5});
1674 // Remove the content, too
1675 var elem_content
= $("CICD-" + id
);
1677 Element
.remove(elem_content
);
1680 if (id
== getActiveArticleId()) {
1681 setActiveArticleId(0);
1685 exception_error("dismissArticle", e
);
1689 function dismissSelectedArticles() {
1692 var ids
= getVisibleArticleIds();
1696 for (var i
= 0; i
< ids
.length
; i
++) {
1697 var elem
= $("RROW-" + ids
[i
]);
1699 if (elem
.className
&& elem
.hasClassName("Selected") &&
1700 ids
[i
] != getActiveArticleId()) {
1701 new Effect
.Fade(elem
, {duration
: 0.5});
1704 // Remove the content, too
1705 var elem_content
= $("CICD-" + ids
[i
]);
1707 Element
.remove(elem_content
);
1715 selectionToggleUnread(false);
1719 exception_error("dismissSelectedArticles", e
);
1723 function dismissReadArticles() {
1726 var ids
= getVisibleArticleIds();
1729 for (var i
= 0; i
< ids
.length
; i
++) {
1730 var elem
= $("RROW-" + ids
[i
]);
1732 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1733 !elem
.hasClassName("Selected")) {
1735 new Effect
.Fade(elem
, {duration
: 0.5});
1737 // Remove the content, too
1738 var elem_content
= $("CICD-" + ids
[i
]);
1740 Element
.remove(elem_content
);
1748 exception_error("dismissReadArticles", e
);
1752 function getVisibleArticleIds() {
1757 getLoadedArticleIds().each(function(id
) {
1758 var elem
= $("RROW-" + id
);
1759 if (elem
&& Element
.visible(elem
))
1764 exception_error("getVisibleArticleIds", e
);
1770 function cdmClicked(event
, id
) {
1772 //var shift_key = event.shiftKey;
1774 if (!event
.ctrlKey
) {
1776 if (!getInitParam("cdm_expanded")) {
1777 return cdmExpandArticle(id
);
1780 var elem
= $("RROW-" + getActiveArticleId());
1782 if (elem
) elem
.removeClassName("active");
1784 selectArticles("none");
1787 var elem
= $("RROW-" + id
);
1788 var article_is_unread
= elem
.hasClassName("Unread");
1790 elem
.removeClassName("Unread");
1791 elem
.addClassName("active");
1793 setActiveArticleId(id
);
1795 if (article_is_unread
) {
1796 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1797 updateFloatingTitle(true);
1800 var query
= "?op=rpc&method=catchupSelected" +
1801 "&cmode=0&ids=" + param_escape(id
);
1803 new Ajax
.Request("backend.php", {
1805 onComplete: function(transport
) {
1806 handle_rpc_json(transport
);
1809 return !event
.shiftKey
;
1812 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1814 toggleSelected(id
, true);
1816 var elem
= $("RROW-" + id
);
1817 var article_is_unread
= elem
.hasClassName("Unread");
1819 if (article_is_unread
) {
1820 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1823 toggleUnread(id
, 0, false);
1825 openArticleInNewWindow(id
);
1828 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1829 request_counters(unread_in_buffer
== 0);
1832 exception_error("cdmClicked");
1838 function hlClicked(event
, id
) {
1840 if (event
.which
== 2) {
1843 } else if (event
.ctrlKey
) {
1844 toggleSelected(id
, true);
1845 toggleUnread(id
, 0, false);
1846 openArticleInNewWindow(id
);
1854 exception_error("hlClicked");
1858 function getFirstVisibleHeadlineId() {
1859 var rows
= getVisibleArticleIds();
1864 function getLastVisibleHeadlineId() {
1865 var rows
= getVisibleArticleIds();
1866 return rows
[rows
.length
-1];
1869 function openArticleInNewWindow(id
) {
1870 toggleUnread(id
, 0, false);
1871 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1874 function isCdmMode() {
1875 return getInitParam("combined_display_mode");
1878 function markHeadline(id
, marked
) {
1879 if (marked
== undefined) marked
= true;
1881 var row
= $("RROW-" + id
);
1883 var check
= dijit
.getEnclosingWidget(
1884 row
.getElementsByClassName("rchk")[0]);
1887 check
.attr("checked", marked
);
1891 row
.addClassName("Selected");
1893 row
.removeClassName("Selected");
1897 function getRelativePostIds(id
, limit
) {
1903 if (!limit
) limit
= 6; //3
1905 var ids
= getVisibleArticleIds();
1907 for (var i
= 0; i
< ids
.length
; i
++) {
1909 for (var k
= 1; k
<= limit
; k
++) {
1910 //if (i > k-1) tmp.push(ids[i-k]);
1911 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1918 exception_error("getRelativePostIds", e
);
1924 function correctHeadlinesOffset(id
) {
1928 var container
= $("headlines-frame");
1929 var row
= $("RROW-" + id
);
1931 if (!container
|| !row
) return;
1933 var viewport
= container
.offsetHeight
;
1935 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1936 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1938 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1939 //console.log("Vport: " + viewport);
1941 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1942 container
.scrollTop
= row
.offsetTop
;
1943 } else if (rel_offset_bottom
> viewport
) {
1945 /* doesn't properly work with Opera in some cases because
1946 Opera fucks up element scrolling */
1948 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1952 exception_error("correctHeadlinesOffset", e
);
1957 function headlineActionsChange(elem
) {
1960 elem
.attr('value', 'false');
1962 exception_error("headlineActionsChange", e
);
1966 function closeArticlePanel() {
1968 if (dijit
.byId("content-insert"))
1969 dijit
.byId("headlines-wrap-inner").removeChild(
1970 dijit
.byId("content-insert"));
1973 function initFloatingMenu() {
1975 if (dijit
.byId("floatingMenu"))
1976 dijit
.byId("floatingMenu").destroyRecursive();
1978 var menu
= new dijit
.Menu({
1980 targetNodeIds
: ["floatingTitle"]
1983 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1985 headlinesMenuCommon(menu
, id
);
1989 exception_error("initFloatingMenu", e
);
1993 function headlinesMenuCommon(menu
, base_id
) {
1996 menu
.addChild(new dijit
.MenuItem({
1997 label
: __("Open original article"),
1998 onClick: function(event
) {
1999 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
2002 menu
.addChild(new dijit
.MenuItem({
2003 label
: __("Display article URL"),
2004 onClick: function(event
) {
2005 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
2008 menu
.addChild(new dijit
.MenuSeparator());
2010 menu
.addChild(new dijit
.MenuItem({
2011 label
: __("Toggle unread"),
2012 onClick: function(event
) {
2013 var ids
= getSelectedArticleIds2();
2015 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2016 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2018 selectionToggleUnread(undefined, false, true, ids
);
2021 menu
.addChild(new dijit
.MenuItem({
2022 label
: __("Toggle starred"),
2023 onClick: function(event
) {
2024 var ids
= getSelectedArticleIds2();
2026 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2027 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2029 selectionToggleMarked(undefined, false, true, ids
);
2032 menu
.addChild(new dijit
.MenuItem({
2033 label
: __("Toggle published"),
2034 onClick: function(event
) {
2035 var ids
= getSelectedArticleIds2();
2037 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2038 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2040 selectionTogglePublished(undefined, false, true, ids
);
2043 menu
.addChild(new dijit
.MenuSeparator());
2045 menu
.addChild(new dijit
.MenuItem({
2046 label
: __("Mark above as read"),
2047 onClick: function(event
) {
2048 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2051 menu
.addChild(new dijit
.MenuItem({
2052 label
: __("Mark below as read"),
2053 onClick: function(event
) {
2054 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2058 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2062 menu
.addChild(new dijit
.MenuSeparator());
2064 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2065 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2067 labels
.each(function(label
) {
2068 var id
= label
.id
[0];
2069 var bare_id
= id
.substr(id
.indexOf(":")+1);
2070 var name
= label
.name
[0];
2072 bare_id
= feed_to_label_id(bare_id
);
2074 labelAddMenu
.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 selectionAssignLabel(this.labelId
, ids
);
2087 labelDelMenu
.addChild(new dijit
.MenuItem({
2090 onClick: function(event
) {
2091 var ids
= getSelectedArticleIds2();
2093 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2095 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2097 selectionRemoveLabel(this.labelId
, ids
);
2102 menu
.addChild(new dijit
.PopupMenuItem({
2103 label
: __("Assign label"),
2104 popup
: labelAddMenu
,
2107 menu
.addChild(new dijit
.PopupMenuItem({
2108 label
: __("Remove label"),
2109 popup
: labelDelMenu
,
2116 exception_error("headlinesMenuCommon", e
);
2120 function initHeadlinesMenu() {
2122 if (dijit
.byId("headlinesMenu"))
2123 dijit
.byId("headlinesMenu").destroyRecursive();
2128 nodes
= $$("#headlines-frame > div[id*=RROW]");
2130 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2133 nodes
.each(function(node
) {
2137 var menu
= new dijit
.Menu({
2138 id
: "headlinesMenu",
2142 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2143 var callerNode
= event
.target
, match
= null, tries
= 0;
2145 while (match
== null && callerNode
&& tries
<= 3) {
2146 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2147 callerNode
= callerNode
.parentNode
;
2151 if (match
) this.callerRowId
= parseInt(match
[1]);
2155 headlinesMenuCommon(menu
, false);
2159 /* vgroup feed title menu */
2161 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2164 nodes
.each(function(node
) {
2168 if (ids
.length
> 0) {
2169 if (dijit
.byId("headlinesFeedTitleMenu"))
2170 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2172 var menu
= new dijit
.Menu({
2173 id
: "headlinesFeedTitleMenu",
2177 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2178 var callerNode
= event
.target
, match
= null, tries
= 0;
2180 while (match
== null && callerNode
&& tries
<= 3) {
2181 console
.log(callerNode
.id
);
2183 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2184 callerNode
= callerNode
.parentNode
;
2187 console
.log(match
[1]);
2190 if (match
) this.callerRowId
= parseInt(match
[1]);
2194 menu
.addChild(new dijit
.MenuItem({
2195 label
: __("Select articles in group"),
2196 onClick: function(event
) {
2197 selectArticles("all",
2198 "#headlines-frame > div[id*=RROW]"+
2199 "[orig-feed-id='"+menu
.callerRowId
+"']");
2203 menu
.addChild(new dijit
.MenuItem({
2204 label
: __("Mark group as read"),
2205 onClick: function(event
) {
2206 selectArticles("none");
2207 selectArticles("all",
2208 "#headlines-frame > div[id*=RROW]"+
2209 "[orig-feed-id='"+menu
.callerRowId
+"']");
2215 menu
.addChild(new dijit
.MenuItem({
2216 label
: __("Mark feed as read"),
2217 onClick: function(event
) {
2218 catchupFeedInGroup(menu
.callerRowId
);
2226 exception_error("initHeadlinesMenu", e
);
2230 function cache_set(id
, obj
) {
2231 //console.log("cache_set: " + id);
2234 sessionStorage
[id
] = obj
;
2236 sessionStorage
.clear();
2240 function cache_get(id
) {
2242 return sessionStorage
[id
];
2245 function cache_clear() {
2247 sessionStorage
.clear();
2250 function cache_delete(id
) {
2252 sessionStorage
.removeItem(id
);
2255 function cancelSearch() {
2260 exception_error("cancelSearch", e
);
2264 function setSelectionScore() {
2266 var ids
= getSelectedArticleIds2();
2268 if (ids
.length
> 0) {
2271 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2273 if (score
!= undefined) {
2274 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2275 "&score=" + param_escape(score
);
2277 new Ajax
.Request("backend.php", {
2279 onComplete: function(transport
) {
2280 var reply
= JSON
.parse(transport
.responseText
);
2284 ids
.each(function(id
) {
2285 var row
= $("RROW-" + id
);
2288 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2291 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2292 reply
["score_pic"]);
2293 pic
.setAttribute("score", score
);
2302 alert(__("No articles are selected."));
2305 exception_error("setSelectionScore", e
);
2309 function updateScore(id
) {
2311 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2315 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2317 new Ajax
.Request("backend.php", {
2319 onComplete: function(transport
) {
2320 console
.log(transport
.responseText
);
2322 var reply
= JSON
.parse(transport
.responseText
);
2325 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2326 pic
.setAttribute("score", reply
["score"]);
2327 pic
.setAttribute("title", reply
["score"]);
2333 exception_error("updateScore", e
);
2337 function changeScore(id
, pic
) {
2339 var score
= pic
.getAttribute("score");
2341 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2343 if (new_score
!= undefined) {
2345 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2346 "&score=" + param_escape(new_score
);
2348 new Ajax
.Request("backend.php", {
2350 onComplete: function(transport
) {
2351 var reply
= JSON
.parse(transport
.responseText
);
2354 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2355 pic
.setAttribute("score", new_score
);
2356 pic
.setAttribute("title", new_score
);
2361 exception_error("changeScore", e
);
2365 function displayArticleUrl(id
) {
2367 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2369 new Ajax
.Request("backend.php", {
2371 onComplete: function(transport
) {
2372 var reply
= JSON
.parse(transport
.responseText
);
2374 if (reply
&& reply
.link
) {
2375 prompt(__("Article URL:"), reply
.link
);
2379 exception_error("changeScore", e
);
2383 function openSelectedAttachment(elem
) {
2385 var url
= elem
[elem
.selectedIndex
].value
;
2389 elem
.selectedIndex
= 0;
2393 exception_error("openSelectedAttachment", e
);
2397 function scrollToRowId(id
) {
2402 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2405 exception_error("scrollToRowId", e
);
2409 function updateFloatingTitle(unread_only
) {
2411 if (!isCdmMode()) return;
2413 var hf
= $("headlines-frame");
2415 var elems
= $$("#headlines-frame > div[id*=RROW]");
2417 for (var i
= 0; i
< elems
.length
; i
++) {
2419 var child
= elems
[i
];
2421 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2423 var header
= child
.getElementsByClassName("cdmHeader")[0];
2425 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2426 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2427 $("floatingTitle").setAttribute("rowid", child
.id
);
2428 $("floatingTitle").innerHTML
= header
.innerHTML
;
2429 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2433 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2436 cb
.parentNode
.removeChild(cb
);
2439 if (child
.hasClassName("Unread"))
2440 $("floatingTitle").addClassName("Unread");
2442 $("floatingTitle").removeClassName("Unread");
2444 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2447 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2448 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2449 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2450 $("floatingTitle").style
.visibility
= "visible";
2452 $("floatingTitle").style
.visibility
= "hidden";
2460 exception_error("updateFloatingTitle", e
);
2464 function cdmFooterClick(event
) {
2465 event
.stopPropagation();