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
= getVisibleArticleIds();
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_afh(effect
) {
699 var elem
= effect
.element
;
700 elem
.style
.backgroundColor
= "";
703 exception_error("toggleUnread_afh", e
);
707 function toggleUnread(id
, cmode
, effect
) {
710 var row
= $("RROW-" + id
);
712 var tmpClassName
= row
.className
;
714 if (cmode
== undefined || cmode
== 2) {
715 if (row
.hasClassName("Unread")) {
716 row
.removeClassName("Unread");
719 row
.addClassName("Unread");
722 } else if (cmode
== 0) {
724 row
.removeClassName("Unread");
726 } else if (cmode
== 1) {
727 row
.addClassName("Unread");
730 if (cmode
== undefined) cmode
= 2;
732 var query
= "?op=rpc&method=catchupSelected" +
733 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
735 // notify_progress("Loading, please wait...");
737 if (tmpClassName
!= row
.className
) {
738 new Ajax
.Request("backend.php", {
740 onComplete: function (transport
) {
741 handle_rpc_json(transport
);
749 exception_error("toggleUnread", e
);
753 function selectionRemoveLabel(id
, ids
) {
756 if (!ids
) ids
= getSelectedArticleIds2();
758 if (ids
.length
== 0) {
759 alert(__("No articles are selected."));
763 var query
= "?op=article&method=removeFromLabel&ids=" +
764 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
768 new Ajax
.Request("backend.php", {
770 onComplete: function(transport
) {
771 handle_rpc_json(transport
);
772 show_labels_in_headlines(transport
);
776 exception_error("selectionAssignLabel", e
);
781 function selectionAssignLabel(id
, ids
) {
784 if (!ids
) ids
= getSelectedArticleIds2();
786 if (ids
.length
== 0) {
787 alert(__("No articles are selected."));
791 var query
= "?op=article&method=assignToLabel&ids=" +
792 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
796 new Ajax
.Request("backend.php", {
798 onComplete: function(transport
) {
799 handle_rpc_json(transport
);
800 show_labels_in_headlines(transport
);
804 exception_error("selectionAssignLabel", e
);
809 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
811 var rows
= ids
? ids
: getSelectedArticleIds2();
813 if (rows
.length
== 0 && !no_error
) {
814 alert(__("No articles are selected."));
818 for (var i
= 0; i
< rows
.length
; i
++) {
819 var row
= $("RROW-" + rows
[i
]);
821 if (set_state
== undefined) {
822 if (row
.hasClassName("Unread")) {
823 row
.removeClassName("Unread");
825 row
.addClassName("Unread");
829 if (set_state
== false) {
830 row
.removeClassName("Unread");
833 if (set_state
== true) {
834 row
.addClassName("Unread");
839 updateFloatingTitle(true);
841 if (rows
.length
> 0) {
845 if (set_state
== undefined) {
847 } else if (set_state
== true) {
849 } else if (set_state
== false) {
853 var query
= "?op=rpc&method=catchupSelected" +
854 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
856 notify_progress("Loading, please wait...");
858 new Ajax
.Request("backend.php", {
860 onComplete: function(transport
) {
861 handle_rpc_json(transport
);
862 if (callback
) callback(transport
);
868 exception_error("selectionToggleUnread", e
);
873 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
876 var rows
= ids
? ids
: getSelectedArticleIds2();
878 if (rows
.length
== 0 && !no_error
) {
879 alert(__("No articles are selected."));
883 for (var i
= 0; i
< rows
.length
; i
++) {
884 toggleMark(rows
[i
], true, true);
887 if (rows
.length
> 0) {
889 var query
= "?op=rpc&method=markSelected&ids=" +
890 param_escape(rows
.toString()) + "&cmode=2";
892 new Ajax
.Request("backend.php", {
894 onComplete: function(transport
) {
895 handle_rpc_json(transport
);
896 if (callback
) callback(transport
);
902 exception_error("selectionToggleMarked", e
);
907 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
910 var rows
= ids
? ids
: getSelectedArticleIds2();
912 if (rows
.length
== 0 && !no_error
) {
913 alert(__("No articles are selected."));
917 for (var i
= 0; i
< rows
.length
; i
++) {
918 togglePub(rows
[i
], true, true);
921 if (rows
.length
> 0) {
923 var query
= "?op=rpc&method=publishSelected&ids=" +
924 param_escape(rows
.toString()) + "&cmode=2";
926 new Ajax
.Request("backend.php", {
928 onComplete: function(transport
) {
929 handle_rpc_json(transport
);
935 exception_error("selectionToggleMarked", e
);
939 function getSelectedArticleIds2() {
943 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
945 rv
.push(child
.id
.replace("RROW-", ""));
951 function getLoadedArticleIds() {
954 var children
= $$("#headlines-frame > div[id*=RROW-]");
956 children
.each(function(child
) {
957 rv
.push(child
.id
.replace("RROW-", ""));
964 // mode = all,none,unread,invert,marked,published
965 function selectArticles(mode
, query
) {
968 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
970 var children
= $$(query
);
972 children
.each(function(child
) {
973 var id
= child
.id
.replace("RROW-", "");
975 var cb
= dijit
.getEnclosingWidget(
976 child
.getElementsByClassName("rchk")[0]);
979 child
.addClassName("Selected");
980 if (cb
) cb
.attr("checked", true);
981 } else if (mode
== "unread") {
982 if (child
.hasClassName("Unread")) {
983 child
.addClassName("Selected");
984 if (cb
) cb
.attr("checked", true);
986 child
.removeClassName("Selected");
987 if (cb
) cb
.attr("checked", false);
989 } else if (mode
== "marked") {
990 if (child
.hasClassName("marked")) {
991 child
.addClassName("Selected");
992 if (cb
) cb
.attr("checked", true);
994 child
.removeClassName("Selected");
995 if (cb
) cb
.attr("checked", false);
997 } else if (mode
== "published") {
998 if (child
.hasClassName("published")) {
999 child
.addClassName("Selected");
1000 if (cb
) cb
.attr("checked", true);
1002 child
.removeClassName("Selected");
1003 if (cb
) cb
.attr("checked", false);
1006 } else if (mode
== "invert") {
1007 if (child
.hasClassName("Selected")) {
1008 child
.removeClassName("Selected");
1009 if (cb
) cb
.attr("checked", false);
1011 child
.addClassName("Selected");
1012 if (cb
) cb
.attr("checked", true);
1016 child
.removeClassName("Selected");
1017 if (cb
) cb
.attr("checked", false);
1021 updateSelectedPrompt();
1024 exception_error("selectArticles", e
);
1028 function deleteSelection() {
1032 var rows
= getSelectedArticleIds2();
1034 if (rows
.length
== 0) {
1035 alert(__("No articles are selected."));
1039 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1042 if (getActiveFeedId() != 0) {
1043 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1045 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1048 str
= str
.replace("%d", rows
.length
);
1049 str
= str
.replace("%s", fn
);
1051 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1055 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1059 new Ajax
.Request("backend.php", {
1061 onComplete: function(transport
) {
1062 handle_rpc_json(transport
);
1067 exception_error("deleteSelection", e
);
1071 function archiveSelection() {
1075 var rows
= getSelectedArticleIds2();
1077 if (rows
.length
== 0) {
1078 alert(__("No articles are selected."));
1082 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1086 if (getActiveFeedId() != 0) {
1087 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1090 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1092 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1097 str
= str
.replace("%d", rows
.length
);
1098 str
= str
.replace("%s", fn
);
1100 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1104 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1108 for (var i
= 0; i
< rows
.length
; i
++) {
1109 cache_delete("article:" + rows
[i
]);
1112 new Ajax
.Request("backend.php", {
1114 onComplete: function(transport
) {
1115 handle_rpc_json(transport
);
1120 exception_error("archiveSelection", e
);
1124 function catchupSelection() {
1128 var rows
= getSelectedArticleIds2();
1130 if (rows
.length
== 0) {
1131 alert(__("No articles are selected."));
1135 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1137 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1139 str
= str
.replace("%d", rows
.length
);
1140 str
= str
.replace("%s", fn
);
1142 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1146 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1149 exception_error("catchupSelection", e
);
1153 function editArticleTags(id
) {
1154 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1156 if (dijit
.byId("editTagsDlg"))
1157 dijit
.byId("editTagsDlg").destroyRecursive();
1159 dialog
= new dijit
.Dialog({
1161 title
: __("Edit article Tags"),
1162 style
: "width: 600px",
1163 execute: function() {
1164 if (this.validate()) {
1165 var query
= dojo
.objectToQuery(this.attr('value'));
1167 notify_progress("Saving article tags...", true);
1169 new Ajax
.Request("backend.php", {
1171 onComplete: function(transport
) {
1176 var data
= JSON
.parse(transport
.responseText
);
1183 var tags
= $("ATSTR-" + id
);
1184 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1186 if (tags
) tags
.innerHTML
= data
.content
;
1187 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1190 exception_error("editArticleTags/inner", e
);
1199 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1200 dojo
.disconnect(tmph
);
1202 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1203 "backend.php?op=article&method=completeTags",
1204 { tokens
: ',', paramName
: "search" });
1211 function cdmScrollToArticleId(id
, force
) {
1213 var ctr
= $("headlines-frame");
1214 var e
= $("RROW-" + id
);
1216 if (!e
|| !ctr
) return;
1218 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1219 e
.offsetTop
< ctr
.scrollTop
) {
1221 // expanded cdm has a 4px margin now
1222 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1226 exception_error("cdmScrollToArticleId", e
);
1230 function setActiveArticleId(id
) {
1231 console
.log("setActiveArticleId:" + id
);
1233 _active_article_id
= id
;
1234 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1237 function getActiveArticleId() {
1238 return _active_article_id
;
1241 function postMouseIn(e
, id
) {
1242 post_under_pointer
= id
;
1245 function postMouseOut(id
) {
1246 post_under_pointer
= false;
1249 function unpackVisibleHeadlines() {
1251 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1253 $$("#headlines-frame > div[id*=RROW]").each(
1255 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1256 $("headlines-frame").offsetHeight
) {
1258 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1261 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1262 cencw
.setAttribute('id', '');
1264 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1266 Element
.show(cencw
);
1273 exception_error("unpackVisibleHeadlines", e
);
1277 function headlines_scroll_handler(e
) {
1279 var hsp
= $("headlines-spacer");
1281 unpackVisibleHeadlines();
1283 // set topmost child in the buffer as active
1284 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1285 getSelectedArticleIds2().length
<= 1 &&
1286 getInitParam("cdm_expanded")) {
1287 var rows
= $$("#headlines-frame > div[id*=RROW]");
1289 for (var i
= 0; i
< rows
.length
; i
++) {
1290 var child
= rows
[i
];
1292 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1293 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1294 child
.id
.replace("RROW-", "") != _active_article_id
) {
1296 if (_active_article_id
) {
1297 var row
= $("RROW-" + _active_article_id
);
1298 if (row
) row
.removeClassName("active");
1301 _active_article_id
= child
.id
.replace("RROW-", "");
1302 showArticleInHeadlines(_active_article_id
, true);
1303 updateSelectedPrompt();
1309 if (!_infscroll_disable
) {
1310 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1312 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1313 __("Loading, please wait...") + "</span>";
1315 loadMoreHeadlines();
1322 updateFloatingTitle();
1325 catchupCurrentBatchIfNeeded();
1327 if (getInitParam("cdm_auto_catchup") == 1) {
1329 // let's get DOM some time to settle down
1330 var ts
= new Date().getTime();
1331 if (ts
- _last_headlines_update
< 100) return;
1333 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1335 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1336 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1338 var id
= child
.id
.replace("RROW-", "");
1340 if (catchup_id_batch
.indexOf(id
) == -1)
1341 catchup_id_batch
.push(id
);
1343 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1348 if (_infscroll_disable
) {
1349 var child
= $$("#headlines-frame div[id*=RROW]").last();
1351 if (child
&& $("headlines-frame").scrollTop
>
1352 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1354 console
.log("we seem to be at an end");
1356 if (getInitParam("on_catchup_show_next_feed") == "1") {
1357 openNextUnreadFeed();
1364 console
.warn("headlines_scroll_handler: " + e
);
1368 function openNextUnreadFeed() {
1370 var is_cat
= activeFeedIsCat();
1371 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1372 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1374 exception_error("openNextUnreadFeed", e
);
1378 function catchupBatchedArticles() {
1380 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1382 console
.log("catchupBatchedArticles: working");
1384 // make a copy of the array
1385 var batch
= catchup_id_batch
.slice();
1386 var query
= "?op=rpc&method=catchupSelected" +
1387 "&cmode=0&ids=" + param_escape(batch
.toString());
1391 _catchup_request_sent
= true;
1393 new Ajax
.Request("backend.php", {
1395 onComplete: function(transport
) {
1396 handle_rpc_json(transport
);
1398 _catchup_request_sent
= false;
1400 reply
= JSON
.parse(transport
.responseText
);
1401 var batch
= reply
.ids
;
1403 batch
.each(function(id
) {
1405 var elem
= $("RROW-" + id
);
1406 if (elem
) elem
.removeClassName("Unread");
1407 catchup_id_batch
.remove(id
);
1410 updateFloatingTitle(true);
1416 exception_error("catchupBatchedArticles", e
);
1420 function catchupRelativeToArticle(below
, id
) {
1424 if (!id
) id
= getActiveArticleId();
1427 alert(__("No article is selected."));
1431 var visible_ids
= getVisibleArticleIds();
1433 var ids_to_mark
= new Array();
1436 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1437 if (visible_ids
[i
] != id
) {
1438 var e
= $("RROW-" + visible_ids
[i
]);
1440 if (e
&& e
.hasClassName("Unread")) {
1441 ids_to_mark
.push(visible_ids
[i
]);
1448 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1449 if (visible_ids
[i
] != id
) {
1450 var e
= $("RROW-" + visible_ids
[i
]);
1452 if (e
&& e
.hasClassName("Unread")) {
1453 ids_to_mark
.push(visible_ids
[i
]);
1461 if (ids_to_mark
.length
== 0) {
1462 alert(__("No articles found to mark"));
1464 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1466 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1468 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1469 var e
= $("RROW-" + ids_to_mark
[i
]);
1470 e
.removeClassName("Unread");
1473 var query
= "?op=rpc&method=catchupSelected" +
1474 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1476 new Ajax
.Request("backend.php", {
1478 onComplete: function(transport
) {
1479 handle_rpc_json(transport
);
1486 exception_error("catchupRelativeToArticle", e
);
1490 function cdmCollapseArticle(event
, id
, unmark
) {
1492 if (unmark
== undefined) unmark
= true;
1494 var row
= $("RROW-" + id
);
1495 var elem
= $("CICD-" + id
);
1498 var collapse
= $$("div#RROW-" + id
+
1499 " span[class='collapseBtn']")[0];
1502 Element
.show("CEXC-" + id
);
1503 Element
.hide(collapse
);
1506 row
.removeClassName("active");
1508 markHeadline(id
, false);
1510 if (id
== getActiveArticleId()) {
1511 setActiveArticleId(0);
1514 updateSelectedPrompt();
1517 if (event
) Event
.stop(event
);
1519 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1521 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1522 scrollToRowId(row
.id
);
1524 $("floatingTitle").style
.visibility
= "hidden";
1525 $("floatingTitle").setAttribute("rowid", false);
1529 exception_error("cdmCollapseArticle", e
);
1533 function cdmExpandArticle(id
, noexpand
) {
1535 console
.log("cdmExpandArticle " + id
);
1537 if (!$("RROW-" + id
)) return false;
1539 var oldrow
= $("RROW-" + getActiveArticleId());
1541 var elem
= $("CICD-" + getActiveArticleId());
1543 if (id
== getActiveArticleId() && Element
.visible(elem
))
1546 selectArticles("none");
1548 var old_offset
= $("RROW-" + id
).offsetTop
;
1550 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1551 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1552 " span[class='collapseBtn']")[0];
1555 Element
.show("CEXC-" + getActiveArticleId());
1556 Element
.hide(collapse
);
1559 if (oldrow
) oldrow
.removeClassName("active");
1561 setActiveArticleId(id
);
1563 elem
= $("CICD-" + id
);
1565 var collapse
= $$("div#RROW-" + id
+
1566 " span[class='collapseBtn']")[0];
1568 var cencw
= $("CENCW-" + id
);
1570 if (!Element
.visible(elem
) && !noexpand
) {
1572 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1573 cencw
.setAttribute('id', '');
1574 Element
.show(cencw
);
1578 Element
.hide("CEXC-" + id
);
1579 Element
.show(collapse
);
1582 var new_offset
= $("RROW-" + id
).offsetTop
;
1584 if (old_offset
> new_offset
)
1585 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1588 if (catchup_id_batch
.indexOf(id
) == -1)
1589 catchup_id_batch
.push(id
);
1591 catchupCurrentBatchIfNeeded();
1595 $("RROW-" + id
).addClassName("active");
1597 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1600 exception_error("cdmExpandArticle", e
);
1606 function getArticleUnderPointer() {
1607 return post_under_pointer
;
1610 function scrollArticle(offset
) {
1613 var ci
= $("content-insert");
1615 ci
.scrollTop
+= offset
;
1618 var hi
= $("headlines-frame");
1620 hi
.scrollTop
+= offset
;
1625 exception_error("scrollArticle", e
);
1629 function show_labels_in_headlines(transport
) {
1631 var data
= JSON
.parse(transport
.responseText
);
1634 data
['info-for-headlines'].each(function(elem
) {
1635 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1636 ctr
.innerHTML
= elem
.labels
;
1641 exception_error("show_labels_in_headlines", e
);
1645 function dismissArticle(id
) {
1647 var elem
= $("RROW-" + id
);
1651 toggleUnread(id
, 0, true);
1653 new Effect
.Fade(elem
, {duration
: 0.5});
1655 // Remove the content, too
1656 var elem_content
= $("CICD-" + id
);
1658 Element
.remove(elem_content
);
1661 if (id
== getActiveArticleId()) {
1662 setActiveArticleId(0);
1666 exception_error("dismissArticle", e
);
1670 function dismissSelectedArticles() {
1673 var ids
= getVisibleArticleIds();
1677 for (var i
= 0; i
< ids
.length
; i
++) {
1678 var elem
= $("RROW-" + ids
[i
]);
1680 if (elem
.className
&& elem
.hasClassName("Selected") &&
1681 ids
[i
] != getActiveArticleId()) {
1682 new Effect
.Fade(elem
, {duration
: 0.5});
1685 // Remove the content, too
1686 var elem_content
= $("CICD-" + ids
[i
]);
1688 Element
.remove(elem_content
);
1696 selectionToggleUnread(false);
1700 exception_error("dismissSelectedArticles", e
);
1704 function dismissReadArticles() {
1707 var ids
= getVisibleArticleIds();
1710 for (var i
= 0; i
< ids
.length
; i
++) {
1711 var elem
= $("RROW-" + ids
[i
]);
1713 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1714 !elem
.hasClassName("Selected")) {
1716 new Effect
.Fade(elem
, {duration
: 0.5});
1718 // Remove the content, too
1719 var elem_content
= $("CICD-" + ids
[i
]);
1721 Element
.remove(elem_content
);
1729 exception_error("dismissReadArticles", e
);
1733 // we don't really hide rows anymore
1734 function getVisibleArticleIds() {
1735 return getLoadedArticleIds();
1741 getLoadedArticleIds().each(function(id) {
1742 var elem = $("RROW-" + id);
1743 if (elem && Element.visible(elem))
1748 exception_error("getVisibleArticleIds", e);
1754 function cdmClicked(event
, id
) {
1756 //var shift_key = event.shiftKey;
1758 if (!event
.ctrlKey
) {
1760 if (!getInitParam("cdm_expanded")) {
1761 return cdmExpandArticle(id
);
1764 var elem
= $("RROW-" + getActiveArticleId());
1766 if (elem
) elem
.removeClassName("active");
1768 selectArticles("none");
1771 var elem
= $("RROW-" + id
);
1772 var article_is_unread
= elem
.hasClassName("Unread");
1774 elem
.removeClassName("Unread");
1775 elem
.addClassName("active");
1777 setActiveArticleId(id
);
1779 if (article_is_unread
) {
1780 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1781 updateFloatingTitle(true);
1784 var query
= "?op=rpc&method=catchupSelected" +
1785 "&cmode=0&ids=" + param_escape(id
);
1787 new Ajax
.Request("backend.php", {
1789 onComplete: function(transport
) {
1790 handle_rpc_json(transport
);
1793 return !event
.shiftKey
;
1796 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1798 toggleSelected(id
, true);
1800 var elem
= $("RROW-" + id
);
1801 var article_is_unread
= elem
.hasClassName("Unread");
1803 if (article_is_unread
) {
1804 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1807 toggleUnread(id
, 0, false);
1809 openArticleInNewWindow(id
);
1812 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1813 request_counters(unread_in_buffer
== 0);
1816 exception_error("cdmClicked");
1822 function hlClicked(event
, id
) {
1824 if (event
.which
== 2) {
1827 } else if (event
.ctrlKey
) {
1828 toggleSelected(id
, true);
1829 toggleUnread(id
, 0, false);
1830 openArticleInNewWindow(id
);
1838 exception_error("hlClicked");
1842 function getFirstVisibleHeadlineId() {
1843 var rows
= getVisibleArticleIds();
1848 function getLastVisibleHeadlineId() {
1849 var rows
= getVisibleArticleIds();
1850 return rows
[rows
.length
-1];
1853 function openArticleInNewWindow(id
) {
1854 toggleUnread(id
, 0, false);
1855 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1858 function isCdmMode() {
1859 return getInitParam("combined_display_mode");
1862 function markHeadline(id
, marked
) {
1863 if (marked
== undefined) marked
= true;
1865 var row
= $("RROW-" + id
);
1867 var check
= dijit
.getEnclosingWidget(
1868 row
.getElementsByClassName("rchk")[0]);
1871 check
.attr("checked", marked
);
1875 row
.addClassName("Selected");
1877 row
.removeClassName("Selected");
1881 function getRelativePostIds(id
, limit
) {
1887 if (!limit
) limit
= 6; //3
1889 var ids
= getVisibleArticleIds();
1891 for (var i
= 0; i
< ids
.length
; i
++) {
1893 for (var k
= 1; k
<= limit
; k
++) {
1894 //if (i > k-1) tmp.push(ids[i-k]);
1895 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1902 exception_error("getRelativePostIds", e
);
1908 function correctHeadlinesOffset(id
) {
1912 var container
= $("headlines-frame");
1913 var row
= $("RROW-" + id
);
1915 if (!container
|| !row
) return;
1917 var viewport
= container
.offsetHeight
;
1919 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1920 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1922 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1923 //console.log("Vport: " + viewport);
1925 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1926 container
.scrollTop
= row
.offsetTop
;
1927 } else if (rel_offset_bottom
> viewport
) {
1929 /* doesn't properly work with Opera in some cases because
1930 Opera fucks up element scrolling */
1932 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1936 exception_error("correctHeadlinesOffset", e
);
1941 function headlineActionsChange(elem
) {
1944 elem
.attr('value', 'false');
1946 exception_error("headlineActionsChange", e
);
1950 function closeArticlePanel() {
1952 if (dijit
.byId("content-insert"))
1953 dijit
.byId("headlines-wrap-inner").removeChild(
1954 dijit
.byId("content-insert"));
1957 function initFloatingMenu() {
1959 if (dijit
.byId("floatingMenu"))
1960 dijit
.byId("floatingMenu").destroyRecursive();
1962 var menu
= new dijit
.Menu({
1964 targetNodeIds
: ["floatingTitle"]
1967 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1969 headlinesMenuCommon(menu
, id
);
1973 exception_error("initFloatingMenu", e
);
1977 function headlinesMenuCommon(menu
, base_id
) {
1980 menu
.addChild(new dijit
.MenuItem({
1981 label
: __("Open original article"),
1982 onClick: function(event
) {
1983 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1986 menu
.addChild(new dijit
.MenuItem({
1987 label
: __("Display article URL"),
1988 onClick: function(event
) {
1989 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1992 menu
.addChild(new dijit
.MenuSeparator());
1994 menu
.addChild(new dijit
.MenuItem({
1995 label
: __("Toggle unread"),
1996 onClick: function(event
) {
1997 var ids
= getSelectedArticleIds2();
1999 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2000 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2002 selectionToggleUnread(undefined, false, true, ids
);
2005 menu
.addChild(new dijit
.MenuItem({
2006 label
: __("Toggle starred"),
2007 onClick: function(event
) {
2008 var ids
= getSelectedArticleIds2();
2010 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2011 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2013 selectionToggleMarked(undefined, false, true, ids
);
2016 menu
.addChild(new dijit
.MenuItem({
2017 label
: __("Toggle published"),
2018 onClick: function(event
) {
2019 var ids
= getSelectedArticleIds2();
2021 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2022 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2024 selectionTogglePublished(undefined, false, true, ids
);
2027 menu
.addChild(new dijit
.MenuSeparator());
2029 menu
.addChild(new dijit
.MenuItem({
2030 label
: __("Mark above as read"),
2031 onClick: function(event
) {
2032 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2035 menu
.addChild(new dijit
.MenuItem({
2036 label
: __("Mark below as read"),
2037 onClick: function(event
) {
2038 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2042 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2046 menu
.addChild(new dijit
.MenuSeparator());
2048 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2049 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2051 labels
.each(function(label
) {
2052 var id
= label
.id
[0];
2053 var bare_id
= id
.substr(id
.indexOf(":")+1);
2054 var name
= label
.name
[0];
2056 bare_id
= feed_to_label_id(bare_id
);
2058 labelAddMenu
.addChild(new dijit
.MenuItem({
2061 onClick: function(event
) {
2062 var ids
= getSelectedArticleIds2();
2064 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2066 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2068 selectionAssignLabel(this.labelId
, ids
);
2071 labelDelMenu
.addChild(new dijit
.MenuItem({
2074 onClick: function(event
) {
2075 var ids
= getSelectedArticleIds2();
2077 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2079 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2081 selectionRemoveLabel(this.labelId
, ids
);
2086 menu
.addChild(new dijit
.PopupMenuItem({
2087 label
: __("Assign label"),
2091 menu
.addChild(new dijit
.PopupMenuItem({
2092 label
: __("Remove label"),
2100 exception_error("headlinesMenuCommon", e
);
2104 function initHeadlinesMenu() {
2106 if (dijit
.byId("headlinesMenu"))
2107 dijit
.byId("headlinesMenu").destroyRecursive();
2112 nodes
= $$("#headlines-frame > div[id*=RROW]");
2114 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2117 nodes
.each(function(node
) {
2121 var menu
= new dijit
.Menu({
2122 id
: "headlinesMenu",
2126 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2127 var callerNode
= event
.target
, match
= null, tries
= 0;
2129 while (match
== null && callerNode
&& tries
<= 3) {
2130 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2131 callerNode
= callerNode
.parentNode
;
2135 if (match
) this.callerRowId
= parseInt(match
[1]);
2139 headlinesMenuCommon(menu
, false);
2143 /* vgroup feed title menu */
2145 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2148 nodes
.each(function(node
) {
2152 if (ids
.length
> 0) {
2153 if (dijit
.byId("headlinesFeedTitleMenu"))
2154 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2156 var menu
= new dijit
.Menu({
2157 id
: "headlinesFeedTitleMenu",
2161 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2162 var callerNode
= event
.target
, match
= null, tries
= 0;
2164 while (match
== null && callerNode
&& tries
<= 3) {
2165 console
.log(callerNode
.id
);
2167 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2168 callerNode
= callerNode
.parentNode
;
2171 console
.log(match
[1]);
2174 if (match
) this.callerRowId
= parseInt(match
[1]);
2178 menu
.addChild(new dijit
.MenuItem({
2179 label
: __("Select articles in group"),
2180 onClick: function(event
) {
2181 selectArticles("all",
2182 "#headlines-frame > div[id*=RROW]"+
2183 "[orig-feed-id='"+menu
.callerRowId
+"']");
2187 menu
.addChild(new dijit
.MenuItem({
2188 label
: __("Mark group as read"),
2189 onClick: function(event
) {
2190 selectArticles("none");
2191 selectArticles("all",
2192 "#headlines-frame > div[id*=RROW]"+
2193 "[orig-feed-id='"+menu
.callerRowId
+"']");
2199 menu
.addChild(new dijit
.MenuItem({
2200 label
: __("Mark feed as read"),
2201 onClick: function(event
) {
2202 catchupFeedInGroup(menu
.callerRowId
);
2205 menu
.addChild(new dijit
.MenuItem({
2206 label
: __("Edit feed"),
2207 onClick: function(event
) {
2208 editFeed(menu
.callerRowId
);
2216 exception_error("initHeadlinesMenu", e
);
2220 function cache_set(id
, obj
) {
2221 //console.log("cache_set: " + id);
2224 sessionStorage
[id
] = obj
;
2226 sessionStorage
.clear();
2230 function cache_get(id
) {
2232 return sessionStorage
[id
];
2235 function cache_clear() {
2237 sessionStorage
.clear();
2240 function cache_delete(id
) {
2242 sessionStorage
.removeItem(id
);
2245 function cancelSearch() {
2250 exception_error("cancelSearch", e
);
2254 function setSelectionScore() {
2256 var ids
= getSelectedArticleIds2();
2258 if (ids
.length
> 0) {
2261 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2263 if (score
!= undefined) {
2264 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2265 "&score=" + param_escape(score
);
2267 new Ajax
.Request("backend.php", {
2269 onComplete: function(transport
) {
2270 var reply
= JSON
.parse(transport
.responseText
);
2274 ids
.each(function(id
) {
2275 var row
= $("RROW-" + id
);
2278 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2281 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2282 reply
["score_pic"]);
2283 pic
.setAttribute("score", score
);
2292 alert(__("No articles are selected."));
2295 exception_error("setSelectionScore", e
);
2299 function updateScore(id
) {
2301 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2305 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2307 new Ajax
.Request("backend.php", {
2309 onComplete: function(transport
) {
2310 console
.log(transport
.responseText
);
2312 var reply
= JSON
.parse(transport
.responseText
);
2315 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2316 pic
.setAttribute("score", reply
["score"]);
2317 pic
.setAttribute("title", reply
["score"]);
2323 exception_error("updateScore", e
);
2327 function changeScore(id
, pic
) {
2329 var score
= pic
.getAttribute("score");
2331 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2333 if (new_score
!= undefined) {
2335 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2336 "&score=" + param_escape(new_score
);
2338 new Ajax
.Request("backend.php", {
2340 onComplete: function(transport
) {
2341 var reply
= JSON
.parse(transport
.responseText
);
2344 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2345 pic
.setAttribute("score", new_score
);
2346 pic
.setAttribute("title", new_score
);
2351 exception_error("changeScore", e
);
2355 function displayArticleUrl(id
) {
2357 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2359 new Ajax
.Request("backend.php", {
2361 onComplete: function(transport
) {
2362 var reply
= JSON
.parse(transport
.responseText
);
2364 if (reply
&& reply
.link
) {
2365 prompt(__("Article URL:"), reply
.link
);
2369 exception_error("changeScore", e
);
2373 function scrollToRowId(id
) {
2378 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2381 exception_error("scrollToRowId", e
);
2385 function updateFloatingTitle(unread_only
) {
2387 if (!isCdmMode()) return;
2389 var hf
= $("headlines-frame");
2391 var elems
= $$("#headlines-frame > div[id*=RROW]");
2393 for (var i
= 0; i
< elems
.length
; i
++) {
2395 var child
= elems
[i
];
2397 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2399 var header
= child
.getElementsByClassName("cdmHeader")[0];
2401 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2402 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2403 $("floatingTitle").setAttribute("rowid", child
.id
);
2404 $("floatingTitle").innerHTML
= header
.innerHTML
;
2405 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2409 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2412 cb
.parentNode
.removeChild(cb
);
2415 if (child
.hasClassName("Unread"))
2416 $("floatingTitle").addClassName("Unread");
2418 $("floatingTitle").removeClassName("Unread");
2420 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2423 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2424 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2425 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2426 $("floatingTitle").style
.visibility
= "visible";
2428 $("floatingTitle").style
.visibility
= "hidden";
2436 exception_error("updateFloatingTitle", e
);
2440 function catchupCurrentBatchIfNeeded() {
2441 if (catchup_id_batch
.length
> 0) {
2442 window
.clearTimeout(catchup_timeout_id
);
2443 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2445 if (catchup_id_batch
.length
>= 10) {
2446 catchupBatchedArticles();
2451 function cdmFooterClick(event
) {
2452 event
.stopPropagation();