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 handle_rpc_reply(transport
);
29 setTimeout(callback
, 10);
32 exception_error("catchup_callback2", e
, transport
);
36 function headlines_callback2(transport
, feed_cur_page
) {
39 if (!handle_rpc_reply(transport
)) return;
41 loading_set_progress(100);
43 console
.log("headlines_callback2 [page=" + feed_cur_page
+ "]");
45 if (!transport_error_check(transport
)) return;
47 clean_feed_selections();
52 if (transport
.responseXML
) {
53 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
55 is_cat
= headlines
.getAttribute("is_cat");
56 feed_id
= headlines
.getAttribute("id");
57 setActiveFeedId(feed_id
, is_cat
);
61 var ll
= $('FLL-' + feed_id
);
63 if (ll
&& ll
.parentNode
)
64 ll
.parentNode
.removeChild(ll
);
67 var feedr
= $("FEEDR-" + feed_id
);
68 if (feedr
&& !feedr
.className
.match("Selected")) {
69 feedr
.className
= feedr
.className
+ "Selected";
72 var feedr
= $("FCAT-" + feed_id
);
73 if (feedr
&& !feedr
.className
.match("Selected")) {
74 feedr
.className
= feedr
.className
+ "Selected";
78 var img
= $('FIMG-' + feed_id
);
84 var f
= $("headlines-frame");
86 if (feed_cur_page
== 0) {
87 //console.log("resetting headlines scrollTop");
92 if (transport
.responseXML
) {
93 var response
= transport
.responseXML
;
95 var headlines
= response
.getElementsByTagName("headlines")[0];
96 var headlines_info
= response
.getElementsByTagName("headlines-info")[0];
99 headlines_info
= JSON
.parse(headlines_info
.firstChild
.nodeValue
);
101 console
.error("didn't find headlines-info object in response");
105 var headlines_count
= headlines_info
.count
;
106 var headlines_unread
= headlines_info
.unread
;
107 var disable_cache
= headlines_info
.disable_cache
;
109 vgroup_last_feed
= headlines_info
.vgroup_last_feed
;
111 if (headlines_count
== 0) {
112 _infscroll_disable
= 1;
114 _infscroll_disable
= 0;
117 var counters
= response
.getElementsByTagName("counters")[0];
118 var articles
= response
.getElementsByTagName("article");
119 var runtime_info
= response
.getElementsByTagName("runtime-info");
121 if (feed_cur_page
== 0) {
123 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
125 var cache_prefix
= "";
133 cache_invalidate(cache_prefix
+ feed_id
);
135 if (!disable_cache
) {
136 cache_inject(cache_prefix
+ feed_id
,
137 headlines
.firstChild
.nodeValue
, headlines_unread
);
141 console
.warn("headlines_callback: returned no data");
142 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
147 if (headlines_count
> 0) {
148 console
.log("adding some more headlines...");
150 var c
= $("headlinesList");
153 c
= $("headlinesInnerContainer");
156 var ids
= getSelectedArticleIds2();
158 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
160 console
.log("restore selected ids: " + ids
);
162 for (var i
= 0; i
< ids
.length
; i
++) {
163 markHeadline(ids
[i
]);
167 console
.log("no new headlines received");
170 console
.warn("headlines_callback: returned no data");
171 notify_error("Error while trying to load more headlines");
177 for (var i
= 0; i
< articles
.length
; i
++) {
178 var a_id
= articles
[i
].getAttribute("id");
179 //console.log("found id: " + a_id);
180 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
183 console
.log("no cached articles received");
187 parse_counters(counters
);
192 parse_runtime_info(runtime_info
[0]);
196 console
.warn("headlines_callback: returned no XML object");
197 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
201 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
204 getActiveFeedId() != -3 &&
205 getInitParam("cdm_auto_catchup") == 1) {
206 console
.log("starting CDM watchdog");
207 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
208 _cdm_wd_vishist
= new Array();
210 console
.log("not in CDM mode or watchdog disabled");
213 _feed_cur_page
= feed_cur_page
;
214 _infscroll_request_sent
= 0;
221 exception_error("headlines_callback2", e
, transport
);
225 function render_article(article
) {
227 var f
= $("content-frame");
232 var fi
= $("content-insert");
238 fi
.innerHTML
= article
;
240 // article.evalScripts();
243 exception_error("render_article", e
);
247 function showArticleInHeadlines(id
) {
251 cleanSelected("headlinesList");
253 var crow
= $("RROW-" + id
);
257 var article_is_unread
= crow
.className
.match("Unread");
259 crow
.className
= crow
.className
.replace("Unread", "");
261 selectArticles('none');
263 var upd_img_pic
= $("FUPDPIC-" + id
);
265 var cache_prefix
= "";
267 if (activeFeedIsCat()) {
273 var view_mode
= false;
276 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
277 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
282 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
283 upd_img_pic
.src
.match("fresh_sign.png"))) {
285 upd_img_pic
.src
= "images/blank_icon.gif";
287 cache_invalidate(cache_prefix
+ getActiveFeedId());
289 cache_inject(cache_prefix
+ getActiveFeedId(),
290 $("headlines-frame").innerHTML
,
291 get_feed_unread(getActiveFeedId()));
293 } else if (article_is_unread
&& view_mode
== "all_articles") {
295 cache_invalidate(cache_prefix
+ getActiveFeedId());
297 cache_inject(cache_prefix
+ getActiveFeedId(),
298 $("headlines-frame").innerHTML
,
299 get_feed_unread(getActiveFeedId())-1);
301 } else if (article_is_unread
) {
302 cache_invalidate(cache_prefix
+ getActiveFeedId());
307 if (article_is_unread
)
308 _force_scheduled_update
= true;
311 exception_error("showArticleInHeadlines", e
);
315 function article_callback2(transport
, id
) {
317 console
.log("article_callback2 " + id
);
319 if (!handle_rpc_reply(transport
)) return;
321 if (transport
.responseXML
) {
323 if (!transport_error_check(transport
)) return;
325 /* var ll = $('LL-' + id);
326 var content = $('HLC-' + id);
328 if (ll && content) content.removeChild(ll); */
330 var upic
= $('FUPDPIC-' + id
);
333 upic
.src
= 'images/blank_icon.gif';
336 if (id
!= last_requested_article
) {
337 console
.log("requested article id is out of sequence, aborting");
341 // active_post_id = id;
343 //console.log("looking for articles to cache...");
345 var articles
= transport
.responseXML
.getElementsByTagName("article");
347 for (var i
= 0; i
< articles
.length
; i
++) {
348 var a_id
= articles
[i
].getAttribute("id");
350 //console.log("found id: " + a_id);
352 if (a_id
== active_post_id
) {
353 //console.log("active article, rendering...");
354 render_article(articles
[i
].firstChild
.nodeValue
);
357 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
361 // showArticleInHeadlines(id);
364 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id
]);
367 var reply
= transport
.responseXML
.firstChild
.firstChild
;
370 console
.warn("article_callback: returned no XML object");
371 //var f = $("content-frame");
372 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
375 var date
= new Date();
376 last_article_view
= date
.getTime() / 1000;
378 if (_reload_feedlist_after_view
) {
379 setTimeout('updateFeedList(false, false)', 50);
380 _reload_feedlist_after_view
= false;
387 exception_error("article_callback2", e
, transport
);
393 console
.log("loading article: " + id
);
395 if (offline_mode
) return view_offline(id
);
397 var cached_article
= cache_find(id
);
399 console
.log("cache check result: " + (cached_article
!= false));
404 var query
= "?op=view&id=" + param_escape(id
);
406 var neighbor_ids
= getRelativePostIds(active_post_id
);
408 /* only request uncached articles */
410 var cids_to_request
= Array();
412 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
413 if (!cache_check(neighbor_ids
[i
])) {
414 cids_to_request
.push(neighbor_ids
[i
]);
418 console
.log("additional ids: " + cids_to_request
.toString());
420 /* additional info for piggyback counters */
422 if (tagsAreDisplayed()) {
423 query
= query
+ "&omode=lt";
425 query
= query
+ "&omode=flc";
428 query
= query
+ "&cids=" + cids_to_request
.toString();
430 var crow
= $("RROW-" + id
);
431 var article_is_unread
= crow
.className
.match("Unread");
434 showArticleInHeadlines(id
);
436 if (!cached_article
) {
438 var upic
= $('FUPDPIC-' + id
);
441 upic
.src
= getInitParam("sign_progress");
444 } else if (cached_article
&& article_is_unread
) {
446 query
= query
+ "&mode=prefetch";
448 render_article(cached_article
);
450 } else if (cached_article
) {
452 query
= query
+ "&mode=prefetch_old";
453 render_article(cached_article
);
459 last_requested_article
= id
;
461 new Ajax
.Request("backend.php", {
463 onComplete: function(transport
) {
464 article_callback2(transport
, id
);
470 exception_error("view", e
);
475 return toggleMark(id
);
479 return togglePub(id
);
482 function tMark_afh_off(effect
) {
484 var elem
= effect
.effects
[0].element
;
486 //console.log("tMark_afh_off : " + elem.id);
489 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
490 elem
.alt
= __("Star article");
495 exception_error("tMark_afh_off", e
);
499 function tPub_afh_off(effect
) {
501 var elem
= effect
.effects
[0].element
;
503 //console.log("tPub_afh_off : " + elem.id);
506 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
507 elem
.alt
= __("Publish article");
512 exception_error("tPub_afh_off", e
);
516 function toggleMark(id
, client_only
, no_effects
) {
520 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
522 query
= query
+ "&afid=" + getActiveFeedId();
524 if (tagsAreDisplayed()) {
525 query
= query
+ "&omode=tl";
527 query
= query
+ "&omode=flc";
530 var mark_img
= $("FMPIC-" + id
);
532 if (!mark_img
) return;
534 var vfeedu
= $("FEEDU--1");
535 var crow
= $("RROW-" + id
);
537 if (mark_img
.src
.match("mark_unset")) {
538 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
539 mark_img
.alt
= __("Unstar article");
540 query
= query
+ "&mark=1";
543 db
.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id
]);
547 mark_img
.alt
= __("Please wait...");
548 query
= query
+ "&mark=0";
550 if (!isCdmMode() && !no_effects
) {
551 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
553 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
554 mark_img
.alt
= __("Star article");
558 db
.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id
]);
563 if (!no_effects
) update_local_feedlist_counters();
566 //console.log(query);
568 new Ajax
.Request("backend.php", {
570 onComplete: function(transport
) {
571 handle_rpc_reply(transport
);
577 exception_error("toggleMark", e
);
581 function togglePub(id
, client_only
, no_effects
, note
) {
585 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
587 query
= query
+ "&afid=" + getActiveFeedId();
589 if (note
!= undefined) {
590 query
= query
+ "¬e=" + param_escape(note
);
592 query
= query
+ "¬e=undefined";
595 if (tagsAreDisplayed()) {
596 query
= query
+ "&omode=tl";
598 query
= query
+ "&omode=flc";
601 var mark_img
= $("FPPIC-" + id
);
603 if (!mark_img
) return;
605 var vfeedu
= $("FEEDU--2");
606 var crow
= $("RROW-" + id
);
608 if (mark_img
.src
.match("pub_unset") || note
!= undefined) {
609 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
610 mark_img
.alt
= __("Unpublish article");
611 query
= query
+ "&pub=1";
614 mark_img
.alt
= __("Please wait...");
615 query
= query
+ "&pub=0";
617 if (!isCdmMode() && !no_effects
) {
618 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
620 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
621 mark_img
.alt
= __("Publish article");
626 new Ajax
.Request("backend.php", {
628 onComplete: function(transport
) {
629 handle_rpc_reply(transport
);
631 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
634 var note_id
= note
.getAttribute("id");
635 var note_size
= note
.getAttribute("size");
636 var note_content
= note
.firstChild
.nodeValue
;
638 var container
= $('POSTNOTE-' + note_id
);
640 cache_invalidate(note_id
);
643 if (note_size
== "0") {
644 Element
.hide(container
);
646 container
.innerHTML
= note_content
;
647 Element
.show(container
);
656 exception_error("togglePub", e
);
660 function correctHeadlinesOffset(id
) {
664 var hlist
= $("headlinesList");
665 var container
= $("headlinesInnerContainer");
666 var row
= $("RROW-" + id
);
668 var viewport
= container
.offsetHeight
;
670 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
671 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
673 console
.log("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
674 console
.log("Vport: " + viewport
);
676 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
677 container
.scrollTop
= row
.offsetTop
;
678 } else if (rel_offset_bottom
> viewport
) {
680 /* doesn't properly work with Opera in some cases because
681 Opera fucks up element scrolling */
683 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
687 exception_error("correctHeadlinesOffset", e
);
692 function moveToPost(mode
) {
696 var rows
= getVisibleArticleIds();
701 if (!$('RROW-' + active_post_id
)) {
702 active_post_id
= false;
705 if (active_post_id
== false) {
706 next_id
= getFirstVisibleHeadlineId();
707 prev_id
= getLastVisibleHeadlineId();
709 for (var i
= 0; i
< rows
.length
; i
++) {
710 if (rows
[i
] == active_post_id
) {
717 if (mode
== "next") {
721 cdmExpandArticle(next_id
);
722 cdmScrollToArticleId(next_id
);
725 correctHeadlinesOffset(next_id
);
726 view(next_id
, getActiveFeedId());
731 if (mode
== "prev") {
734 cdmExpandArticle(prev_id
);
735 cdmScrollToArticleId(prev_id
);
737 correctHeadlinesOffset(prev_id
);
738 view(prev_id
, getActiveFeedId());
744 exception_error("moveToPost", e
);
748 function toggleSelected(id
) {
751 var cb
= $("RCHK-" + id
);
753 var row
= $("RROW-" + id
);
755 var nc
= row
.className
;
757 if (!nc
.match("Selected")) {
758 nc
= nc
+ "Selected";
763 // In CDM basically last selected article == active article
764 if (isCdmMode()) active_post_id
= id
;
766 nc
= nc
.replace("Selected", "");
776 exception_error("toggleSelected", e
);
780 function toggleUnread_afh(effect
) {
783 var elem
= effect
.element
;
784 elem
.style
.backgroundColor
= "";
787 exception_error("toggleUnread_afh", e
);
791 function toggleUnread(id
, cmode
, effect
) {
794 var row
= $("RROW-" + id
);
796 var nc
= row
.className
;
797 var is_selected
= row
.className
.match("Selected");
798 nc
= nc
.replace("Unread", "");
799 nc
= nc
.replace("Selected", "");
801 // since we are removing selection from the object, uncheck
802 // corresponding checkbox
804 var cb
= $("RCHK-" + id
);
809 // NOTE: I'm not sure that resetting selection here is a feature -fox
811 if (cmode
== undefined || cmode
== 2) {
812 if (row
.className
.match("Unread")) {
816 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
817 afterFinish
: toggleUnread_afh
,
818 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
822 row
.className
= nc
+ "Unread";
826 db
.execute("UPDATE articles SET unread = not unread "+
827 "WHERE id = ?", [id
]);
830 } else if (cmode
== 0) {
834 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
835 afterFinish
: toggleUnread_afh
,
836 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
840 db
.execute("UPDATE articles SET unread = 0 "+
841 "WHERE id = ?", [id
]);
844 } else if (cmode
== 1) {
845 row
.className
= nc
+ "Unread";
848 db
.execute("UPDATE articles SET unread = 1 "+
849 "WHERE id = ?", [id
]);
854 update_local_feedlist_counters();
856 // Disable unmarking as selected for the time being (16.05.08) -fox
857 if (is_selected
) row
.className
= row
.className
+ "Selected";
859 if (cmode
== undefined) cmode
= 2;
861 var query
= "?op=rpc&subop=catchupSelected" +
862 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
864 // notify_progress("Loading, please wait...");
866 new Ajax
.Request("backend.php", {
868 onComplete: function(transport
) {
869 handle_rpc_reply(transport
);
875 exception_error("toggleUnread", e
);
879 function selectionRemoveLabel(id
) {
882 var ids
= getSelectedArticleIds2();
884 if (ids
.length
== 0) {
885 alert(__("No articles are selected."));
889 // var ok = confirm(__("Remove selected articles from label?"));
893 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
894 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
898 // notify_progress("Loading, please wait...");
900 cache_invalidate("F:" + (-11 - id
));
902 new Ajax
.Request("backend.php", {
904 onComplete: function(transport
) {
905 show_labels_in_headlines(transport
);
906 handle_rpc_reply(transport
);
912 exception_error("selectionAssignLabel", e
);
917 function selectionAssignLabel(id
) {
920 var ids
= getSelectedArticleIds2();
922 if (ids
.length
== 0) {
923 alert(__("No articles are selected."));
927 // var ok = confirm(__("Assign selected articles to label?"));
931 cache_invalidate("F:" + (-11 - id
));
933 var query
= "?op=rpc&subop=assignToLabel&ids=" +
934 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
938 // notify_progress("Loading, please wait...");
940 new Ajax
.Request("backend.php", {
942 onComplete: function(transport
) {
943 show_labels_in_headlines(transport
);
944 handle_rpc_reply(transport
);
950 exception_error("selectionAssignLabel", e
);
955 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
957 var rows
= getSelectedArticleIds2();
959 if (rows
.length
== 0 && !no_error
) {
960 alert(__("No articles are selected."));
964 for (i
= 0; i
< rows
.length
; i
++) {
965 var row
= $("RROW-" + rows
[i
]);
967 var nc
= row
.className
;
968 nc
= nc
.replace("Unread", "");
969 nc
= nc
.replace("Selected", "");
971 if (set_state
== undefined) {
972 if (row
.className
.match("Unread")) {
973 row
.className
= nc
+ "Selected";
975 row
.className
= nc
+ "UnreadSelected";
978 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
983 if (set_state
== false) {
984 row
.className
= nc
+ "Selected";
986 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
991 if (set_state
== true) {
992 row
.className
= nc
+ "UnreadSelected";
994 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1001 if (rows
.length
> 0) {
1003 update_local_feedlist_counters();
1007 if (set_state
== undefined) {
1009 } else if (set_state
== true) {
1011 } else if (set_state
== false) {
1015 var query
= "?op=rpc&subop=catchupSelected" +
1016 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
1018 notify_progress("Loading, please wait...");
1020 new Ajax
.Request("backend.php", {
1022 onComplete: function(transport
) {
1023 catchup_callback2(transport
, callback_func
);
1029 exception_error("selectionToggleUnread", e
);
1033 function selectionToggleMarked() {
1036 var rows
= getSelectedArticleIds2();
1038 if (rows
.length
== 0) {
1039 alert(__("No articles are selected."));
1043 for (i
= 0; i
< rows
.length
; i
++) {
1044 toggleMark(rows
[i
], true, true);
1047 update_local_feedlist_counters();
1049 if (rows
.length
> 0) {
1051 var query
= "?op=rpc&subop=markSelected&ids=" +
1052 param_escape(rows
.toString()) + "&cmode=2";
1054 query
= query
+ "&afid=" + getActiveFeedId();
1056 query
= query
+ "&omode=lc";
1058 new Ajax
.Request("backend.php", {
1060 onComplete: function(transport
) {
1061 handle_rpc_reply(transport
);
1067 exception_error("selectionToggleMarked", e
);
1071 function selectionTogglePublished() {
1074 var rows
= getSelectedArticleIds2();
1076 if (rows
.length
== 0) {
1077 alert(__("No articles are selected."));
1081 for (i
= 0; i
< rows
.length
; i
++) {
1082 togglePub(rows
[i
], true, true);
1085 if (rows
.length
> 0) {
1087 var query
= "?op=rpc&subop=publishSelected&ids=" +
1088 param_escape(rows
.toString()) + "&cmode=2";
1090 query
= query
+ "&afid=" + getActiveFeedId();
1092 query
= query
+ "&omode=lc";
1094 new Ajax
.Request("backend.php", {
1096 onComplete: function(transport
) {
1097 handle_rpc_reply(transport
);
1103 exception_error("selectionToggleMarked", e
);
1107 function getSelectedArticleIds2() {
1108 var sel_articles
= new Array();
1113 var children
= $("headlinesInnerContainer").childNodes
;
1115 var children
= $("headlinesList").rows
;
1117 for (i
= 0; i
< children
.length
; i
++) {
1118 var child
= children
[i
];
1120 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1121 var c_id
= child
.id
.replace("RROW-", "");
1122 sel_articles
.push(c_id
);
1126 return sel_articles
;
1129 function getLoadedArticleIds() {
1130 var sel_articles
= new Array();
1133 var children
= $("headlinesInnerContainer").childNodes
;
1135 var children
= $("headlinesList").rows
;
1137 if (!children
) return sel_articles
;
1139 for (i
= 0; i
< children
.length
; i
++) {
1140 var child
= children
[i
];
1142 if (child
.id
&& child
.id
.match("RROW-")) {
1143 var c_id
= child
.id
.replace("RROW-", "");
1144 sel_articles
.push(c_id
);
1148 return sel_articles
;
1151 // mode = all,none,unread,invert
1152 function selectArticles(mode
) {
1158 var children
= $("headlinesInnerContainer").childNodes
;
1160 var children
= $("headlinesList").rows
;
1162 for (i
= 0; i
< children
.length
; i
++) {
1163 var child
= children
[i
];
1165 if (child
.id
&& child
.id
.match("RROW-")) {
1166 var aid
= child
.id
.replace("RROW-", "");
1168 var cb
= $("RCHK-" + aid
);
1170 if (mode
== "all") {
1171 if (!child
.className
.match("Selected")) {
1172 child
.className
= child
.className
+ "Selected";
1175 } else if (mode
== "unread") {
1176 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1177 child
.className
= child
.className
+ "Selected";
1180 } else if (mode
== "invert") {
1181 if (child
.className
.match("Selected")) {
1182 child
.className
= child
.className
.replace("Selected", "");
1185 child
.className
= child
.className
+ "Selected";
1190 child
.className
= child
.className
.replace("Selected", "");
1197 exception_error("selectArticles", e
);
1201 function catchupPage() {
1203 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1205 var str
= __("Mark all visible articles in %s as read?");
1207 str
= str
.replace("%s", fn
);
1209 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1213 selectArticles('all');
1214 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1215 selectArticles('none');
1218 function deleteSelection() {
1222 var rows
= getSelectedArticleIds2();
1224 if (rows
.length
== 0) {
1225 alert(__("No articles are selected."));
1229 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1233 if (getActiveFeedId() != 0) {
1234 str
= __("Delete %d selected articles in %s?");
1236 str
= __("Delete %d selected articles?");
1239 str
= str
.replace("%d", rows
.length
);
1240 str
= str
.replace("%s", fn
);
1242 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1246 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1250 new Ajax
.Request("backend.php", {
1252 onComplete: function(transport
) {
1257 exception_error("deleteSelection", e
);
1261 function archiveSelection() {
1265 var rows
= getSelectedArticleIds2();
1267 if (rows
.length
== 0) {
1268 alert(__("No articles are selected."));
1272 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1276 if (getActiveFeedId() != 0) {
1277 str
= __("Archive %d selected articles in %s?");
1280 str
= __("Move %d archived articles back?");
1284 str
= str
.replace("%d", rows
.length
);
1285 str
= str
.replace("%s", fn
);
1287 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1291 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1295 for (var i
= 0; i
< rows
.length
; i
++) {
1296 cache_invalidate(rows
[i
]);
1299 new Ajax
.Request("backend.php", {
1301 onComplete: function(transport
) {
1306 exception_error("archiveSelection", e
);
1310 function catchupSelection() {
1314 var rows
= getSelectedArticleIds2();
1316 if (rows
.length
== 0) {
1317 alert(__("No articles are selected."));
1321 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1323 var str
= __("Mark %d selected articles in %s as read?");
1325 str
= str
.replace("%d", rows
.length
);
1326 str
= str
.replace("%s", fn
);
1328 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1332 if ($("headlinesList")) {
1333 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1335 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1339 exception_error("catchupSelection", e
);
1343 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1344 displayDlg('editArticleTags', id
,
1346 $("tags_str").focus();
1348 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1349 "backend.php?op=rpc&subop=completeTags",
1350 { tokens
: ',', paramName
: "search" });
1354 function editTagsSave() {
1356 notify_progress("Saving article tags...");
1358 var form
= document
.forms
["tag_edit_form"];
1360 var query
= Form
.serialize("tag_edit_form");
1362 query
= "?op=rpc&subop=setArticleTags&" + query
;
1364 //console.log(query);
1366 new Ajax
.Request("backend.php", {
1368 onComplete: function(transport
) {
1370 //console.log("tags saved...");
1375 if (tagsAreDisplayed()) {
1376 _reload_feedlist_after_view
= true;
1379 if (transport
.responseXML
) {
1380 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1383 var id
= tags_str
.getAttribute("id");
1386 var tags
= $("ATSTR-" + id
);
1388 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1391 cache_invalidate(id
);
1397 exception_error("editTagsSave", e
);
1402 function editTagsInsert() {
1405 var form
= document
.forms
["tag_edit_form"];
1407 var found_tags
= form
.found_tags
;
1408 var tags_str
= form
.tags_str
;
1410 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1412 if (tags_str
.value
.length
> 0 &&
1413 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1415 tags_str
.value
= tags_str
.value
+ ", ";
1418 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1420 found_tags
.selectedIndex
= 0;
1423 exception_error("editTagsInsert", e
);
1427 function cdmScrollToArticleId(id
) {
1429 var ctr
= $("headlinesInnerContainer");
1430 var e
= $("RROW-" + id
);
1432 if (!e
|| !ctr
) return;
1434 ctr
.scrollTop
= e
.offsetTop
;
1437 exception_error("cdmScrollToArticleId", e
);
1441 function cdmWatchdog() {
1445 var ctr
= $("headlinesInnerContainer");
1449 var ids
= new Array();
1451 var e
= ctr
.firstChild
;
1454 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1455 e
.id
.match("RROW-")) {
1457 // article fits in viewport OR article is longer than viewport and
1458 // its bottom is visible
1460 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1461 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1463 // console.log(e.id + " is visible " + e.offsetTop + "." +
1464 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1465 // (ctr.scrollTop + ctr.offsetHeight));
1467 ids
.push(e
.id
.replace("RROW-", ""));
1469 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1470 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1471 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1473 ids
.push(e
.id
.replace("RROW-", ""));
1477 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1479 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1480 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1482 ids.push(e.id.replace("RROW-", ""));
1491 console
.log("cdmWatchdog, ids= " + ids
.toString());
1493 if (ids
.length
> 0) {
1495 for (var i
= 0; i
< ids
.length
; i
++) {
1496 var e
= $("RROW-" + ids
[i
]);
1498 e
.className
= e
.className
.replace("Unread", "");
1502 var query
= "?op=rpc&subop=catchupSelected" +
1503 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1505 new Ajax
.Request("backend.php", {
1507 onComplete: function(transport
) {
1508 handle_rpc_reply(transport
);
1513 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1516 exception_error("cdmWatchdog", e
);
1522 function cache_inject(id
, article
, param
) {
1525 if (!cache_check_param(id
, param
)) {
1526 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1528 var date
= new Date();
1529 var ts
= Math
.round(date
.getTime() / 1000);
1533 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1534 [id
, article
, param
, ts
]);
1539 cache_obj
["id"] = id
;
1540 cache_obj
["data"] = article
;
1541 cache_obj
["param"] = param
;
1543 if (param
) id
= id
+ ":" + param
;
1545 cache_added
["TS:" + id
] = ts
;
1547 if (has_local_storage())
1548 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1550 article_cache
.push(cache_obj
);
1554 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1557 exception_error("cache_inject", e
);
1561 function cache_find(id
) {
1564 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1567 if (rs
.isValidRow()) {
1568 var a
= rs
.field(0);
1577 if (has_local_storage()) {
1578 var cache_obj
= localStorage
.getItem(id
);
1581 cache_obj
= JSON
.parse(cache_obj
);
1584 return cache_obj
['data'];
1588 for (var i
= 0; i
< article_cache
.length
; i
++) {
1589 if (article_cache
[i
]["id"] == id
) {
1590 return article_cache
[i
]["data"];
1598 function cache_find_param(id
, param
) {
1601 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1605 if (rs
.isValidRow()) {
1615 if (has_local_storage()) {
1617 if (param
) id
= id
+ ":" + param
;
1619 var cache_obj
= localStorage
.getItem(id
);
1622 cache_obj
= JSON
.parse(cache_obj
);
1625 return cache_obj
['data'];
1629 for (var i
= 0; i
< article_cache
.length
; i
++) {
1630 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1631 return article_cache
[i
]["data"];
1639 function cache_check(id
) {
1642 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1646 if (rs
.isValidRow()) {
1647 a
= rs
.field(0) != "0";
1655 if (has_local_storage()) {
1656 if (localStorage
.getItem(id
))
1659 for (var i
= 0; i
< article_cache
.length
; i
++) {
1660 if (article_cache
[i
]["id"] == id
) {
1669 function cache_check_param(id
, param
) {
1672 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1676 if (rs
.isValidRow()) {
1677 a
= rs
.field(0) != "0";
1686 if (has_local_storage()) {
1688 if (param
) id
= id
+ ":" + param
;
1690 if (localStorage
.getItem(id
))
1694 for (var i
= 0; i
< article_cache
.length
; i
++) {
1695 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1704 function cache_expire() {
1706 var date
= new Date();
1707 var ts
= Math
.round(date
.getTime() / 1000);
1709 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1710 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1711 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1715 if (has_local_storage()) {
1717 var date
= new Date();
1718 var timestamp
= Math
.round(date
.getTime() / 1000);
1720 for (var i
= 0; i
< localStorage
.length
; i
++) {
1722 var id
= localStorage
.key(i
);
1724 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1725 localStorage
.removeItem(id
);
1730 while (article_cache
.length
> 25) {
1731 article_cache
.shift();
1737 function cache_flush() {
1739 db
.execute("DELETE FROM cache");
1740 } else if (has_local_storage()) {
1741 localStorage
.clear();
1743 article_cache
= new Array();
1747 function cache_invalidate(id
) {
1751 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1752 return rs
.rowsAffected
!= 0;
1755 if (has_local_storage()) {
1759 for (var i
= 0; i
< localStorage
.length
; i
++) {
1760 var key
= localStorage
.key(i
);
1762 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1764 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1765 localStorage
.removeItem(key
);
1776 while (i
< article_cache
.length
) {
1777 if (article_cache
[i
]["id"] == id
) {
1778 //console.log("cache_invalidate: removed id " + id);
1779 article_cache
.splice(i
, 1);
1787 //console.log("cache_invalidate: id not found: " + id);
1790 exception_error("cache_invalidate", e
);
1794 function getActiveArticleId() {
1795 return active_post_id
;
1798 function preloadBatchedArticles() {
1801 var query
= "?op=rpc&subop=getArticles&ids=" +
1802 preload_id_batch
.toString();
1804 new Ajax
.Request("backend.php", {
1806 onComplete: function(transport
) {
1808 preload_id_batch
= [];
1810 var articles
= transport
.responseXML
.getElementsByTagName("article");
1812 for (var i
= 0; i
< articles
.length
; i
++) {
1813 var id
= articles
[i
].getAttribute("id");
1814 if (!cache_check(id
)) {
1815 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1816 console
.log("preloaded article: " + id
);
1822 exception_error("preloadBatchedArticles", e
);
1826 function preloadArticleUnderPointer(id
) {
1828 if (getInitParam("bw_limit") == "1") return;
1830 if (post_under_pointer
== id
&& !cache_check(id
)) {
1832 console
.log("trying to preload article " + id
);
1834 var neighbor_ids
= getRelativePostIds(id
, 1);
1836 /* only request uncached articles */
1838 if (preload_id_batch
.indexOf(id
) == -1) {
1839 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1840 if (!cache_check(neighbor_ids
[i
])) {
1841 preload_id_batch
.push(neighbor_ids
[i
]);
1846 if (preload_id_batch
.indexOf(id
) == -1)
1847 preload_id_batch
.push(id
);
1849 //console.log("preload ids batch: " + preload_id_batch.toString());
1851 window
.clearTimeout(preload_timeout_id
);
1852 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1856 exception_error("preloadArticleUnderPointer", e
);
1860 function postMouseIn(id
) {
1862 if (post_under_pointer
!= id
) {
1863 post_under_pointer
= id
;
1865 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1870 exception_error("postMouseIn", e
);
1874 function postMouseOut(id
) {
1876 post_under_pointer
= false;
1878 exception_error("postMouseOut", e
);
1882 function headlines_scroll_handler() {
1885 var e
= $("headlinesInnerContainer");
1887 var toolbar_form
= document
.forms
["main_toolbar_form"];
1889 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1890 // _infscroll_disable);
1892 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1893 if (!_infscroll_disable
) {
1899 exception_error("headlines_scroll_handler", e
);
1903 function catchupRelativeToArticle(below
) {
1908 if (!getActiveArticleId()) {
1909 alert(__("No article is selected."));
1913 var visible_ids
= getVisibleArticleIds();
1915 var ids_to_mark
= new Array();
1918 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1919 if (visible_ids
[i
] != getActiveArticleId()) {
1920 var e
= $("RROW-" + visible_ids
[i
]);
1922 if (e
&& e
.className
.match("Unread")) {
1923 ids_to_mark
.push(visible_ids
[i
]);
1930 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1931 if (visible_ids
[i
] != getActiveArticleId()) {
1932 var e
= $("RROW-" + visible_ids
[i
]);
1934 if (e
&& e
.className
.match("Unread")) {
1935 ids_to_mark
.push(visible_ids
[i
]);
1943 if (ids_to_mark
.length
== 0) {
1944 alert(__("No articles found to mark"));
1946 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1948 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1950 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1951 var e
= $("RROW-" + ids_to_mark
[i
]);
1952 e
.className
= e
.className
.replace("Unread", "");
1955 var query
= "?op=rpc&subop=catchupSelected" +
1956 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1958 new Ajax
.Request("backend.php", {
1960 onComplete: function(transport
) {
1961 catchup_callback2(transport
);
1968 exception_error("catchupRelativeToArticle", e
);
1972 function cdmExpandArticle(id
) {
1977 var elem
= $("CICD-" + active_post_id
);
1979 if (id
== active_post_id
&& Element
.visible(elem
))
1982 selectArticles("none");
1984 var old_offset
= $("RROW-" + id
).offsetTop
;
1986 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1988 Element
.show("CEXC-" + active_post_id
);
1991 active_post_id
= id
;
1993 elem
= $("CICD-" + id
);
1995 if (!Element
.visible(elem
)) {
1997 Element
.hide("CEXC-" + id
);
2000 var new_offset
= $("RROW-" + id
).offsetTop
;
2002 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
2004 if ($("RROW-" + id
).offsetTop
!= old_offset
)
2005 $("headlinesInnerContainer").scrollTop
= new_offset
;
2007 toggleUnread(id
, 0, true);
2011 exception_error("cdmExpandArticle", e
);
2017 function fixHeadlinesOrder(ids
) {
2019 for (var i
= 0; i
< ids
.length
; i
++) {
2020 var e
= $("RROW-" + ids
[i
]);
2024 e
.className
= e
.className
.replace("even", "odd");
2026 e
.className
= e
.className
.replace("odd", "even");
2031 exception_error("fixHeadlinesOrder", e
);
2035 function invertHeadlineSelection() {
2037 var rows
= new Array();
2041 r
= document
.getElementsByTagName("TR");
2043 r
= document
.getElementsByTagName("DIV");
2046 for (var i
= 0; i
< r
.length
; i
++) {
2047 if (r
[i
].id
&& r
[i
].id
.match("RROW-")) {
2052 for (var i
= 0; i
< rows
.length
; i
++) {
2053 var nc
= rows
[i
].className
;
2054 var id
= rows
[i
].id
.replace("RROW-", "");
2055 var cb
= $("RCHK-" + id
);
2057 if (!rows
[i
].className
.match("Selected")) {
2058 nc
= nc
+ "Selected";
2061 nc
= nc
.replace("Selected", "");
2065 rows
[i
].className
= nc
;
2070 exception_error("invertHeadlineSelection", e
);
2074 function getArticleUnderPointer() {
2075 return post_under_pointer
;
2078 function zoomToArticle(id
) {
2080 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
2082 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2085 exception_error("zoomToArticle", e
);
2089 function scrollArticle(offset
) {
2092 var ci
= $("content-insert");
2094 ci
.scrollTop
+= offset
;
2097 var hi
= $("headlinesInnerContainer");
2099 hi
.scrollTop
+= offset
;
2104 exception_error("scrollArticle", e
);
2108 function show_labels_in_headlines(transport
) {
2110 if (transport
.responseXML
) {
2111 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2113 var elems
= info
.getElementsByTagName("entry");
2115 for (var l
= 0; l
< elems
.length
; l
++) {
2116 var e_id
= elems
[l
].getAttribute("id");
2120 var ctr
= $("HLLCTR-" + e_id
);
2123 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2131 exception_error("show_labels_in_headlines", e
);
2136 function toggleHeadlineActions() {
2138 var e
= $("headlineActionsBody");
2139 var p
= $("headlineActionsDrop");
2141 if (!Element
.visible(e
)) {
2148 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2149 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2152 exception_error("toggleHeadlineActions", e
);
2156 function publishWithNote(id
, def_note
) {
2158 if (!def_note
) def_note
= '';
2160 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2162 if (note
!= undefined) {
2163 togglePub(id
, false, false, note
);
2167 exception_error("publishWithNote", e
);
2171 function emailArticle(id
) {
2174 var ids
= getSelectedArticleIds2();
2176 if (ids
.length
== 0) {
2177 alert(__("No articles are selected."));
2181 id
= ids
.toString();
2184 displayDlg('emailArticle', id
,
2186 document
.forms
['article_email_form'].destination
.focus();
2188 new Ajax
.Autocompleter('destination', 'destination_choices',
2189 "backend.php?op=rpc&subop=completeEmails",
2190 { tokens
: '', paramName
: "search" });
2195 exception_error("emailArticle", e
);
2199 function emailArticleDo() {
2201 var f
= document
.forms
['article_email_form'];
2203 if (f
.destination
.value
== "") {
2204 alert("Please fill in the destination email.");
2208 if (f
.subject
.value
== "") {
2209 alert("Please fill in the subject.");
2213 var query
= Form
.serialize("article_email_form");
2215 // console.log(query);
2217 new Ajax
.Request("backend.php", {
2219 onComplete: function(transport
) {
2222 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2225 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2227 notify_info('Your message has been sent.');
2232 exception_error("sendEmailDo", e
);
2238 exception_error("emailArticleDo", e
);
2242 function dismissArticle(id
) {
2244 var elem
= $("RROW-" + id
);
2246 toggleUnread(id
, 0, true);
2248 new Effect
.Fade(elem
, {duration
: 0.5});
2251 exception_error("dismissArticle", e
);
2255 function dismissSelectedArticles() {
2258 var ids
= getVisibleArticleIds();
2262 for (var i
= 0; i
< ids
.length
; i
++) {
2263 var elem
= $("RROW-" + ids
[i
]);
2265 if (elem
.className
&& elem
.className
.match("Selected")) {
2266 new Effect
.Fade(elem
, {duration
: 0.5});
2274 selectionToggleUnread(false);
2276 fixHeadlinesOrder(tmp
);
2279 exception_error("dismissSelectedArticles", e
);
2283 function dismissReadArticles() {
2286 var ids
= getVisibleArticleIds();
2289 for (var i
= 0; i
< ids
.length
; i
++) {
2290 var elem
= $("RROW-" + ids
[i
]);
2292 if (elem
.className
&& !elem
.className
.match("Unread") &&
2293 !elem
.className
.match("Selected")) {
2295 new Effect
.Fade(elem
, {duration
: 0.5});
2301 fixHeadlinesOrder(tmp
);
2304 exception_error("dismissSelectedArticles", e
);
2308 function getVisibleArticleIds() {
2312 var tmp
= getLoadedArticleIds();
2314 for (var i
= 0; i
< tmp
.length
; i
++) {
2315 var elem
= $("RROW-" + tmp
[i
]);
2316 if (elem
&& Element
.visible(elem
))
2321 exception_error("getVisibleArticleIds", e
);
2327 function cdmClicked(event
, id
) {
2329 var shift_key
= event
.shiftKey
;
2333 if (!event
.ctrlKey
) {
2334 selectArticles("none");
2337 var elem
= $("RROW-" + id
);
2340 elem
.className
= elem
.className
.replace("Unread", "");
2342 var query
= "?op=rpc&subop=catchupSelected" +
2343 "&cmode=0&ids=" + param_escape(id
);
2345 new Ajax
.Request("backend.php", {
2347 onComplete: function(transport
) {
2348 handle_rpc_reply(transport
);
2357 exception_error("cdmClicked");
2363 function hlClicked(event
, id
) {
2365 var shift_key
= event
.shiftKey
;
2367 if (!event
.ctrlKey
) {
2376 exception_error("hlClicked");
2382 function getFirstVisibleHeadlineId() {
2383 var rows
= getVisibleArticleIds();
2388 function getLastVisibleHeadlineId() {
2389 var rows
= getVisibleArticleIds();
2390 return rows
[rows
.length
-1];
2393 // this only searches loaded headlines list, not in CDM
2394 function getRelativePostIds(id
, limit
) {
2396 if (!limit
) limit
= 3;
2398 //console.log("getRelativePostIds: " + id + " limit=" + limit);
2400 var ids
= new Array();
2401 var container
= $("headlinesList");
2404 var rows
= container
.rows
;
2406 for (var i
= 0; i
< rows
.length
; i
++) {
2407 var r_id
= rows
[i
].id
.replace("RROW-", "");
2410 for (var k
= 1; k
<= limit
; k
++) {
2413 if (i
> k
-1) var nid
= rows
[i
-k
].id
.replace("RROW-", "");
2414 if (nid
) ids
.push(nid
);
2416 if (i
< rows
.length
-k
) nid
= rows
[i
+k
].id
.replace("RROW-", "");
2417 if (nid
) ids
.push(nid
);
2428 function openArticleInNewWindow(id
) {
2430 console
.log("openArticleInNewWindow: " + id
);
2432 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2433 var wname
= "ttrss_article_" + id
;
2435 console
.log(query
+ " " + wname
);
2437 var w
= window
.open("", wname
);
2439 if (!w
) notify_error("Failed to open window for the article");
2441 new Ajax
.Request("backend.php", {
2443 onComplete: function(transport
) {
2445 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2446 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2448 console
.log("open_article received link: " + link
);
2452 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2454 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2456 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2458 if (!w
) { notify_error("Failed to load article in new window"); }
2461 id
= id
.firstChild
.nodeValue
;
2462 if (!$("headlinesList")) {
2463 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2467 notify_error("Can't open article: received invalid article link");
2472 exception_error("openArticleInNewWindow", e
);
2476 function isCdmMode() {
2477 return !$("headlinesList");
2480 function markHeadline(id
) {
2481 var row
= $("RROW-" + id
);
2483 var is_active
= false;
2485 if (row
.className
.match("Active")) {
2488 row
.className
= row
.className
.replace("Selected", "");
2489 row
.className
= row
.className
.replace("Active", "");
2490 row
.className
= row
.className
.replace("Insensitive", "");
2493 row
.className
= row
.className
= "Active";
2496 var check
= $("RCHK-" + id
);
2499 check
.checked
= true;
2502 row
.className
= row
.className
+ "Selected";