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 dijit
.byId("headlines-frame").attr('content',
90 reply
['headlines']['content']);
92 //dijit.byId("headlines-toolbar").attr('content',
93 // reply['headlines']['toolbar']);
95 dojo
.html
.set($("headlines-toolbar"),
96 reply
['headlines']['toolbar'],
97 {parseContent
: true});
99 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
100 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
101 row
.parentNode
.removeChild(row
);
103 loaded_article_ids
.push(row
.id
);
107 var hsp
= $("headlines-spacer");
108 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
109 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
113 if (_infscroll_disable
)
114 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
115 __("Click to open next unread feed.") + "</a>";
118 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
119 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
125 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
126 console
.log("adding some more headlines: " + headlines_count
);
128 var c
= dijit
.byId("headlines-frame");
129 var ids
= getSelectedArticleIds2();
132 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
134 var hsp
= $("headlines-spacer");
137 c
.domNode
.removeChild(hsp
);
139 $$("#headlines-tmp > div").each(function(row
) {
140 if (row
.className
== 'cdmFeedTitle') {
141 row
.style
.display
= 'none';
142 c
.domNode
.appendChild(row
);
144 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
145 row
.style
.display
= 'none';
146 c
.domNode
.appendChild(row
);
148 loaded_article_ids
.push(row
.id
);
150 row
.parentNode
.removeChild(row
);
154 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
156 // if (getInitParam("cdm_auto_catchup") == 1) {
157 c
.domNode
.appendChild(hsp
);
160 console
.log("added " + new_elems
.size() + " headlines");
162 if (new_elems
.size() == 0)
163 _infscroll_disable
= true;
165 console
.log("restore selected ids: " + ids
);
167 for (var i
= 0; i
< ids
.length
; i
++) {
168 markHeadline(ids
[i
]);
173 new_elems
.each(function(child
) {
174 dojo
.parser
.parse(child
);
176 if (!Element
.visible(child
))
177 new Effect
.Appear(child
, { duration
: 0.5 });
180 if (_infscroll_disable
) {
181 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
182 __("Click to open next unread feed.") + "</a>";
186 console
.log("no new headlines received");
188 var first_id_changed
= reply
['headlines']['first_id_changed'];
189 console
.log("first id changed:" + first_id_changed
);
191 var hsp
= $("headlines-spacer");
194 if (first_id_changed
) {
195 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
196 __("New articles found, reload feed to continue.") + "</a>";
198 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
199 __("Click to open next unread feed.") + "</a>";
208 for (var i
= 0; i
< articles
.length
; i
++) {
209 var a_id
= articles
[i
]['id'];
210 cache_set("article:" + a_id
, articles
[i
]['content']);
213 console
.log("no cached articles received");
217 parse_counters(counters
);
219 request_counters(true);
222 console
.error("Invalid object received: " + transport
.responseText
);
223 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
224 __('Could not update headlines (invalid object received - see error console for details)') +
228 _infscroll_request_sent
= 0;
229 _last_headlines_update
= new Date().getTime();
231 unpackVisibleHeadlines();
233 // if we have some more space in the buffer, why not try to fill it
235 if (!_infscroll_disable
&& $("headlines-spacer") &&
236 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
238 window
.setTimeout(function() {
246 exception_error("headlines_callback2", e
, transport
);
250 function render_article(article
) {
252 dijit
.byId("headlines-wrap-inner").addChild(
253 dijit
.byId("content-insert"));
255 var c
= dijit
.byId("content-insert");
258 c
.domNode
.scrollTop
= 0;
261 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, article
);
263 c
.attr('content', article
);
265 correctHeadlinesOffset(getActiveArticleId());
272 exception_error("render_article", e
);
276 function showArticleInHeadlines(id
, noexpand
) {
279 selectArticles("none");
281 var crow
= $("RROW-" + id
);
285 var article_is_unread
= crow
.hasClassName("Unread");
288 crow
.removeClassName("Unread");
289 crow
.addClassName("active");
291 selectArticles('none');
293 var view_mode
= false;
296 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
297 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
304 if (article_is_unread
&& !noexpand
)
305 _force_scheduled_update
= true;
308 exception_error("showArticleInHeadlines", e
);
312 function article_callback2(transport
, id
) {
314 console
.log("article_callback2 " + id
);
316 handle_rpc_json(transport
);
321 reply
= JSON
.parse(transport
.responseText
);
328 reply
.each(function(article
) {
329 if (getActiveArticleId() == article
['id']) {
330 render_article(article
['content']);
332 cids_requested
.remove(article
['id']);
334 cache_set("article:" + article
['id'], article
['content']);
337 // if (id != last_requested_article) {
338 // console.log("requested article id is out of sequence, aborting");
343 console
.error("Invalid object received: " + transport
.responseText
);
345 render_article("<div class='whiteBox'>" +
346 __('Could not display article (invalid object received - see error console for details)') + "</div>");
349 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
350 request_counters(unread_in_buffer
== 0);
352 //headlines_scroll_handler($("headlines-frame"));
355 if (!_infscroll_disable &&
356 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
366 exception_error("article_callback2", e
, transport
);
370 function view(id
, activefeed
, noexpand
) {
372 var oldrow
= $("RROW-" + getActiveArticleId());
373 if (oldrow
) oldrow
.removeClassName("active");
375 var crow
= $("RROW-" + id
);
379 setActiveArticleId(id
);
380 showArticleInHeadlines(id
, noexpand
);
384 console
.log("loading article: " + id
);
386 var cached_article
= cache_get("article:" + id
);
388 console
.log("cache check result: " + (cached_article
!= false));
390 var query
= "?op=article&method=view&id=" + param_escape(id
);
392 var neighbor_ids
= getRelativePostIds(id
);
394 /* only request uncached articles */
396 var cids_to_request
= [];
398 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
399 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
400 if (!cache_get("article:" + neighbor_ids
[i
])) {
401 cids_to_request
.push(neighbor_ids
[i
]);
402 cids_requested
.push(neighbor_ids
[i
]);
406 console
.log("additional ids: " + cids_to_request
.toString());
408 query
= query
+ "&cids=" + cids_to_request
.toString();
410 var article_is_unread
= crow
.hasClassName("Unread");
412 setActiveArticleId(id
);
413 showArticleInHeadlines(id
);
415 if (cached_article
&& article_is_unread
) {
417 query
= query
+ "&mode=prefetch";
419 render_article(cached_article
);
421 } else if (cached_article
) {
423 query
= query
+ "&mode=prefetch_old";
424 render_article(cached_article
);
426 // if we don't need to request any relative ids, we might as well skip
427 // the server roundtrip altogether
428 if (cids_to_request
.length
== 0) {
431 if (!_infscroll_disable &&
432 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
440 //headlines_scroll_handler($("headlines-frame"));
446 last_requested_article
= id
;
450 if (article_is_unread
) {
451 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
454 new Ajax
.Request("backend.php", {
456 onComplete: function(transport
) {
457 article_callback2(transport
, id
);
463 exception_error("view", e
);
467 function toggleMark(id
, client_only
) {
469 var query
= "?op=rpc&id=" + id
+ "&method=mark";
471 var row
= $("RROW-" + id
);
476 var row_imgs
= row
.getElementsByClassName("markedPic");
478 for (var i
= 0; i
< row_imgs
.length
; i
++)
479 imgs
.push(row_imgs
[i
]);
481 var ft
= $("floatingTitle");
483 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
484 var fte
= ft
.getElementsByClassName("markedPic");
486 for (var i
= 0; i
< fte
.length
; i
++)
490 for (i
= 0; i
< imgs
.length
; i
++) {
493 if (!row
.hasClassName("marked")) {
494 img
.src
= img
.src
.replace("mark_unset", "mark_set");
495 img
.alt
= __("Unstar article");
496 query
= query
+ "&mark=1";
498 img
.src
= img
.src
.replace("mark_set", "mark_unset");
499 img
.alt
= __("Star article");
500 query
= query
+ "&mark=0";
504 row
.toggleClassName("marked");
507 new Ajax
.Request("backend.php", {
509 onComplete: function(transport
) {
510 handle_rpc_json(transport
);
515 exception_error("toggleMark", e
);
519 function togglePub(id
, client_only
, no_effects
, note
) {
521 var query
= "?op=rpc&id=" + id
+ "&method=publ";
523 if (note
!= undefined) {
524 query
= query
+ "¬e=" + param_escape(note
);
526 query
= query
+ "¬e=undefined";
529 var row
= $("RROW-" + id
);
534 var row_imgs
= row
.getElementsByClassName("pubPic");
536 for (var i
= 0; i
< row_imgs
.length
; i
++)
537 imgs
.push(row_imgs
[i
]);
539 var ft
= $("floatingTitle");
541 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
542 var fte
= ft
.getElementsByClassName("pubPic");
544 for (var i
= 0; i
< fte
.length
; i
++)
548 for (i
= 0; i
< imgs
.length
; i
++) {
551 if (!row
.hasClassName("published") || note
!= undefined) {
552 img
.src
= img
.src
.replace("pub_unset", "pub_set");
553 img
.alt
= __("Unpublish article");
554 query
= query
+ "&pub=1";
556 img
.src
= img
.src
.replace("pub_set", "pub_unset");
557 img
.alt
= __("Publish article");
558 query
= query
+ "&pub=0";
562 if (note
!= undefined)
563 row
.addClassName("published");
565 row
.toggleClassName("published");
568 new Ajax
.Request("backend.php", {
570 onComplete: function(transport
) {
571 handle_rpc_json(transport
);
576 exception_error("togglePub", e
);
580 function moveToPost(mode
, noscroll
, noexpand
) {
584 var rows
= getVisibleArticleIds();
589 if (!$('RROW-' + getActiveArticleId())) {
590 setActiveArticleId(0);
593 if (!getActiveArticleId()) {
595 prev_id
= rows
[rows
.length
-1]
597 for (var i
= 0; i
< rows
.length
; i
++) {
598 if (rows
[i
] == getActiveArticleId()) {
600 // Account for adjacent identical article ids.
601 if (i
> 0) prev_id
= rows
[i
-1];
603 for (var j
= i
+1; j
< rows
.length
; j
++) {
604 if (rows
[j
] != getActiveArticleId()) {
614 if (mode
== "next") {
615 if (next_id
|| getActiveArticleId()) {
618 var article
= $("RROW-" + getActiveArticleId());
619 var ctr
= $("headlines-frame");
621 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
622 ctr
.scrollTop
+ ctr
.offsetHeight
) {
624 scrollArticle(ctr
.offsetHeight
/4);
626 } else if (next_id
) {
627 cdmExpandArticle(next_id
, noexpand
);
628 cdmScrollToArticleId(next_id
, true);
631 } else if (next_id
) {
632 correctHeadlinesOffset(next_id
);
633 view(next_id
, getActiveFeedId(), noexpand
);
638 if (mode
== "prev") {
639 if (prev_id
|| getActiveArticleId()) {
642 var article
= $("RROW-" + getActiveArticleId());
643 var prev_article
= $("RROW-" + prev_id
);
644 var ctr
= $("headlines-frame");
646 if (!getInitParam("cdm_expanded")) {
648 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
649 scrollArticle(-ctr
.offsetHeight
/4);
651 cdmExpandArticle(prev_id
, noexpand
);
652 cdmScrollToArticleId(prev_id
, true);
656 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
657 scrollArticle(-ctr
.offsetHeight
/3);
658 } else if (!noscroll
&& prev_article
&&
659 prev_article
.offsetTop
< ctr
.scrollTop
) {
660 cdmExpandArticle(prev_id
, noexpand
);
661 scrollArticle(-ctr
.offsetHeight
/4);
662 } else if (prev_id
) {
663 cdmExpandArticle(prev_id
, noexpand
);
664 cdmScrollToArticleId(prev_id
, noscroll
);
668 } else if (prev_id
) {
669 correctHeadlinesOffset(prev_id
);
670 view(prev_id
, getActiveFeedId(), noexpand
);
676 exception_error("moveToPost", e
);
680 function toggleSelected(id
, force_on
) {
682 var row
= $("RROW-" + id
);
685 var cb
= dijit
.getEnclosingWidget(
686 row
.getElementsByClassName("rchk")[0]);
688 if (row
.hasClassName('Selected') && !force_on
) {
689 row
.removeClassName('Selected');
690 if (cb
) cb
.attr("checked", false);
692 row
.addClassName('Selected');
693 if (cb
) cb
.attr("checked", true);
697 updateSelectedPrompt();
699 exception_error("toggleSelected", e
);
703 function updateSelectedPrompt() {
705 var count
= getSelectedArticleIds2().size();
706 var elem
= $("selected_prompt");
709 elem
.innerHTML
= ngettext("%d article selected",
710 "%d articles selected", count
).replace("%d", count
);
719 exception_error("updateSelectedPrompt", e
);
723 function toggleUnread_afh(effect
) {
726 var elem
= effect
.element
;
727 elem
.style
.backgroundColor
= "";
730 exception_error("toggleUnread_afh", e
);
734 function toggleUnread(id
, cmode
, effect
) {
737 var row
= $("RROW-" + id
);
739 if (cmode
== undefined || cmode
== 2) {
740 if (row
.hasClassName("Unread")) {
741 row
.removeClassName("Unread");
744 row
.addClassName("Unread");
747 } else if (cmode
== 0) {
749 row
.removeClassName("Unread");
751 } else if (cmode
== 1) {
752 row
.addClassName("Unread");
755 if (cmode
== undefined) cmode
= 2;
757 var query
= "?op=rpc&method=catchupSelected" +
758 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
760 // notify_progress("Loading, please wait...");
762 new Ajax
.Request("backend.php", {
764 onComplete: function(transport
) {
765 handle_rpc_json(transport
);
771 exception_error("toggleUnread", e
);
775 function selectionRemoveLabel(id
, ids
) {
778 if (!ids
) ids
= getSelectedArticleIds2();
780 if (ids
.length
== 0) {
781 alert(__("No articles are selected."));
785 var query
= "?op=article&method=removeFromLabel&ids=" +
786 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
790 new Ajax
.Request("backend.php", {
792 onComplete: function(transport
) {
793 handle_rpc_json(transport
);
794 show_labels_in_headlines(transport
);
798 exception_error("selectionAssignLabel", e
);
803 function selectionAssignLabel(id
, ids
) {
806 if (!ids
) ids
= getSelectedArticleIds2();
808 if (ids
.length
== 0) {
809 alert(__("No articles are selected."));
813 var query
= "?op=article&method=assignToLabel&ids=" +
814 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
818 new Ajax
.Request("backend.php", {
820 onComplete: function(transport
) {
821 handle_rpc_json(transport
);
822 show_labels_in_headlines(transport
);
826 exception_error("selectionAssignLabel", e
);
831 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
833 var rows
= ids
? ids
: getSelectedArticleIds2();
835 if (rows
.length
== 0 && !no_error
) {
836 alert(__("No articles are selected."));
840 for (var i
= 0; i
< rows
.length
; i
++) {
841 var row
= $("RROW-" + rows
[i
]);
843 if (set_state
== undefined) {
844 if (row
.hasClassName("Unread")) {
845 row
.removeClassName("Unread");
847 row
.addClassName("Unread");
851 if (set_state
== false) {
852 row
.removeClassName("Unread");
855 if (set_state
== true) {
856 row
.addClassName("Unread");
861 updateFloatingTitle(true);
863 if (rows
.length
> 0) {
867 if (set_state
== undefined) {
869 } else if (set_state
== true) {
871 } else if (set_state
== false) {
875 var query
= "?op=rpc&method=catchupSelected" +
876 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
878 notify_progress("Loading, please wait...");
880 new Ajax
.Request("backend.php", {
882 onComplete: function(transport
) {
883 handle_rpc_json(transport
);
884 if (callback
) callback(transport
);
890 exception_error("selectionToggleUnread", e
);
895 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
898 var rows
= ids
? ids
: getSelectedArticleIds2();
900 if (rows
.length
== 0 && !no_error
) {
901 alert(__("No articles are selected."));
905 for (var i
= 0; i
< rows
.length
; i
++) {
906 toggleMark(rows
[i
], true, true);
909 if (rows
.length
> 0) {
911 var query
= "?op=rpc&method=markSelected&ids=" +
912 param_escape(rows
.toString()) + "&cmode=2";
914 new Ajax
.Request("backend.php", {
916 onComplete: function(transport
) {
917 handle_rpc_json(transport
);
918 if (callback
) callback(transport
);
924 exception_error("selectionToggleMarked", e
);
929 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
932 var rows
= ids
? ids
: getSelectedArticleIds2();
934 if (rows
.length
== 0 && !no_error
) {
935 alert(__("No articles are selected."));
939 for (var i
= 0; i
< rows
.length
; i
++) {
940 togglePub(rows
[i
], true, true);
943 if (rows
.length
> 0) {
945 var query
= "?op=rpc&method=publishSelected&ids=" +
946 param_escape(rows
.toString()) + "&cmode=2";
948 new Ajax
.Request("backend.php", {
950 onComplete: function(transport
) {
951 handle_rpc_json(transport
);
957 exception_error("selectionToggleMarked", e
);
961 function getSelectedArticleIds2() {
965 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
967 rv
.push(child
.id
.replace("RROW-", ""));
973 function getLoadedArticleIds() {
976 var children
= $$("#headlines-frame > div[id*=RROW-]");
978 children
.each(function(child
) {
979 rv
.push(child
.id
.replace("RROW-", ""));
986 // mode = all,none,unread,invert,marked,published
987 function selectArticles(mode
, query
) {
990 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
992 var children
= $$(query
);
994 children
.each(function(child
) {
995 var id
= child
.id
.replace("RROW-", "");
997 var cb
= dijit
.getEnclosingWidget(
998 child
.getElementsByClassName("rchk")[0]);
1000 if (mode
== "all") {
1001 child
.addClassName("Selected");
1002 if (cb
) cb
.attr("checked", true);
1003 } else if (mode
== "unread") {
1004 if (child
.hasClassName("Unread")) {
1005 child
.addClassName("Selected");
1006 if (cb
) cb
.attr("checked", true);
1008 child
.removeClassName("Selected");
1009 if (cb
) cb
.attr("checked", false);
1011 } else if (mode
== "marked") {
1012 if (child
.hasClassName("marked")) {
1013 child
.addClassName("Selected");
1014 if (cb
) cb
.attr("checked", true);
1016 child
.removeClassName("Selected");
1017 if (cb
) cb
.attr("checked", false);
1019 } else if (mode
== "published") {
1020 if (child
.hasClassName("published")) {
1021 child
.addClassName("Selected");
1022 if (cb
) cb
.attr("checked", true);
1024 child
.removeClassName("Selected");
1025 if (cb
) cb
.attr("checked", false);
1028 } else if (mode
== "invert") {
1029 if (child
.hasClassName("Selected")) {
1030 child
.removeClassName("Selected");
1031 if (cb
) cb
.attr("checked", false);
1033 child
.addClassName("Selected");
1034 if (cb
) cb
.attr("checked", true);
1038 child
.removeClassName("Selected");
1039 if (cb
) cb
.attr("checked", false);
1043 updateSelectedPrompt();
1046 exception_error("selectArticles", e
);
1050 function deleteSelection() {
1054 var rows
= getSelectedArticleIds2();
1056 if (rows
.length
== 0) {
1057 alert(__("No articles are selected."));
1061 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1064 if (getActiveFeedId() != 0) {
1065 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1067 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1070 str
= str
.replace("%d", rows
.length
);
1071 str
= str
.replace("%s", fn
);
1073 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1077 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1081 new Ajax
.Request("backend.php", {
1083 onComplete: function(transport
) {
1084 handle_rpc_json(transport
);
1089 exception_error("deleteSelection", e
);
1093 function archiveSelection() {
1097 var rows
= getSelectedArticleIds2();
1099 if (rows
.length
== 0) {
1100 alert(__("No articles are selected."));
1104 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1108 if (getActiveFeedId() != 0) {
1109 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1112 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1114 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1119 str
= str
.replace("%d", rows
.length
);
1120 str
= str
.replace("%s", fn
);
1122 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1126 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1130 for (var i
= 0; i
< rows
.length
; i
++) {
1131 cache_delete("article:" + rows
[i
]);
1134 new Ajax
.Request("backend.php", {
1136 onComplete: function(transport
) {
1137 handle_rpc_json(transport
);
1142 exception_error("archiveSelection", e
);
1146 function catchupSelection() {
1150 var rows
= getSelectedArticleIds2();
1152 if (rows
.length
== 0) {
1153 alert(__("No articles are selected."));
1157 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1159 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1161 str
= str
.replace("%d", rows
.length
);
1162 str
= str
.replace("%s", fn
);
1164 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1168 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1171 exception_error("catchupSelection", e
);
1175 function editArticleTags(id
) {
1176 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1178 if (dijit
.byId("editTagsDlg"))
1179 dijit
.byId("editTagsDlg").destroyRecursive();
1181 dialog
= new dijit
.Dialog({
1183 title
: __("Edit article Tags"),
1184 style
: "width: 600px",
1185 execute: function() {
1186 if (this.validate()) {
1187 var query
= dojo
.objectToQuery(this.attr('value'));
1189 notify_progress("Saving article tags...", true);
1191 new Ajax
.Request("backend.php", {
1193 onComplete: function(transport
) {
1198 var data
= JSON
.parse(transport
.responseText
);
1205 var tags
= $("ATSTR-" + id
);
1206 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1208 if (tags
) tags
.innerHTML
= data
.content
;
1209 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1212 exception_error("editArticleTags/inner", e
);
1221 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1222 dojo
.disconnect(tmph
);
1224 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1225 "backend.php?op=article&method=completeTags",
1226 { tokens
: ',', paramName
: "search" });
1233 function cdmScrollToArticleId(id
, force
) {
1235 var ctr
= $("headlines-frame");
1236 var e
= $("RROW-" + id
);
1238 if (!e
|| !ctr
) return;
1240 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1241 e
.offsetTop
< ctr
.scrollTop
) {
1243 // expanded cdm has a 4px margin now
1244 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1248 exception_error("cdmScrollToArticleId", e
);
1252 function setActiveArticleId(id
) {
1253 _active_article_id
= id
;
1254 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1257 function getActiveArticleId() {
1258 return _active_article_id
;
1261 function postMouseIn(e
, id
) {
1262 post_under_pointer
= id
;
1265 function postMouseOut(id
) {
1266 post_under_pointer
= false;
1269 function unpackVisibleHeadlines() {
1271 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1273 $$("#headlines-frame > div[id*=RROW]").each(
1275 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1276 $("headlines-frame").offsetHeight
) {
1278 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1281 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1283 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1284 cencw
.setAttribute('id', '');
1285 Element
.show(cencw
);
1292 exception_error("unpackVisibleHeadlines", e
);
1296 function headlines_scroll_handler(e
) {
1298 var hsp
= $("headlines-spacer");
1300 unpackVisibleHeadlines();
1302 // set topmost child in the buffer as active
1303 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1304 getSelectedArticleIds2().length
<= 1 &&
1305 getInitParam("cdm_expanded")) {
1306 var rows
= $$("#headlines-frame > div[id*=RROW]");
1308 for (var i
= 0; i
< rows
.length
; i
++) {
1309 var child
= rows
[i
];
1311 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1312 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1313 child
.id
.replace("RROW-", "") != _active_article_id
) {
1315 if (_active_article_id
) {
1316 var row
= $("RROW-" + _active_article_id
);
1317 if (row
) row
.removeClassName("active");
1320 _active_article_id
= child
.id
.replace("RROW-", "");
1321 showArticleInHeadlines(_active_article_id
, true);
1322 updateSelectedPrompt();
1328 if (!_infscroll_disable
) {
1329 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1330 (e
.scrollHeight
!= 0 &&
1331 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1334 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1335 __("Loading, please wait...") + "</span>";
1337 loadMoreHeadlines();
1343 if (_infscroll_disable)
1344 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1345 __("Click to open next unread feed.") + "</a>";
1352 updateFloatingTitle();
1355 if (getInitParam("cdm_auto_catchup") == 1) {
1357 // let's get DOM some time to settle down
1358 var ts
= new Date().getTime();
1359 if (ts
- _last_headlines_update
< 100) return;
1361 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1363 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1364 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1366 var id
= child
.id
.replace("RROW-", "");
1368 if (catchup_id_batch
.indexOf(id
) == -1)
1369 catchup_id_batch
.push(id
);
1371 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1376 if (catchup_id_batch
.length
> 0) {
1377 window
.clearTimeout(catchup_timeout_id
);
1379 if (!_infscroll_request_sent
) {
1380 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1385 if (_infscroll_disable
) {
1386 var child
= $$("#headlines-frame div[id*=RROW]").last();
1388 if (child
&& $("headlines-frame").scrollTop
>
1389 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1391 console
.log("we seem to be at an end");
1393 if (getInitParam("on_catchup_show_next_feed") == "1") {
1394 openNextUnreadFeed();
1401 console
.warn("headlines_scroll_handler: " + e
);
1405 function openNextUnreadFeed() {
1407 var is_cat
= activeFeedIsCat();
1408 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1409 if (nuf
) viewfeed(nuf
, '', is_cat
);
1411 exception_error("openNextUnreadFeed", e
);
1415 function catchupBatchedArticles() {
1417 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1419 // make a copy of the array
1420 var batch
= catchup_id_batch
.slice();
1421 var query
= "?op=rpc&method=catchupSelected" +
1422 "&cmode=0&ids=" + param_escape(batch
.toString());
1426 new Ajax
.Request("backend.php", {
1428 onComplete: function(transport
) {
1429 handle_rpc_json(transport
);
1431 reply
= JSON
.parse(transport
.responseText
);
1432 var batch
= reply
.ids
;
1434 batch
.each(function(id
) {
1436 var elem
= $("RROW-" + id
);
1437 if (elem
) elem
.removeClassName("Unread");
1438 catchup_id_batch
.remove(id
);
1441 updateFloatingTitle(true);
1447 exception_error("catchupBatchedArticles", e
);
1451 function catchupRelativeToArticle(below
, id
) {
1455 if (!id
) id
= getActiveArticleId();
1458 alert(__("No article is selected."));
1462 var visible_ids
= getVisibleArticleIds();
1464 var ids_to_mark
= new Array();
1467 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1468 if (visible_ids
[i
] != id
) {
1469 var e
= $("RROW-" + visible_ids
[i
]);
1471 if (e
&& e
.hasClassName("Unread")) {
1472 ids_to_mark
.push(visible_ids
[i
]);
1479 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1480 if (visible_ids
[i
] != id
) {
1481 var e
= $("RROW-" + visible_ids
[i
]);
1483 if (e
&& e
.hasClassName("Unread")) {
1484 ids_to_mark
.push(visible_ids
[i
]);
1492 if (ids_to_mark
.length
== 0) {
1493 alert(__("No articles found to mark"));
1495 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1497 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1499 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1500 var e
= $("RROW-" + ids_to_mark
[i
]);
1501 e
.removeClassName("Unread");
1504 var query
= "?op=rpc&method=catchupSelected" +
1505 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1507 new Ajax
.Request("backend.php", {
1509 onComplete: function(transport
) {
1510 handle_rpc_json(transport
);
1517 exception_error("catchupRelativeToArticle", e
);
1521 function cdmCollapseArticle(event
, id
, unmark
) {
1523 if (unmark
== undefined) unmark
= true;
1525 var row
= $("RROW-" + id
);
1526 var elem
= $("CICD-" + id
);
1529 var collapse
= $$("div#RROW-" + id
+
1530 " span[class='collapseBtn']")[0];
1533 Element
.show("CEXC-" + id
);
1534 Element
.hide(collapse
);
1537 row
.removeClassName("active");
1539 markHeadline(id
, false);
1541 if (id
== getActiveArticleId()) {
1542 setActiveArticleId(0);
1545 updateSelectedPrompt();
1548 if (event
) Event
.stop(event
);
1550 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1552 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1553 scrollToRowId(row
.id
);
1555 $("floatingTitle").style
.visibility
= "hidden";
1556 $("floatingTitle").setAttribute("rowid", false);
1560 exception_error("cdmCollapseArticle", e
);
1564 function cdmExpandArticle(id
, noexpand
) {
1566 console
.log("cdmExpandArticle " + id
);
1568 if (!$("RROW-" + id
)) return false;
1570 var oldrow
= $("RROW-" + getActiveArticleId());
1572 var elem
= $("CICD-" + getActiveArticleId());
1574 if (id
== getActiveArticleId() && Element
.visible(elem
))
1577 selectArticles("none");
1579 var old_offset
= $("RROW-" + id
).offsetTop
;
1581 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1582 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1583 " span[class='collapseBtn']")[0];
1586 Element
.show("CEXC-" + getActiveArticleId());
1587 Element
.hide(collapse
);
1590 if (oldrow
) oldrow
.removeClassName("active");
1592 setActiveArticleId(id
);
1594 elem
= $("CICD-" + id
);
1596 var collapse
= $$("div#RROW-" + id
+
1597 " span[class='collapseBtn']")[0];
1599 var cencw
= $("CENCW-" + id
);
1601 if (!Element
.visible(elem
) && !noexpand
) {
1603 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1604 cencw
.setAttribute('id', '');
1605 Element
.show(cencw
);
1609 Element
.hide("CEXC-" + id
);
1610 Element
.show(collapse
);
1613 var new_offset
= $("RROW-" + id
).offsetTop
;
1615 if (old_offset
> new_offset
)
1616 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1619 toggleUnread(id
, 0, true);
1621 $("RROW-" + id
).addClassName("active");
1623 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1626 exception_error("cdmExpandArticle", e
);
1632 function getArticleUnderPointer() {
1633 return post_under_pointer
;
1636 function scrollArticle(offset
) {
1639 var ci
= $("content-insert");
1641 ci
.scrollTop
+= offset
;
1644 var hi
= $("headlines-frame");
1646 hi
.scrollTop
+= offset
;
1651 exception_error("scrollArticle", e
);
1655 function show_labels_in_headlines(transport
) {
1657 var data
= JSON
.parse(transport
.responseText
);
1660 data
['info-for-headlines'].each(function(elem
) {
1661 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1662 ctr
.innerHTML
= elem
.labels
;
1667 exception_error("show_labels_in_headlines", e
);
1671 function dismissArticle(id
) {
1673 var elem
= $("RROW-" + id
);
1677 toggleUnread(id
, 0, true);
1679 new Effect
.Fade(elem
, {duration
: 0.5});
1681 // Remove the content, too
1682 var elem_content
= $("CICD-" + id
);
1684 Element
.remove(elem_content
);
1687 if (id
== getActiveArticleId()) {
1688 setActiveArticleId(0);
1692 exception_error("dismissArticle", e
);
1696 function dismissSelectedArticles() {
1699 var ids
= getVisibleArticleIds();
1703 for (var i
= 0; i
< ids
.length
; i
++) {
1704 var elem
= $("RROW-" + ids
[i
]);
1706 if (elem
.className
&& elem
.hasClassName("Selected") &&
1707 ids
[i
] != getActiveArticleId()) {
1708 new Effect
.Fade(elem
, {duration
: 0.5});
1711 // Remove the content, too
1712 var elem_content
= $("CICD-" + ids
[i
]);
1714 Element
.remove(elem_content
);
1722 selectionToggleUnread(false);
1726 exception_error("dismissSelectedArticles", e
);
1730 function dismissReadArticles() {
1733 var ids
= getVisibleArticleIds();
1736 for (var i
= 0; i
< ids
.length
; i
++) {
1737 var elem
= $("RROW-" + ids
[i
]);
1739 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1740 !elem
.hasClassName("Selected")) {
1742 new Effect
.Fade(elem
, {duration
: 0.5});
1744 // Remove the content, too
1745 var elem_content
= $("CICD-" + ids
[i
]);
1747 Element
.remove(elem_content
);
1755 exception_error("dismissReadArticles", e
);
1759 function getVisibleArticleIds() {
1764 getLoadedArticleIds().each(function(id
) {
1765 var elem
= $("RROW-" + id
);
1766 if (elem
&& Element
.visible(elem
))
1771 exception_error("getVisibleArticleIds", e
);
1777 function cdmClicked(event
, id
) {
1779 //var shift_key = event.shiftKey;
1781 if (!event
.ctrlKey
) {
1783 if (!getInitParam("cdm_expanded")) {
1784 return cdmExpandArticle(id
);
1787 var elem
= $("RROW-" + getActiveArticleId());
1789 if (elem
) elem
.removeClassName("active");
1791 selectArticles("none");
1794 var elem
= $("RROW-" + id
);
1795 var article_is_unread
= elem
.hasClassName("Unread");
1797 elem
.removeClassName("Unread");
1798 elem
.addClassName("active");
1800 setActiveArticleId(id
);
1802 if (article_is_unread
) {
1803 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1804 updateFloatingTitle(true);
1807 var query
= "?op=rpc&method=catchupSelected" +
1808 "&cmode=0&ids=" + param_escape(id
);
1810 new Ajax
.Request("backend.php", {
1812 onComplete: function(transport
) {
1813 handle_rpc_json(transport
);
1816 return !event
.shiftKey
;
1819 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1821 toggleSelected(id
, true);
1823 var elem
= $("RROW-" + id
);
1824 var article_is_unread
= elem
.hasClassName("Unread");
1826 if (article_is_unread
) {
1827 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1830 toggleUnread(id
, 0, false);
1832 openArticleInNewWindow(id
);
1835 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1836 request_counters(unread_in_buffer
== 0);
1839 exception_error("cdmClicked");
1845 function hlClicked(event
, id
) {
1847 if (event
.which
== 2) {
1850 } else if (event
.ctrlKey
) {
1851 toggleSelected(id
, true);
1852 toggleUnread(id
, 0, false);
1853 openArticleInNewWindow(id
);
1861 exception_error("hlClicked");
1865 function getFirstVisibleHeadlineId() {
1866 var rows
= getVisibleArticleIds();
1871 function getLastVisibleHeadlineId() {
1872 var rows
= getVisibleArticleIds();
1873 return rows
[rows
.length
-1];
1876 function openArticleInNewWindow(id
) {
1877 toggleUnread(id
, 0, false);
1878 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1881 function isCdmMode() {
1882 return getInitParam("combined_display_mode");
1885 function markHeadline(id
, marked
) {
1886 if (marked
== undefined) marked
= true;
1888 var row
= $("RROW-" + id
);
1890 var check
= dijit
.getEnclosingWidget(
1891 row
.getElementsByClassName("rchk")[0]);
1894 check
.attr("checked", marked
);
1898 row
.addClassName("Selected");
1900 row
.removeClassName("Selected");
1904 function getRelativePostIds(id
, limit
) {
1910 if (!limit
) limit
= 6; //3
1912 var ids
= getVisibleArticleIds();
1914 for (var i
= 0; i
< ids
.length
; i
++) {
1916 for (var k
= 1; k
<= limit
; k
++) {
1917 //if (i > k-1) tmp.push(ids[i-k]);
1918 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1925 exception_error("getRelativePostIds", e
);
1931 function correctHeadlinesOffset(id
) {
1935 var container
= $("headlines-frame");
1936 var row
= $("RROW-" + id
);
1938 if (!container
|| !row
) return;
1940 var viewport
= container
.offsetHeight
;
1942 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1943 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1945 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1946 //console.log("Vport: " + viewport);
1948 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1949 container
.scrollTop
= row
.offsetTop
;
1950 } else if (rel_offset_bottom
> viewport
) {
1952 /* doesn't properly work with Opera in some cases because
1953 Opera fucks up element scrolling */
1955 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1959 exception_error("correctHeadlinesOffset", e
);
1964 function headlineActionsChange(elem
) {
1967 elem
.attr('value', 'false');
1969 exception_error("headlineActionsChange", e
);
1973 function closeArticlePanel() {
1975 if (dijit
.byId("content-insert"))
1976 dijit
.byId("headlines-wrap-inner").removeChild(
1977 dijit
.byId("content-insert"));
1980 function initFloatingMenu() {
1982 if (dijit
.byId("floatingMenu"))
1983 dijit
.byId("floatingMenu").destroyRecursive();
1985 var menu
= new dijit
.Menu({
1987 targetNodeIds
: ["floatingTitle"]
1990 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1992 headlinesMenuCommon(menu
, id
);
1996 exception_error("initFloatingMenu", e
);
2000 function headlinesMenuCommon(menu
, base_id
) {
2003 menu
.addChild(new dijit
.MenuItem({
2004 label
: __("Open original article"),
2005 onClick: function(event
) {
2006 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
2009 menu
.addChild(new dijit
.MenuItem({
2010 label
: __("Display article URL"),
2011 onClick: function(event
) {
2012 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
2015 menu
.addChild(new dijit
.MenuSeparator());
2017 menu
.addChild(new dijit
.MenuItem({
2018 label
: __("Toggle unread"),
2019 onClick: function(event
) {
2020 var ids
= getSelectedArticleIds2();
2022 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2023 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2025 selectionToggleUnread(undefined, false, true, ids
);
2028 menu
.addChild(new dijit
.MenuItem({
2029 label
: __("Toggle starred"),
2030 onClick: function(event
) {
2031 var ids
= getSelectedArticleIds2();
2033 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2034 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2036 selectionToggleMarked(undefined, false, true, ids
);
2039 menu
.addChild(new dijit
.MenuItem({
2040 label
: __("Toggle published"),
2041 onClick: function(event
) {
2042 var ids
= getSelectedArticleIds2();
2044 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
2045 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2047 selectionTogglePublished(undefined, false, true, ids
);
2050 menu
.addChild(new dijit
.MenuSeparator());
2052 menu
.addChild(new dijit
.MenuItem({
2053 label
: __("Mark above as read"),
2054 onClick: function(event
) {
2055 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
2058 menu
.addChild(new dijit
.MenuItem({
2059 label
: __("Mark below as read"),
2060 onClick: function(event
) {
2061 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
2065 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2069 menu
.addChild(new dijit
.MenuSeparator());
2071 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2072 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2074 labels
.each(function(label
) {
2075 var id
= label
.id
[0];
2076 var bare_id
= id
.substr(id
.indexOf(":")+1);
2077 var name
= label
.name
[0];
2079 bare_id
= feed_to_label_id(bare_id
);
2081 labelAddMenu
.addChild(new dijit
.MenuItem({
2084 onClick: function(event
) {
2085 var ids
= getSelectedArticleIds2();
2087 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2089 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2091 selectionAssignLabel(this.labelId
, ids
);
2094 labelDelMenu
.addChild(new dijit
.MenuItem({
2097 onClick: function(event
) {
2098 var ids
= getSelectedArticleIds2();
2100 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
2102 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
2104 selectionRemoveLabel(this.labelId
, ids
);
2109 menu
.addChild(new dijit
.PopupMenuItem({
2110 label
: __("Assign label"),
2111 popup
: labelAddMenu
,
2114 menu
.addChild(new dijit
.PopupMenuItem({
2115 label
: __("Remove label"),
2116 popup
: labelDelMenu
,
2123 exception_error("headlinesMenuCommon", e
);
2127 function initHeadlinesMenu() {
2129 if (dijit
.byId("headlinesMenu"))
2130 dijit
.byId("headlinesMenu").destroyRecursive();
2135 nodes
= $$("#headlines-frame > div[id*=RROW]");
2137 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2140 nodes
.each(function(node
) {
2144 var menu
= new dijit
.Menu({
2145 id
: "headlinesMenu",
2149 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2150 var callerNode
= event
.target
, match
= null, tries
= 0;
2152 while (match
== null && callerNode
&& tries
<= 3) {
2153 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2154 callerNode
= callerNode
.parentNode
;
2158 if (match
) this.callerRowId
= parseInt(match
[1]);
2162 headlinesMenuCommon(menu
, false);
2166 /* vgroup feed title menu */
2168 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2171 nodes
.each(function(node
) {
2175 if (ids
.length
> 0) {
2176 if (dijit
.byId("headlinesFeedTitleMenu"))
2177 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2179 var menu
= new dijit
.Menu({
2180 id
: "headlinesFeedTitleMenu",
2184 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2185 var callerNode
= event
.target
, match
= null, tries
= 0;
2187 while (match
== null && callerNode
&& tries
<= 3) {
2188 console
.log(callerNode
.id
);
2190 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2191 callerNode
= callerNode
.parentNode
;
2194 console
.log(match
[1]);
2197 if (match
) this.callerRowId
= parseInt(match
[1]);
2201 menu
.addChild(new dijit
.MenuItem({
2202 label
: __("Select articles in group"),
2203 onClick: function(event
) {
2204 selectArticles("all",
2205 "#headlines-frame > div[id*=RROW]"+
2206 "[orig-feed-id='"+menu
.callerRowId
+"']");
2210 menu
.addChild(new dijit
.MenuItem({
2211 label
: __("Mark group as read"),
2212 onClick: function(event
) {
2213 selectArticles("none");
2214 selectArticles("all",
2215 "#headlines-frame > div[id*=RROW]"+
2216 "[orig-feed-id='"+menu
.callerRowId
+"']");
2222 menu
.addChild(new dijit
.MenuItem({
2223 label
: __("Mark feed as read"),
2224 onClick: function(event
) {
2225 catchupFeedInGroup(menu
.callerRowId
);
2233 exception_error("initHeadlinesMenu", e
);
2237 function cache_set(id
, obj
) {
2238 //console.log("cache_set: " + id);
2241 sessionStorage
[id
] = obj
;
2243 sessionStorage
.clear();
2247 function cache_get(id
) {
2249 return sessionStorage
[id
];
2252 function cache_clear() {
2254 sessionStorage
.clear();
2257 function cache_delete(id
) {
2259 sessionStorage
.removeItem(id
);
2262 function cancelSearch() {
2267 exception_error("cancelSearch", e
);
2271 function setSelectionScore() {
2273 var ids
= getSelectedArticleIds2();
2275 if (ids
.length
> 0) {
2278 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2280 if (score
!= undefined) {
2281 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2282 "&score=" + param_escape(score
);
2284 new Ajax
.Request("backend.php", {
2286 onComplete: function(transport
) {
2287 var reply
= JSON
.parse(transport
.responseText
);
2291 ids
.each(function(id
) {
2292 var row
= $("RROW-" + id
);
2295 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2298 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2299 reply
["score_pic"]);
2300 pic
.setAttribute("score", score
);
2309 alert(__("No articles are selected."));
2312 exception_error("setSelectionScore", e
);
2316 function updateScore(id
) {
2318 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2322 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2324 new Ajax
.Request("backend.php", {
2326 onComplete: function(transport
) {
2327 console
.log(transport
.responseText
);
2329 var reply
= JSON
.parse(transport
.responseText
);
2332 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2333 pic
.setAttribute("score", reply
["score"]);
2334 pic
.setAttribute("title", reply
["score"]);
2340 exception_error("updateScore", e
);
2344 function changeScore(id
, pic
) {
2346 var score
= pic
.getAttribute("score");
2348 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2350 if (new_score
!= undefined) {
2352 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2353 "&score=" + param_escape(new_score
);
2355 new Ajax
.Request("backend.php", {
2357 onComplete: function(transport
) {
2358 var reply
= JSON
.parse(transport
.responseText
);
2361 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2362 pic
.setAttribute("score", new_score
);
2363 pic
.setAttribute("title", new_score
);
2368 exception_error("changeScore", e
);
2372 function displayArticleUrl(id
) {
2374 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2376 new Ajax
.Request("backend.php", {
2378 onComplete: function(transport
) {
2379 var reply
= JSON
.parse(transport
.responseText
);
2381 if (reply
&& reply
.link
) {
2382 prompt(__("Article URL:"), reply
.link
);
2386 exception_error("changeScore", e
);
2390 function openSelectedAttachment(elem
) {
2392 var url
= elem
[elem
.selectedIndex
].value
;
2396 elem
.selectedIndex
= 0;
2400 exception_error("openSelectedAttachment", e
);
2404 function scrollToRowId(id
) {
2409 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2412 exception_error("scrollToRowId", e
);
2416 function updateFloatingTitle(unread_only
) {
2418 if (!isCdmMode()) return;
2420 var hf
= $("headlines-frame");
2422 var elems
= $$("#headlines-frame > div[id*=RROW]");
2424 for (var i
= 0; i
< elems
.length
; i
++) {
2426 var child
= elems
[i
];
2428 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2430 var header
= child
.getElementsByClassName("cdmHeader")[0];
2432 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2433 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2434 $("floatingTitle").setAttribute("rowid", child
.id
);
2435 $("floatingTitle").innerHTML
= header
.innerHTML
;
2436 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2440 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2443 cb
.parentNode
.removeChild(cb
);
2446 if (child
.hasClassName("Unread"))
2447 $("floatingTitle").addClassName("Unread");
2449 $("floatingTitle").removeClassName("Unread");
2451 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2454 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2455 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2456 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2457 $("floatingTitle").style
.visibility
= "visible";
2459 $("floatingTitle").style
.visibility
= "hidden";
2467 exception_error("updateFloatingTitle", e
);
2471 function cdmFooterClick(event
) {
2472 event
.stopPropagation();