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 _headlines_scroll_offset
= 0;
17 var current_first_id
= 0;
19 var _catchup_request_sent
= false;
21 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
23 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
25 handle_rpc_json(transport
);
27 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
35 reply
= JSON
.parse(transport
.responseText
);
42 is_cat
= reply
['headlines']['is_cat'];
43 feed_id
= reply
['headlines']['id'];
46 var content
= reply
['headlines']['content'];
48 content
= content
+ "<div id='headlines-spacer'></div>";
52 if (feed_id
!= -7 && (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat()))
55 /* dijit.getEnclosingWidget(
56 document.forms["main_toolbar_form"].update).attr('disabled',
57 is_cat || feed_id <= 0); */
60 if (infscroll_req
== false) {
61 $("headlines-frame").scrollTop
= 0;
63 $("floatingTitle").style
.visibility
= "hidden";
64 $("floatingTitle").setAttribute("rowid", 0);
65 $("floatingTitle").innerHTML
= "";
69 $("headlines-frame").removeClassName("cdm");
70 $("headlines-frame").removeClassName("normal");
72 $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
74 var headlines_count
= reply
['headlines-info']['count'];
76 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
78 if (parseInt(headlines_count
) < 30) {
79 _infscroll_disable
= 1;
81 _infscroll_disable
= 0;
84 current_first_id
= reply
['headlines']['first_id'];
85 var counters
= reply
['counters'];
86 var articles
= reply
['articles'];
87 //var runtime_info = reply['runtime-info'];
89 if (infscroll_req
== false) {
90 loaded_article_ids
= [];
92 dojo
.html
.set($("headlines-toolbar"),
93 reply
['headlines']['toolbar'],
94 {parseContent
: true});
96 /*dojo.html.set($("headlines-frame"),
97 reply['headlines']['content'],
98 {parseContent: true});
100 $$("#headlines-frame div[id*='RROW']").each(function(row) {
101 loaded_article_ids.push(row.id);
104 $("headlines-frame").innerHTML
= '';
106 var tmp
= new Element("div");
107 tmp
.innerHTML
= reply
['headlines']['content'];
108 dojo
.parser
.parse(tmp
);
110 while (tmp
.hasChildNodes()) {
111 var row
= tmp
.removeChild(tmp
.firstChild
);
113 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
114 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
116 loaded_article_ids
.push(row
.id
);
120 var hsp
= $("headlines-spacer");
121 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
122 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
126 if (_infscroll_disable
)
127 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
128 __("Click to open next unread feed.") + "</a>";
131 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
132 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
138 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
139 console
.log("adding some more headlines: " + headlines_count
);
141 var c
= dijit
.byId("headlines-frame");
142 var ids
= getSelectedArticleIds2();
144 var hsp
= $("headlines-spacer");
147 c
.domNode
.removeChild(hsp
);
149 var tmp
= new Element("div");
150 tmp
.innerHTML
= reply
['headlines']['content'];
151 dojo
.parser
.parse(tmp
);
153 while (tmp
.hasChildNodes()) {
154 var row
= tmp
.removeChild(tmp
.firstChild
);
156 if (loaded_article_ids
.indexOf(row
.id
) == -1 || row
.hasClassName("cdmFeedTitle")) {
157 dijit
.byId("headlines-frame").domNode
.appendChild(row
);
159 loaded_article_ids
.push(row
.id
);
163 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
164 c
.domNode
.appendChild(hsp
);
166 if (headlines_count
< 30) _infscroll_disable
= true;
168 console
.log("restore selected ids: " + ids
);
170 for (var i
= 0; i
< ids
.length
; i
++) {
171 markHeadline(ids
[i
]);
176 if (_infscroll_disable
) {
177 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
178 __("Click to open next unread feed.") + "</a>";
182 console
.log("no new headlines received");
184 var first_id_changed
= reply
['headlines']['first_id_changed'];
185 console
.log("first id changed:" + first_id_changed
);
187 var hsp
= $("headlines-spacer");
190 if (first_id_changed
) {
191 hsp
.innerHTML
= "<a href='#' onclick='viewCurrentFeed()'>" +
192 __("New articles found, reload feed to continue.") + "</a>";
194 hsp
.innerHTML
= "<a href='#' onclick='openNextUnreadFeed()'>" +
195 __("Click to open next unread feed.") + "</a>";
204 for (var i
= 0; i
< articles
.length
; i
++) {
205 var a_id
= articles
[i
]['id'];
206 cache_set("article:" + a_id
, articles
[i
]['content']);
209 console
.log("no cached articles received");
213 parse_counters(counters
);
215 request_counters(true);
218 console
.error("Invalid object received: " + transport
.responseText
);
219 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
220 __('Could not update headlines (invalid object received - see error console for details)') +
224 _infscroll_request_sent
= 0;
225 _last_headlines_update
= new Date().getTime();
227 unpackVisibleHeadlines();
229 // if we have some more space in the buffer, why not try to fill it
231 if (!_infscroll_disable
&& $("headlines-spacer") &&
232 $("headlines-spacer").offsetTop
< $("headlines-frame").offsetHeight
) {
234 window
.setTimeout(function() {
242 exception_error("headlines_callback2", e
, transport
);
246 function render_article(article
) {
248 cleanup_memory("content-insert");
250 dijit
.byId("headlines-wrap-inner").addChild(
251 dijit
.byId("content-insert"));
253 var c
= dijit
.byId("content-insert");
256 c
.domNode
.scrollTop
= 0;
259 c
.attr('content', article
);
260 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED
, c
.domNode
);
262 correctHeadlinesOffset(getActiveArticleId());
269 exception_error("render_article", e
);
273 function showArticleInHeadlines(id
, noexpand
) {
276 selectArticles("none");
278 var crow
= $("RROW-" + id
);
282 var article_is_unread
= crow
.hasClassName("Unread");
285 crow
.removeClassName("Unread");
286 crow
.addClassName("active");
288 selectArticles('none');
290 var view_mode
= false;
293 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
294 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
301 if (article_is_unread
&& !noexpand
)
302 _force_scheduled_update
= true;
305 exception_error("showArticleInHeadlines", e
);
309 function article_callback2(transport
, id
) {
311 console
.log("article_callback2 " + id
);
313 handle_rpc_json(transport
);
318 reply
= JSON
.parse(transport
.responseText
);
325 reply
.each(function(article
) {
326 if (getActiveArticleId() == article
['id']) {
327 render_article(article
['content']);
329 cids_requested
.remove(article
['id']);
331 cache_set("article:" + article
['id'], article
['content']);
334 // if (id != last_requested_article) {
335 // console.log("requested article id is out of sequence, aborting");
340 console
.error("Invalid object received: " + transport
.responseText
);
342 render_article("<div class='whiteBox'>" +
343 __('Could not display article (invalid object received - see error console for details)') + "</div>");
346 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
347 request_counters(unread_in_buffer
== 0);
351 exception_error("article_callback2", e
, transport
);
355 function view(id
, activefeed
, noexpand
) {
357 var oldrow
= $("RROW-" + getActiveArticleId());
358 if (oldrow
) oldrow
.removeClassName("active");
360 var crow
= $("RROW-" + id
);
364 setActiveArticleId(id
);
365 showArticleInHeadlines(id
, noexpand
);
369 console
.log("loading article: " + id
);
371 var cached_article
= cache_get("article:" + id
);
373 console
.log("cache check result: " + (cached_article
!= false));
375 var query
= "?op=article&method=view&id=" + param_escape(id
);
377 var neighbor_ids
= getRelativePostIds(id
);
379 /* only request uncached articles */
381 var cids_to_request
= [];
383 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
384 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
385 if (!cache_get("article:" + neighbor_ids
[i
])) {
386 cids_to_request
.push(neighbor_ids
[i
]);
387 cids_requested
.push(neighbor_ids
[i
]);
391 console
.log("additional ids: " + cids_to_request
.toString());
393 query
= query
+ "&cids=" + cids_to_request
.toString();
395 var article_is_unread
= crow
.hasClassName("Unread");
397 setActiveArticleId(id
);
398 showArticleInHeadlines(id
);
400 if (cached_article
&& article_is_unread
) {
402 query
= query
+ "&mode=prefetch";
404 render_article(cached_article
);
406 } else if (cached_article
) {
408 query
= query
+ "&mode=prefetch_old";
409 render_article(cached_article
);
411 // if we don't need to request any relative ids, we might as well skip
412 // the server roundtrip altogether
413 if (cids_to_request
.length
== 0) {
418 last_requested_article
= id
;
422 if (article_is_unread
) {
423 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
426 new Ajax
.Request("backend.php", {
428 onComplete: function(transport
) {
429 article_callback2(transport
, id
);
435 exception_error("view", e
);
439 function toggleMark(id
, client_only
) {
441 var query
= "?op=rpc&id=" + id
+ "&method=mark";
443 var row
= $("RROW-" + id
);
448 var row_imgs
= row
.getElementsByClassName("markedPic");
450 for (var i
= 0; i
< row_imgs
.length
; i
++)
451 imgs
.push(row_imgs
[i
]);
453 var ft
= $("floatingTitle");
455 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
456 var fte
= ft
.getElementsByClassName("markedPic");
458 for (var i
= 0; i
< fte
.length
; i
++)
462 for (i
= 0; i
< imgs
.length
; i
++) {
465 if (!row
.hasClassName("marked")) {
466 img
.src
= img
.src
.replace("mark_unset", "mark_set");
467 img
.alt
= __("Unstar article");
468 query
= query
+ "&mark=1";
470 img
.src
= img
.src
.replace("mark_set", "mark_unset");
471 img
.alt
= __("Star article");
472 query
= query
+ "&mark=0";
476 row
.toggleClassName("marked");
479 new Ajax
.Request("backend.php", {
481 onComplete: function(transport
) {
482 handle_rpc_json(transport
);
487 exception_error("toggleMark", e
);
491 function togglePub(id
, client_only
, no_effects
, note
) {
493 var query
= "?op=rpc&id=" + id
+ "&method=publ";
495 if (note
!= undefined) {
496 query
= query
+ "¬e=" + param_escape(note
);
498 query
= query
+ "¬e=undefined";
501 var row
= $("RROW-" + id
);
506 var row_imgs
= row
.getElementsByClassName("pubPic");
508 for (var i
= 0; i
< row_imgs
.length
; i
++)
509 imgs
.push(row_imgs
[i
]);
511 var ft
= $("floatingTitle");
513 if (ft
&& ft
.getAttribute("rowid") == "RROW-" + id
) {
514 var fte
= ft
.getElementsByClassName("pubPic");
516 for (var i
= 0; i
< fte
.length
; i
++)
520 for (i
= 0; i
< imgs
.length
; i
++) {
523 if (!row
.hasClassName("published") || note
!= undefined) {
524 img
.src
= img
.src
.replace("pub_unset", "pub_set");
525 img
.alt
= __("Unpublish article");
526 query
= query
+ "&pub=1";
528 img
.src
= img
.src
.replace("pub_set", "pub_unset");
529 img
.alt
= __("Publish article");
530 query
= query
+ "&pub=0";
534 if (note
!= undefined)
535 row
.addClassName("published");
537 row
.toggleClassName("published");
540 new Ajax
.Request("backend.php", {
542 onComplete: function(transport
) {
543 handle_rpc_json(transport
);
548 exception_error("togglePub", e
);
552 function moveToPost(mode
, noscroll
, noexpand
) {
556 var rows
= getLoadedArticleIds();
561 if (!$('RROW-' + getActiveArticleId())) {
562 setActiveArticleId(0);
565 if (!getActiveArticleId()) {
567 prev_id
= rows
[rows
.length
-1]
569 for (var i
= 0; i
< rows
.length
; i
++) {
570 if (rows
[i
] == getActiveArticleId()) {
572 // Account for adjacent identical article ids.
573 if (i
> 0) prev_id
= rows
[i
-1];
575 for (var j
= i
+1; j
< rows
.length
; j
++) {
576 if (rows
[j
] != getActiveArticleId()) {
586 console
.log("cur: " + getActiveArticleId() + " next: " + next_id
);
588 if (mode
== "next") {
589 if (next_id
|| getActiveArticleId()) {
592 var article
= $("RROW-" + getActiveArticleId());
593 var ctr
= $("headlines-frame");
595 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
596 ctr
.scrollTop
+ ctr
.offsetHeight
) {
598 scrollArticle(ctr
.offsetHeight
/4);
600 } else if (next_id
) {
601 cdmExpandArticle(next_id
, noexpand
);
602 cdmScrollToArticleId(next_id
, true);
605 } else if (next_id
) {
606 correctHeadlinesOffset(next_id
);
607 view(next_id
, getActiveFeedId(), noexpand
);
612 if (mode
== "prev") {
613 if (prev_id
|| getActiveArticleId()) {
616 var article
= $("RROW-" + getActiveArticleId());
617 var prev_article
= $("RROW-" + prev_id
);
618 var ctr
= $("headlines-frame");
620 if (!getInitParam("cdm_expanded")) {
622 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
623 scrollArticle(-ctr
.offsetHeight
/4);
625 cdmExpandArticle(prev_id
, noexpand
);
626 cdmScrollToArticleId(prev_id
, true);
630 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
631 scrollArticle(-ctr
.offsetHeight
/3);
632 } else if (!noscroll
&& prev_article
&&
633 prev_article
.offsetTop
< ctr
.scrollTop
) {
634 cdmExpandArticle(prev_id
, noexpand
);
635 scrollArticle(-ctr
.offsetHeight
/4);
636 } else if (prev_id
) {
637 cdmExpandArticle(prev_id
, noexpand
);
638 cdmScrollToArticleId(prev_id
, noscroll
);
642 } else if (prev_id
) {
643 correctHeadlinesOffset(prev_id
);
644 view(prev_id
, getActiveFeedId(), noexpand
);
650 exception_error("moveToPost", e
);
654 function toggleSelected(id
, force_on
) {
656 var row
= $("RROW-" + id
);
659 var cb
= dijit
.getEnclosingWidget(
660 row
.getElementsByClassName("rchk")[0]);
662 if (row
.hasClassName('Selected') && !force_on
) {
663 row
.removeClassName('Selected');
664 if (cb
) cb
.attr("checked", false);
666 row
.addClassName('Selected');
667 if (cb
) cb
.attr("checked", true);
671 updateSelectedPrompt();
673 exception_error("toggleSelected", e
);
677 function updateSelectedPrompt() {
679 var count
= getSelectedArticleIds2().size();
680 var elem
= $("selected_prompt");
683 elem
.innerHTML
= ngettext("%d article selected",
684 "%d articles selected", count
).replace("%d", count
);
693 exception_error("updateSelectedPrompt", e
);
697 function toggleUnread(id
, cmode
, effect
) {
700 var row
= $("RROW-" + id
);
702 var tmpClassName
= row
.className
;
704 if (cmode
== undefined || cmode
== 2) {
705 if (row
.hasClassName("Unread")) {
706 row
.removeClassName("Unread");
709 row
.addClassName("Unread");
712 } else if (cmode
== 0) {
714 row
.removeClassName("Unread");
716 } else if (cmode
== 1) {
717 row
.addClassName("Unread");
720 if (cmode
== undefined) cmode
= 2;
722 var query
= "?op=rpc&method=catchupSelected" +
723 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
725 // notify_progress("Loading, please wait...");
727 if (tmpClassName
!= row
.className
) {
728 new Ajax
.Request("backend.php", {
730 onComplete: function (transport
) {
731 handle_rpc_json(transport
);
739 exception_error("toggleUnread", e
);
743 function selectionRemoveLabel(id
, ids
) {
746 if (!ids
) ids
= getSelectedArticleIds2();
748 if (ids
.length
== 0) {
749 alert(__("No articles are selected."));
753 var query
= "?op=article&method=removeFromLabel&ids=" +
754 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
758 new Ajax
.Request("backend.php", {
760 onComplete: function(transport
) {
761 handle_rpc_json(transport
);
762 show_labels_in_headlines(transport
);
766 exception_error("selectionAssignLabel", e
);
771 function selectionAssignLabel(id
, ids
) {
774 if (!ids
) ids
= getSelectedArticleIds2();
776 if (ids
.length
== 0) {
777 alert(__("No articles are selected."));
781 var query
= "?op=article&method=assignToLabel&ids=" +
782 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
786 new Ajax
.Request("backend.php", {
788 onComplete: function(transport
) {
789 handle_rpc_json(transport
);
790 show_labels_in_headlines(transport
);
794 exception_error("selectionAssignLabel", e
);
799 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
801 var rows
= ids
? ids
: getSelectedArticleIds2();
803 if (rows
.length
== 0 && !no_error
) {
804 alert(__("No articles are selected."));
808 for (var i
= 0; i
< rows
.length
; i
++) {
809 var row
= $("RROW-" + rows
[i
]);
811 if (set_state
== undefined) {
812 if (row
.hasClassName("Unread")) {
813 row
.removeClassName("Unread");
815 row
.addClassName("Unread");
819 if (set_state
== false) {
820 row
.removeClassName("Unread");
823 if (set_state
== true) {
824 row
.addClassName("Unread");
829 updateFloatingTitle(true);
831 if (rows
.length
> 0) {
835 if (set_state
== undefined) {
837 } else if (set_state
== true) {
839 } else if (set_state
== false) {
843 var query
= "?op=rpc&method=catchupSelected" +
844 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
846 notify_progress("Loading, please wait...");
848 new Ajax
.Request("backend.php", {
850 onComplete: function(transport
) {
851 handle_rpc_json(transport
);
852 if (callback
) callback(transport
);
858 exception_error("selectionToggleUnread", e
);
863 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
866 var rows
= ids
? ids
: getSelectedArticleIds2();
868 if (rows
.length
== 0 && !no_error
) {
869 alert(__("No articles are selected."));
873 for (var i
= 0; i
< rows
.length
; i
++) {
874 toggleMark(rows
[i
], true, true);
877 if (rows
.length
> 0) {
879 var query
= "?op=rpc&method=markSelected&ids=" +
880 param_escape(rows
.toString()) + "&cmode=2";
882 new Ajax
.Request("backend.php", {
884 onComplete: function(transport
) {
885 handle_rpc_json(transport
);
886 if (callback
) callback(transport
);
892 exception_error("selectionToggleMarked", e
);
897 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
900 var rows
= ids
? ids
: getSelectedArticleIds2();
902 if (rows
.length
== 0 && !no_error
) {
903 alert(__("No articles are selected."));
907 for (var i
= 0; i
< rows
.length
; i
++) {
908 togglePub(rows
[i
], true, true);
911 if (rows
.length
> 0) {
913 var query
= "?op=rpc&method=publishSelected&ids=" +
914 param_escape(rows
.toString()) + "&cmode=2";
916 new Ajax
.Request("backend.php", {
918 onComplete: function(transport
) {
919 handle_rpc_json(transport
);
925 exception_error("selectionToggleMarked", e
);
929 function getSelectedArticleIds2() {
933 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
935 rv
.push(child
.id
.replace("RROW-", ""));
941 function getLoadedArticleIds() {
944 var children
= $$("#headlines-frame > div[id*=RROW-]");
946 children
.each(function(child
) {
947 rv
.push(child
.id
.replace("RROW-", ""));
954 // mode = all,none,unread,invert,marked,published
955 function selectArticles(mode
, query
) {
958 if (!query
) query
= "#headlines-frame > div[id*=RROW]";
960 var children
= $$(query
);
962 children
.each(function(child
) {
963 var id
= child
.id
.replace("RROW-", "");
965 var cb
= dijit
.getEnclosingWidget(
966 child
.getElementsByClassName("rchk")[0]);
969 child
.addClassName("Selected");
970 if (cb
) cb
.attr("checked", true);
971 } else if (mode
== "unread") {
972 if (child
.hasClassName("Unread")) {
973 child
.addClassName("Selected");
974 if (cb
) cb
.attr("checked", true);
976 child
.removeClassName("Selected");
977 if (cb
) cb
.attr("checked", false);
979 } else if (mode
== "marked") {
980 if (child
.hasClassName("marked")) {
981 child
.addClassName("Selected");
982 if (cb
) cb
.attr("checked", true);
984 child
.removeClassName("Selected");
985 if (cb
) cb
.attr("checked", false);
987 } else if (mode
== "published") {
988 if (child
.hasClassName("published")) {
989 child
.addClassName("Selected");
990 if (cb
) cb
.attr("checked", true);
992 child
.removeClassName("Selected");
993 if (cb
) cb
.attr("checked", false);
996 } else if (mode
== "invert") {
997 if (child
.hasClassName("Selected")) {
998 child
.removeClassName("Selected");
999 if (cb
) cb
.attr("checked", false);
1001 child
.addClassName("Selected");
1002 if (cb
) cb
.attr("checked", true);
1006 child
.removeClassName("Selected");
1007 if (cb
) cb
.attr("checked", false);
1011 updateSelectedPrompt();
1014 exception_error("selectArticles", e
);
1018 function deleteSelection() {
1022 var rows
= getSelectedArticleIds2();
1024 if (rows
.length
== 0) {
1025 alert(__("No articles are selected."));
1029 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1032 if (getActiveFeedId() != 0) {
1033 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
1035 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
1038 str
= str
.replace("%d", rows
.length
);
1039 str
= str
.replace("%s", fn
);
1041 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1045 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1049 new Ajax
.Request("backend.php", {
1051 onComplete: function(transport
) {
1052 handle_rpc_json(transport
);
1057 exception_error("deleteSelection", e
);
1061 function archiveSelection() {
1065 var rows
= getSelectedArticleIds2();
1067 if (rows
.length
== 0) {
1068 alert(__("No articles are selected."));
1072 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1076 if (getActiveFeedId() != 0) {
1077 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1080 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1082 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1087 str
= str
.replace("%d", rows
.length
);
1088 str
= str
.replace("%s", fn
);
1090 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1094 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1098 for (var i
= 0; i
< rows
.length
; i
++) {
1099 cache_delete("article:" + rows
[i
]);
1102 new Ajax
.Request("backend.php", {
1104 onComplete: function(transport
) {
1105 handle_rpc_json(transport
);
1110 exception_error("archiveSelection", e
);
1114 function catchupSelection() {
1118 var rows
= getSelectedArticleIds2();
1120 if (rows
.length
== 0) {
1121 alert(__("No articles are selected."));
1125 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1127 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1129 str
= str
.replace("%d", rows
.length
);
1130 str
= str
.replace("%s", fn
);
1132 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1136 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1139 exception_error("catchupSelection", e
);
1143 function editArticleTags(id
) {
1144 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1146 if (dijit
.byId("editTagsDlg"))
1147 dijit
.byId("editTagsDlg").destroyRecursive();
1149 dialog
= new dijit
.Dialog({
1151 title
: __("Edit article Tags"),
1152 style
: "width: 600px",
1153 execute: function() {
1154 if (this.validate()) {
1155 var query
= dojo
.objectToQuery(this.attr('value'));
1157 notify_progress("Saving article tags...", true);
1159 new Ajax
.Request("backend.php", {
1161 onComplete: function(transport
) {
1166 var data
= JSON
.parse(transport
.responseText
);
1173 var tags
= $("ATSTR-" + id
);
1174 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1176 if (tags
) tags
.innerHTML
= data
.content
;
1177 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1180 exception_error("editArticleTags/inner", e
);
1189 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1190 dojo
.disconnect(tmph
);
1192 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1193 "backend.php?op=article&method=completeTags",
1194 { tokens
: ',', paramName
: "search" });
1201 function cdmScrollToArticleId(id
, force
) {
1203 var ctr
= $("headlines-frame");
1204 var e
= $("RROW-" + id
);
1206 if (!e
|| !ctr
) return;
1208 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1209 e
.offsetTop
< ctr
.scrollTop
) {
1211 // expanded cdm has a 4px margin now
1212 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1216 exception_error("cdmScrollToArticleId", e
);
1220 function setActiveArticleId(id
) {
1221 console
.log("setActiveArticleId:" + id
);
1223 _active_article_id
= id
;
1224 PluginHost
.run(PluginHost
.HOOK_ARTICLE_SET_ACTIVE
, _active_article_id
);
1227 function getActiveArticleId() {
1228 return _active_article_id
;
1231 function postMouseIn(e
, id
) {
1232 post_under_pointer
= id
;
1235 function postMouseOut(id
) {
1236 post_under_pointer
= false;
1239 function unpackVisibleHeadlines() {
1241 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1243 $$("#headlines-frame > div[id*=RROW]").each(
1245 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1246 $("headlines-frame").offsetHeight
) {
1248 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1251 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1252 cencw
.setAttribute('id', '');
1254 PluginHost
.run(PluginHost
.HOOK_ARTICLE_RENDERED_CDM
, child
);
1256 Element
.show(cencw
);
1263 exception_error("unpackVisibleHeadlines", e
);
1267 function headlines_scroll_handler(e
) {
1270 // rate-limit in case of smooth scrolling and similar abominations
1271 if (Math
.max(e
.scrollTop
, _headlines_scroll_offset
) - Math
.min(e
.scrollTop
, _headlines_scroll_offset
) < 25) {
1275 _headlines_scroll_offset
= e
.scrollTop
;
1277 var hsp
= $("headlines-spacer");
1279 unpackVisibleHeadlines();
1281 // set topmost child in the buffer as active
1282 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1283 getSelectedArticleIds2().length
<= 1 &&
1284 getInitParam("cdm_expanded")) {
1286 var rows
= $$("#headlines-frame > div[id*=RROW]");
1288 for (var i
= 0; i
< rows
.length
; i
++) {
1289 var child
= rows
[i
];
1291 if ($("headlines-frame").scrollTop
<= child
.offsetTop
&&
1292 child
.offsetTop
- $("headlines-frame").scrollTop
< 100 &&
1293 child
.id
.replace("RROW-", "") != _active_article_id
) {
1295 if (_active_article_id
) {
1296 var row
= $("RROW-" + _active_article_id
);
1297 if (row
) row
.removeClassName("active");
1300 _active_article_id
= child
.id
.replace("RROW-", "");
1301 showArticleInHeadlines(_active_article_id
, true);
1302 updateSelectedPrompt();
1308 if (!_infscroll_disable
) {
1309 if (hsp
&& hsp
.offsetTop
- 250 <= e
.scrollTop
+ e
.offsetHeight
) {
1311 hsp
.innerHTML
= "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1312 __("Loading, please wait...") + "</span>";
1314 loadMoreHeadlines();
1321 updateFloatingTitle();
1324 catchupCurrentBatchIfNeeded();
1326 if (getInitParam("cdm_auto_catchup") == 1) {
1328 // let's get DOM some time to settle down
1329 var ts
= new Date().getTime();
1330 if (ts
- _last_headlines_update
< 100) return;
1332 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1334 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1335 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1337 var id
= child
.id
.replace("RROW-", "");
1339 if (catchup_id_batch
.indexOf(id
) == -1)
1340 catchup_id_batch
.push(id
);
1342 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1347 if (_infscroll_disable
) {
1348 var child
= $$("#headlines-frame div[id*=RROW]").last();
1350 if (child
&& $("headlines-frame").scrollTop
>
1351 (child
.offsetTop
+ child
.offsetHeight
- 50)) {
1353 console
.log("we seem to be at an end");
1355 if (getInitParam("on_catchup_show_next_feed") == "1") {
1356 openNextUnreadFeed();
1363 console
.warn("headlines_scroll_handler: " + e
);
1367 function openNextUnreadFeed() {
1369 var is_cat
= activeFeedIsCat();
1370 var nuf
= getNextUnreadFeed(getActiveFeedId(), is_cat
);
1371 if (nuf
) viewfeed({feed
: nuf
, is_cat
: is_cat
});
1373 exception_error("openNextUnreadFeed", e
);
1377 function catchupBatchedArticles() {
1379 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
&& !_catchup_request_sent
) {
1381 console
.log("catchupBatchedArticles: working");
1383 // make a copy of the array
1384 var batch
= catchup_id_batch
.slice();
1385 var query
= "?op=rpc&method=catchupSelected" +
1386 "&cmode=0&ids=" + param_escape(batch
.toString());
1390 _catchup_request_sent
= true;
1392 new Ajax
.Request("backend.php", {
1394 onComplete: function(transport
) {
1395 handle_rpc_json(transport
);
1397 _catchup_request_sent
= false;
1399 reply
= JSON
.parse(transport
.responseText
);
1400 var batch
= reply
.ids
;
1402 batch
.each(function(id
) {
1404 var elem
= $("RROW-" + id
);
1405 if (elem
) elem
.removeClassName("Unread");
1406 catchup_id_batch
.remove(id
);
1409 updateFloatingTitle(true);
1415 exception_error("catchupBatchedArticles", e
);
1419 function catchupRelativeToArticle(below
, id
) {
1423 if (!id
) id
= getActiveArticleId();
1426 alert(__("No article is selected."));
1430 var visible_ids
= getLoadedArticleIds();
1432 var ids_to_mark
= new Array();
1435 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1436 if (visible_ids
[i
] != id
) {
1437 var e
= $("RROW-" + visible_ids
[i
]);
1439 if (e
&& e
.hasClassName("Unread")) {
1440 ids_to_mark
.push(visible_ids
[i
]);
1447 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1448 if (visible_ids
[i
] != id
) {
1449 var e
= $("RROW-" + visible_ids
[i
]);
1451 if (e
&& e
.hasClassName("Unread")) {
1452 ids_to_mark
.push(visible_ids
[i
]);
1460 if (ids_to_mark
.length
== 0) {
1461 alert(__("No articles found to mark"));
1463 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1465 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1467 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1468 var e
= $("RROW-" + ids_to_mark
[i
]);
1469 e
.removeClassName("Unread");
1472 var query
= "?op=rpc&method=catchupSelected" +
1473 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1475 new Ajax
.Request("backend.php", {
1477 onComplete: function(transport
) {
1478 handle_rpc_json(transport
);
1485 exception_error("catchupRelativeToArticle", e
);
1489 function cdmCollapseArticle(event
, id
, unmark
) {
1491 if (unmark
== undefined) unmark
= true;
1493 var row
= $("RROW-" + id
);
1494 var elem
= $("CICD-" + id
);
1497 var collapse
= $$("div#RROW-" + id
+
1498 " span[class='collapseBtn']")[0];
1501 Element
.show("CEXC-" + id
);
1502 Element
.hide(collapse
);
1505 row
.removeClassName("active");
1507 markHeadline(id
, false);
1509 if (id
== getActiveArticleId()) {
1510 setActiveArticleId(0);
1513 updateSelectedPrompt();
1516 if (event
) Event
.stop(event
);
1518 PluginHost
.run(PluginHost
.HOOK_ARTICLE_COLLAPSED
, id
);
1520 if (row
.offsetTop
< $("headlines-frame").scrollTop
)
1521 scrollToRowId(row
.id
);
1523 $("floatingTitle").style
.visibility
= "hidden";
1524 $("floatingTitle").setAttribute("rowid", false);
1528 exception_error("cdmCollapseArticle", e
);
1532 function cdmExpandArticle(id
, noexpand
) {
1534 console
.log("cdmExpandArticle " + id
);
1536 if (!$("RROW-" + id
)) return false;
1538 var oldrow
= $("RROW-" + getActiveArticleId());
1540 var elem
= $("CICD-" + getActiveArticleId());
1542 if (id
== getActiveArticleId() && Element
.visible(elem
))
1545 selectArticles("none");
1547 var old_offset
= $("RROW-" + id
).offsetTop
;
1549 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1550 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1551 " span[class='collapseBtn']")[0];
1554 Element
.show("CEXC-" + getActiveArticleId());
1555 Element
.hide(collapse
);
1558 if (oldrow
) oldrow
.removeClassName("active");
1560 setActiveArticleId(id
);
1562 elem
= $("CICD-" + id
);
1564 var collapse
= $$("div#RROW-" + id
+
1565 " span[class='collapseBtn']")[0];
1567 var cencw
= $("CENCW-" + id
);
1569 if (!Element
.visible(elem
) && !noexpand
) {
1571 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1572 cencw
.setAttribute('id', '');
1573 Element
.show(cencw
);
1577 Element
.hide("CEXC-" + id
);
1578 Element
.show(collapse
);
1581 var new_offset
= $("RROW-" + id
).offsetTop
;
1583 if (old_offset
> new_offset
)
1584 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1587 if (catchup_id_batch
.indexOf(id
) == -1)
1588 catchup_id_batch
.push(id
);
1590 catchupCurrentBatchIfNeeded();
1594 $("RROW-" + id
).addClassName("active");
1596 PluginHost
.run(PluginHost
.HOOK_ARTICLE_EXPANDED
, id
);
1599 exception_error("cdmExpandArticle", e
);
1605 function getArticleUnderPointer() {
1606 return post_under_pointer
;
1609 function scrollArticle(offset
) {
1612 var ci
= $("content-insert");
1614 ci
.scrollTop
+= offset
;
1617 var hi
= $("headlines-frame");
1619 hi
.scrollTop
+= offset
;
1624 exception_error("scrollArticle", e
);
1628 function show_labels_in_headlines(transport
) {
1630 var data
= JSON
.parse(transport
.responseText
);
1633 data
['info-for-headlines'].each(function(elem
) {
1634 $$(".HLLCTR-" + elem
.id
).each(function(ctr
) {
1635 ctr
.innerHTML
= elem
.labels
;
1640 exception_error("show_labels_in_headlines", e
);
1644 function cdmClicked(event
, id
) {
1646 //var shift_key = event.shiftKey;
1648 if (!event
.ctrlKey
&& !event
.metaKey
) {
1650 if (!getInitParam("cdm_expanded")) {
1651 return cdmExpandArticle(id
);
1654 var elem
= $("RROW-" + getActiveArticleId());
1656 if (elem
) elem
.removeClassName("active");
1658 selectArticles("none");
1661 var elem
= $("RROW-" + id
);
1662 var article_is_unread
= elem
.hasClassName("Unread");
1664 elem
.removeClassName("Unread");
1665 elem
.addClassName("active");
1667 setActiveArticleId(id
);
1669 if (article_is_unread
) {
1670 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1671 updateFloatingTitle(true);
1674 var query
= "?op=rpc&method=catchupSelected" +
1675 "&cmode=0&ids=" + param_escape(id
);
1677 new Ajax
.Request("backend.php", {
1679 onComplete: function(transport
) {
1680 handle_rpc_json(transport
);
1683 return !event
.shiftKey
;
1686 } else if (event
.target
.parents(".cdmHeader").length
> 0) {
1688 toggleSelected(id
, true);
1690 var elem
= $("RROW-" + id
);
1691 var article_is_unread
= elem
.hasClassName("Unread");
1693 if (article_is_unread
) {
1694 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1697 toggleUnread(id
, 0, false);
1699 openArticleInNewWindow(id
);
1702 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1703 request_counters(unread_in_buffer
== 0);
1706 exception_error("cdmClicked");
1712 function hlClicked(event
, id
) {
1714 if (event
.which
== 2) {
1717 } else if (event
.ctrlKey
|| event
.metaKey
) {
1718 toggleSelected(id
, true);
1719 toggleUnread(id
, 0, false);
1720 openArticleInNewWindow(id
);
1728 exception_error("hlClicked");
1732 function openArticleInNewWindow(id
) {
1733 toggleUnread(id
, 0, false);
1734 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1737 function isCdmMode() {
1738 return getInitParam("combined_display_mode");
1741 function markHeadline(id
, marked
) {
1742 if (marked
== undefined) marked
= true;
1744 var row
= $("RROW-" + id
);
1746 var check
= dijit
.getEnclosingWidget(
1747 row
.getElementsByClassName("rchk")[0]);
1750 check
.attr("checked", marked
);
1754 row
.addClassName("Selected");
1756 row
.removeClassName("Selected");
1760 function getRelativePostIds(id
, limit
) {
1766 if (!limit
) limit
= 6; //3
1768 var ids
= getLoadedArticleIds();
1770 for (var i
= 0; i
< ids
.length
; i
++) {
1772 for (var k
= 1; k
<= limit
; k
++) {
1773 //if (i > k-1) tmp.push(ids[i-k]);
1774 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1781 exception_error("getRelativePostIds", e
);
1787 function correctHeadlinesOffset(id
) {
1791 var container
= $("headlines-frame");
1792 var row
= $("RROW-" + id
);
1794 if (!container
|| !row
) return;
1796 var viewport
= container
.offsetHeight
;
1798 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1799 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1801 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1802 //console.log("Vport: " + viewport);
1804 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1805 container
.scrollTop
= row
.offsetTop
;
1806 } else if (rel_offset_bottom
> viewport
) {
1808 /* doesn't properly work with Opera in some cases because
1809 Opera fucks up element scrolling */
1811 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1815 exception_error("correctHeadlinesOffset", e
);
1820 function headlineActionsChange(elem
) {
1823 elem
.attr('value', 'false');
1825 exception_error("headlineActionsChange", e
);
1829 function closeArticlePanel() {
1831 if (dijit
.byId("content-insert"))
1832 dijit
.byId("headlines-wrap-inner").removeChild(
1833 dijit
.byId("content-insert"));
1836 function initFloatingMenu() {
1838 if (dijit
.byId("floatingMenu"))
1839 dijit
.byId("floatingMenu").destroyRecursive();
1841 var menu
= new dijit
.Menu({
1843 targetNodeIds
: ["floatingTitle"]
1846 var id
= $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1848 headlinesMenuCommon(menu
, id
);
1852 exception_error("initFloatingMenu", e
);
1856 function headlinesMenuCommon(menu
, base_id
) {
1859 menu
.addChild(new dijit
.MenuItem({
1860 label
: __("Open original article"),
1861 onClick: function(event
) {
1862 openArticleInNewWindow(base_id
? base_id
: this.getParent().callerRowId
);
1865 menu
.addChild(new dijit
.MenuItem({
1866 label
: __("Display article URL"),
1867 onClick: function(event
) {
1868 displayArticleUrl(base_id
? base_id
: this.getParent().callerRowId
);
1871 menu
.addChild(new dijit
.MenuSeparator());
1873 menu
.addChild(new dijit
.MenuItem({
1874 label
: __("Toggle unread"),
1875 onClick: function(event
) {
1876 var ids
= getSelectedArticleIds2();
1878 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1879 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1881 selectionToggleUnread(undefined, false, true, ids
);
1884 menu
.addChild(new dijit
.MenuItem({
1885 label
: __("Toggle starred"),
1886 onClick: function(event
) {
1887 var ids
= getSelectedArticleIds2();
1889 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1890 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1892 selectionToggleMarked(undefined, false, true, ids
);
1895 menu
.addChild(new dijit
.MenuItem({
1896 label
: __("Toggle published"),
1897 onClick: function(event
) {
1898 var ids
= getSelectedArticleIds2();
1900 var id
= (base_id
? base_id
: this.getParent().callerRowId
) + "";
1901 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1903 selectionTogglePublished(undefined, false, true, ids
);
1906 menu
.addChild(new dijit
.MenuSeparator());
1908 menu
.addChild(new dijit
.MenuItem({
1909 label
: __("Mark above as read"),
1910 onClick: function(event
) {
1911 catchupRelativeToArticle(0, base_id
? base_id
: this.getParent().callerRowId
);
1914 menu
.addChild(new dijit
.MenuItem({
1915 label
: __("Mark below as read"),
1916 onClick: function(event
) {
1917 catchupRelativeToArticle(1, base_id
? base_id
: this.getParent().callerRowId
);
1921 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1925 menu
.addChild(new dijit
.MenuSeparator());
1927 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1928 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1930 labels
.each(function(label
) {
1931 var id
= label
.id
[0];
1932 var bare_id
= id
.substr(id
.indexOf(":")+1);
1933 var name
= label
.name
[0];
1935 bare_id
= feed_to_label_id(bare_id
);
1937 labelAddMenu
.addChild(new dijit
.MenuItem({
1940 onClick: function(event
) {
1941 var ids
= getSelectedArticleIds2();
1943 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
1945 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1947 selectionAssignLabel(this.labelId
, ids
);
1950 labelDelMenu
.addChild(new dijit
.MenuItem({
1953 onClick: function(event
) {
1954 var ids
= getSelectedArticleIds2();
1956 var id
= (base_id
? base_id
: this.getParent().ownerMenu
.callerRowId
) + "";
1958 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1960 selectionRemoveLabel(this.labelId
, ids
);
1965 menu
.addChild(new dijit
.PopupMenuItem({
1966 label
: __("Assign label"),
1970 menu
.addChild(new dijit
.PopupMenuItem({
1971 label
: __("Remove label"),
1979 exception_error("headlinesMenuCommon", e
);
1983 function initHeadlinesMenu() {
1985 if (dijit
.byId("headlinesMenu"))
1986 dijit
.byId("headlinesMenu").destroyRecursive();
1991 nodes
= $$("#headlines-frame > div[id*=RROW]");
1993 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1996 nodes
.each(function(node
) {
2000 var menu
= new dijit
.Menu({
2001 id
: "headlinesMenu",
2005 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2006 var callerNode
= event
.target
, match
= null, tries
= 0;
2008 while (match
== null && callerNode
&& tries
<= 3) {
2009 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2010 callerNode
= callerNode
.parentNode
;
2014 if (match
) this.callerRowId
= parseInt(match
[1]);
2018 headlinesMenuCommon(menu
, false);
2022 /* vgroup feed title menu */
2024 var nodes
= $$("#headlines-frame > div[class='cdmFeedTitle']");
2027 nodes
.each(function(node
) {
2031 if (ids
.length
> 0) {
2032 if (dijit
.byId("headlinesFeedTitleMenu"))
2033 dijit
.byId("headlinesFeedTitleMenu").destroyRecursive();
2035 var menu
= new dijit
.Menu({
2036 id
: "headlinesFeedTitleMenu",
2040 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2041 var callerNode
= event
.target
, match
= null, tries
= 0;
2043 while (match
== null && callerNode
&& tries
<= 3) {
2044 console
.log(callerNode
.id
);
2046 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2047 callerNode
= callerNode
.parentNode
;
2050 console
.log(match
[1]);
2053 if (match
) this.callerRowId
= parseInt(match
[1]);
2057 menu
.addChild(new dijit
.MenuItem({
2058 label
: __("Select articles in group"),
2059 onClick: function(event
) {
2060 selectArticles("all",
2061 "#headlines-frame > div[id*=RROW]"+
2062 "[orig-feed-id='"+menu
.callerRowId
+"']");
2066 menu
.addChild(new dijit
.MenuItem({
2067 label
: __("Mark group as read"),
2068 onClick: function(event
) {
2069 selectArticles("none");
2070 selectArticles("all",
2071 "#headlines-frame > div[id*=RROW]"+
2072 "[orig-feed-id='"+menu
.callerRowId
+"']");
2078 menu
.addChild(new dijit
.MenuItem({
2079 label
: __("Mark feed as read"),
2080 onClick: function(event
) {
2081 catchupFeedInGroup(menu
.callerRowId
);
2084 menu
.addChild(new dijit
.MenuItem({
2085 label
: __("Edit feed"),
2086 onClick: function(event
) {
2087 editFeed(menu
.callerRowId
);
2095 exception_error("initHeadlinesMenu", e
);
2099 function cache_set(id
, obj
) {
2100 //console.log("cache_set: " + id);
2103 sessionStorage
[id
] = obj
;
2105 sessionStorage
.clear();
2109 function cache_get(id
) {
2111 return sessionStorage
[id
];
2114 function cache_clear() {
2116 sessionStorage
.clear();
2119 function cache_delete(id
) {
2121 sessionStorage
.removeItem(id
);
2124 function cancelSearch() {
2129 exception_error("cancelSearch", e
);
2133 function setSelectionScore() {
2135 var ids
= getSelectedArticleIds2();
2137 if (ids
.length
> 0) {
2140 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2142 if (score
!= undefined) {
2143 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2144 "&score=" + param_escape(score
);
2146 new Ajax
.Request("backend.php", {
2148 onComplete: function(transport
) {
2149 var reply
= JSON
.parse(transport
.responseText
);
2153 ids
.each(function(id
) {
2154 var row
= $("RROW-" + id
);
2157 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2160 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2161 reply
["score_pic"]);
2162 pic
.setAttribute("score", score
);
2171 alert(__("No articles are selected."));
2174 exception_error("setSelectionScore", e
);
2178 function updateScore(id
) {
2180 var pic
= $$("#RROW-" + id
+ " .hlScorePic")[0];
2184 var query
= "op=article&method=getScore&id=" + param_escape(id
);
2186 new Ajax
.Request("backend.php", {
2188 onComplete: function(transport
) {
2189 console
.log(transport
.responseText
);
2191 var reply
= JSON
.parse(transport
.responseText
);
2194 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2195 pic
.setAttribute("score", reply
["score"]);
2196 pic
.setAttribute("title", reply
["score"]);
2202 exception_error("updateScore", e
);
2206 function changeScore(id
, pic
) {
2208 var score
= pic
.getAttribute("score");
2210 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2212 if (new_score
!= undefined) {
2214 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2215 "&score=" + param_escape(new_score
);
2217 new Ajax
.Request("backend.php", {
2219 onComplete: function(transport
) {
2220 var reply
= JSON
.parse(transport
.responseText
);
2223 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2224 pic
.setAttribute("score", new_score
);
2225 pic
.setAttribute("title", new_score
);
2230 exception_error("changeScore", e
);
2234 function displayArticleUrl(id
) {
2236 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2238 new Ajax
.Request("backend.php", {
2240 onComplete: function(transport
) {
2241 var reply
= JSON
.parse(transport
.responseText
);
2243 if (reply
&& reply
.link
) {
2244 prompt(__("Article URL:"), reply
.link
);
2248 exception_error("changeScore", e
);
2252 function scrollToRowId(id
) {
2257 $("headlines-frame").scrollTop
= row
.offsetTop
- 4;
2260 exception_error("scrollToRowId", e
);
2264 function updateFloatingTitle(unread_only
) {
2266 if (!isCdmMode()) return;
2268 var hf
= $("headlines-frame");
2270 var elems
= $$("#headlines-frame > div[id*=RROW]");
2272 for (var i
= 0; i
< elems
.length
; i
++) {
2274 var child
= elems
[i
];
2276 if (child
&& child
.offsetTop
+ child
.offsetHeight
> hf
.scrollTop
) {
2278 var header
= child
.getElementsByClassName("cdmHeader")[0];
2280 if (unread_only
|| child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2281 if (child
.id
!= $("floatingTitle").getAttribute("rowid")) {
2282 $("floatingTitle").setAttribute("rowid", child
.id
);
2283 $("floatingTitle").innerHTML
= header
.innerHTML
;
2284 $("floatingTitle").firstChild
.innerHTML
= "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child
.id
+"')\">" + $("floatingTitle").firstChild
.innerHTML
;
2288 var cb
= $$("#floatingTitle .dijitCheckBox")[0];
2291 cb
.parentNode
.removeChild(cb
);
2294 if (child
.hasClassName("Unread"))
2295 $("floatingTitle").addClassName("Unread");
2297 $("floatingTitle").removeClassName("Unread");
2299 PluginHost
.run(PluginHost
.HOOK_FLOATING_TITLE
, child
);
2302 $("floatingTitle").style
.marginRight
= hf
.offsetWidth
- child
.offsetWidth
+ "px";
2303 if (header
.offsetTop
+ header
.offsetHeight
< hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5 &&
2304 child
.offsetTop
+ child
.offsetHeight
>= hf
.scrollTop
+ $("floatingTitle").offsetHeight
- 5)
2305 $("floatingTitle").style
.visibility
= "visible";
2307 $("floatingTitle").style
.visibility
= "hidden";
2315 exception_error("updateFloatingTitle", e
);
2319 function catchupCurrentBatchIfNeeded() {
2320 if (catchup_id_batch
.length
> 0) {
2321 window
.clearTimeout(catchup_timeout_id
);
2322 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()', 1000);
2324 if (catchup_id_batch
.length
>= 10) {
2325 catchupBatchedArticles();
2330 function cdmFooterClick(event
) {
2331 event
.stopPropagation();