1 var article_cache
= new Array();
3 var _active_article_id
= 0;
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
13 var cids_requested
= [];
14 var loaded_article_ids
= [];
15 var _last_headlines_update
= 0;
16 var current_first_id
= 0;
18 var _catchup_request_sent
= false;
20 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
22 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
24 handle_rpc_json(transport
);
26 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
34 reply
= JSON
.parse(transport
.responseText
);
41 is_cat
= reply
['headlines']['is_cat'];
42 feed_id
= reply
['headlines']['id'];
45 var content
= reply
['headlines']['content'];
47 content
= content
+ "<div id='headlines-spacer'></div>";
51 if (feed_id
!= -7 && (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat()))
54 /* dijit.getEnclosingWidget(
55 document.forms["main_toolbar_form"].update).attr('disabled',
56 is_cat || feed_id <= 0); */
59 if (infscroll_req
== false) {
60 $("headlines-frame").scrollTop
= 0;
62 $("floatingTitle").style
.visibility
= "hidden";
63 $("floatingTitle").setAttribute("rowid", 0);
64 $("floatingTitle").innerHTML
= "";
68 $("headlines-frame").removeClassName("cdm");
69 $("headlines-frame").removeClassName("normal");
71 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
73 var headlines_count
= reply
['headlines-info']['count'];
75 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
77 if (parseInt(headlines_count
) < 30) {
78 _infscroll_disable
= 1;
80 _infscroll_disable
= 0;
83 current_first_id
= reply
['headlines']['first_id'];
84 var counters
= reply
['counters'];
85 var articles
= reply
['articles'];
86 //var runtime_info = reply['runtime-info'];
88 if (infscroll_req
== false) {
89 loaded_article_ids
= [];
91 dojo
.html
.set($("headlines-toolbar"),
92 reply
['headlines']['toolbar'],
93 {parseContent
: true});
95 /*dojo.html.set($("headlines-frame"),
96 reply['headlines']['content'],
97 {parseContent: true});
99 $$("#headlines-frame div[id*='RROW']").each(function(row) {
100 loaded_article_ids.push(row.id);
103 $("headlines-frame").innerHTML
= '';
105 var tmp
= new Element("div");
106 tmp
.innerHTML
= reply
['headlines']['content'];
107 dojo
.parser
.parse(tmp
);
109 while (tmp
.hasChildNodes()) {
110 var row
= tmp
.removeChild(tmp
.firstChild
);
112 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
113 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
115 loaded_article_ids
.push(row
.id
);
119 var hsp
= $("headlines-spacer");
120 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
121 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
125 if (_infscroll_disable
)
126 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
127 __("Click to open next unread feed.") + "</a>";
130 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
131 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
137 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
138 console
.log("adding some more headlines: " + headlines_count
);
140 var c
= dijit
.byId("headlines-frame");
141 var ids
= getSelectedArticleIds2();
143 var hsp
= $("headlines-spacer");
146 c
.domNode
.removeChild(hsp
);
148 var tmp
= new Element("div");
149 tmp
.innerHTML
= reply
['headlines']['content'];
150 dojo
.parser
.parse(tmp
);
152 while (tmp
.hasChildNodes()) {
153 var row
= tmp
.removeChild(tmp
.firstChild
);
155 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
156 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
158 loaded_article_ids
.push(row
.id
);
162 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
163 c
.domNode
.appendChild(hsp
);
165 if (headlines_count
< 30) _infscroll_disable
= true;
167 console
.log("restore selected ids: " + ids
);
169 for (var i
= 0; i
< ids
.length
; i
++) {
170 markHeadline(ids
[i
]);
175 if (_infscroll_disable
) {
176 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
177 __("Click to open next unread feed.") + "</a>";
181 console
.log("no new headlines received");
183 var first_id_changed
= reply
['headlines']['first_id_changed'];
184 console
.log("first id changed:" + first_id_changed
);
186 var hsp
= $("headlines-spacer");
189 if (first_id_changed
) {
190 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
191 __("New articles found, reload feed to continue.") + "</a>";
193 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
194 __("Click to open next unread feed.") + "</a>";
203 for (var i
= 0; i
< articles
.length
; i
++) {
204 var a_id
= articles
[i
]['id'];
205 cache_set("article:" + a_id
, articles
[i
]['content']);
208 console
.log("no cached articles received");
212 parse_counters(counters
);
214 request_counters(true);
217 console
.error("Invalid object received: " + transport
.responseText
);
218 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
219 __('Could not update headlines (invalid object received - see error console for details)') +
223 _infscroll_request_sent
= 0;
224 _last_headlines_update
= new Date().getTime();
226 unpackVisibleHeadlines();
228 // if we have some more space in the buffer, why not try to fill it
230 if (!_infscroll_disable
&& $("headlines-spacer") &&
231 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
233 window
.setTimeout(function() {
241 exception_error("headlines_callback2", e
, transport
);
245 function render_article(article
) {
247 cleanup_memory("content-insert");
249 dijit
.byId("headlines-wrap-inner").addChild(
250 dijit
.byId("content-insert"));
252 var c
= dijit
.byId("content-insert");
255 c
.domNode
.scrollTop
= 0;
258 c
.attr('content', article
);
259 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
261 correctHeadlinesOffset(getActiveArticleId());
268 exception_error("render_article", e
);
272 function showArticleInHeadlines(id
, noexpand
) {
275 selectArticles("none");
277 var crow
= $("RROW-" + id
);
281 var article_is_unread
= crow
.hasClassName("Unread");
284 crow
.removeClassName("Unread");
285 crow
.addClassName("active");
287 selectArticles('none');
289 var view_mode
= false;
292 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
293 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
300 if (article_is_unread
&& !noexpand
)
301 _force_scheduled_update
= true;
304 exception_error("showArticleInHeadlines", e
);
308 function article_callback2(transport
, id
) {
310 console
.log("article_callback2 " + id
);
312 handle_rpc_json(transport
);
317 reply
= JSON
.parse(transport
.responseText
);
324 reply
.each(function(article
) {
325 if (getActiveArticleId() == article
['id']) {
326 render_article(article
['content']);
328 cids_requested
.remove(article
['id']);
330 cache_set("article:" + article
['id'], article
['content']);
333 // if (id != last_requested_article) {
334 // console.log("requested article id is out of sequence, aborting");
339 console
.error("Invalid object received: " + transport
.responseText
);
341 render_article("<div class='whiteBox'>" +
342 __('Could not display article (invalid object received - see error console for details)') + "</div>");
345 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
346 request_counters(unread_in_buffer
== 0);
350 exception_error("article_callback2", e
, transport
);
354 function view(id
, activefeed
, noexpand
) {
356 var oldrow
= $("RROW-" + getActiveArticleId());
357 if (oldrow
) oldrow
.removeClassName("active");
359 var crow
= $("RROW-" + id
);
363 setActiveArticleId(id
);
364 showArticleInHeadlines(id
, noexpand
);
368 console
.log("loading article: " + id
);
370 var cached_article
= cache_get("article:" + id
);
372 console
.log("cache check result: " + (cached_article
!= false));
374 var query
= "?op=article&method=view&id=" + param_escape(id
);
376 var neighbor_ids
= getRelativePostIds(id
);
378 /* only request uncached articles */
380 var cids_to_request
= [];
382 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
383 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
384 if (!cache_get("article:" + neighbor_ids
[i
])) {
385 cids_to_request
.push(neighbor_ids
[i
]);
386 cids_requested
.push(neighbor_ids
[i
]);
390 console
.log("additional ids: " + cids_to_request
.toString());
392 query
= query
+ "&cids=" + cids_to_request
.toString();
394 var article_is_unread
= crow
.hasClassName("Unread");
396 setActiveArticleId(id
);
397 showArticleInHeadlines(id
);
399 if (cached_article
&& article_is_unread
) {
401 query
= query
+ "&mode=prefetch";
403 render_article(cached_article
);
405 } else if (cached_article
) {
407 query
= query
+ "&mode=prefetch_old";
408 render_article(cached_article
);
410 // if we don't need to request any relative ids, we might as well skip
411 // the server roundtrip altogether
412 if (cids_to_request
.length
== 0) {
417 last_requested_article
= id
;
421 if (article_is_unread
) {
422 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
425 new Ajax
.Request("backend.php", {
427 onComplete: function(transport
) {
428 article_callback2(transport
, id
);
434 exception_error("view", e
);
438 function toggleMark(id
, client_only
) {
440 var query
= "?op=rpc&id=" + id
+ "&method=mark";
442 var row
= $("RROW-" + id
);
447 var row_imgs
= row
.getElementsByClassName("markedPic");
449 for (var i
= 0; i
< row_imgs
.length
; i
++)
450 imgs
.push(row_imgs
[i
]);
452 var ft
= $("floatingTitle");
454 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
455 var fte
= ft
.getElementsByClassName("markedPic");
457 for (var i
= 0; i
< fte
.length
; i
++)
461 for (i
= 0; i
< imgs
.length
; i
++) {
464 if (!row
.hasClassName("marked")) {
465 img
.src
= img
.src
.replace("mark_unset", "mark_set");
466 img
.alt
= __("Unstar article");
467 query
= query
+ "&mark=1";
469 img
.src
= img
.src
.replace("mark_set", "mark_unset");
470 img
.alt
= __("Star article");
471 query
= query
+ "&mark=0";
475 row
.toggleClassName("marked");
478 new Ajax
.Request("backend.php", {
480 onComplete: function(transport
) {
481 handle_rpc_json(transport
);
486 exception_error("toggleMark", e
);
490 function togglePub(id
, client_only
, no_effects
, note
) {
492 var query
= "?op=rpc&id=" + id
+ "&method=publ";
494 if (note
!= undefined) {
495 query
= query
+ "¬e=" + param_escape(note
);
497 query
= query
+ "¬e=undefined";
500 var row
= $("RROW-" + id
);
505 var row_imgs
= row
.getElementsByClassName("pubPic");
507 for (var i
= 0; i
< row_imgs
.length
; i
++)
508 imgs
.push(row_imgs
[i
]);
510 var ft
= $("floatingTitle");
512 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
513 var fte
= ft
.getElementsByClassName("pubPic");
515 for (var i
= 0; i
< fte
.length
; i
++)
519 for (i
= 0; i
< imgs
.length
; i
++) {
522 if (!row
.hasClassName("published") || note
!= undefined) {
523 img
.src
= img
.src
.replace("pub_unset", "pub_set");
524 img
.alt
= __("Unpublish article");
525 query
= query
+ "&pub=1";
527 img
.src
= img
.src
.replace("pub_set", "pub_unset");
528 img
.alt
= __("Publish article");
529 query
= query
+ "&pub=0";
533 if (note
!= undefined)
534 row
.addClassName("published");
536 row
.toggleClassName("published");
539 new Ajax
.Request("backend.php", {
541 onComplete: function(transport
) {
542 handle_rpc_json(transport
);
547 exception_error("togglePub", e
);
551 function moveToPost(mode
, noscroll
, noexpand
) {
555 var rows
= getLoadedArticleIds();
560 if (!$('RROW-' + getActiveArticleId())) {
561 setActiveArticleId(0);
564 if (!getActiveArticleId()) {
566 prev_id
= rows
[rows
.length
-1]
568 for (var i
= 0; i
< rows
.length
; i
++) {
569 if (rows
[i
] == getActiveArticleId()) {
571 // Account for adjacent identical article ids.
572 if (i
> 0) prev_id
= rows
[i
-1];
574 for (var j
= i
+1; j
< rows
.length
; j
++) {
575 if (rows
[j
] != getActiveArticleId()) {
585 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
587 if (mode
== "next") {
588 if (next_id
|| getActiveArticleId()) {
591 var article
= $("RROW-" + getActiveArticleId());
592 var ctr
= $("headlines-frame");
594 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
595 ctr
.scrollTop
+ ctr
.offsetHeight
) {
597 scrollArticle(ctr
.offsetHeight
/4);
599 } else if (next_id
) {
600 cdmExpandArticle(next_id
, noexpand
);
601 cdmScrollToArticleId(next_id
, true);
604 } else if (next_id
) {
605 correctHeadlinesOffset(next_id
);
606 view(next_id
, getActiveFeedId(), noexpand
);
611 if (mode
== "prev") {
612 if (prev_id
|| getActiveArticleId()) {
615 var article
= $("RROW-" + getActiveArticleId());
616 var prev_article
= $("RROW-" + prev_id
);
617 var ctr
= $("headlines-frame");
619 if (!getInitParam("cdm_expanded")) {
621 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
622 scrollArticle(-ctr
.offsetHeight
/4);
624 cdmExpandArticle(prev_id
, noexpand
);
625 cdmScrollToArticleId(prev_id
, true);
629 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
630 scrollArticle(-ctr
.offsetHeight
/3);
631 } else if (!noscroll
&& prev_article
&&
632 prev_article
.offsetTop
< ctr
.scrollTop
) {
633 cdmExpandArticle(prev_id
, noexpand
);
634 scrollArticle(-ctr
.offsetHeight
/4);
635 } else if (prev_id
) {
636 cdmExpandArticle(prev_id
, noexpand
);
637 cdmScrollToArticleId(prev_id
, noscroll
);
641 } else if (prev_id
) {
642 correctHeadlinesOffset(prev_id
);
643 view(prev_id
, getActiveFeedId(), noexpand
);
649 exception_error("moveToPost", e
);
653 function toggleSelected(id
, force_on
) {
655 var row
= $("RROW-" + id
);
658 var cb
= dijit
.getEnclosingWidget(
659 row
.getElementsByClassName("rchk")[0]);
661 if (row
.hasClassName('Selected') && !force_on
) {
662 row
.removeClassName('Selected');
663 if (cb
) cb
.attr("checked", false);
665 row
.addClassName('Selected');
666 if (cb
) cb
.attr("checked", true);
670 updateSelectedPrompt();
672 exception_error("toggleSelected", e
);
676 function updateSelectedPrompt() {
678 var count
= getSelectedArticleIds2().size();
679 var elem
= $("selected_prompt");
682 elem
.innerHTML
= ngettext("%d article selected",
683 "%d articles selected", count
).replace("%d", count
);
692 exception_error("updateSelectedPrompt", e
);
696 function toggleUnread(id
, cmode
, effect
) {
699 var row
= $("RROW-" + id
);
701 var tmpClassName
= row
.className
;
703 if (cmode
== undefined || cmode
== 2) {
704 if (row
.hasClassName("Unread")) {
705 row
.removeClassName("Unread");
708 row
.addClassName("Unread");
711 } else if (cmode
== 0) {
713 row
.removeClassName("Unread");
715 } else if (cmode
== 1) {
716 row
.addClassName("Unread");
719 if (cmode
== undefined) cmode
= 2;
721 var query
= "?op=rpc&method=catchupSelected" +
722 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
724 // notify_progress("Loading, please wait...");
726 if (tmpClassName
!= row
.className
) {
727 new Ajax
.Request("backend.php", {
729 onComplete: function (transport
) {
730 handle_rpc_json(transport
);
738 exception_error("toggleUnread", e
);
742 function selectionRemoveLabel(id
, ids
) {
745 if (!ids
) ids
= getSelectedArticleIds2();
747 if (ids
.length
== 0) {
748 alert(__("No articles are selected."));
752 var query
= "?op=article&method=removeFromLabel&ids=" +
753 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
757 new Ajax
.Request("backend.php", {
759 onComplete: function(transport
) {
760 handle_rpc_json(transport
);
761 show_labels_in_headlines(transport
);
765 exception_error("selectionAssignLabel", e
);
770 function selectionAssignLabel(id
, ids
) {
773 if (!ids
) ids
= getSelectedArticleIds2();
775 if (ids
.length
== 0) {
776 alert(__("No articles are selected."));
780 var query
= "?op=article&method=assignToLabel&ids=" +
781 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
785 new Ajax
.Request("backend.php", {
787 onComplete: function(transport
) {
788 handle_rpc_json(transport
);
789 show_labels_in_headlines(transport
);
793 exception_error("selectionAssignLabel", e
);
798 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
800 var rows
= ids
? ids
: getSelectedArticleIds2();
802 if (rows
.length
== 0 && !no_error
) {
803 alert(__("No articles are selected."));
807 for (var i
= 0; i
< rows
.length
; i
++) {
808 var row
= $("RROW-" + rows
[i
]);
810 if (set_state
== undefined) {
811 if (row
.hasClassName("Unread")) {
812 row
.removeClassName("Unread");
814 row
.addClassName("Unread");
818 if (set_state
== false) {
819 row
.removeClassName("Unread");
822 if (set_state
== true) {
823 row
.addClassName("Unread");
828 updateFloatingTitle(true);
830 if (rows
.length
> 0) {
834 if (set_state
== undefined) {
836 } else if (set_state
== true) {
838 } else if (set_state
== false) {
842 var query
= "?op=rpc&method=catchupSelected" +
843 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
845 notify_progress("Loading, please wait...");
847 new Ajax
.Request("backend.php", {
849 onComplete: function(transport
) {
850 handle_rpc_json(transport
);
851 if (callback
) callback(transport
);
857 exception_error("selectionToggleUnread", e
);
862 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
865 var rows
= ids
? ids
: getSelectedArticleIds2();
867 if (rows
.length
== 0 && !no_error
) {
868 alert(__("No articles are selected."));
872 for (var i
= 0; i
< rows
.length
; i
++) {
873 toggleMark(rows
[i
], true, true);
876 if (rows
.length
> 0) {
878 var query
= "?op=rpc&method=markSelected&ids=" +
879 param_escape(rows
.toString()) + "&cmode=2";
881 new Ajax
.Request("backend.php", {
883 onComplete: function(transport
) {
884 handle_rpc_json(transport
);
885 if (callback
) callback(transport
);
891 exception_error("selectionToggleMarked", e
);
896 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
899 var rows
= ids
? ids
: getSelectedArticleIds2();
901 if (rows
.length
== 0 && !no_error
) {
902 alert(__("No articles are selected."));
906 for (var i
= 0; i
< rows
.length
; i
++) {
907 togglePub(rows
[i
], true, true);
910 if (rows
.length
> 0) {
912 var query
= "?op=rpc&method=publishSelected&ids=" +
913 param_escape(rows
.toString()) + "&cmode=2";
915 new Ajax
.Request("backend.php", {
917 onComplete: function(transport
) {
918 handle_rpc_json(transport
);
924 exception_error("selectionToggleMarked", e
);
928 function getSelectedArticleIds2() {
932 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
934 rv
.push(child
.id
.replace("RROW-", ""));
940 function getLoadedArticleIds() {
943 var children
= $$("#headlines-frame > div[id*=RROW-]");
945 children
.each(function(child
) {
946 rv
.push(child
.id
.replace("RROW-", ""));
953 // mode = all,none,unread,invert,marked,published
954 function selectArticles(mode
, query
) {
957 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
959 var children
= $$(query
);
961 children
.each(function(child
) {
962 var id
= child
.id
.replace("RROW-", "");
964 var cb
= dijit
.getEnclosingWidget(
965 child
.getElementsByClassName("rchk")[0]);
968 child
.addClassName("Selected");
969 if (cb
) cb
.attr("checked", true);
970 } else if (mode
== "unread") {
971 if (child
.hasClassName("Unread")) {
972 child
.addClassName("Selected");
973 if (cb
) cb
.attr("checked", true);
975 child
.removeClassName("Selected");
976 if (cb
) cb
.attr("checked", false);
978 } else if (mode
== "marked") {
979 if (child
.hasClassName("marked")) {
980 child
.addClassName("Selected");
981 if (cb
) cb
.attr("checked", true);
983 child
.removeClassName("Selected");
984 if (cb
) cb
.attr("checked", false);
986 } else if (mode
== "published") {
987 if (child
.hasClassName("published")) {
988 child
.addClassName("Selected");
989 if (cb
) cb
.attr("checked", true);
991 child
.removeClassName("Selected");
992 if (cb
) cb
.attr("checked", false);
995 } else if (mode
== "invert") {
996 if (child
.hasClassName("Selected")) {
997 child
.removeClassName("Selected");
998 if (cb
) cb
.attr("checked", false);
1000 child
.addClassName("Selected");
1001 if (cb
) cb
.attr("checked", true);
1005 child
.removeClassName("Selected");
1006 if (cb
) cb
.attr("checked", false);
1010 updateSelectedPrompt();
1013 exception_error("selectArticles", e
);
1017 function deleteSelection() {
1021 var rows
= getSelectedArticleIds2();
1023 if (rows
.length
== 0) {
1024 alert(__("No articles are selected."));
1028 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1031 if (getActiveFeedId() != 0) {
1032 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1034 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1037 str
= str
.replace("%d", rows
.length
);
1038 str
= str
.replace("%s", fn
);
1040 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1044 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1048 new Ajax
.Request("backend.php", {
1050 onComplete: function(transport
) {
1051 handle_rpc_json(transport
);
1056 exception_error("deleteSelection", e
);
1060 function archiveSelection() {
1064 var rows
= getSelectedArticleIds2();
1066 if (rows
.length
== 0) {
1067 alert(__("No articles are selected."));
1071 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1075 if (getActiveFeedId() != 0) {
1076 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1079 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1081 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1086 str
= str
.replace("%d", rows
.length
);
1087 str
= str
.replace("%s", fn
);
1089 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1093 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1097 for (var i
= 0; i
< rows
.length
; i
++) {
1098 cache_delete("article:" + rows
[i
]);
1101 new Ajax
.Request("backend.php", {
1103 onComplete: function(transport
) {
1104 handle_rpc_json(transport
);
1109 exception_error("archiveSelection", e
);
1113 function catchupSelection() {
1117 var rows
= getSelectedArticleIds2();
1119 if (rows
.length
== 0) {
1120 alert(__("No articles are selected."));
1124 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1126 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1128 str
= str
.replace("%d", rows
.length
);
1129 str
= str
.replace("%s", fn
);
1131 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1135 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1138 exception_error("catchupSelection", e
);
1142 function editArticleTags(id
) {
1143 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1145 if (dijit
.byId("editTagsDlg"))
1146 dijit
.byId("editTagsDlg").destroyRecursive();
1148 dialog
= new dijit
.Dialog({
1150 title
: __("Edit article Tags"),
1151 style
: "width: 600px",
1152 execute: function() {
1153 if (this.validate()) {
1154 var query
= dojo
.objectToQuery(this.attr('value'));
1156 notify_progress("Saving article tags...", true);
1158 new Ajax
.Request("backend.php", {
1160 onComplete: function(transport
) {
1165 var data
= JSON
.parse(transport
.responseText
);
1172 var tags
= $("ATSTR-" + id
);
1173 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1175 if (tags
) tags
.innerHTML
= data
.content
;
1176 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1179 exception_error("editArticleTags/inner", e
);
1188 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1189 dojo
.disconnect(tmph
);
1191 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1192 "backend.php?op=article&method=completeTags",
1193 { tokens
: ',', paramName
: "search" });
1200 function cdmScrollToArticleId(id
, force
) {
1202 var ctr
= $("headlines-frame");
1203 var e
= $("RROW-" + id
);
1205 if (!e
|| !ctr
) return;
1207 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1208 e
.offsetTop
< ctr
.scrollTop
) {
1210 // expanded cdm has a 4px margin now
1211 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1215 exception_error("cdmScrollToArticleId", e
);
1219 function setActiveArticleId(id
) {
1220 console
.log("setActiveArticleId:" + id
);
1222 _active_article_id
= id
;
1223 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1226 function getActiveArticleId() {
1227 return _active_article_id
;
1230 function postMouseIn(e
, id
) {
1231 post_under_pointer
= id
;
1234 function postMouseOut(id
) {
1235 post_under_pointer
= false;
1238 function unpackVisibleHeadlines() {
1240 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1242 $$("#headlines-frame > div[id*=RROW]").each(
1244 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1245 $("headlines-frame").offsetHeight
) {
1247 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1250 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1251 cencw
.setAttribute('id', '');
1253 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1255 Element
.show(cencw
);
1262 exception_error("unpackVisibleHeadlines", e
);
1266 function headlines_scroll_handler(e
) {
1268 var hsp
= $("headlines-spacer");
1270 unpackVisibleHeadlines();
1272 // set topmost child in the buffer as active
1273 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1274 getSelectedArticleIds2().length
<= 1 &&
1275 getInitParam("cdm_expanded")) {
1276 var rows
= $$("#headlines-frame > div[id*=RROW]");
1278 for (var i
= 0; i
< rows
.length
; i
++) {
1279 var child
= rows
[i
];
1281 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1282 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1283 child
.id
.replace("RROW-", "") != _active_article_id
) {
1285 if (_active_article_id
) {
1286 var row
= $("RROW-" + _active_article_id
);
1287 if (row
) row
.removeClassName("active");
1290 _active_article_id
= child
.id
.replace("RROW-", "");
1291 showArticleInHeadlines(_active_article_id
, true);
1292 updateSelectedPrompt();
1298 if (!_infscroll_disable
) {
1299 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1301 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1302 __("Loading, please wait...") + "</span>";
1304 loadMoreHeadlines();
1311 updateFloatingTitle();
1314 catchupCurrentBatchIfNeeded();
1316 if (getInitParam("cdm_auto_catchup") == 1) {
1318 // let's get DOM some time to settle down
1319 var ts
= new Date().getTime();
1320 if (ts
- _last_headlines_update
< 100) return;
1322 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1324 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1325 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1327 var id
= child
.id
.replace("RROW-", "");
1329 if (catchup_id_batch
.indexOf(id
) == -1)
1330 catchup_id_batch
.push(id
);
1332 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1337 if (_infscroll_disable
) {
1338 var child
= $$("#headlines-frame div[id*=RROW]").last();
1340 if (child
&& $("headlines-frame").scrollTop
>
1341 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1343 console
.log("we seem to be at an end");
1345 if (getInitParam("on_catchup_show_next_feed") == "1") {
1346 openNextUnreadFeed();
1353 console
.warn("headlines_scroll_handler: " + e
);
1357 function openNextUnreadFeed() {
1359 var is_cat
= activeFeedIsCat();
1360 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1361 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1363 exception_error("openNextUnreadFeed", e
);
1367 function catchupBatchedArticles() {
1369 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1371 console
.log("catchupBatchedArticles: working");
1373 // make a copy of the array
1374 var batch
= catchup_id_batch
.slice();
1375 var query
= "?op=rpc&method=catchupSelected" +
1376 "&cmode=0&ids=" + param_escape(batch
.toString());
1380 _catchup_request_sent
= true;
1382 new Ajax
.Request("backend.php", {
1384 onComplete: function(transport
) {
1385 handle_rpc_json(transport
);
1387 _catchup_request_sent
= false;
1389 reply
= JSON
.parse(transport
.responseText
);
1390 var batch
= reply
.ids
;
1392 batch
.each(function(id
) {
1394 var elem
= $("RROW-" + id
);
1395 if (elem
) elem
.removeClassName("Unread");
1396 catchup_id_batch
.remove(id
);
1399 updateFloatingTitle(true);
1405 exception_error("catchupBatchedArticles", e
);
1409 function catchupRelativeToArticle(below
, id
) {
1413 if (!id
) id
= getActiveArticleId();
1416 alert(__("No article is selected."));
1420 var visible_ids
= getLoadedArticleIds();
1422 var ids_to_mark
= new Array();
1425 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1426 if (visible_ids
[i
] != id
) {
1427 var e
= $("RROW-" + visible_ids
[i
]);
1429 if (e
&& e
.hasClassName("Unread")) {
1430 ids_to_mark
.push(visible_ids
[i
]);
1437 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1438 if (visible_ids
[i
] != id
) {
1439 var e
= $("RROW-" + visible_ids
[i
]);
1441 if (e
&& e
.hasClassName("Unread")) {
1442 ids_to_mark
.push(visible_ids
[i
]);
1450 if (ids_to_mark
.length
== 0) {
1451 alert(__("No articles found to mark"));
1453 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1455 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1457 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1458 var e
= $("RROW-" + ids_to_mark
[i
]);
1459 e
.removeClassName("Unread");
1462 var query
= "?op=rpc&method=catchupSelected" +
1463 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1465 new Ajax
.Request("backend.php", {
1467 onComplete: function(transport
) {
1468 handle_rpc_json(transport
);
1475 exception_error("catchupRelativeToArticle", e
);
1479 function cdmCollapseArticle(event
, id
, unmark
) {
1481 if (unmark
== undefined) unmark
= true;
1483 var row
= $("RROW-" + id
);
1484 var elem
= $("CICD-" + id
);
1487 var collapse
= $$("div#RROW-" + id
+
1488 " span[class='collapseBtn']")[0];
1491 Element
.show("CEXC-" + id
);
1492 Element
.hide(collapse
);
1495 row
.removeClassName("active");
1497 markHeadline(id
, false);
1499 if (id
== getActiveArticleId()) {
1500 setActiveArticleId(0);
1503 updateSelectedPrompt();
1506 if (event
) Event
.stop(event
);
1508 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1510 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1511 scrollToRowId(row
.id
);
1513 $("floatingTitle").style
.visibility
= "hidden";
1514 $("floatingTitle").setAttribute("rowid", false);
1518 exception_error("cdmCollapseArticle", e
);
1522 function cdmExpandArticle(id
, noexpand
) {
1524 console
.log("cdmExpandArticle " + id
);
1526 if (!$("RROW-" + id
)) return false;
1528 var oldrow
= $("RROW-" + getActiveArticleId());
1530 var elem
= $("CICD-" + getActiveArticleId());
1532 if (id
== getActiveArticleId() && Element
.visible(elem
))
1535 selectArticles("none");
1537 var old_offset
= $("RROW-" + id
).offsetTop
;
1539 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1540 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1541 " span[class='collapseBtn']")[0];
1544 Element
.show("CEXC-" + getActiveArticleId());
1545 Element
.hide(collapse
);
1548 if (oldrow
) oldrow
.removeClassName("active");
1550 setActiveArticleId(id
);
1552 elem
= $("CICD-" + id
);
1554 var collapse
= $$("div#RROW-" + id
+
1555 " span[class='collapseBtn']")[0];
1557 var cencw
= $("CENCW-" + id
);
1559 if (!Element
.visible(elem
) && !noexpand
) {
1561 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1562 cencw
.setAttribute('id', '');
1563 Element
.show(cencw
);
1567 Element
.hide("CEXC-" + id
);
1568 Element
.show(collapse
);
1571 var new_offset
= $("RROW-" + id
).offsetTop
;
1573 if (old_offset
> new_offset
)
1574 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1577 if (catchup_id_batch
.indexOf(id
) == -1)
1578 catchup_id_batch
.push(id
);
1580 catchupCurrentBatchIfNeeded();
1584 $("RROW-" + id
).addClassName("active");
1586 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1589 exception_error("cdmExpandArticle", e
);
1595 function getArticleUnderPointer() {
1596 return post_under_pointer
;
1599 function scrollArticle(offset
) {
1602 var ci
= $("content-insert");
1604 ci
.scrollTop
+= offset
;
1607 var hi
= $("headlines-frame");
1609 hi
.scrollTop
+= offset
;
1614 exception_error("scrollArticle", e
);
1618 function show_labels_in_headlines(transport
) {
1620 var data
= JSON
.parse(transport
.responseText
);
1623 data
['info-for-headlines'].each(function(elem
) {
1624 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1625 ctr
.innerHTML
= elem
.labels
;
1630 exception_error("show_labels_in_headlines", e
);
1634 function dismissArticles(ids
) {
1637 console
.log("dismissArticles: " + ids
);
1639 for (var i
= 0; i
< ids
.length
; i
++) {
1640 var elem
= $("RROW-" + ids
[i
]);
1642 new Effect
.Fade(elem
, {
1643 duration
: 0.5, afterFinish: function (obj
) {
1644 Element
.remove(obj
.element
);
1648 if (ids
[i
] == getActiveArticleId()) {
1649 setActiveArticleId(0);
1653 selectionToggleUnread(false, false, false, ids
);
1656 exception_error("dismissArticles", e
);
1661 function dismissArticle(id
) {
1663 dismissArticles([id
]);
1665 exception_error("dismissArticle", e
);
1669 function dismissSelectedArticles() {
1671 dismissArticles(getSelectedArticleIds2());
1673 exception_error("dismissSelectedArticles", e
);
1677 function dismissReadArticles() {
1679 var ids
= getLoadedArticleIds();
1682 ids
.each(function(id
) {
1683 var elem
= $("RROW-" + id
);
1685 if (elem
&& !elem
.hasClassName("Unread")) {
1691 dismissArticles(tmp
);
1694 exception_error("dismissReadArticles", e
);
1698 function cdmClicked(event
, id
) {
1700 //var shift_key = event.shiftKey;
1702 if (!event
.ctrlKey
&& !event
.metaKey
) {
1704 if (!getInitParam("cdm_expanded")) {
1705 return cdmExpandArticle(id
);
1708 var elem
= $("RROW-" + getActiveArticleId());
1710 if (elem
) elem
.removeClassName("active");
1712 selectArticles("none");
1715 var elem
= $("RROW-" + id
);
1716 var article_is_unread
= elem
.hasClassName("Unread");
1718 elem
.removeClassName("Unread");
1719 elem
.addClassName("active");
1721 setActiveArticleId(id
);
1723 if (article_is_unread
) {
1724 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1725 updateFloatingTitle(true);
1728 var query
= "?op=rpc&method=catchupSelected" +
1729 "&cmode=0&ids=" + param_escape(id
);
1731 new Ajax
.Request("backend.php", {
1733 onComplete: function(transport
) {
1734 handle_rpc_json(transport
);
1737 return !event
.shiftKey
;
1740 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1742 toggleSelected(id
, true);
1744 var elem
= $("RROW-" + id
);
1745 var article_is_unread
= elem
.hasClassName("Unread");
1747 if (article_is_unread
) {
1748 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1751 toggleUnread(id
, 0, false);
1753 openArticleInNewWindow(id
);
1756 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1757 request_counters(unread_in_buffer
== 0);
1760 exception_error("cdmClicked");
1766 function hlClicked(event
, id
) {
1768 if (event
.which
== 2) {
1771 } else if (event
.ctrlKey
|| event
.metaKey
) {
1772 toggleSelected(id
, true);
1773 toggleUnread(id
, 0, false);
1774 openArticleInNewWindow(id
);
1782 exception_error("hlClicked");
1786 function openArticleInNewWindow(id
) {
1787 toggleUnread(id
, 0, false);
1788 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1791 function isCdmMode() {
1792 return getInitParam("combined_display_mode");
1795 function markHeadline(id
, marked
) {
1796 if (marked
== undefined) marked
= true;
1798 var row
= $("RROW-" + id
);
1800 var check
= dijit
.getEnclosingWidget(
1801 row
.getElementsByClassName("rchk")[0]);
1804 check
.attr("checked", marked
);
1808 row
.addClassName("Selected");
1810 row
.removeClassName("Selected");
1814 function getRelativePostIds(id
, limit
) {
1820 if (!limit
) limit
= 6; //3
1822 var ids
= getLoadedArticleIds();
1824 for (var i
= 0; i
< ids
.length
; i
++) {
1826 for (var k
= 1; k
<= limit
; k
++) {
1827 //if (i > k-1) tmp.push(ids[i-k]);
1828 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1835 exception_error("getRelativePostIds", e
);
1841 function correctHeadlinesOffset(id
) {
1845 var container
= $("headlines-frame");
1846 var row
= $("RROW-" + id
);
1848 if (!container
|| !row
) return;
1850 var viewport
= container
.offsetHeight
;
1852 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1853 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1855 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1856 //console.log("Vport: " + viewport);
1858 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1859 container
.scrollTop
= row
.offsetTop
;
1860 } else if (rel_offset_bottom
> viewport
) {
1862 /* doesn't properly work with Opera in some cases because
1863 Opera fucks up element scrolling */
1865 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1869 exception_error("correctHeadlinesOffset", e
);
1874 function headlineActionsChange(elem
) {
1877 elem
.attr('value', 'false');
1879 exception_error("headlineActionsChange", e
);
1883 function closeArticlePanel() {
1885 if (dijit
.byId("content-insert"))
1886 dijit
.byId("headlines-wrap-inner").removeChild(
1887 dijit
.byId("content-insert"));
1890 function initFloatingMenu() {
1892 if (dijit
.byId("floatingMenu"))
1893 dijit
.byId("floatingMenu").destroyRecursive();
1895 var menu
= new dijit
.Menu({
1897 targetNodeIds
: ["floatingTitle"]
1900 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1902 headlinesMenuCommon(menu
, id
);
1906 exception_error("initFloatingMenu", e
);
1910 function headlinesMenuCommon(menu
, base_id
) {
1913 menu
.addChild(new dijit
.MenuItem({
1914 label
: __("Open original article"),
1915 onClick: function(event
) {
1916 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1919 menu
.addChild(new dijit
.MenuItem({
1920 label
: __("Display article URL"),
1921 onClick: function(event
) {
1922 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1925 menu
.addChild(new dijit
.MenuSeparator());
1927 menu
.addChild(new dijit
.MenuItem({
1928 label
: __("Toggle unread"),
1929 onClick: function(event
) {
1930 var ids
= getSelectedArticleIds2();
1932 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1933 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1935 selectionToggleUnread(undefined, false, true, ids
);
1938 menu
.addChild(new dijit
.MenuItem({
1939 label
: __("Toggle starred"),
1940 onClick: function(event
) {
1941 var ids
= getSelectedArticleIds2();
1943 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1944 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1946 selectionToggleMarked(undefined, false, true, ids
);
1949 menu
.addChild(new dijit
.MenuItem({
1950 label
: __("Toggle published"),
1951 onClick: function(event
) {
1952 var ids
= getSelectedArticleIds2();
1954 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1955 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1957 selectionTogglePublished(undefined, false, true, ids
);
1960 menu
.addChild(new dijit
.MenuSeparator());
1962 menu
.addChild(new dijit
.MenuItem({
1963 label
: __("Mark above as read"),
1964 onClick: function(event
) {
1965 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
1968 menu
.addChild(new dijit
.MenuItem({
1969 label
: __("Mark below as read"),
1970 onClick: function(event
) {
1971 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
1975 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1979 menu
.addChild(new dijit
.MenuSeparator());
1981 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1982 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1984 labels
.each(function(label
) {
1985 var id
= label
.id
[0];
1986 var bare_id
= id
.substr(id
.indexOf(":")+1);
1987 var name
= label
.name
[0];
1989 bare_id
= feed_to_label_id(bare_id
);
1991 labelAddMenu
.addChild(new dijit
.MenuItem({
1994 onClick: function(event
) {
1995 var ids
= getSelectedArticleIds2();
1997 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
1999 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2001 selectionAssignLabel(this.labelId
, ids
);
2004 labelDelMenu
.addChild(new dijit
.MenuItem({
2007 onClick: function(event
) {
2008 var ids
= getSelectedArticleIds2();
2010 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2012 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2014 selectionRemoveLabel(this.labelId
, ids
);
2019 menu
.addChild(new dijit
.PopupMenuItem({
2020 label
: __("Assign label"),
2024 menu
.addChild(new dijit
.PopupMenuItem({
2025 label
: __("Remove label"),
2033 exception_error("headlinesMenuCommon", e
);
2037 function initHeadlinesMenu() {
2039 if (dijit
.byId("headlinesMenu"))
2040 dijit
.byId("headlinesMenu").destroyRecursive();
2045 nodes
= $$("#headlines-frame > div[id*=RROW]");
2047 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2050 nodes
.each(function(node
) {
2054 var menu
= new dijit
.Menu({
2055 id
: "headlinesMenu",
2059 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2060 var callerNode
= event
.target
, match
= null, tries
= 0;
2062 while (match
== null && callerNode
&& tries
<= 3) {
2063 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2064 callerNode
= callerNode
.parentNode
;
2068 if (match
) this.callerRowId
= parseInt(match
[1]);
2072 headlinesMenuCommon(menu
, false);
2076 /* vgroup feed title menu */
2078 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2081 nodes
.each(function(node
) {
2085 if (ids
.length
> 0) {
2086 if (dijit
.byId("headlinesFeedTitleMenu"))
2087 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2089 var menu
= new dijit
.Menu({
2090 id
: "headlinesFeedTitleMenu",
2094 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2095 var callerNode
= event
.target
, match
= null, tries
= 0;
2097 while (match
== null && callerNode
&& tries
<= 3) {
2098 console
.log(callerNode
.id
);
2100 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2101 callerNode
= callerNode
.parentNode
;
2104 console
.log(match
[1]);
2107 if (match
) this.callerRowId
= parseInt(match
[1]);
2111 menu
.addChild(new dijit
.MenuItem({
2112 label
: __("Select articles in group"),
2113 onClick: function(event
) {
2114 selectArticles("all",
2115 "#headlines-frame > div[id*=RROW]"+
2116 "[orig-feed-id='"+menu
.callerRowId
+"']");
2120 menu
.addChild(new dijit
.MenuItem({
2121 label
: __("Mark group as read"),
2122 onClick: function(event
) {
2123 selectArticles("none");
2124 selectArticles("all",
2125 "#headlines-frame > div[id*=RROW]"+
2126 "[orig-feed-id='"+menu
.callerRowId
+"']");
2132 menu
.addChild(new dijit
.MenuItem({
2133 label
: __("Mark feed as read"),
2134 onClick: function(event
) {
2135 catchupFeedInGroup(menu
.callerRowId
);
2138 menu
.addChild(new dijit
.MenuItem({
2139 label
: __("Edit feed"),
2140 onClick: function(event
) {
2141 editFeed(menu
.callerRowId
);
2149 exception_error("initHeadlinesMenu", e
);
2153 function cache_set(id
, obj
) {
2154 //console.log("cache_set: " + id);
2157 sessionStorage
[id
] = obj
;
2159 sessionStorage
.clear();
2163 function cache_get(id
) {
2165 return sessionStorage
[id
];
2168 function cache_clear() {
2170 sessionStorage
.clear();
2173 function cache_delete(id
) {
2175 sessionStorage
.removeItem(id
);
2178 function cancelSearch() {
2183 exception_error("cancelSearch", e
);
2187 function setSelectionScore() {
2189 var ids
= getSelectedArticleIds2();
2191 if (ids
.length
> 0) {
2194 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2196 if (score
!= undefined) {
2197 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2198 "&score=" + param_escape(score
);
2200 new Ajax
.Request("backend.php", {
2202 onComplete: function(transport
) {
2203 var reply
= JSON
.parse(transport
.responseText
);
2207 ids
.each(function(id
) {
2208 var row
= $("RROW-" + id
);
2211 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2214 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2215 reply
["score_pic"]);
2216 pic
.setAttribute("score", score
);
2225 alert(__("No articles are selected."));
2228 exception_error("setSelectionScore", e
);
2232 function updateScore(id
) {
2234 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2238 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2240 new Ajax
.Request("backend.php", {
2242 onComplete: function(transport
) {
2243 console
.log(transport
.responseText
);
2245 var reply
= JSON
.parse(transport
.responseText
);
2248 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2249 pic
.setAttribute("score", reply
["score"]);
2250 pic
.setAttribute("title", reply
["score"]);
2256 exception_error("updateScore", e
);
2260 function changeScore(id
, pic
) {
2262 var score
= pic
.getAttribute("score");
2264 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2266 if (new_score
!= undefined) {
2268 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2269 "&score=" + param_escape(new_score
);
2271 new Ajax
.Request("backend.php", {
2273 onComplete: function(transport
) {
2274 var reply
= JSON
.parse(transport
.responseText
);
2277 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2278 pic
.setAttribute("score", new_score
);
2279 pic
.setAttribute("title", new_score
);
2284 exception_error("changeScore", e
);
2288 function displayArticleUrl(id
) {
2290 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2292 new Ajax
.Request("backend.php", {
2294 onComplete: function(transport
) {
2295 var reply
= JSON
.parse(transport
.responseText
);
2297 if (reply
&& reply
.link
) {
2298 prompt(__("Article URL:"), reply
.link
);
2302 exception_error("changeScore", e
);
2306 function scrollToRowId(id
) {
2311 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2314 exception_error("scrollToRowId", e
);
2318 function updateFloatingTitle(unread_only
) {
2320 if (!isCdmMode()) return;
2322 var hf
= $("headlines-frame");
2324 var elems
= $$("#headlines-frame > div[id*=RROW]");
2326 for (var i
= 0; i
< elems
.length
; i
++) {
2328 var child
= elems
[i
];
2330 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2332 var header
= child
.getElementsByClassName("cdmHeader")[0];
2334 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2335 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2336 $("floatingTitle").setAttribute("rowid", child
.id
);
2337 $("floatingTitle").innerHTML
= header
.innerHTML
;
2338 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2342 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2345 cb
.parentNode
.removeChild(cb
);
2348 if (child
.hasClassName("Unread"))
2349 $("floatingTitle").addClassName("Unread");
2351 $("floatingTitle").removeClassName("Unread");
2353 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2356 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2357 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2358 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2359 $("floatingTitle").style
.visibility
= "visible";
2361 $("floatingTitle").style
.visibility
= "hidden";
2369 exception_error("updateFloatingTitle", e
);
2373 function catchupCurrentBatchIfNeeded() {
2374 if (catchup_id_batch
.length
> 0) {
2375 window
.clearTimeout(catchup_timeout_id
);
2376 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2378 if (catchup_id_batch
.length
>= 10) {
2379 catchupBatchedArticles();
2384 function cdmFooterClick(event
) {
2385 event
.stopPropagation();