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 cdmClicked(event
, id
) {
1636 //var shift_key = event.shiftKey;
1638 if (!event
.ctrlKey
&& !event
.metaKey
) {
1640 if (!getInitParam("cdm_expanded")) {
1641 return cdmExpandArticle(id
);
1644 var elem
= $("RROW-" + getActiveArticleId());
1646 if (elem
) elem
.removeClassName("active");
1648 selectArticles("none");
1651 var elem
= $("RROW-" + id
);
1652 var article_is_unread
= elem
.hasClassName("Unread");
1654 elem
.removeClassName("Unread");
1655 elem
.addClassName("active");
1657 setActiveArticleId(id
);
1659 if (article_is_unread
) {
1660 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1661 updateFloatingTitle(true);
1664 var query
= "?op=rpc&method=catchupSelected" +
1665 "&cmode=0&ids=" + param_escape(id
);
1667 new Ajax
.Request("backend.php", {
1669 onComplete: function(transport
) {
1670 handle_rpc_json(transport
);
1673 return !event
.shiftKey
;
1676 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1678 toggleSelected(id
, true);
1680 var elem
= $("RROW-" + id
);
1681 var article_is_unread
= elem
.hasClassName("Unread");
1683 if (article_is_unread
) {
1684 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1687 toggleUnread(id
, 0, false);
1689 openArticleInNewWindow(id
);
1692 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1693 request_counters(unread_in_buffer
== 0);
1696 exception_error("cdmClicked");
1702 function hlClicked(event
, id
) {
1704 if (event
.which
== 2) {
1707 } else if (event
.ctrlKey
|| event
.metaKey
) {
1708 toggleSelected(id
, true);
1709 toggleUnread(id
, 0, false);
1710 openArticleInNewWindow(id
);
1718 exception_error("hlClicked");
1722 function openArticleInNewWindow(id
) {
1723 toggleUnread(id
, 0, false);
1724 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1727 function isCdmMode() {
1728 return getInitParam("combined_display_mode");
1731 function markHeadline(id
, marked
) {
1732 if (marked
== undefined) marked
= true;
1734 var row
= $("RROW-" + id
);
1736 var check
= dijit
.getEnclosingWidget(
1737 row
.getElementsByClassName("rchk")[0]);
1740 check
.attr("checked", marked
);
1744 row
.addClassName("Selected");
1746 row
.removeClassName("Selected");
1750 function getRelativePostIds(id
, limit
) {
1756 if (!limit
) limit
= 6; //3
1758 var ids
= getLoadedArticleIds();
1760 for (var i
= 0; i
< ids
.length
; i
++) {
1762 for (var k
= 1; k
<= limit
; k
++) {
1763 //if (i > k-1) tmp.push(ids[i-k]);
1764 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1771 exception_error("getRelativePostIds", e
);
1777 function correctHeadlinesOffset(id
) {
1781 var container
= $("headlines-frame");
1782 var row
= $("RROW-" + id
);
1784 if (!container
|| !row
) return;
1786 var viewport
= container
.offsetHeight
;
1788 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1789 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1791 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1792 //console.log("Vport: " + viewport);
1794 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1795 container
.scrollTop
= row
.offsetTop
;
1796 } else if (rel_offset_bottom
> viewport
) {
1798 /* doesn't properly work with Opera in some cases because
1799 Opera fucks up element scrolling */
1801 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1805 exception_error("correctHeadlinesOffset", e
);
1810 function headlineActionsChange(elem
) {
1813 elem
.attr('value', 'false');
1815 exception_error("headlineActionsChange", e
);
1819 function closeArticlePanel() {
1821 if (dijit
.byId("content-insert"))
1822 dijit
.byId("headlines-wrap-inner").removeChild(
1823 dijit
.byId("content-insert"));
1826 function initFloatingMenu() {
1828 if (dijit
.byId("floatingMenu"))
1829 dijit
.byId("floatingMenu").destroyRecursive();
1831 var menu
= new dijit
.Menu({
1833 targetNodeIds
: ["floatingTitle"]
1836 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1838 headlinesMenuCommon(menu
, id
);
1842 exception_error("initFloatingMenu", e
);
1846 function headlinesMenuCommon(menu
, base_id
) {
1849 menu
.addChild(new dijit
.MenuItem({
1850 label
: __("Open original article"),
1851 onClick: function(event
) {
1852 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1855 menu
.addChild(new dijit
.MenuItem({
1856 label
: __("Display article URL"),
1857 onClick: function(event
) {
1858 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1861 menu
.addChild(new dijit
.MenuSeparator());
1863 menu
.addChild(new dijit
.MenuItem({
1864 label
: __("Toggle unread"),
1865 onClick: function(event
) {
1866 var ids
= getSelectedArticleIds2();
1868 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1869 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1871 selectionToggleUnread(undefined, false, true, ids
);
1874 menu
.addChild(new dijit
.MenuItem({
1875 label
: __("Toggle starred"),
1876 onClick: function(event
) {
1877 var ids
= getSelectedArticleIds2();
1879 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1880 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1882 selectionToggleMarked(undefined, false, true, ids
);
1885 menu
.addChild(new dijit
.MenuItem({
1886 label
: __("Toggle published"),
1887 onClick: function(event
) {
1888 var ids
= getSelectedArticleIds2();
1890 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1891 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1893 selectionTogglePublished(undefined, false, true, ids
);
1896 menu
.addChild(new dijit
.MenuSeparator());
1898 menu
.addChild(new dijit
.MenuItem({
1899 label
: __("Mark above as read"),
1900 onClick: function(event
) {
1901 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
1904 menu
.addChild(new dijit
.MenuItem({
1905 label
: __("Mark below as read"),
1906 onClick: function(event
) {
1907 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
1911 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1915 menu
.addChild(new dijit
.MenuSeparator());
1917 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1918 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1920 labels
.each(function(label
) {
1921 var id
= label
.id
[0];
1922 var bare_id
= id
.substr(id
.indexOf(":")+1);
1923 var name
= label
.name
[0];
1925 bare_id
= feed_to_label_id(bare_id
);
1927 labelAddMenu
.addChild(new dijit
.MenuItem({
1930 onClick: function(event
) {
1931 var ids
= getSelectedArticleIds2();
1933 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
1935 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1937 selectionAssignLabel(this.labelId
, ids
);
1940 labelDelMenu
.addChild(new dijit
.MenuItem({
1943 onClick: function(event
) {
1944 var ids
= getSelectedArticleIds2();
1946 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
1948 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1950 selectionRemoveLabel(this.labelId
, ids
);
1955 menu
.addChild(new dijit
.PopupMenuItem({
1956 label
: __("Assign label"),
1960 menu
.addChild(new dijit
.PopupMenuItem({
1961 label
: __("Remove label"),
1969 exception_error("headlinesMenuCommon", e
);
1973 function initHeadlinesMenu() {
1975 if (dijit
.byId("headlinesMenu"))
1976 dijit
.byId("headlinesMenu").destroyRecursive();
1981 nodes
= $$("#headlines-frame > div[id*=RROW]");
1983 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1986 nodes
.each(function(node
) {
1990 var menu
= new dijit
.Menu({
1991 id
: "headlinesMenu",
1995 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1996 var callerNode
= event
.target
, match
= null, tries
= 0;
1998 while (match
== null && callerNode
&& tries
<= 3) {
1999 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2000 callerNode
= callerNode
.parentNode
;
2004 if (match
) this.callerRowId
= parseInt(match
[1]);
2008 headlinesMenuCommon(menu
, false);
2012 /* vgroup feed title menu */
2014 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2017 nodes
.each(function(node
) {
2021 if (ids
.length
> 0) {
2022 if (dijit
.byId("headlinesFeedTitleMenu"))
2023 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2025 var menu
= new dijit
.Menu({
2026 id
: "headlinesFeedTitleMenu",
2030 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2031 var callerNode
= event
.target
, match
= null, tries
= 0;
2033 while (match
== null && callerNode
&& tries
<= 3) {
2034 console
.log(callerNode
.id
);
2036 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2037 callerNode
= callerNode
.parentNode
;
2040 console
.log(match
[1]);
2043 if (match
) this.callerRowId
= parseInt(match
[1]);
2047 menu
.addChild(new dijit
.MenuItem({
2048 label
: __("Select articles in group"),
2049 onClick: function(event
) {
2050 selectArticles("all",
2051 "#headlines-frame > div[id*=RROW]"+
2052 "[orig-feed-id='"+menu
.callerRowId
+"']");
2056 menu
.addChild(new dijit
.MenuItem({
2057 label
: __("Mark group as read"),
2058 onClick: function(event
) {
2059 selectArticles("none");
2060 selectArticles("all",
2061 "#headlines-frame > div[id*=RROW]"+
2062 "[orig-feed-id='"+menu
.callerRowId
+"']");
2068 menu
.addChild(new dijit
.MenuItem({
2069 label
: __("Mark feed as read"),
2070 onClick: function(event
) {
2071 catchupFeedInGroup(menu
.callerRowId
);
2074 menu
.addChild(new dijit
.MenuItem({
2075 label
: __("Edit feed"),
2076 onClick: function(event
) {
2077 editFeed(menu
.callerRowId
);
2085 exception_error("initHeadlinesMenu", e
);
2089 function cache_set(id
, obj
) {
2090 //console.log("cache_set: " + id);
2093 sessionStorage
[id
] = obj
;
2095 sessionStorage
.clear();
2099 function cache_get(id
) {
2101 return sessionStorage
[id
];
2104 function cache_clear() {
2106 sessionStorage
.clear();
2109 function cache_delete(id
) {
2111 sessionStorage
.removeItem(id
);
2114 function cancelSearch() {
2119 exception_error("cancelSearch", e
);
2123 function setSelectionScore() {
2125 var ids
= getSelectedArticleIds2();
2127 if (ids
.length
> 0) {
2130 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2132 if (score
!= undefined) {
2133 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2134 "&score=" + param_escape(score
);
2136 new Ajax
.Request("backend.php", {
2138 onComplete: function(transport
) {
2139 var reply
= JSON
.parse(transport
.responseText
);
2143 ids
.each(function(id
) {
2144 var row
= $("RROW-" + id
);
2147 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2150 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2151 reply
["score_pic"]);
2152 pic
.setAttribute("score", score
);
2161 alert(__("No articles are selected."));
2164 exception_error("setSelectionScore", e
);
2168 function updateScore(id
) {
2170 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2174 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2176 new Ajax
.Request("backend.php", {
2178 onComplete: function(transport
) {
2179 console
.log(transport
.responseText
);
2181 var reply
= JSON
.parse(transport
.responseText
);
2184 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2185 pic
.setAttribute("score", reply
["score"]);
2186 pic
.setAttribute("title", reply
["score"]);
2192 exception_error("updateScore", e
);
2196 function changeScore(id
, pic
) {
2198 var score
= pic
.getAttribute("score");
2200 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2202 if (new_score
!= undefined) {
2204 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2205 "&score=" + param_escape(new_score
);
2207 new Ajax
.Request("backend.php", {
2209 onComplete: function(transport
) {
2210 var reply
= JSON
.parse(transport
.responseText
);
2213 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2214 pic
.setAttribute("score", new_score
);
2215 pic
.setAttribute("title", new_score
);
2220 exception_error("changeScore", e
);
2224 function displayArticleUrl(id
) {
2226 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2228 new Ajax
.Request("backend.php", {
2230 onComplete: function(transport
) {
2231 var reply
= JSON
.parse(transport
.responseText
);
2233 if (reply
&& reply
.link
) {
2234 prompt(__("Article URL:"), reply
.link
);
2238 exception_error("changeScore", e
);
2242 function scrollToRowId(id
) {
2247 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2250 exception_error("scrollToRowId", e
);
2254 function updateFloatingTitle(unread_only
) {
2256 if (!isCdmMode()) return;
2258 var hf
= $("headlines-frame");
2260 var elems
= $$("#headlines-frame > div[id*=RROW]");
2262 for (var i
= 0; i
< elems
.length
; i
++) {
2264 var child
= elems
[i
];
2266 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2268 var header
= child
.getElementsByClassName("cdmHeader")[0];
2270 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2271 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2272 $("floatingTitle").setAttribute("rowid", child
.id
);
2273 $("floatingTitle").innerHTML
= header
.innerHTML
;
2274 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2278 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2281 cb
.parentNode
.removeChild(cb
);
2284 if (child
.hasClassName("Unread"))
2285 $("floatingTitle").addClassName("Unread");
2287 $("floatingTitle").removeClassName("Unread");
2289 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2292 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2293 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2294 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2295 $("floatingTitle").style
.visibility
= "visible";
2297 $("floatingTitle").style
.visibility
= "hidden";
2305 exception_error("updateFloatingTitle", e
);
2309 function catchupCurrentBatchIfNeeded() {
2310 if (catchup_id_batch
.length
> 0) {
2311 window
.clearTimeout(catchup_timeout_id
);
2312 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2314 if (catchup_id_batch
.length
>= 10) {
2315 catchupBatchedArticles();
2320 function cdmFooterClick(event
) {
2321 event
.stopPropagation();