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 has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
20 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
22 handle_rpc_json(transport
);
24 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
32 reply
= JSON
.parse(transport
.responseText
);
39 is_cat
= reply
['headlines']['is_cat'];
40 feed_id
= reply
['headlines']['id'];
43 var content
= reply
['headlines']['content'];
45 content
= content
+ "<div id='headlines-spacer'></div>";
49 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
52 /* dijit.getEnclosingWidget(
53 document.forms["main_toolbar_form"].update).attr('disabled',
54 is_cat || feed_id <= 0); */
57 if (infscroll_req
== false) {
58 $("headlines-frame").scrollTop
= 0;
60 $("floatingTitle").style
.visibility
= "hidden";
61 $("floatingTitle").setAttribute("rowid", 0);
62 $("floatingTitle").innerHTML
= "";
66 $("headlines-frame").removeClassName("cdm");
67 $("headlines-frame").removeClassName("normal");
69 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
71 var headlines_count
= reply
['headlines-info']['count'];
73 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
75 if (parseInt(headlines_count
) < 30) {
76 _infscroll_disable
= 1;
78 _infscroll_disable
= 0;
81 current_first_id
= reply
['headlines']['first_id'];
82 var counters
= reply
['counters'];
83 var articles
= reply
['articles'];
84 //var runtime_info = reply['runtime-info'];
86 if (infscroll_req
== false) {
87 loaded_article_ids
= [];
89 dojo
.html
.set($("headlines-toolbar"),
90 reply
['headlines']['toolbar'],
91 {parseContent
: true});
93 dijit
.byId("headlines-frame").attr("content", "");
95 reply
['headlines']['content'].each(function(row
) {
96 if (loaded_article_ids
.indexOf(row
.id
) == -1) {
97 loaded_article_ids
.push(row
.id
);
100 var tmp
= new Element("div");
101 tmp
.innerHTML
= row
.html
;
103 dojo
.parser
.parse(tmp
.firstChild
);
104 dijit
.byId("headlines-frame").domNode
.appendChild(tmp
.firstChild
);
108 var hsp
= $("headlines-spacer");
109 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
110 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
114 if (_infscroll_disable
)
115 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
116 __("Click to open next unread feed.") + "</a>";
119 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
120 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
126 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
127 console
.log("adding some more headlines: " + headlines_count
);
129 var c
= dijit
.byId("headlines-frame");
130 var ids
= getSelectedArticleIds2();
132 var hsp
= $("headlines-spacer");
135 c
.domNode
.removeChild(hsp
);
137 reply
['headlines']['content'].each(function(row
) {
138 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.kind
== 'feed_title') {
139 loaded_article_ids
.push(row
.id
);
141 var tmp
= new Element("div");
142 tmp
.innerHTML
= row
.html
;
144 dojo
.parser
.parse(tmp
.firstChild
);
145 dijit
.byId("headlines-frame").domNode
.appendChild(tmp
.firstChild
);
151 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
152 c
.domNode
.appendChild(hsp
);
154 console
.log("added " + reply
['headlines']['content'].size() + " headlines");
156 if (reply
['headlines']['content'].size() == 0) _infscroll_disable
= true;
158 console
.log("restore selected ids: " + ids
);
160 for (var i
= 0; i
< ids
.length
; i
++) {
161 markHeadline(ids
[i
]);
166 if (_infscroll_disable
) {
167 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
168 __("Click to open next unread feed.") + "</a>";
172 console
.log("no new headlines received");
174 var first_id_changed
= reply
['headlines']['first_id_changed'];
175 console
.log("first id changed:" + first_id_changed
);
177 var hsp
= $("headlines-spacer");
180 if (first_id_changed
) {
181 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
182 __("New articles found, reload feed to continue.") + "</a>";
184 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
185 __("Click to open next unread feed.") + "</a>";
194 for (var i
= 0; i
< articles
.length
; i
++) {
195 var a_id
= articles
[i
]['id'];
196 cache_set("article:" + a_id
, articles
[i
]['content']);
199 console
.log("no cached articles received");
203 parse_counters(counters
);
205 request_counters(true);
208 console
.error("Invalid object received: " + transport
.responseText
);
209 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
210 __('Could not update headlines (invalid object received - see error console for details)') +
214 _infscroll_request_sent
= 0;
215 _last_headlines_update
= new Date().getTime();
217 unpackVisibleHeadlines();
219 // if we have some more space in the buffer, why not try to fill it
221 if (!_infscroll_disable
&& $("headlines-spacer") &&
222 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
224 window
.setTimeout(function() {
232 exception_error("headlines_callback2", e
, transport
);
236 function render_article(article
) {
238 dijit
.byId("headlines-wrap-inner").addChild(
239 dijit
.byId("content-insert"));
241 var c
= dijit
.byId("content-insert");
244 c
.domNode
.scrollTop
= 0;
247 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
249 c
.attr('content', article
);
251 correctHeadlinesOffset(getActiveArticleId());
258 exception_error("render_article", e
);
262 function showArticleInHeadlines(id
, noexpand
) {
265 selectArticles("none");
267 var crow
= $("RROW-" + id
);
271 var article_is_unread
= crow
.hasClassName("Unread");
274 crow
.removeClassName("Unread");
275 crow
.addClassName("active");
277 selectArticles('none');
279 var view_mode
= false;
282 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
283 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
290 if (article_is_unread
&& !noexpand
)
291 _force_scheduled_update
= true;
294 exception_error("showArticleInHeadlines", e
);
298 function article_callback2(transport
, id
) {
300 console
.log("article_callback2 " + id
);
302 handle_rpc_json(transport
);
307 reply
= JSON
.parse(transport
.responseText
);
314 reply
.each(function(article
) {
315 if (getActiveArticleId() == article
['id']) {
316 render_article(article
['content']);
318 cids_requested
.remove(article
['id']);
320 cache_set("article:" + article
['id'], article
['content']);
323 // if (id != last_requested_article) {
324 // console.log("requested article id is out of sequence, aborting");
329 console
.error("Invalid object received: " + transport
.responseText
);
331 render_article("<div class='whiteBox'>" +
332 __('Could not display article (invalid object received - see error console for details)') + "</div>");
335 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
336 request_counters(unread_in_buffer
== 0);
340 exception_error("article_callback2", e
, transport
);
344 function view(id
, activefeed
, noexpand
) {
346 var oldrow
= $("RROW-" + getActiveArticleId());
347 if (oldrow
) oldrow
.removeClassName("active");
349 var crow
= $("RROW-" + id
);
353 setActiveArticleId(id
);
354 showArticleInHeadlines(id
, noexpand
);
358 console
.log("loading article: " + id
);
360 var cached_article
= cache_get("article:" + id
);
362 console
.log("cache check result: " + (cached_article
!= false));
364 var query
= "?op=article&method=view&id=" + param_escape(id
);
366 var neighbor_ids
= getRelativePostIds(id
);
368 /* only request uncached articles */
370 var cids_to_request
= [];
372 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
373 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
374 if (!cache_get("article:" + neighbor_ids
[i
])) {
375 cids_to_request
.push(neighbor_ids
[i
]);
376 cids_requested
.push(neighbor_ids
[i
]);
380 console
.log("additional ids: " + cids_to_request
.toString());
382 query
= query
+ "&cids=" + cids_to_request
.toString();
384 var article_is_unread
= crow
.hasClassName("Unread");
386 setActiveArticleId(id
);
387 showArticleInHeadlines(id
);
389 if (cached_article
&& article_is_unread
) {
391 query
= query
+ "&mode=prefetch";
393 render_article(cached_article
);
395 } else if (cached_article
) {
397 query
= query
+ "&mode=prefetch_old";
398 render_article(cached_article
);
400 // if we don't need to request any relative ids, we might as well skip
401 // the server roundtrip altogether
402 if (cids_to_request
.length
== 0) {
407 last_requested_article
= id
;
411 if (article_is_unread
) {
412 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
415 new Ajax
.Request("backend.php", {
417 onComplete: function(transport
) {
418 article_callback2(transport
, id
);
424 exception_error("view", e
);
428 function toggleMark(id
, client_only
) {
430 var query
= "?op=rpc&id=" + id
+ "&method=mark";
432 var row
= $("RROW-" + id
);
437 var row_imgs
= row
.getElementsByClassName("markedPic");
439 for (var i
= 0; i
< row_imgs
.length
; i
++)
440 imgs
.push(row_imgs
[i
]);
442 var ft
= $("floatingTitle");
444 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
445 var fte
= ft
.getElementsByClassName("markedPic");
447 for (var i
= 0; i
< fte
.length
; i
++)
451 for (i
= 0; i
< imgs
.length
; i
++) {
454 if (!row
.hasClassName("marked")) {
455 img
.src
= img
.src
.replace("mark_unset", "mark_set");
456 img
.alt
= __("Unstar article");
457 query
= query
+ "&mark=1";
459 img
.src
= img
.src
.replace("mark_set", "mark_unset");
460 img
.alt
= __("Star article");
461 query
= query
+ "&mark=0";
465 row
.toggleClassName("marked");
468 new Ajax
.Request("backend.php", {
470 onComplete: function(transport
) {
471 handle_rpc_json(transport
);
476 exception_error("toggleMark", e
);
480 function togglePub(id
, client_only
, no_effects
, note
) {
482 var query
= "?op=rpc&id=" + id
+ "&method=publ";
484 if (note
!= undefined) {
485 query
= query
+ "¬e=" + param_escape(note
);
487 query
= query
+ "¬e=undefined";
490 var row
= $("RROW-" + id
);
495 var row_imgs
= row
.getElementsByClassName("pubPic");
497 for (var i
= 0; i
< row_imgs
.length
; i
++)
498 imgs
.push(row_imgs
[i
]);
500 var ft
= $("floatingTitle");
502 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
503 var fte
= ft
.getElementsByClassName("pubPic");
505 for (var i
= 0; i
< fte
.length
; i
++)
509 for (i
= 0; i
< imgs
.length
; i
++) {
512 if (!row
.hasClassName("published") || note
!= undefined) {
513 img
.src
= img
.src
.replace("pub_unset", "pub_set");
514 img
.alt
= __("Unpublish article");
515 query
= query
+ "&pub=1";
517 img
.src
= img
.src
.replace("pub_set", "pub_unset");
518 img
.alt
= __("Publish article");
519 query
= query
+ "&pub=0";
523 if (note
!= undefined)
524 row
.addClassName("published");
526 row
.toggleClassName("published");
529 new Ajax
.Request("backend.php", {
531 onComplete: function(transport
) {
532 handle_rpc_json(transport
);
537 exception_error("togglePub", e
);
541 function moveToPost(mode
, noscroll
, noexpand
) {
545 var rows
= getVisibleArticleIds();
550 if (!$('RROW-' + getActiveArticleId())) {
551 setActiveArticleId(0);
554 if (!getActiveArticleId()) {
556 prev_id
= rows
[rows
.length
-1]
558 for (var i
= 0; i
< rows
.length
; i
++) {
559 if (rows
[i
] == getActiveArticleId()) {
561 // Account for adjacent identical article ids.
562 if (i
> 0) prev_id
= rows
[i
-1];
564 for (var j
= i
+1; j
< rows
.length
; j
++) {
565 if (rows
[j
] != getActiveArticleId()) {
575 if (mode
== "next") {
576 if (next_id
|| getActiveArticleId()) {
579 var article
= $("RROW-" + getActiveArticleId());
580 var ctr
= $("headlines-frame");
582 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
583 ctr
.scrollTop
+ ctr
.offsetHeight
) {
585 scrollArticle(ctr
.offsetHeight
/4);
587 } else if (next_id
) {
588 cdmExpandArticle(next_id
, noexpand
);
589 cdmScrollToArticleId(next_id
, true);
592 } else if (next_id
) {
593 correctHeadlinesOffset(next_id
);
594 view(next_id
, getActiveFeedId(), noexpand
);
599 if (mode
== "prev") {
600 if (prev_id
|| getActiveArticleId()) {
603 var article
= $("RROW-" + getActiveArticleId());
604 var prev_article
= $("RROW-" + prev_id
);
605 var ctr
= $("headlines-frame");
607 if (!getInitParam("cdm_expanded")) {
609 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
610 scrollArticle(-ctr
.offsetHeight
/4);
612 cdmExpandArticle(prev_id
, noexpand
);
613 cdmScrollToArticleId(prev_id
, true);
617 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
618 scrollArticle(-ctr
.offsetHeight
/3);
619 } else if (!noscroll
&& prev_article
&&
620 prev_article
.offsetTop
< ctr
.scrollTop
) {
621 cdmExpandArticle(prev_id
, noexpand
);
622 scrollArticle(-ctr
.offsetHeight
/4);
623 } else if (prev_id
) {
624 cdmExpandArticle(prev_id
, noexpand
);
625 cdmScrollToArticleId(prev_id
, noscroll
);
629 } else if (prev_id
) {
630 correctHeadlinesOffset(prev_id
);
631 view(prev_id
, getActiveFeedId(), noexpand
);
637 exception_error("moveToPost", e
);
641 function toggleSelected(id
, force_on
) {
643 var row
= $("RROW-" + id
);
646 var cb
= dijit
.getEnclosingWidget(
647 row
.getElementsByClassName("rchk")[0]);
649 if (row
.hasClassName('Selected') && !force_on
) {
650 row
.removeClassName('Selected');
651 if (cb
) cb
.attr("checked", false);
653 row
.addClassName('Selected');
654 if (cb
) cb
.attr("checked", true);
658 updateSelectedPrompt();
660 exception_error("toggleSelected", e
);
664 function updateSelectedPrompt() {
666 var count
= getSelectedArticleIds2().size();
667 var elem
= $("selected_prompt");
670 elem
.innerHTML
= ngettext("%d article selected",
671 "%d articles selected", count
).replace("%d", count
);
680 exception_error("updateSelectedPrompt", e
);
684 function toggleUnread_afh(effect
) {
687 var elem
= effect
.element
;
688 elem
.style
.backgroundColor
= "";
691 exception_error("toggleUnread_afh", e
);
695 function toggleUnread(id
, cmode
, effect
) {
698 var row
= $("RROW-" + id
);
700 if (cmode
== undefined || cmode
== 2) {
701 if (row
.hasClassName("Unread")) {
702 row
.removeClassName("Unread");
705 row
.addClassName("Unread");
708 } else if (cmode
== 0) {
710 row
.removeClassName("Unread");
712 } else if (cmode
== 1) {
713 row
.addClassName("Unread");
716 if (cmode
== undefined) cmode
= 2;
718 var query
= "?op=rpc&method=catchupSelected" +
719 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
721 // notify_progress("Loading, please wait...");
723 new Ajax
.Request("backend.php", {
725 onComplete: function(transport
) {
726 handle_rpc_json(transport
);
732 exception_error("toggleUnread", e
);
736 function selectionRemoveLabel(id
, ids
) {
739 if (!ids
) ids
= getSelectedArticleIds2();
741 if (ids
.length
== 0) {
742 alert(__("No articles are selected."));
746 var query
= "?op=article&method=removeFromLabel&ids=" +
747 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
751 new Ajax
.Request("backend.php", {
753 onComplete: function(transport
) {
754 handle_rpc_json(transport
);
755 show_labels_in_headlines(transport
);
759 exception_error("selectionAssignLabel", e
);
764 function selectionAssignLabel(id
, ids
) {
767 if (!ids
) ids
= getSelectedArticleIds2();
769 if (ids
.length
== 0) {
770 alert(__("No articles are selected."));
774 var query
= "?op=article&method=assignToLabel&ids=" +
775 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
779 new Ajax
.Request("backend.php", {
781 onComplete: function(transport
) {
782 handle_rpc_json(transport
);
783 show_labels_in_headlines(transport
);
787 exception_error("selectionAssignLabel", e
);
792 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
794 var rows
= ids
? ids
: getSelectedArticleIds2();
796 if (rows
.length
== 0 && !no_error
) {
797 alert(__("No articles are selected."));
801 for (var i
= 0; i
< rows
.length
; i
++) {
802 var row
= $("RROW-" + rows
[i
]);
804 if (set_state
== undefined) {
805 if (row
.hasClassName("Unread")) {
806 row
.removeClassName("Unread");
808 row
.addClassName("Unread");
812 if (set_state
== false) {
813 row
.removeClassName("Unread");
816 if (set_state
== true) {
817 row
.addClassName("Unread");
822 updateFloatingTitle(true);
824 if (rows
.length
> 0) {
828 if (set_state
== undefined) {
830 } else if (set_state
== true) {
832 } else if (set_state
== false) {
836 var query
= "?op=rpc&method=catchupSelected" +
837 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
839 notify_progress("Loading, please wait...");
841 new Ajax
.Request("backend.php", {
843 onComplete: function(transport
) {
844 handle_rpc_json(transport
);
845 if (callback
) callback(transport
);
851 exception_error("selectionToggleUnread", e
);
856 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
859 var rows
= ids
? ids
: getSelectedArticleIds2();
861 if (rows
.length
== 0 && !no_error
) {
862 alert(__("No articles are selected."));
866 for (var i
= 0; i
< rows
.length
; i
++) {
867 toggleMark(rows
[i
], true, true);
870 if (rows
.length
> 0) {
872 var query
= "?op=rpc&method=markSelected&ids=" +
873 param_escape(rows
.toString()) + "&cmode=2";
875 new Ajax
.Request("backend.php", {
877 onComplete: function(transport
) {
878 handle_rpc_json(transport
);
879 if (callback
) callback(transport
);
885 exception_error("selectionToggleMarked", e
);
890 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
893 var rows
= ids
? ids
: getSelectedArticleIds2();
895 if (rows
.length
== 0 && !no_error
) {
896 alert(__("No articles are selected."));
900 for (var i
= 0; i
< rows
.length
; i
++) {
901 togglePub(rows
[i
], true, true);
904 if (rows
.length
> 0) {
906 var query
= "?op=rpc&method=publishSelected&ids=" +
907 param_escape(rows
.toString()) + "&cmode=2";
909 new Ajax
.Request("backend.php", {
911 onComplete: function(transport
) {
912 handle_rpc_json(transport
);
918 exception_error("selectionToggleMarked", e
);
922 function getSelectedArticleIds2() {
926 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
928 rv
.push(child
.id
.replace("RROW-", ""));
934 function getLoadedArticleIds() {
937 var children
= $$("#headlines-frame > div[id*=RROW-]");
939 children
.each(function(child
) {
940 rv
.push(child
.id
.replace("RROW-", ""));
947 // mode = all,none,unread,invert,marked,published
948 function selectArticles(mode
, query
) {
951 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
953 var children
= $$(query
);
955 children
.each(function(child
) {
956 var id
= child
.id
.replace("RROW-", "");
958 var cb
= dijit
.getEnclosingWidget(
959 child
.getElementsByClassName("rchk")[0]);
962 child
.addClassName("Selected");
963 if (cb
) cb
.attr("checked", true);
964 } else if (mode
== "unread") {
965 if (child
.hasClassName("Unread")) {
966 child
.addClassName("Selected");
967 if (cb
) cb
.attr("checked", true);
969 child
.removeClassName("Selected");
970 if (cb
) cb
.attr("checked", false);
972 } else if (mode
== "marked") {
973 if (child
.hasClassName("marked")) {
974 child
.addClassName("Selected");
975 if (cb
) cb
.attr("checked", true);
977 child
.removeClassName("Selected");
978 if (cb
) cb
.attr("checked", false);
980 } else if (mode
== "published") {
981 if (child
.hasClassName("published")) {
982 child
.addClassName("Selected");
983 if (cb
) cb
.attr("checked", true);
985 child
.removeClassName("Selected");
986 if (cb
) cb
.attr("checked", false);
989 } else if (mode
== "invert") {
990 if (child
.hasClassName("Selected")) {
991 child
.removeClassName("Selected");
992 if (cb
) cb
.attr("checked", false);
994 child
.addClassName("Selected");
995 if (cb
) cb
.attr("checked", true);
999 child
.removeClassName("Selected");
1000 if (cb
) cb
.attr("checked", false);
1004 updateSelectedPrompt();
1007 exception_error("selectArticles", e
);
1011 function deleteSelection() {
1015 var rows
= getSelectedArticleIds2();
1017 if (rows
.length
== 0) {
1018 alert(__("No articles are selected."));
1022 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1025 if (getActiveFeedId() != 0) {
1026 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1028 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1031 str
= str
.replace("%d", rows
.length
);
1032 str
= str
.replace("%s", fn
);
1034 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1038 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1045 handle_rpc_json(transport
);
1050 exception_error("deleteSelection", e
);
1054 function archiveSelection() {
1058 var rows
= getSelectedArticleIds2();
1060 if (rows
.length
== 0) {
1061 alert(__("No articles are selected."));
1065 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1069 if (getActiveFeedId() != 0) {
1070 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1073 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1075 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1080 str
= str
.replace("%d", rows
.length
);
1081 str
= str
.replace("%s", fn
);
1083 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1087 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1091 for (var i
= 0; i
< rows
.length
; i
++) {
1092 cache_delete("article:" + rows
[i
]);
1095 new Ajax
.Request("backend.php", {
1097 onComplete: function(transport
) {
1098 handle_rpc_json(transport
);
1103 exception_error("archiveSelection", e
);
1107 function catchupSelection() {
1111 var rows
= getSelectedArticleIds2();
1113 if (rows
.length
== 0) {
1114 alert(__("No articles are selected."));
1118 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1120 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1122 str
= str
.replace("%d", rows
.length
);
1123 str
= str
.replace("%s", fn
);
1125 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1129 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1132 exception_error("catchupSelection", e
);
1136 function editArticleTags(id
) {
1137 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1139 if (dijit
.byId("editTagsDlg"))
1140 dijit
.byId("editTagsDlg").destroyRecursive();
1142 dialog
= new dijit
.Dialog({
1144 title
: __("Edit article Tags"),
1145 style
: "width: 600px",
1146 execute: function() {
1147 if (this.validate()) {
1148 var query
= dojo
.objectToQuery(this.attr('value'));
1150 notify_progress("Saving article tags...", true);
1152 new Ajax
.Request("backend.php", {
1154 onComplete: function(transport
) {
1159 var data
= JSON
.parse(transport
.responseText
);
1166 var tags
= $("ATSTR-" + id
);
1167 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1169 if (tags
) tags
.innerHTML
= data
.content
;
1170 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1173 exception_error("editArticleTags/inner", e
);
1182 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1183 dojo
.disconnect(tmph
);
1185 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1186 "backend.php?op=article&method=completeTags",
1187 { tokens
: ',', paramName
: "search" });
1194 function cdmScrollToArticleId(id
, force
) {
1196 var ctr
= $("headlines-frame");
1197 var e
= $("RROW-" + id
);
1199 if (!e
|| !ctr
) return;
1201 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1202 e
.offsetTop
< ctr
.scrollTop
) {
1204 // expanded cdm has a 4px margin now
1205 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1209 exception_error("cdmScrollToArticleId", e
);
1213 function setActiveArticleId(id
) {
1214 _active_article_id
= id
;
1215 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1218 function getActiveArticleId() {
1219 return _active_article_id
;
1222 function postMouseIn(e
, id
) {
1223 post_under_pointer
= id
;
1226 function postMouseOut(id
) {
1227 post_under_pointer
= false;
1230 function unpackVisibleHeadlines() {
1232 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1234 $$("#headlines-frame > div[id*=RROW]").each(
1236 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1237 $("headlines-frame").offsetHeight
) {
1239 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1242 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1244 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1245 cencw
.setAttribute('id', '');
1246 Element
.show(cencw
);
1253 exception_error("unpackVisibleHeadlines", e
);
1257 function headlines_scroll_handler(e
) {
1259 var hsp
= $("headlines-spacer");
1261 unpackVisibleHeadlines();
1263 // set topmost child in the buffer as active
1264 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1265 getSelectedArticleIds2().length
<= 1 &&
1266 getInitParam("cdm_expanded")) {
1267 var rows
= $$("#headlines-frame > div[id*=RROW]");
1269 for (var i
= 0; i
< rows
.length
; i
++) {
1270 var child
= rows
[i
];
1272 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1273 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1274 child
.id
.replace("RROW-", "") != _active_article_id
) {
1276 if (_active_article_id
) {
1277 var row
= $("RROW-" + _active_article_id
);
1278 if (row
) row
.removeClassName("active");
1281 _active_article_id
= child
.id
.replace("RROW-", "");
1282 showArticleInHeadlines(_active_article_id
, true);
1283 updateSelectedPrompt();
1289 if (!_infscroll_disable
) {
1290 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1291 (e
.scrollHeight
!= 0 &&
1292 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1295 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1296 __("Loading, please wait...") + "</span>";
1298 loadMoreHeadlines();
1304 if (_infscroll_disable)
1305 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1306 __("Click to open next unread feed.") + "</a>";
1313 updateFloatingTitle();
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 (catchup_id_batch
.length
> 0) {
1338 window
.clearTimeout(catchup_timeout_id
);
1340 if (!_infscroll_request_sent
) {
1341 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1346 if (_infscroll_disable
) {
1347 var child
= $$("#headlines-frame div[id*=RROW]").last();
1349 if (child
&& $("headlines-frame").scrollTop
>
1350 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1352 console
.log("we seem to be at an end");
1354 if (getInitParam("on_catchup_show_next_feed") == "1") {
1355 openNextUnreadFeed();
1362 console
.warn("headlines_scroll_handler: " + e
);
1366 function openNextUnreadFeed() {
1368 var is_cat
= activeFeedIsCat();
1369 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1370 if (nuf
) viewfeed(nuf
, '', is_cat
);
1372 exception_error("openNextUnreadFeed", e
);
1376 function catchupBatchedArticles() {
1378 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1380 // make a copy of the array
1381 var batch
= catchup_id_batch
.slice();
1382 var query
= "?op=rpc&method=catchupSelected" +
1383 "&cmode=0&ids=" + param_escape(batch
.toString());
1387 new Ajax
.Request("backend.php", {
1389 onComplete: function(transport
) {
1390 handle_rpc_json(transport
);
1392 reply
= JSON
.parse(transport
.responseText
);
1393 var batch
= reply
.ids
;
1395 batch
.each(function(id
) {
1397 var elem
= $("RROW-" + id
);
1398 if (elem
) elem
.removeClassName("Unread");
1399 catchup_id_batch
.remove(id
);
1402 updateFloatingTitle(true);
1408 exception_error("catchupBatchedArticles", e
);
1412 function catchupRelativeToArticle(below
, id
) {
1416 if (!id
) id
= getActiveArticleId();
1419 alert(__("No article is selected."));
1423 var visible_ids
= getVisibleArticleIds();
1425 var ids_to_mark
= new Array();
1428 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1429 if (visible_ids
[i
] != id
) {
1430 var e
= $("RROW-" + visible_ids
[i
]);
1432 if (e
&& e
.hasClassName("Unread")) {
1433 ids_to_mark
.push(visible_ids
[i
]);
1440 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1441 if (visible_ids
[i
] != id
) {
1442 var e
= $("RROW-" + visible_ids
[i
]);
1444 if (e
&& e
.hasClassName("Unread")) {
1445 ids_to_mark
.push(visible_ids
[i
]);
1453 if (ids_to_mark
.length
== 0) {
1454 alert(__("No articles found to mark"));
1456 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1458 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1460 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1461 var e
= $("RROW-" + ids_to_mark
[i
]);
1462 e
.removeClassName("Unread");
1465 var query
= "?op=rpc&method=catchupSelected" +
1466 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1468 new Ajax
.Request("backend.php", {
1470 onComplete: function(transport
) {
1471 handle_rpc_json(transport
);
1478 exception_error("catchupRelativeToArticle", e
);
1482 function cdmCollapseArticle(event
, id
, unmark
) {
1484 if (unmark
== undefined) unmark
= true;
1486 var row
= $("RROW-" + id
);
1487 var elem
= $("CICD-" + id
);
1490 var collapse
= $$("div#RROW-" + id
+
1491 " span[class='collapseBtn']")[0];
1494 Element
.show("CEXC-" + id
);
1495 Element
.hide(collapse
);
1498 row
.removeClassName("active");
1500 markHeadline(id
, false);
1502 if (id
== getActiveArticleId()) {
1503 setActiveArticleId(0);
1506 updateSelectedPrompt();
1509 if (event
) Event
.stop(event
);
1511 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1513 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1514 scrollToRowId(row
.id
);
1516 $("floatingTitle").style
.visibility
= "hidden";
1517 $("floatingTitle").setAttribute("rowid", false);
1521 exception_error("cdmCollapseArticle", e
);
1525 function cdmExpandArticle(id
, noexpand
) {
1527 console
.log("cdmExpandArticle " + id
);
1529 if (!$("RROW-" + id
)) return false;
1531 var oldrow
= $("RROW-" + getActiveArticleId());
1533 var elem
= $("CICD-" + getActiveArticleId());
1535 if (id
== getActiveArticleId() && Element
.visible(elem
))
1538 selectArticles("none");
1540 var old_offset
= $("RROW-" + id
).offsetTop
;
1542 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1543 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1544 " span[class='collapseBtn']")[0];
1547 Element
.show("CEXC-" + getActiveArticleId());
1548 Element
.hide(collapse
);
1551 if (oldrow
) oldrow
.removeClassName("active");
1553 setActiveArticleId(id
);
1555 elem
= $("CICD-" + id
);
1557 var collapse
= $$("div#RROW-" + id
+
1558 " span[class='collapseBtn']")[0];
1560 var cencw
= $("CENCW-" + id
);
1562 if (!Element
.visible(elem
) && !noexpand
) {
1564 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1565 cencw
.setAttribute('id', '');
1566 Element
.show(cencw
);
1570 Element
.hide("CEXC-" + id
);
1571 Element
.show(collapse
);
1574 var new_offset
= $("RROW-" + id
).offsetTop
;
1576 if (old_offset
> new_offset
)
1577 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1580 toggleUnread(id
, 0, true);
1582 $("RROW-" + id
).addClassName("active");
1584 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1587 exception_error("cdmExpandArticle", e
);
1593 function getArticleUnderPointer() {
1594 return post_under_pointer
;
1597 function scrollArticle(offset
) {
1600 var ci
= $("content-insert");
1602 ci
.scrollTop
+= offset
;
1605 var hi
= $("headlines-frame");
1607 hi
.scrollTop
+= offset
;
1612 exception_error("scrollArticle", e
);
1616 function show_labels_in_headlines(transport
) {
1618 var data
= JSON
.parse(transport
.responseText
);
1621 data
['info-for-headlines'].each(function(elem
) {
1622 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1623 ctr
.innerHTML
= elem
.labels
;
1628 exception_error("show_labels_in_headlines", e
);
1632 function dismissArticle(id
) {
1634 var elem
= $("RROW-" + id
);
1638 toggleUnread(id
, 0, true);
1640 new Effect
.Fade(elem
, {duration
: 0.5});
1642 // Remove the content, too
1643 var elem_content
= $("CICD-" + id
);
1645 Element
.remove(elem_content
);
1648 if (id
== getActiveArticleId()) {
1649 setActiveArticleId(0);
1653 exception_error("dismissArticle", e
);
1657 function dismissSelectedArticles() {
1660 var ids
= getVisibleArticleIds();
1664 for (var i
= 0; i
< ids
.length
; i
++) {
1665 var elem
= $("RROW-" + ids
[i
]);
1667 if (elem
.className
&& elem
.hasClassName("Selected") &&
1668 ids
[i
] != getActiveArticleId()) {
1669 new Effect
.Fade(elem
, {duration
: 0.5});
1672 // Remove the content, too
1673 var elem_content
= $("CICD-" + ids
[i
]);
1675 Element
.remove(elem_content
);
1683 selectionToggleUnread(false);
1687 exception_error("dismissSelectedArticles", e
);
1691 function dismissReadArticles() {
1694 var ids
= getVisibleArticleIds();
1697 for (var i
= 0; i
< ids
.length
; i
++) {
1698 var elem
= $("RROW-" + ids
[i
]);
1700 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1701 !elem
.hasClassName("Selected")) {
1703 new Effect
.Fade(elem
, {duration
: 0.5});
1705 // Remove the content, too
1706 var elem_content
= $("CICD-" + ids
[i
]);
1708 Element
.remove(elem_content
);
1716 exception_error("dismissReadArticles", e
);
1720 function getVisibleArticleIds() {
1725 getLoadedArticleIds().each(function(id
) {
1726 var elem
= $("RROW-" + id
);
1727 if (elem
&& Element
.visible(elem
))
1732 exception_error("getVisibleArticleIds", e
);
1738 function cdmClicked(event
, id
) {
1740 //var shift_key = event.shiftKey;
1742 if (!event
.ctrlKey
) {
1744 if (!getInitParam("cdm_expanded")) {
1745 return cdmExpandArticle(id
);
1748 var elem
= $("RROW-" + getActiveArticleId());
1750 if (elem
) elem
.removeClassName("active");
1752 selectArticles("none");
1755 var elem
= $("RROW-" + id
);
1756 var article_is_unread
= elem
.hasClassName("Unread");
1758 elem
.removeClassName("Unread");
1759 elem
.addClassName("active");
1761 setActiveArticleId(id
);
1763 if (article_is_unread
) {
1764 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1765 updateFloatingTitle(true);
1768 var query
= "?op=rpc&method=catchupSelected" +
1769 "&cmode=0&ids=" + param_escape(id
);
1771 new Ajax
.Request("backend.php", {
1773 onComplete: function(transport
) {
1774 handle_rpc_json(transport
);
1777 return !event
.shiftKey
;
1780 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1782 toggleSelected(id
, true);
1784 var elem
= $("RROW-" + id
);
1785 var article_is_unread
= elem
.hasClassName("Unread");
1787 if (article_is_unread
) {
1788 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1791 toggleUnread(id
, 0, false);
1793 openArticleInNewWindow(id
);
1796 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1797 request_counters(unread_in_buffer
== 0);
1800 exception_error("cdmClicked");
1806 function hlClicked(event
, id
) {
1808 if (event
.which
== 2) {
1811 } else if (event
.ctrlKey
) {
1812 toggleSelected(id
, true);
1813 toggleUnread(id
, 0, false);
1814 openArticleInNewWindow(id
);
1822 exception_error("hlClicked");
1826 function getFirstVisibleHeadlineId() {
1827 var rows
= getVisibleArticleIds();
1832 function getLastVisibleHeadlineId() {
1833 var rows
= getVisibleArticleIds();
1834 return rows
[rows
.length
-1];
1837 function openArticleInNewWindow(id
) {
1838 toggleUnread(id
, 0, false);
1839 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1842 function isCdmMode() {
1843 return getInitParam("combined_display_mode");
1846 function markHeadline(id
, marked
) {
1847 if (marked
== undefined) marked
= true;
1849 var row
= $("RROW-" + id
);
1851 var check
= dijit
.getEnclosingWidget(
1852 row
.getElementsByClassName("rchk")[0]);
1855 check
.attr("checked", marked
);
1859 row
.addClassName("Selected");
1861 row
.removeClassName("Selected");
1865 function getRelativePostIds(id
, limit
) {
1871 if (!limit
) limit
= 6; //3
1873 var ids
= getVisibleArticleIds();
1875 for (var i
= 0; i
< ids
.length
; i
++) {
1877 for (var k
= 1; k
<= limit
; k
++) {
1878 //if (i > k-1) tmp.push(ids[i-k]);
1879 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1886 exception_error("getRelativePostIds", e
);
1892 function correctHeadlinesOffset(id
) {
1896 var container
= $("headlines-frame");
1897 var row
= $("RROW-" + id
);
1899 if (!container
|| !row
) return;
1901 var viewport
= container
.offsetHeight
;
1903 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1904 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1906 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1907 //console.log("Vport: " + viewport);
1909 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1910 container
.scrollTop
= row
.offsetTop
;
1911 } else if (rel_offset_bottom
> viewport
) {
1913 /* doesn't properly work with Opera in some cases because
1914 Opera fucks up element scrolling */
1916 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1920 exception_error("correctHeadlinesOffset", e
);
1925 function headlineActionsChange(elem
) {
1928 elem
.attr('value', 'false');
1930 exception_error("headlineActionsChange", e
);
1934 function closeArticlePanel() {
1936 if (dijit
.byId("content-insert"))
1937 dijit
.byId("headlines-wrap-inner").removeChild(
1938 dijit
.byId("content-insert"));
1941 function initFloatingMenu() {
1943 if (dijit
.byId("floatingMenu"))
1944 dijit
.byId("floatingMenu").destroyRecursive();
1946 var menu
= new dijit
.Menu({
1948 targetNodeIds
: ["floatingTitle"]
1951 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1953 headlinesMenuCommon(menu
, id
);
1957 exception_error("initFloatingMenu", e
);
1961 function headlinesMenuCommon(menu
, base_id
) {
1964 menu
.addChild(new dijit
.MenuItem({
1965 label
: __("Open original article"),
1966 onClick: function(event
) {
1967 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1970 menu
.addChild(new dijit
.MenuItem({
1971 label
: __("Display article URL"),
1972 onClick: function(event
) {
1973 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1976 menu
.addChild(new dijit
.MenuSeparator());
1978 menu
.addChild(new dijit
.MenuItem({
1979 label
: __("Toggle unread"),
1980 onClick: function(event
) {
1981 var ids
= getSelectedArticleIds2();
1983 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1984 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1986 selectionToggleUnread(undefined, false, true, ids
);
1989 menu
.addChild(new dijit
.MenuItem({
1990 label
: __("Toggle starred"),
1991 onClick: function(event
) {
1992 var ids
= getSelectedArticleIds2();
1994 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1995 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1997 selectionToggleMarked(undefined, false, true, ids
);
2000 menu
.addChild(new dijit
.MenuItem({
2001 label
: __("Toggle published"),
2002 onClick: function(event
) {
2003 var ids
= getSelectedArticleIds2();
2005 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2006 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2008 selectionTogglePublished(undefined, false, true, ids
);
2011 menu
.addChild(new dijit
.MenuSeparator());
2013 menu
.addChild(new dijit
.MenuItem({
2014 label
: __("Mark above as read"),
2015 onClick: function(event
) {
2016 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2019 menu
.addChild(new dijit
.MenuItem({
2020 label
: __("Mark below as read"),
2021 onClick: function(event
) {
2022 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2026 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2030 menu
.addChild(new dijit
.MenuSeparator());
2032 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2033 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2035 labels
.each(function(label
) {
2036 var id
= label
.id
[0];
2037 var bare_id
= id
.substr(id
.indexOf(":")+1);
2038 var name
= label
.name
[0];
2040 bare_id
= feed_to_label_id(bare_id
);
2042 labelAddMenu
.addChild(new dijit
.MenuItem({
2045 onClick: function(event
) {
2046 var ids
= getSelectedArticleIds2();
2048 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2050 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2052 selectionAssignLabel(this.labelId
, ids
);
2055 labelDelMenu
.addChild(new dijit
.MenuItem({
2058 onClick: function(event
) {
2059 var ids
= getSelectedArticleIds2();
2061 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2063 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2065 selectionRemoveLabel(this.labelId
, ids
);
2070 menu
.addChild(new dijit
.PopupMenuItem({
2071 label
: __("Assign label"),
2075 menu
.addChild(new dijit
.PopupMenuItem({
2076 label
: __("Remove label"),
2084 exception_error("headlinesMenuCommon", e
);
2088 function initHeadlinesMenu() {
2090 if (dijit
.byId("headlinesMenu"))
2091 dijit
.byId("headlinesMenu").destroyRecursive();
2096 nodes
= $$("#headlines-frame > div[id*=RROW]");
2098 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2101 nodes
.each(function(node
) {
2105 var menu
= new dijit
.Menu({
2106 id
: "headlinesMenu",
2110 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2111 var callerNode
= event
.target
, match
= null, tries
= 0;
2113 while (match
== null && callerNode
&& tries
<= 3) {
2114 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2115 callerNode
= callerNode
.parentNode
;
2119 if (match
) this.callerRowId
= parseInt(match
[1]);
2123 headlinesMenuCommon(menu
, false);
2127 /* vgroup feed title menu */
2129 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2132 nodes
.each(function(node
) {
2136 if (ids
.length
> 0) {
2137 if (dijit
.byId("headlinesFeedTitleMenu"))
2138 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2140 var menu
= new dijit
.Menu({
2141 id
: "headlinesFeedTitleMenu",
2145 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2146 var callerNode
= event
.target
, match
= null, tries
= 0;
2148 while (match
== null && callerNode
&& tries
<= 3) {
2149 console
.log(callerNode
.id
);
2151 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2152 callerNode
= callerNode
.parentNode
;
2155 console
.log(match
[1]);
2158 if (match
) this.callerRowId
= parseInt(match
[1]);
2162 menu
.addChild(new dijit
.MenuItem({
2163 label
: __("Select articles in group"),
2164 onClick: function(event
) {
2165 selectArticles("all",
2166 "#headlines-frame > div[id*=RROW]"+
2167 "[orig-feed-id='"+menu
.callerRowId
+"']");
2171 menu
.addChild(new dijit
.MenuItem({
2172 label
: __("Mark group as read"),
2173 onClick: function(event
) {
2174 selectArticles("none");
2175 selectArticles("all",
2176 "#headlines-frame > div[id*=RROW]"+
2177 "[orig-feed-id='"+menu
.callerRowId
+"']");
2183 menu
.addChild(new dijit
.MenuItem({
2184 label
: __("Mark feed as read"),
2185 onClick: function(event
) {
2186 catchupFeedInGroup(menu
.callerRowId
);
2194 exception_error("initHeadlinesMenu", e
);
2198 function cache_set(id
, obj
) {
2199 //console.log("cache_set: " + id);
2202 sessionStorage
[id
] = obj
;
2204 sessionStorage
.clear();
2208 function cache_get(id
) {
2210 return sessionStorage
[id
];
2213 function cache_clear() {
2215 sessionStorage
.clear();
2218 function cache_delete(id
) {
2220 sessionStorage
.removeItem(id
);
2223 function cancelSearch() {
2228 exception_error("cancelSearch", e
);
2232 function setSelectionScore() {
2234 var ids
= getSelectedArticleIds2();
2236 if (ids
.length
> 0) {
2239 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2241 if (score
!= undefined) {
2242 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2243 "&score=" + param_escape(score
);
2245 new Ajax
.Request("backend.php", {
2247 onComplete: function(transport
) {
2248 var reply
= JSON
.parse(transport
.responseText
);
2252 ids
.each(function(id
) {
2253 var row
= $("RROW-" + id
);
2256 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2259 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2260 reply
["score_pic"]);
2261 pic
.setAttribute("score", score
);
2270 alert(__("No articles are selected."));
2273 exception_error("setSelectionScore", e
);
2277 function updateScore(id
) {
2279 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2283 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2285 new Ajax
.Request("backend.php", {
2287 onComplete: function(transport
) {
2288 console
.log(transport
.responseText
);
2290 var reply
= JSON
.parse(transport
.responseText
);
2293 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2294 pic
.setAttribute("score", reply
["score"]);
2295 pic
.setAttribute("title", reply
["score"]);
2301 exception_error("updateScore", e
);
2305 function changeScore(id
, pic
) {
2307 var score
= pic
.getAttribute("score");
2309 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2311 if (new_score
!= undefined) {
2313 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2314 "&score=" + param_escape(new_score
);
2316 new Ajax
.Request("backend.php", {
2318 onComplete: function(transport
) {
2319 var reply
= JSON
.parse(transport
.responseText
);
2322 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2323 pic
.setAttribute("score", new_score
);
2324 pic
.setAttribute("title", new_score
);
2329 exception_error("changeScore", e
);
2333 function displayArticleUrl(id
) {
2335 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2337 new Ajax
.Request("backend.php", {
2339 onComplete: function(transport
) {
2340 var reply
= JSON
.parse(transport
.responseText
);
2342 if (reply
&& reply
.link
) {
2343 prompt(__("Article URL:"), reply
.link
);
2347 exception_error("changeScore", e
);
2351 function openSelectedAttachment(elem
) {
2353 var url
= elem
[elem
.selectedIndex
].value
;
2357 elem
.selectedIndex
= 0;
2361 exception_error("openSelectedAttachment", e
);
2365 function scrollToRowId(id
) {
2370 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2373 exception_error("scrollToRowId", e
);
2377 function updateFloatingTitle(unread_only
) {
2379 if (!isCdmMode()) return;
2381 var hf
= $("headlines-frame");
2383 var elems
= $$("#headlines-frame > div[id*=RROW]");
2385 for (var i
= 0; i
< elems
.length
; i
++) {
2387 var child
= elems
[i
];
2389 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2391 var header
= child
.getElementsByClassName("cdmHeader")[0];
2393 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2394 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2395 $("floatingTitle").setAttribute("rowid", child
.id
);
2396 $("floatingTitle").innerHTML
= header
.innerHTML
;
2397 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2401 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2404 cb
.parentNode
.removeChild(cb
);
2407 if (child
.hasClassName("Unread"))
2408 $("floatingTitle").addClassName("Unread");
2410 $("floatingTitle").removeClassName("Unread");
2412 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2415 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2416 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2417 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2418 $("floatingTitle").style
.visibility
= "visible";
2420 $("floatingTitle").style
.visibility
= "hidden";
2428 exception_error("updateFloatingTitle", e
);
2432 function cdmFooterClick(event
) {
2433 event
.stopPropagation();