1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 // FIXME: kludges, needs proper implementation
6 var _reload_feedlist_after_view
= false;
8 var _cdm_wd_timeout
= false;
9 var _cdm_wd_vishist
= new Array();
11 var article_cache
= new Array();
13 var vgroup_last_feed
= false;
14 var post_under_pointer
= false;
16 var last_requested_article
= false;
18 var preload_id_batch
= [];
19 var preload_timeout_id
= false;
23 function catchup_callback2(transport
, callback
) {
25 console
.log("catchup_callback2 " + transport
+ ", " + callback
);
27 all_counters_callback2(transport
);
29 setTimeout(callback
, 10);
32 exception_error("catchup_callback2", e
, transport
);
36 function clean_feed_selections() {
38 var feeds
= $("feedList").getElementsByTagName("LI");
40 for (var i
= 0; i
< feeds
.length
; i
++) {
41 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
42 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
44 if (feeds
[i
].id
&& feeds
[i
].id
.match("FCAT-")) {
45 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
49 exception_error("clean_feed_selections", e
);
53 function headlines_callback2(transport
, feed_cur_page
) {
56 if (!transport
.responseText
&& db
) {
57 offlineConfirmModeChange();
61 loading_set_progress(100);
63 console
.log("headlines_callback2 [page=" + feed_cur_page
+ "]");
65 if (!transport_error_check(transport
)) return;
67 clean_feed_selections();
72 if (transport
.responseXML
) {
73 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
75 is_cat
= headlines
.getAttribute("is_cat");
76 feed_id
= headlines
.getAttribute("id");
77 setActiveFeedId(feed_id
, is_cat
);
81 var ll
= $('FLL-' + feed_id
);
84 var feedr
= $("FEEDR-" + feed_id
);
85 if (feedr
&& !feedr
.className
.match("Selected")) {
86 feedr
.className
= feedr
.className
+ "Selected";
88 if (feedr
&& ll
) feedr
.removeChild(ll
);
90 var feedr
= $("FCAT-" + feed_id
);
91 if (feedr
&& !feedr
.className
.match("Selected")) {
92 feedr
.className
= feedr
.className
+ "Selected";
95 var fcap
= $("FCAP-" + feed_id
);
96 if (fcap
&& ll
) fcap
.removeChild(ll
);
100 var img
= $('FIMG-' + feed_id
);
102 if (img
&& !is_cat
) {
106 var f
= $("headlines-frame");
108 if (feed_cur_page
== 0) {
109 console
.log("resetting headlines scrollTop");
114 if (transport
.responseXML
) {
115 var response
= transport
.responseXML
;
117 var headlines
= response
.getElementsByTagName("headlines")[0];
118 var headlines_info
= response
.getElementsByTagName("headlines-info")[0];
121 headlines_info
= JSON
.parse(headlines_info
.firstChild
.nodeValue
);
123 console
.log("didn't find headlines-info object in response");
125 var headlines_count
= headlines_info
.count
;
126 var headlines_unread
= headlines_info
.unread
;
127 var disable_cache
= headlines_info
.disable_cache
;
129 vgroup_last_feed
= headlines_info
.vgroup_last_feed
;
131 if (headlines_count
== 0) {
132 _infscroll_disable
= 1;
134 _infscroll_disable
= 0;
137 var counters
= response
.getElementsByTagName("counters")[0];
138 var articles
= response
.getElementsByTagName("article");
139 var runtime_info
= response
.getElementsByTagName("runtime-info");
141 if (feed_cur_page
== 0) {
143 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
145 var cache_prefix
= "";
153 cache_invalidate(cache_prefix
+ feed_id
);
155 if (!disable_cache
) {
156 cache_inject(cache_prefix
+ feed_id
,
157 headlines
.firstChild
.nodeValue
, headlines_unread
);
161 console
.log("headlines_callback: returned no data");
162 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
167 if (headlines_count
> 0) {
168 console
.log("adding some more headlines...");
170 var c
= $("headlinesList");
173 c
= $("headlinesInnerContainer");
176 var ids
= getSelectedArticleIds2();
178 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
180 console
.log("restore selected ids: " + ids
);
182 for (var i
= 0; i
< ids
.length
; i
++) {
183 markHeadline(ids
[i
]);
187 console
.log("no new headlines received");
190 console
.log("headlines_callback: returned no data");
191 notify_error("Error while trying to load more headlines");
197 for (var i
= 0; i
< articles
.length
; i
++) {
198 var a_id
= articles
[i
].getAttribute("id");
199 console
.log("found id: " + a_id
);
200 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
203 console
.log("no cached articles received");
207 console
.log("parsing piggybacked counters: " + counters
);
208 parse_counters(counters
, false);
210 console
.log("counters container not found in reply, requesting...");
215 console
.log("parsing runtime info: " + runtime_info
[0]);
216 parse_runtime_info(runtime_info
[0]);
218 console
.log("runtime info container not found in reply");
222 console
.log("headlines_callback: returned no XML object");
223 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
227 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
229 if (!$("headlinesList") &&
230 getActiveFeedId() != -3 &&
231 getInitParam("cdm_auto_catchup") == 1) {
232 console
.log("starting CDM watchdog");
233 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
234 _cdm_wd_vishist
= new Array();
236 console
.log("not in CDM mode or watchdog disabled");
239 _feed_cur_page
= feed_cur_page
;
240 _infscroll_request_sent
= 0;
247 exception_error("headlines_callback2", e
, transport
);
251 function render_article(article
) {
253 var f
= $("content-frame");
258 var fi
= $("content-insert");
264 fi
.innerHTML
= article
;
266 // article.evalScripts();
269 exception_error("render_article", e
);
273 function showArticleInHeadlines(id
) {
277 cleanSelected("headlinesList");
279 var crow
= $("RROW-" + id
);
283 var article_is_unread
= crow
.className
.match("Unread");
285 crow
.className
= crow
.className
.replace("Unread", "");
287 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
289 var upd_img_pic
= $("FUPDPIC-" + id
);
291 var cache_prefix
= "";
293 if (activeFeedIsCat()) {
299 var view_mode
= false;
302 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
303 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
308 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
309 upd_img_pic
.src
.match("fresh_sign.png"))) {
311 upd_img_pic
.src
= "images/blank_icon.gif";
313 cache_invalidate(cache_prefix
+ getActiveFeedId());
315 cache_inject(cache_prefix
+ getActiveFeedId(),
316 $("headlines-frame").innerHTML
,
317 get_feed_unread(getActiveFeedId()));
319 } else if (article_is_unread
&& view_mode
== "all_articles") {
321 cache_invalidate(cache_prefix
+ getActiveFeedId());
323 cache_inject(cache_prefix
+ getActiveFeedId(),
324 $("headlines-frame").innerHTML
,
325 get_feed_unread(getActiveFeedId())-1);
327 } else if (article_is_unread
) {
328 cache_invalidate(cache_prefix
+ getActiveFeedId());
334 exception_error("showArticleInHeadlines", e
);
338 function article_callback2(transport
, id
) {
340 console
.log("article_callback2 " + id
);
342 if (!transport
.responseText
&& db
) {
343 offlineConfirmModeChange();
347 if (transport
.responseXML
) {
349 if (!transport_error_check(transport
)) return;
351 /* var ll = $('LL-' + id);
352 var content = $('HLC-' + id);
354 if (ll && content) content.removeChild(ll); */
356 var upic
= $('FUPDPIC-' + id
);
359 upic
.src
= 'images/blank_icon.gif';
362 if (id
!= last_requested_article
) {
363 console
.log("requested article id is out of sequence, aborting");
369 console
.log("looking for articles to cache...");
371 var articles
= transport
.responseXML
.getElementsByTagName("article");
373 for (var i
= 0; i
< articles
.length
; i
++) {
374 var a_id
= articles
[i
].getAttribute("id");
376 console
.log("found id: " + a_id
);
378 if (a_id
== active_post_id
) {
379 console
.log("active article, rendering...");
380 render_article(articles
[i
].firstChild
.nodeValue
);
383 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
387 showArticleInHeadlines(id
);
390 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id
]);
393 var reply
= transport
.responseXML
.firstChild
.firstChild
;
396 console
.log("article_callback: returned no XML object");
397 //var f = $("content-frame");
398 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
401 var date
= new Date();
402 last_article_view
= date
.getTime() / 1000;
404 if (_reload_feedlist_after_view
) {
405 setTimeout('updateFeedList(false, false)', 50);
406 _reload_feedlist_after_view
= false;
408 if (transport
.responseXML
) {
409 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
412 console
.log("parsing piggybacked counters: " + counters
);
413 parse_counters(counters
, false);
415 console
.log("counters container not found in reply, requesting...");
423 exception_error("article_callback2", e
, transport
);
429 console
.log("loading article: " + id
);
431 if (offline_mode
) return view_offline(id
);
433 var cached_article
= cache_find(id
);
435 console
.log("cache check result: " + (cached_article
!= false));
440 var query
= "?op=view&id=" + param_escape(id
);
442 var neighbor_ids
= getRelativePostIds(active_post_id
);
444 /* only request uncached articles */
446 var cids_to_request
= Array();
448 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
449 if (!cache_check(neighbor_ids
[i
])) {
450 cids_to_request
.push(neighbor_ids
[i
]);
454 console
.log("additional ids: " + cids_to_request
.toString());
456 /* additional info for piggyback counters */
458 if (tagsAreDisplayed()) {
459 query
= query
+ "&omode=lt";
461 query
= query
+ "&omode=flc";
464 query
= query
+ "&cids=" + cids_to_request
.toString();
466 var crow
= $("RROW-" + id
);
467 var article_is_unread
= crow
.className
.match("Unread");
469 showArticleInHeadlines(id
);
471 if (!cached_article
) {
473 var upic
= $('FUPDPIC-' + id
);
476 upic
.src
= getInitParam("sign_progress");
479 } else if (cached_article
&& article_is_unread
) {
481 query
= query
+ "&mode=prefetch";
483 render_article(cached_article
);
485 } else if (cached_article
) {
487 query
= query
+ "&mode=prefetch_old";
488 render_article(cached_article
);
494 last_requested_article
= id
;
496 new Ajax
.Request("backend.php", {
498 onComplete: function(transport
) {
499 article_callback2(transport
, id
);
505 exception_error("view", e
);
510 return toggleMark(id
);
514 return togglePub(id
);
517 function tMark_afh_off(effect
) {
519 var elem
= effect
.effects
[0].element
;
521 console
.log("tMark_afh_off : " + elem
.id
);
524 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
525 elem
.alt
= __("Star article");
530 exception_error("tMark_afh_off", e
);
534 function tPub_afh_off(effect
) {
536 var elem
= effect
.effects
[0].element
;
538 console
.log("tPub_afh_off : " + elem
.id
);
541 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
542 elem
.alt
= __("Publish article");
547 exception_error("tPub_afh_off", e
);
551 function toggleMark(id
, client_only
, no_effects
) {
555 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
557 query
= query
+ "&afid=" + getActiveFeedId();
559 if (tagsAreDisplayed()) {
560 query
= query
+ "&omode=tl";
562 query
= query
+ "&omode=flc";
565 var mark_img
= $("FMPIC-" + id
);
567 if (!mark_img
) return;
569 var vfeedu
= $("FEEDU--1");
570 var crow
= $("RROW-" + id
);
572 if (mark_img
.src
.match("mark_unset")) {
573 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
574 mark_img
.alt
= __("Unstar article");
575 query
= query
+ "&mark=1";
578 db
.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id
]);
582 mark_img
.alt
= __("Please wait...");
583 query
= query
+ "&mark=0";
585 if ($("headlinesList") && !no_effects
) {
586 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
588 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
589 mark_img
.alt
= __("Star article");
593 db
.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id
]);
598 if (!no_effects
) update_local_feedlist_counters();
603 new Ajax
.Request("backend.php", {
605 onComplete: function(transport
) {
606 all_counters_callback2(transport
);
612 exception_error("toggleMark", e
);
616 function togglePub(id
, client_only
, no_effects
, note
) {
620 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
622 query
= query
+ "&afid=" + getActiveFeedId();
624 if (note
!= undefined) {
625 query
= query
+ "¬e=" + param_escape(note
);
627 query
= query
+ "¬e=undefined";
630 if (tagsAreDisplayed()) {
631 query
= query
+ "&omode=tl";
633 query
= query
+ "&omode=flc";
636 var mark_img
= $("FPPIC-" + id
);
638 if (!mark_img
) return;
640 var vfeedu
= $("FEEDU--2");
641 var crow
= $("RROW-" + id
);
643 if (mark_img
.src
.match("pub_unset") || note
!= undefined) {
644 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
645 mark_img
.alt
= __("Unpublish article");
646 query
= query
+ "&pub=1";
649 mark_img
.alt
= __("Please wait...");
650 query
= query
+ "&pub=0";
652 if ($("headlinesList") && !no_effects
) {
653 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
655 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
656 mark_img
.alt
= __("Publish article");
661 new Ajax
.Request("backend.php", {
663 onComplete: function(transport
) {
664 all_counters_callback2(transport
);
666 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
669 var note_id
= note
.getAttribute("id");
670 var note_size
= note
.getAttribute("size");
671 var note_content
= note
.firstChild
.nodeValue
;
673 var container
= $('POSTNOTE-' + note_id
);
675 cache_invalidate(note_id
);
678 if (note_size
== "0") {
679 Element
.hide(container
);
681 container
.innerHTML
= note_content
;
682 Element
.show(container
);
691 exception_error("togglePub", e
);
695 function correctHeadlinesOffset(id
) {
699 var hlist
= $("headlinesList");
700 var container
= $("headlinesInnerContainer");
701 var row
= $("RROW-" + id
);
703 var viewport
= container
.offsetHeight
;
705 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
706 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
708 console
.log("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
709 console
.log("Vport: " + viewport
);
711 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
712 container
.scrollTop
= row
.offsetTop
;
713 } else if (rel_offset_bottom
> viewport
) {
715 /* doesn't properly work with Opera in some cases because
716 Opera fucks up element scrolling */
718 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
722 exception_error("correctHeadlinesOffset", e
);
727 function moveToPost(mode
) {
734 rows
= cdmGetVisibleArticles();
736 rows
= getVisibleHeadlineIds();
742 if (!$('RROW-' + active_post_id
)) {
743 active_post_id
= false;
746 if (active_post_id
== false) {
747 next_id
= getFirstVisibleHeadlineId();
748 prev_id
= getLastVisibleHeadlineId();
750 for (var i
= 0; i
< rows
.length
; i
++) {
751 if (rows
[i
] == active_post_id
) {
758 if (mode
== "next") {
762 cdmExpandArticle(next_id
);
763 cdmScrollToArticleId(next_id
);
766 correctHeadlinesOffset(next_id
);
767 view(next_id
, getActiveFeedId());
772 if (mode
== "prev") {
775 cdmExpandArticle(prev_id
);
776 cdmScrollToArticleId(prev_id
);
778 correctHeadlinesOffset(prev_id
);
779 view(prev_id
, getActiveFeedId());
785 exception_error("moveToPost", e
);
789 function toggleSelected(id
) {
792 var cb
= $("RCHK-" + id
);
794 var row
= $("RROW-" + id
);
796 var nc
= row
.className
;
798 if (!nc
.match("Selected")) {
799 nc
= nc
+ "Selected";
804 // In CDM basically last selected article == active article
805 if (isCdmMode()) active_post_id
= id
;
807 nc
= nc
.replace("Selected", "");
817 exception_error("toggleSelected", e
);
821 function toggleUnread_afh(effect
) {
824 var elem
= effect
.element
;
825 elem
.style
.backgroundColor
= "";
828 exception_error("toggleUnread_afh", e
);
832 function toggleUnread(id
, cmode
, effect
) {
835 var row
= $("RROW-" + id
);
837 var nc
= row
.className
;
838 var is_selected
= row
.className
.match("Selected");
839 nc
= nc
.replace("Unread", "");
840 nc
= nc
.replace("Selected", "");
842 // since we are removing selection from the object, uncheck
843 // corresponding checkbox
845 var cb
= $("RCHK-" + id
);
850 // NOTE: I'm not sure that resetting selection here is a feature -fox
852 if (cmode
== undefined || cmode
== 2) {
853 if (row
.className
.match("Unread")) {
857 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
858 afterFinish
: toggleUnread_afh
,
859 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
863 row
.className
= nc
+ "Unread";
867 db
.execute("UPDATE articles SET unread = not unread "+
868 "WHERE id = ?", [id
]);
871 } else if (cmode
== 0) {
875 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
876 afterFinish
: toggleUnread_afh
,
877 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
881 db
.execute("UPDATE articles SET unread = 0 "+
882 "WHERE id = ?", [id
]);
885 } else if (cmode
== 1) {
886 row
.className
= nc
+ "Unread";
889 db
.execute("UPDATE articles SET unread = 1 "+
890 "WHERE id = ?", [id
]);
895 update_local_feedlist_counters();
897 // Disable unmarking as selected for the time being (16.05.08) -fox
898 if (is_selected
) row
.className
= row
.className
+ "Selected";
900 if (cmode
== undefined) cmode
= 2;
902 var query
= "?op=rpc&subop=catchupSelected" +
903 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
905 // notify_progress("Loading, please wait...");
907 new Ajax
.Request("backend.php", {
909 onComplete: function(transport
) {
910 all_counters_callback2(transport
);
916 exception_error("toggleUnread", e
);
920 function selectionRemoveLabel(id
) {
923 var ids
= getSelectedArticleIds2();
925 if (ids
.length
== 0) {
926 alert(__("No articles are selected."));
930 // var ok = confirm(__("Remove selected articles from label?"));
934 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
935 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
939 // notify_progress("Loading, please wait...");
941 cache_invalidate("F:" + (-11 - id
));
943 new Ajax
.Request("backend.php", {
945 onComplete: function(transport
) {
946 show_labels_in_headlines(transport
);
947 all_counters_callback2(transport
);
953 exception_error("selectionAssignLabel", e
);
958 function selectionAssignLabel(id
) {
961 var ids
= getSelectedArticleIds2();
963 if (ids
.length
== 0) {
964 alert(__("No articles are selected."));
968 // var ok = confirm(__("Assign selected articles to label?"));
972 cache_invalidate("F:" + (-11 - id
));
974 var query
= "?op=rpc&subop=assignToLabel&ids=" +
975 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
979 // notify_progress("Loading, please wait...");
981 new Ajax
.Request("backend.php", {
983 onComplete: function(transport
) {
984 show_labels_in_headlines(transport
);
985 all_counters_callback2(transport
);
991 exception_error("selectionAssignLabel", e
);
996 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
998 var rows
= getSelectedArticleIds2();
1000 if (rows
.length
== 0 && !no_error
) {
1001 alert(__("No articles are selected."));
1005 for (i
= 0; i
< rows
.length
; i
++) {
1006 var row
= $("RROW-" + rows
[i
]);
1008 var nc
= row
.className
;
1009 nc
= nc
.replace("Unread", "");
1010 nc
= nc
.replace("Selected", "");
1012 if (set_state
== undefined) {
1013 if (row
.className
.match("Unread")) {
1014 row
.className
= nc
+ "Selected";
1016 row
.className
= nc
+ "UnreadSelected";
1019 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1024 if (set_state
== false) {
1025 row
.className
= nc
+ "Selected";
1027 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1032 if (set_state
== true) {
1033 row
.className
= nc
+ "UnreadSelected";
1035 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1042 if (rows
.length
> 0) {
1044 update_local_feedlist_counters();
1048 if (set_state
== undefined) {
1050 } else if (set_state
== true) {
1052 } else if (set_state
== false) {
1056 var query
= "?op=rpc&subop=catchupSelected" +
1057 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
1059 notify_progress("Loading, please wait...");
1061 new Ajax
.Request("backend.php", {
1063 onComplete: function(transport
) {
1064 catchup_callback2(transport
, callback_func
);
1070 exception_error("selectionToggleUnread", e
);
1074 function selectionToggleMarked() {
1077 var rows
= getSelectedArticleIds2();
1079 if (rows
.length
== 0) {
1080 alert(__("No articles are selected."));
1084 for (i
= 0; i
< rows
.length
; i
++) {
1085 toggleMark(rows
[i
], true, true);
1088 update_local_feedlist_counters();
1090 if (rows
.length
> 0) {
1092 var query
= "?op=rpc&subop=markSelected&ids=" +
1093 param_escape(rows
.toString()) + "&cmode=2";
1095 query
= query
+ "&afid=" + getActiveFeedId();
1097 query
= query
+ "&omode=lc";
1099 new Ajax
.Request("backend.php", {
1101 onComplete: function(transport
) {
1102 all_counters_callback2(transport
);
1108 exception_error("selectionToggleMarked", e
);
1112 function selectionTogglePublished() {
1115 var rows
= getSelectedArticleIds2();
1117 if (rows
.length
== 0) {
1118 alert(__("No articles are selected."));
1122 for (i
= 0; i
< rows
.length
; i
++) {
1123 togglePub(rows
[i
], true, true);
1126 if (rows
.length
> 0) {
1128 var query
= "?op=rpc&subop=publishSelected&ids=" +
1129 param_escape(rows
.toString()) + "&cmode=2";
1131 query
= query
+ "&afid=" + getActiveFeedId();
1133 query
= query
+ "&omode=lc";
1135 new Ajax
.Request("backend.php", {
1137 onComplete: function(transport
) {
1138 all_counters_callback2(transport
);
1144 exception_error("selectionToggleMarked", e
);
1148 function cdmGetSelectedArticles() {
1149 var sel_articles
= new Array();
1150 var container
= $("headlinesInnerContainer");
1152 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1153 var child
= container
.childNodes
[i
];
1155 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1156 var c_id
= child
.id
.replace("RROW-", "");
1157 sel_articles
.push(c_id
);
1161 return sel_articles
;
1164 function cdmGetVisibleArticles() {
1165 var sel_articles
= new Array();
1166 var container
= $("headlinesInnerContainer");
1168 if (!container
) return sel_articles
;
1170 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1171 var child
= container
.childNodes
[i
];
1173 if (child
.id
&& child
.id
.match("RROW-")) {
1174 var c_id
= child
.id
.replace("RROW-", "");
1175 sel_articles
.push(c_id
);
1179 return sel_articles
;
1182 function cdmGetUnreadArticles() {
1183 var sel_articles
= new Array();
1184 var container
= $("headlinesInnerContainer");
1186 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1187 var child
= container
.childNodes
[i
];
1189 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1190 var c_id
= child
.id
.replace("RROW-", "");
1191 sel_articles
.push(c_id
);
1195 return sel_articles
;
1199 // mode = all,none,unread
1200 function cdmSelectArticles(mode
) {
1201 var container
= $("headlinesInnerContainer");
1203 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1204 var child
= container
.childNodes
[i
];
1206 if (child
.id
&& child
.id
.match("RROW-")) {
1207 var aid
= child
.id
.replace("RROW-", "");
1209 var cb
= $("RCHK-" + aid
);
1211 if (mode
== "all") {
1212 if (!child
.className
.match("Selected")) {
1213 child
.className
= child
.className
+ "Selected";
1216 } else if (mode
== "unread") {
1217 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1218 child
.className
= child
.className
+ "Selected";
1222 child
.className
= child
.className
.replace("Selected", "");
1229 function catchupPage() {
1231 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1233 var str
= __("Mark all visible articles in %s as read?");
1235 str
= str
.replace("%s", fn
);
1237 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1241 if ($("headlinesList")) {
1242 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1243 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1244 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1246 cdmSelectArticles('all');
1247 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1248 cdmSelectArticles('none');
1252 function deleteSelection() {
1256 var rows
= getSelectedArticleIds2();
1258 if (rows
.length
== 0) {
1259 alert(__("No articles are selected."));
1263 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1267 if (getActiveFeedId() != 0) {
1268 str
= __("Delete %d selected articles in %s?");
1270 str
= __("Delete %d selected articles?");
1273 str
= str
.replace("%d", rows
.length
);
1274 str
= str
.replace("%s", fn
);
1276 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1280 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1284 new Ajax
.Request("backend.php", {
1286 onComplete: function(transport
) {
1291 exception_error("deleteSelection", e
);
1295 function archiveSelection() {
1299 var rows
= getSelectedArticleIds2();
1301 if (rows
.length
== 0) {
1302 alert(__("No articles are selected."));
1306 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1310 if (getActiveFeedId() != 0) {
1311 str
= __("Archive %d selected articles in %s?");
1314 str
= __("Move %d archived articles back?");
1318 str
= str
.replace("%d", rows
.length
);
1319 str
= str
.replace("%s", fn
);
1321 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1325 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1329 for (var i
= 0; i
< rows
.length
; i
++) {
1330 cache_invalidate(rows
[i
]);
1333 new Ajax
.Request("backend.php", {
1335 onComplete: function(transport
) {
1340 exception_error("archiveSelection", e
);
1344 function catchupSelection() {
1348 var rows
= getSelectedArticleIds2();
1350 if (rows
.length
== 0) {
1351 alert(__("No articles are selected."));
1355 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1357 var str
= __("Mark %d selected articles in %s as read?");
1359 str
= str
.replace("%d", rows
.length
);
1360 str
= str
.replace("%s", fn
);
1362 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1366 if ($("headlinesList")) {
1367 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1369 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1373 exception_error("catchupSelection", e
);
1377 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1378 displayDlg('editArticleTags', id
,
1380 $("tags_str").focus();
1382 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1383 "backend.php?op=rpc&subop=completeTags",
1384 { tokens
: ',', paramName
: "search" });
1388 function editTagsSave() {
1390 notify_progress("Saving article tags...");
1392 var form
= document
.forms
["tag_edit_form"];
1394 var query
= Form
.serialize("tag_edit_form");
1396 query
= "?op=rpc&subop=setArticleTags&" + query
;
1400 new Ajax
.Request("backend.php", {
1402 onComplete: function(transport
) {
1404 console
.log("tags saved...");
1409 if (tagsAreDisplayed()) {
1410 _reload_feedlist_after_view
= true;
1413 if (transport
.responseXML
) {
1414 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1417 var id
= tags_str
.getAttribute("id");
1420 var tags
= $("ATSTR-" + id
);
1422 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1425 cache_invalidate(id
);
1431 exception_error("editTagsSave", e
);
1436 function editTagsInsert() {
1439 var form
= document
.forms
["tag_edit_form"];
1441 var found_tags
= form
.found_tags
;
1442 var tags_str
= form
.tags_str
;
1444 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1446 if (tags_str
.value
.length
> 0 &&
1447 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1449 tags_str
.value
= tags_str
.value
+ ", ";
1452 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1454 found_tags
.selectedIndex
= 0;
1457 exception_error("editTagsInsert", e
);
1461 function cdmScrollViewport(where
) {
1462 console
.log("cdmScrollViewport: " + where
);
1464 var ctr
= $("headlinesInnerContainer");
1468 if (where
== "bottom") {
1469 ctr
.scrollTop
= ctr
.scrollHeight
;
1471 ctr
.scrollTop
= where
;
1475 function cdmArticleIsBelowViewport(id
) {
1477 var ctr
= $("headlinesInnerContainer");
1478 var e
= $("RROW-" + id
);
1480 if (!e
|| !ctr
) return;
1482 // article starts below viewport
1484 if (ctr
.scrollTop
< e
.offsetTop
) {
1491 exception_error("cdmArticleIsVisible", e
);
1495 function cdmArticleIsAboveViewport(id
) {
1497 var ctr
= $("headlinesInnerContainer");
1498 var e
= $("RROW-" + id
);
1500 if (!e
|| !ctr
) return;
1502 // article starts above viewport
1504 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1511 exception_error("cdmArticleIsVisible", e
);
1515 function cdmScrollToArticleId(id
) {
1517 var ctr
= $("headlinesInnerContainer");
1518 var e
= $("RROW-" + id
);
1520 if (!e
|| !ctr
) return;
1522 ctr
.scrollTop
= e
.offsetTop
;
1525 exception_error("cdmScrollToArticleId", e
);
1529 function cdmArticleIsActuallyVisible(id
) {
1531 var ctr
= $("headlinesInnerContainer");
1532 var e
= $("RROW-" + id
);
1534 if (!e
|| !ctr
) return;
1536 // article fits in viewport OR article is longer than viewport and
1537 // its bottom is visible
1539 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1540 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1544 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1545 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1546 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1555 exception_error("cdmArticleIsVisible", e
);
1559 function cdmWatchdog() {
1563 var ctr
= $("headlinesInnerContainer");
1567 var ids
= new Array();
1569 var e
= ctr
.firstChild
;
1572 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1573 e
.id
.match("RROW-")) {
1575 // article fits in viewport OR article is longer than viewport and
1576 // its bottom is visible
1578 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1579 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1581 // console.log(e.id + " is visible " + e.offsetTop + "." +
1582 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1583 // (ctr.scrollTop + ctr.offsetHeight));
1585 ids
.push(e
.id
.replace("RROW-", ""));
1587 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1588 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1589 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1591 ids
.push(e
.id
.replace("RROW-", ""));
1595 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1597 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1598 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1600 ids.push(e.id.replace("RROW-", ""));
1609 console
.log("cdmWatchdog, ids= " + ids
.toString());
1611 if (ids
.length
> 0) {
1613 for (var i
= 0; i
< ids
.length
; i
++) {
1614 var e
= $("RROW-" + ids
[i
]);
1616 e
.className
= e
.className
.replace("Unread", "");
1620 var query
= "?op=rpc&subop=catchupSelected" +
1621 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1623 new Ajax
.Request("backend.php", {
1625 onComplete: function(transport
) {
1626 all_counters_callback2(transport
);
1631 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1634 exception_error("cdmWatchdog", e
);
1640 function cache_inject(id
, article
, param
) {
1643 if (!cache_check_param(id
, param
)) {
1644 console
.log("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1646 var date
= new Date();
1647 var ts
= Math
.round(date
.getTime() / 1000);
1651 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1652 [id
, article
, param
, ts
]);
1657 cache_obj
["id"] = id
;
1658 cache_obj
["data"] = article
;
1659 cache_obj
["param"] = param
;
1661 if (param
) id
= id
+ ":" + param
;
1663 cache_added
["TS:" + id
] = ts
;
1665 if (has_local_storage())
1666 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1668 article_cache
.push(cache_obj
);
1672 console
.log("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1675 exception_error("cache_inject", e
);
1679 function cache_find(id
) {
1682 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1685 if (rs
.isValidRow()) {
1686 var a
= rs
.field(0);
1695 if (has_local_storage()) {
1696 var cache_obj
= localStorage
.getItem(id
);
1699 cache_obj
= JSON
.parse(cache_obj
);
1702 return cache_obj
['data'];
1706 for (var i
= 0; i
< article_cache
.length
; i
++) {
1707 if (article_cache
[i
]["id"] == id
) {
1708 return article_cache
[i
]["data"];
1716 function cache_find_param(id
, param
) {
1719 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1723 if (rs
.isValidRow()) {
1733 if (has_local_storage()) {
1735 if (param
) id
= id
+ ":" + param
;
1737 var cache_obj
= localStorage
.getItem(id
);
1740 cache_obj
= JSON
.parse(cache_obj
);
1743 return cache_obj
['data'];
1747 for (var i
= 0; i
< article_cache
.length
; i
++) {
1748 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1749 return article_cache
[i
]["data"];
1757 function cache_check(id
) {
1760 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1764 if (rs
.isValidRow()) {
1765 a
= rs
.field(0) != "0";
1773 if (has_local_storage()) {
1774 if (localStorage
.getItem(id
))
1777 for (var i
= 0; i
< article_cache
.length
; i
++) {
1778 if (article_cache
[i
]["id"] == id
) {
1787 function cache_check_param(id
, param
) {
1790 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1794 if (rs
.isValidRow()) {
1795 a
= rs
.field(0) != "0";
1804 if (has_local_storage()) {
1806 if (param
) id
= id
+ ":" + param
;
1808 if (localStorage
.getItem(id
))
1812 for (var i
= 0; i
< article_cache
.length
; i
++) {
1813 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1822 function cache_expire() {
1824 var date
= new Date();
1825 var ts
= Math
.round(date
.getTime() / 1000);
1827 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1828 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1829 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1833 if (has_local_storage()) {
1835 var date
= new Date();
1836 var timestamp
= Math
.round(date
.getTime() / 1000);
1838 for (var i
= 0; i
< localStorage
.length
; i
++) {
1840 var id
= localStorage
.key(i
);
1842 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1843 localStorage
.removeItem(id
);
1848 while (article_cache
.length
> 25) {
1849 article_cache
.shift();
1855 function cache_flush() {
1857 db
.execute("DELETE FROM cache");
1858 } else if (has_local_storage()) {
1859 localStorage
.clear();
1861 article_cache
= new Array();
1865 function cache_invalidate(id
) {
1869 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1870 return rs
.rowsAffected
!= 0;
1873 if (has_local_storage()) {
1877 for (var i
= 0; i
< localStorage
.length
; i
++) {
1878 var key
= localStorage
.key(i
);
1880 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1882 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1883 localStorage
.removeItem(key
);
1894 while (i
< article_cache
.length
) {
1895 if (article_cache
[i
]["id"] == id
) {
1896 console
.log("cache_invalidate: removed id " + id
);
1897 article_cache
.splice(i
, 1);
1905 console
.log("cache_invalidate: id not found: " + id
);
1908 exception_error("cache_invalidate", e
);
1912 function getActiveArticleId() {
1913 return active_post_id
;
1916 function preloadBatchedArticles() {
1919 var query
= "?op=rpc&subop=getArticles&ids=" +
1920 preload_id_batch
.toString();
1922 new Ajax
.Request("backend.php", {
1924 onComplete: function(transport
) {
1926 preload_id_batch
= [];
1928 var articles
= transport
.responseXML
.getElementsByTagName("article");
1930 for (var i
= 0; i
< articles
.length
; i
++) {
1931 var id
= articles
[i
].getAttribute("id");
1932 if (!cache_check(id
)) {
1933 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1934 console
.log("preloaded article: " + id
);
1940 exception_error("preloadBatchedArticles", e
);
1944 function preloadArticleUnderPointer(id
) {
1946 if (getInitParam("bw_limit") == "1") return;
1948 if (post_under_pointer
== id
&& !cache_check(id
)) {
1950 console
.log("trying to preload article " + id
);
1952 var neighbor_ids
= getRelativePostIds(id
, 1);
1954 /* only request uncached articles */
1956 if (preload_id_batch
.indexOf(id
) == -1) {
1957 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1958 if (!cache_check(neighbor_ids
[i
])) {
1959 preload_id_batch
.push(neighbor_ids
[i
]);
1964 if (preload_id_batch
.indexOf(id
) == -1)
1965 preload_id_batch
.push(id
);
1967 console
.log("preload ids batch: " + preload_id_batch
.toString());
1969 window
.clearTimeout(preload_timeout_id
);
1970 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1974 exception_error("preloadArticleUnderPointer", e
);
1978 function postMouseIn(id
) {
1980 if (post_under_pointer
!= id
) {
1981 post_under_pointer
= id
;
1983 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1988 exception_error("postMouseIn", e
);
1992 function postMouseOut(id
) {
1994 post_under_pointer
= false;
1996 exception_error("postMouseOut", e
);
2000 function headlines_scroll_handler() {
2003 var e
= $("headlinesInnerContainer");
2005 var toolbar_form
= document
.forms
["main_toolbar_form"];
2007 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
2008 // _infscroll_disable);
2010 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
2011 if (!_infscroll_disable
) {
2012 console
.log("more cowbell!");
2018 exception_error("headlines_scroll_handler", e
);
2022 function catchupRelativeToArticle(below
) {
2027 if (!getActiveArticleId()) {
2028 alert(__("No article is selected."));
2034 if ($("headlinesList")) {
2035 visible_ids
= getVisibleHeadlineIds();
2037 visible_ids
= cdmGetVisibleArticles();
2040 var ids_to_mark
= new Array();
2043 for (var i
= 0; i
< visible_ids
.length
; i
++) {
2044 if (visible_ids
[i
] != getActiveArticleId()) {
2045 var e
= $("RROW-" + visible_ids
[i
]);
2047 if (e
&& e
.className
.match("Unread")) {
2048 ids_to_mark
.push(visible_ids
[i
]);
2055 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
2056 if (visible_ids
[i
] != getActiveArticleId()) {
2057 var e
= $("RROW-" + visible_ids
[i
]);
2059 if (e
&& e
.className
.match("Unread")) {
2060 ids_to_mark
.push(visible_ids
[i
]);
2068 if (ids_to_mark
.length
== 0) {
2069 alert(__("No articles found to mark"));
2071 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
2073 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
2075 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
2076 var e
= $("RROW-" + ids_to_mark
[i
]);
2077 e
.className
= e
.className
.replace("Unread", "");
2080 var query
= "?op=rpc&subop=catchupSelected" +
2081 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
2083 new Ajax
.Request("backend.php", {
2085 onComplete: function(transport
) {
2086 catchup_callback2(transport
);
2093 exception_error("catchupRelativeToArticle", e
);
2097 function cdmExpandArticle(id
) {
2100 var elem
= $("CICD-" + active_post_id
);
2102 if (id
== active_post_id
&& Element
.visible(elem
))
2105 cdmSelectArticles("none");
2107 var old_offset
= $("RROW-" + id
).offsetTop
;
2109 if (active_post_id
&& elem
) {
2111 Element
.show("CEXC-" + active_post_id
);
2114 active_post_id
= id
;
2116 elem
= $("CICD-" + id
);
2118 if (!Element
.visible(elem
)) {
2120 Element
.hide("CEXC-" + id
);
2123 var new_offset
= $("RROW-" + id
).offsetTop
;
2125 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
2127 if ($("RROW-" + id
).offsetTop
!= old_offset
)
2128 $("headlinesInnerContainer").scrollTop
= new_offset
;
2130 toggleUnread(id
, 0, true);
2134 exception_error("cdmExpandArticle", e
);
2140 function fixHeadlinesOrder(ids
) {
2142 for (var i
= 0; i
< ids
.length
; i
++) {
2143 var e
= $("RROW-" + ids
[i
]);
2147 e
.className
= e
.className
.replace("even", "odd");
2149 e
.className
= e
.className
.replace("odd", "even");
2154 exception_error("fixHeadlinesOrder", e
);
2158 function hideReadHeadlines() {
2162 var vis_ids
= new Array();
2164 if ($("headlinesList")) {
2165 ids
= getVisibleHeadlineIds();
2167 ids
= cdmGetVisibleArticles();
2170 var read_headlines_visible
= true;
2172 for (var i
= 0; i
< ids
.length
; i
++) {
2173 var row
= $("RROW-" + ids
[i
]);
2175 if (row
&& row
.className
) {
2176 if (read_headlines_visible
) {
2177 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
2179 vis_ids
.push(ids
[i
]);
2181 //Effect.Fade(row, {duration : 0.3});
2186 vis_ids
.push(ids
[i
]);
2191 fixHeadlinesOrder(vis_ids
);
2193 read_headlines_visible
= !read_headlines_visible
;
2196 exception_error("hideReadHeadlines", e
);
2200 function invertHeadlineSelection() {
2202 var rows
= new Array();
2206 r
= document
.getElementsByTagName("TR");
2208 r
= document
.getElementsByTagName("DIV");
2211 for (var i
= 0; i
< r
.length
; i
++) {
2212 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
2217 for (var i
= 0; i
< rows
.length
; i
++) {
2218 var nc
= rows
[i
].className
;
2219 var id
= rows
[i
].id
.replace("RROW-", "");
2220 var cb
= $("RCHK-" + id
);
2222 if (!rows
[i
].className
.match("Selected")) {
2223 nc
= nc
+ "Selected";
2226 nc
= nc
.replace("Selected", "");
2230 rows
[i
].className
= nc
;
2235 exception_error("invertHeadlineSelection", e
);
2239 function getArticleUnderPointer() {
2240 return post_under_pointer
;
2243 function zoomToArticle(id
) {
2245 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
2247 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2250 exception_error("zoomToArticle", e
);
2254 function scrollArticle(offset
) {
2257 var ci
= $("content-insert");
2259 ci
.scrollTop
+= offset
;
2262 var hi
= $("headlinesInnerContainer");
2264 hi
.scrollTop
+= offset
;
2269 exception_error("scrollArticle", e
);
2273 function show_labels_in_headlines(transport
) {
2275 if (transport
.responseXML
) {
2276 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2278 var elems
= info
.getElementsByTagName("entry");
2280 for (var l
= 0; l
< elems
.length
; l
++) {
2281 var e_id
= elems
[l
].getAttribute("id");
2285 var ctr
= $("HLLCTR-" + e_id
);
2288 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2296 exception_error("show_labels_in_headlines", e
);
2301 function toggleHeadlineActions() {
2303 var e
= $("headlineActionsBody");
2304 var p
= $("headlineActionsDrop");
2306 if (!Element
.visible(e
)) {
2313 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2314 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2317 exception_error("toggleHeadlineActions", e
);
2321 function publishWithNote(id
, def_note
) {
2323 if (!def_note
) def_note
= '';
2325 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2327 if (note
!= undefined) {
2328 togglePub(id
, false, false, note
);
2332 exception_error("publishWithNote", e
);
2336 function emailArticle(id
) {
2339 var ids
= getSelectedArticleIds2();
2341 if (ids
.length
== 0) {
2342 alert(__("No articles are selected."));
2346 id
= ids
.toString();
2349 displayDlg('emailArticle', id
,
2351 document
.forms
['article_email_form'].destination
.focus();
2353 new Ajax
.Autocompleter('destination', 'destination_choices',
2354 "backend.php?op=rpc&subop=completeEmails",
2355 { tokens
: '', paramName
: "search" });
2360 exception_error("emailArticle", e
);
2364 function emailArticleDo() {
2366 var f
= document
.forms
['article_email_form'];
2368 if (f
.destination
.value
== "") {
2369 alert("Please fill in the destination email.");
2373 if (f
.subject
.value
== "") {
2374 alert("Please fill in the subject.");
2378 var query
= Form
.serialize("article_email_form");
2380 // console.log(query);
2382 new Ajax
.Request("backend.php", {
2384 onComplete: function(transport
) {
2387 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2390 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2392 notify_info('Your message has been sent.');
2397 exception_error("sendEmailDo", e
);
2403 exception_error("emailArticleDo", e
);
2407 function cdmDismissArticle(id
) {
2409 var elem
= $("RROW-" + id
);
2411 toggleUnread(id
, 0, true);
2413 new Effect
.Fade(elem
, {duration
: 0.5});
2416 exception_error("cdmDismissArticle", e
);
2420 function cdmDismissSelectedArticles() {
2423 var ids
= getSelectedArticleIds2();
2425 for (var i
= 0; i
< ids
.length
; i
++) {
2426 var elem
= $("RROW-" + ids
[i
]);
2427 new Effect
.Fade(elem
, {duration
: 0.5});
2431 selectionToggleUnread(false);
2434 exception_error("cdmDismissArticle", e
);