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
);
937 // notify_progress("Loading, please wait...");
939 cache_invalidate("F:" + (-11 - id
));
941 new Ajax
.Request("backend.php", {
943 onComplete: function(transport
) {
944 show_labels_in_headlines(transport
);
945 all_counters_callback2(transport
);
951 exception_error("selectionAssignLabel", e
);
956 function selectionAssignLabel(id
) {
959 var ids
= getSelectedArticleIds2();
961 if (ids
.length
== 0) {
962 alert(__("No articles are selected."));
966 // var ok = confirm(__("Assign selected articles to label?"));
970 cache_invalidate("F:" + (-11 - id
));
972 var query
= "?op=rpc&subop=assignToLabel&ids=" +
973 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
975 // notify_progress("Loading, please wait...");
977 new Ajax
.Request("backend.php", {
979 onComplete: function(transport
) {
980 show_labels_in_headlines(transport
);
981 all_counters_callback2(transport
);
987 exception_error("selectionAssignLabel", e
);
992 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
994 var rows
= getSelectedArticleIds2();
996 if (rows
.length
== 0 && !no_error
) {
997 alert(__("No articles are selected."));
1001 for (i
= 0; i
< rows
.length
; i
++) {
1002 var row
= $("RROW-" + rows
[i
]);
1004 var nc
= row
.className
;
1005 nc
= nc
.replace("Unread", "");
1006 nc
= nc
.replace("Selected", "");
1008 if (set_state
== undefined) {
1009 if (row
.className
.match("Unread")) {
1010 row
.className
= nc
+ "Selected";
1012 row
.className
= nc
+ "UnreadSelected";
1015 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1020 if (set_state
== false) {
1021 row
.className
= nc
+ "Selected";
1023 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1028 if (set_state
== true) {
1029 row
.className
= nc
+ "UnreadSelected";
1031 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1038 if (rows
.length
> 0) {
1040 update_local_feedlist_counters();
1044 if (set_state
== undefined) {
1046 } else if (set_state
== true) {
1048 } else if (set_state
== false) {
1052 var query
= "?op=rpc&subop=catchupSelected" +
1053 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
1055 notify_progress("Loading, please wait...");
1057 new Ajax
.Request("backend.php", {
1059 onComplete: function(transport
) {
1060 catchup_callback2(transport
, callback_func
);
1066 exception_error("selectionToggleUnread", e
);
1070 function selectionToggleMarked() {
1073 var rows
= getSelectedArticleIds2();
1075 if (rows
.length
== 0) {
1076 alert(__("No articles are selected."));
1080 for (i
= 0; i
< rows
.length
; i
++) {
1081 toggleMark(rows
[i
], true, true);
1084 update_local_feedlist_counters();
1086 if (rows
.length
> 0) {
1088 var query
= "?op=rpc&subop=markSelected&ids=" +
1089 param_escape(rows
.toString()) + "&cmode=2";
1091 query
= query
+ "&afid=" + getActiveFeedId();
1093 query
= query
+ "&omode=lc";
1095 new Ajax
.Request("backend.php", {
1097 onComplete: function(transport
) {
1098 all_counters_callback2(transport
);
1104 exception_error("selectionToggleMarked", e
);
1108 function selectionTogglePublished() {
1111 var rows
= getSelectedArticleIds2();
1113 if (rows
.length
== 0) {
1114 alert(__("No articles are selected."));
1118 for (i
= 0; i
< rows
.length
; i
++) {
1119 togglePub(rows
[i
], true, true);
1122 if (rows
.length
> 0) {
1124 var query
= "?op=rpc&subop=publishSelected&ids=" +
1125 param_escape(rows
.toString()) + "&cmode=2";
1127 query
= query
+ "&afid=" + getActiveFeedId();
1129 query
= query
+ "&omode=lc";
1131 new Ajax
.Request("backend.php", {
1133 onComplete: function(transport
) {
1134 all_counters_callback2(transport
);
1140 exception_error("selectionToggleMarked", e
);
1144 function cdmGetSelectedArticles() {
1145 var sel_articles
= new Array();
1146 var container
= $("headlinesInnerContainer");
1148 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1149 var child
= container
.childNodes
[i
];
1151 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1152 var c_id
= child
.id
.replace("RROW-", "");
1153 sel_articles
.push(c_id
);
1157 return sel_articles
;
1160 function cdmGetVisibleArticles() {
1161 var sel_articles
= new Array();
1162 var container
= $("headlinesInnerContainer");
1164 if (!container
) return sel_articles
;
1166 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1167 var child
= container
.childNodes
[i
];
1169 if (child
.id
&& child
.id
.match("RROW-")) {
1170 var c_id
= child
.id
.replace("RROW-", "");
1171 sel_articles
.push(c_id
);
1175 return sel_articles
;
1178 function cdmGetUnreadArticles() {
1179 var sel_articles
= new Array();
1180 var container
= $("headlinesInnerContainer");
1182 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1183 var child
= container
.childNodes
[i
];
1185 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Unread")) {
1186 var c_id
= child
.id
.replace("RROW-", "");
1187 sel_articles
.push(c_id
);
1191 return sel_articles
;
1195 // mode = all,none,unread
1196 function cdmSelectArticles(mode
) {
1197 var container
= $("headlinesInnerContainer");
1199 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
1200 var child
= container
.childNodes
[i
];
1202 if (child
.id
&& child
.id
.match("RROW-")) {
1203 var aid
= child
.id
.replace("RROW-", "");
1205 var cb
= $("RCHK-" + aid
);
1207 if (mode
== "all") {
1208 if (!child
.className
.match("Selected")) {
1209 child
.className
= child
.className
+ "Selected";
1212 } else if (mode
== "unread") {
1213 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1214 child
.className
= child
.className
+ "Selected";
1218 child
.className
= child
.className
.replace("Selected", "");
1225 function catchupPage() {
1227 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1229 var str
= __("Mark all visible articles in %s as read?");
1231 str
= str
.replace("%s", fn
);
1233 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1237 if ($("headlinesList")) {
1238 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
1239 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1240 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1242 cdmSelectArticles('all');
1243 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1244 cdmSelectArticles('none');
1248 function deleteSelection() {
1252 var rows
= getSelectedArticleIds2();
1254 if (rows
.length
== 0) {
1255 alert(__("No articles are selected."));
1259 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1263 if (getActiveFeedId() != 0) {
1264 str
= __("Delete %d selected articles in %s?");
1266 str
= __("Delete %d selected articles?");
1269 str
= str
.replace("%d", rows
.length
);
1270 str
= str
.replace("%s", fn
);
1272 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1276 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1280 new Ajax
.Request("backend.php", {
1282 onComplete: function(transport
) {
1287 exception_error("deleteSelection", e
);
1291 function archiveSelection() {
1295 var rows
= getSelectedArticleIds2();
1297 if (rows
.length
== 0) {
1298 alert(__("No articles are selected."));
1302 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1306 if (getActiveFeedId() != 0) {
1307 str
= __("Archive %d selected articles in %s?");
1310 str
= __("Move %d archived articles back?");
1314 str
= str
.replace("%d", rows
.length
);
1315 str
= str
.replace("%s", fn
);
1317 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1321 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1325 for (var i
= 0; i
< rows
.length
; i
++) {
1326 cache_invalidate(rows
[i
]);
1329 new Ajax
.Request("backend.php", {
1331 onComplete: function(transport
) {
1336 exception_error("archiveSelection", e
);
1340 function catchupSelection() {
1344 var rows
= getSelectedArticleIds2();
1346 if (rows
.length
== 0) {
1347 alert(__("No articles are selected."));
1351 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1353 var str
= __("Mark %d selected articles in %s as read?");
1355 str
= str
.replace("%d", rows
.length
);
1356 str
= str
.replace("%s", fn
);
1358 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1362 if ($("headlinesList")) {
1363 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1365 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1369 exception_error("catchupSelection", e
);
1373 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1374 displayDlg('editArticleTags', id
,
1376 $("tags_str").focus();
1378 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1379 "backend.php?op=rpc&subop=completeTags",
1380 { tokens
: ',', paramName
: "search" });
1384 function editTagsSave() {
1386 notify_progress("Saving article tags...");
1388 var form
= document
.forms
["tag_edit_form"];
1390 var query
= Form
.serialize("tag_edit_form");
1392 query
= "?op=rpc&subop=setArticleTags&" + query
;
1396 new Ajax
.Request("backend.php", {
1398 onComplete: function(transport
) {
1400 console
.log("tags saved...");
1405 if (tagsAreDisplayed()) {
1406 _reload_feedlist_after_view
= true;
1409 if (transport
.responseXML
) {
1410 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1413 var id
= tags_str
.getAttribute("id");
1416 var tags
= $("ATSTR-" + id
);
1418 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1421 cache_invalidate(id
);
1427 exception_error("editTagsSave", e
);
1432 function editTagsInsert() {
1435 var form
= document
.forms
["tag_edit_form"];
1437 var found_tags
= form
.found_tags
;
1438 var tags_str
= form
.tags_str
;
1440 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1442 if (tags_str
.value
.length
> 0 &&
1443 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1445 tags_str
.value
= tags_str
.value
+ ", ";
1448 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1450 found_tags
.selectedIndex
= 0;
1453 exception_error("editTagsInsert", e
);
1457 function cdmScrollViewport(where
) {
1458 console
.log("cdmScrollViewport: " + where
);
1460 var ctr
= $("headlinesInnerContainer");
1464 if (where
== "bottom") {
1465 ctr
.scrollTop
= ctr
.scrollHeight
;
1467 ctr
.scrollTop
= where
;
1471 function cdmArticleIsBelowViewport(id
) {
1473 var ctr
= $("headlinesInnerContainer");
1474 var e
= $("RROW-" + id
);
1476 if (!e
|| !ctr
) return;
1478 // article starts below viewport
1480 if (ctr
.scrollTop
< e
.offsetTop
) {
1487 exception_error("cdmArticleIsVisible", e
);
1491 function cdmArticleIsAboveViewport(id
) {
1493 var ctr
= $("headlinesInnerContainer");
1494 var e
= $("RROW-" + id
);
1496 if (!e
|| !ctr
) return;
1498 // article starts above viewport
1500 if (ctr
.scrollTop
> e
.offsetTop
+ e
.offsetHeight
) {
1507 exception_error("cdmArticleIsVisible", e
);
1511 function cdmScrollToArticleId(id
) {
1513 var ctr
= $("headlinesInnerContainer");
1514 var e
= $("RROW-" + id
);
1516 if (!e
|| !ctr
) return;
1518 ctr
.scrollTop
= e
.offsetTop
;
1521 exception_error("cdmScrollToArticleId", e
);
1525 function cdmArticleIsActuallyVisible(id
) {
1527 var ctr
= $("headlinesInnerContainer");
1528 var e
= $("RROW-" + id
);
1530 if (!e
|| !ctr
) return;
1532 // article fits in viewport OR article is longer than viewport and
1533 // its bottom is visible
1535 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1536 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1540 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1541 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1542 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1551 exception_error("cdmArticleIsVisible", e
);
1555 function cdmWatchdog() {
1559 var ctr
= $("headlinesInnerContainer");
1563 var ids
= new Array();
1565 var e
= ctr
.firstChild
;
1568 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1569 e
.id
.match("RROW-")) {
1571 // article fits in viewport OR article is longer than viewport and
1572 // its bottom is visible
1574 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1575 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1577 // console.log(e.id + " is visible " + e.offsetTop + "." +
1578 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1579 // (ctr.scrollTop + ctr.offsetHeight));
1581 ids
.push(e
.id
.replace("RROW-", ""));
1583 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1584 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1585 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1587 ids
.push(e
.id
.replace("RROW-", ""));
1591 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1593 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1594 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1596 ids.push(e.id.replace("RROW-", ""));
1605 console
.log("cdmWatchdog, ids= " + ids
.toString());
1607 if (ids
.length
> 0) {
1609 for (var i
= 0; i
< ids
.length
; i
++) {
1610 var e
= $("RROW-" + ids
[i
]);
1612 e
.className
= e
.className
.replace("Unread", "");
1616 var query
= "?op=rpc&subop=catchupSelected" +
1617 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1619 new Ajax
.Request("backend.php", {
1621 onComplete: function(transport
) {
1622 all_counters_callback2(transport
);
1627 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1630 exception_error("cdmWatchdog", e
);
1636 function cache_inject(id
, article
, param
) {
1639 if (!cache_check_param(id
, param
)) {
1640 console
.log("cache_article: miss: " + id
+ " [p=" + param
+ "]");
1642 var date
= new Date();
1643 var ts
= Math
.round(date
.getTime() / 1000);
1647 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1648 [id
, article
, param
, ts
]);
1653 cache_obj
["id"] = id
;
1654 cache_obj
["data"] = article
;
1655 cache_obj
["param"] = param
;
1657 if (param
) id
= id
+ ":" + param
;
1659 cache_added
["TS:" + id
] = ts
;
1661 if (has_local_storage())
1662 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1664 article_cache
.push(cache_obj
);
1668 console
.log("cache_article: hit: " + id
+ " [p=" + param
+ "]");
1671 exception_error("cache_inject", e
);
1675 function cache_find(id
) {
1678 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1681 if (rs
.isValidRow()) {
1682 var a
= rs
.field(0);
1691 if (has_local_storage()) {
1692 var cache_obj
= localStorage
.getItem(id
);
1695 cache_obj
= JSON
.parse(cache_obj
);
1698 return cache_obj
['data'];
1702 for (var i
= 0; i
< article_cache
.length
; i
++) {
1703 if (article_cache
[i
]["id"] == id
) {
1704 return article_cache
[i
]["data"];
1712 function cache_find_param(id
, param
) {
1715 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1719 if (rs
.isValidRow()) {
1729 if (has_local_storage()) {
1731 if (param
) id
= id
+ ":" + param
;
1733 var cache_obj
= localStorage
.getItem(id
);
1736 cache_obj
= JSON
.parse(cache_obj
);
1739 return cache_obj
['data'];
1743 for (var i
= 0; i
< article_cache
.length
; i
++) {
1744 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1745 return article_cache
[i
]["data"];
1753 function cache_check(id
) {
1756 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1760 if (rs
.isValidRow()) {
1761 a
= rs
.field(0) != "0";
1769 if (has_local_storage()) {
1770 if (localStorage
.getItem(id
))
1773 for (var i
= 0; i
< article_cache
.length
; i
++) {
1774 if (article_cache
[i
]["id"] == id
) {
1783 function cache_check_param(id
, param
) {
1786 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1790 if (rs
.isValidRow()) {
1791 a
= rs
.field(0) != "0";
1800 if (has_local_storage()) {
1802 if (param
) id
= id
+ ":" + param
;
1804 if (localStorage
.getItem(id
))
1808 for (var i
= 0; i
< article_cache
.length
; i
++) {
1809 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1818 function cache_expire() {
1820 var date
= new Date();
1821 var ts
= Math
.round(date
.getTime() / 1000);
1823 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1824 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1825 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1829 if (has_local_storage()) {
1831 var date
= new Date();
1832 var timestamp
= Math
.round(date
.getTime() / 1000);
1834 for (var id
in cache_added
) {
1837 var key_id
= id
.replace("TS:", "");
1839 //console.warn("CEXP:" + key_id);
1841 if (timestamp
- cache_added
[id
] > 180) {
1842 cache_invalidate(key_id
);
1844 tmp
[id
] = cache_added
[id
];
1851 while (article_cache
.length
> 25) {
1852 article_cache
.shift();
1858 function cache_flush() {
1860 db
.execute("DELETE FROM cache");
1861 } else if (has_local_storage()) {
1862 localStorage
.clear();
1864 article_cache
= new Array();
1868 function cache_invalidate(id
) {
1872 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1873 return rs
.rowsAffected
!= 0;
1876 if (has_local_storage()) {
1881 for (var key
in cache_added
) {
1882 var key_id
= key
.replace("TS:", "");
1884 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1886 if (key_id
== id
|| key_id
.indexOf(id
+ ":") == 0) {
1887 localStorage
.removeItem(key_id
);
1891 tmp
[key
] = cache_added
[key
];
1902 while (i
< article_cache
.length
) {
1903 if (article_cache
[i
]["id"] == id
) {
1904 console
.log("cache_invalidate: removed id " + id
);
1905 article_cache
.splice(i
, 1);
1913 console
.log("cache_invalidate: id not found: " + id
);
1916 exception_error("cache_invalidate", e
);
1920 function getActiveArticleId() {
1921 return active_post_id
;
1924 function preloadBatchedArticles() {
1927 var query
= "?op=rpc&subop=getArticles&ids=" +
1928 preload_id_batch
.toString();
1930 new Ajax
.Request("backend.php", {
1932 onComplete: function(transport
) {
1934 preload_id_batch
= [];
1936 var articles
= transport
.responseXML
.getElementsByTagName("article");
1938 for (var i
= 0; i
< articles
.length
; i
++) {
1939 var id
= articles
[i
].getAttribute("id");
1940 if (!cache_check(id
)) {
1941 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1942 console
.log("preloaded article: " + id
);
1948 exception_error("preloadBatchedArticles", e
);
1952 function preloadArticleUnderPointer(id
) {
1954 if (getInitParam("bw_limit") == "1") return;
1956 if (post_under_pointer
== id
&& !cache_check(id
)) {
1958 console
.log("trying to preload article " + id
);
1960 var neighbor_ids
= getRelativePostIds(id
, 1);
1962 /* only request uncached articles */
1964 if (preload_id_batch
.indexOf(id
) == -1) {
1965 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1966 if (!cache_check(neighbor_ids
[i
])) {
1967 preload_id_batch
.push(neighbor_ids
[i
]);
1972 if (preload_id_batch
.indexOf(id
) == -1)
1973 preload_id_batch
.push(id
);
1975 console
.log("preload ids batch: " + preload_id_batch
.toString());
1977 window
.clearTimeout(preload_timeout_id
);
1978 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1982 exception_error("preloadArticleUnderPointer", e
);
1986 function postMouseIn(id
) {
1988 if (post_under_pointer
!= id
) {
1989 post_under_pointer
= id
;
1991 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1996 exception_error("postMouseIn", e
);
2000 function postMouseOut(id
) {
2002 post_under_pointer
= false;
2004 exception_error("postMouseOut", e
);
2008 function headlines_scroll_handler() {
2011 var e
= $("headlinesInnerContainer");
2013 var toolbar_form
= document
.forms
["main_toolbar_form"];
2015 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
2016 // _infscroll_disable);
2018 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
2019 if (!_infscroll_disable
) {
2020 console
.log("more cowbell!");
2026 exception_error("headlines_scroll_handler", e
);
2030 function catchupRelativeToArticle(below
) {
2035 if (!getActiveArticleId()) {
2036 alert(__("No article is selected."));
2042 if ($("headlinesList")) {
2043 visible_ids
= getVisibleHeadlineIds();
2045 visible_ids
= cdmGetVisibleArticles();
2048 var ids_to_mark
= new Array();
2051 for (var i
= 0; i
< visible_ids
.length
; i
++) {
2052 if (visible_ids
[i
] != getActiveArticleId()) {
2053 var e
= $("RROW-" + visible_ids
[i
]);
2055 if (e
&& e
.className
.match("Unread")) {
2056 ids_to_mark
.push(visible_ids
[i
]);
2063 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
2064 if (visible_ids
[i
] != getActiveArticleId()) {
2065 var e
= $("RROW-" + visible_ids
[i
]);
2067 if (e
&& e
.className
.match("Unread")) {
2068 ids_to_mark
.push(visible_ids
[i
]);
2076 if (ids_to_mark
.length
== 0) {
2077 alert(__("No articles found to mark"));
2079 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
2081 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
2083 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
2084 var e
= $("RROW-" + ids_to_mark
[i
]);
2085 e
.className
= e
.className
.replace("Unread", "");
2088 var query
= "?op=rpc&subop=catchupSelected" +
2089 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
2091 new Ajax
.Request("backend.php", {
2093 onComplete: function(transport
) {
2094 catchup_callback2(transport
);
2101 exception_error("catchupRelativeToArticle", e
);
2105 function cdmExpandArticle(id
) {
2108 var elem
= $("CICD-" + active_post_id
);
2110 if (id
== active_post_id
&& Element
.visible(elem
))
2113 cdmSelectArticles("none");
2115 var old_offset
= $("RROW-" + id
).offsetTop
;
2117 if (active_post_id
&& elem
) {
2119 Element
.show("CEXC-" + active_post_id
);
2122 active_post_id
= id
;
2124 elem
= $("CICD-" + id
);
2126 if (!Element
.visible(elem
)) {
2128 Element
.hide("CEXC-" + id
);
2131 var new_offset
= $("RROW-" + id
).offsetTop
;
2133 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
2135 if ($("RROW-" + id
).offsetTop
!= old_offset
)
2136 $("headlinesInnerContainer").scrollTop
= new_offset
;
2138 toggleUnread(id
, 0, true);
2142 exception_error("cdmExpandArticle", e
);
2148 function fixHeadlinesOrder(ids
) {
2150 for (var i
= 0; i
< ids
.length
; i
++) {
2151 var e
= $("RROW-" + ids
[i
]);
2155 e
.className
= e
.className
.replace("even", "odd");
2157 e
.className
= e
.className
.replace("odd", "even");
2162 exception_error("fixHeadlinesOrder", e
);
2166 function hideReadHeadlines() {
2170 var vis_ids
= new Array();
2172 if ($("headlinesList")) {
2173 ids
= getVisibleHeadlineIds();
2175 ids
= cdmGetVisibleArticles();
2178 var read_headlines_visible
= true;
2180 for (var i
= 0; i
< ids
.length
; i
++) {
2181 var row
= $("RROW-" + ids
[i
]);
2183 if (row
&& row
.className
) {
2184 if (read_headlines_visible
) {
2185 if (row
.className
.match("Unread") || row
.className
.match("Selected")) {
2187 vis_ids
.push(ids
[i
]);
2189 //Effect.Fade(row, {duration : 0.3});
2194 vis_ids
.push(ids
[i
]);
2199 fixHeadlinesOrder(vis_ids
);
2201 read_headlines_visible
= !read_headlines_visible
;
2204 exception_error("hideReadHeadlines", e
);
2208 function invertHeadlineSelection() {
2210 var rows
= new Array();
2214 r
= document
.getElementsByTagName("TR");
2216 r
= document
.getElementsByTagName("DIV");
2219 for (var i
= 0; i
< r
.length
; i
++) {
2220 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
2225 for (var i
= 0; i
< rows
.length
; i
++) {
2226 var nc
= rows
[i
].className
;
2227 var id
= rows
[i
].id
.replace("RROW-", "");
2228 var cb
= $("RCHK-" + id
);
2230 if (!rows
[i
].className
.match("Selected")) {
2231 nc
= nc
+ "Selected";
2234 nc
= nc
.replace("Selected", "");
2238 rows
[i
].className
= nc
;
2243 exception_error("invertHeadlineSelection", e
);
2247 function getArticleUnderPointer() {
2248 return post_under_pointer
;
2251 function zoomToArticle(id
) {
2253 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
2255 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2258 exception_error("zoomToArticle", e
);
2262 function scrollArticle(offset
) {
2265 var ci
= $("content-insert");
2267 ci
.scrollTop
+= offset
;
2270 var hi
= $("headlinesInnerContainer");
2272 hi
.scrollTop
+= offset
;
2277 exception_error("scrollArticle", e
);
2281 function show_labels_in_headlines(transport
) {
2283 if (transport
.responseXML
) {
2284 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2286 var elems
= info
.getElementsByTagName("entry");
2288 for (var l
= 0; l
< elems
.length
; l
++) {
2289 var e_id
= elems
[l
].getAttribute("id");
2293 var ctr
= $("HLLCTR-" + e_id
);
2296 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2304 exception_error("show_labels_in_headlines", e
);
2309 function toggleHeadlineActions() {
2311 var e
= $("headlineActionsBody");
2312 var p
= $("headlineActionsDrop");
2314 if (!Element
.visible(e
)) {
2321 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2322 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2325 exception_error("toggleHeadlineActions", e
);
2329 function publishWithNote(id
, def_note
) {
2331 if (!def_note
) def_note
= '';
2333 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2335 if (note
!= undefined) {
2336 togglePub(id
, false, false, note
);
2340 exception_error("publishWithNote", e
);
2344 function emailArticle(id
) {
2347 var ids
= getSelectedArticleIds2();
2349 if (ids
.length
== 0) {
2350 alert(__("No articles are selected."));
2354 id
= ids
.toString();
2357 displayDlg('emailArticle', id
,
2359 document
.forms
['article_email_form'].destination
.focus();
2361 new Ajax
.Autocompleter('destination', 'destination_choices',
2362 "backend.php?op=rpc&subop=completeEmails",
2363 { tokens
: '', paramName
: "search" });
2368 exception_error("emailArticle", e
);
2372 function emailArticleDo() {
2374 var f
= document
.forms
['article_email_form'];
2376 if (f
.destination
.value
== "") {
2377 alert("Please fill in the destination email.");
2381 if (f
.subject
.value
== "") {
2382 alert("Please fill in the subject.");
2386 var query
= Form
.serialize("article_email_form");
2388 // console.log(query);
2390 new Ajax
.Request("backend.php", {
2392 onComplete: function(transport
) {
2395 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2398 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2400 notify_info('Your message has been sent.');
2405 exception_error("sendEmailDo", e
);
2411 exception_error("emailArticleDo", e
);
2415 function cdmDismissArticle(id
) {
2417 var elem
= $("RROW-" + id
);
2419 toggleUnread(id
, 0, true);
2421 new Effect
.Fade(elem
, {duration
: 0.5});
2424 exception_error("cdmDismissArticle", e
);
2428 function cdmDismissSelectedArticles() {
2431 var ids
= getSelectedArticleIds2();
2433 for (var i
= 0; i
< ids
.length
; i
++) {
2434 var elem
= $("RROW-" + ids
[i
]);
2435 new Effect
.Fade(elem
, {duration
: 0.5});
2439 selectionToggleUnread(false);
2442 exception_error("cdmDismissArticle", e
);