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 update_btn
= document
.forms
["main_toolbar_form"].update
;
63 update_btn
.disabled
= !(feed_id
>= 0 && !is_cat
);
65 var ll
= $('FLL-' + feed_id
);
67 if (ll
&& ll
.parentNode
)
68 ll
.parentNode
.removeChild(ll
);
71 var feedr
= $("FEEDR-" + feed_id
);
72 if (feedr
&& !feedr
.className
.match("Selected")) {
73 feedr
.className
= feedr
.className
+ "Selected";
76 var feedr
= $("FCAT-" + feed_id
);
77 if (feedr
&& !feedr
.className
.match("Selected")) {
78 feedr
.className
= feedr
.className
+ "Selected";
82 var img
= $('FIMG-' + feed_id
);
88 var f
= $("headlines-frame");
90 if (feed_cur_page
== 0) {
91 //console.log("resetting headlines scrollTop");
96 if (transport
.responseXML
) {
97 var response
= transport
.responseXML
;
99 var headlines
= response
.getElementsByTagName("headlines")[0];
100 var headlines_info
= response
.getElementsByTagName("headlines-info")[0];
103 headlines_info
= JSON
.parse(headlines_info
.firstChild
.nodeValue
);
105 console
.error("didn't find headlines-info object in response");
109 var headlines_count
= headlines_info
.count
;
110 var headlines_unread
= headlines_info
.unread
;
111 var disable_cache
= headlines_info
.disable_cache
;
113 vgroup_last_feed
= headlines_info
.vgroup_last_feed
;
115 if (headlines_count
== 0) {
116 _infscroll_disable
= 1;
118 _infscroll_disable
= 0;
121 var counters
= response
.getElementsByTagName("counters")[0];
122 var articles
= response
.getElementsByTagName("article");
123 var runtime_info
= response
.getElementsByTagName("runtime-info");
125 if (feed_cur_page
== 0) {
127 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
129 var cache_prefix
= "";
137 cache_invalidate(cache_prefix
+ feed_id
);
139 if (!disable_cache
) {
140 cache_inject(cache_prefix
+ feed_id
,
141 headlines
.firstChild
.nodeValue
, headlines_unread
);
145 console
.warn("headlines_callback: returned no data");
146 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
151 if (headlines_count
> 0) {
152 console
.log("adding some more headlines...");
154 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 selectArticles("none");
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 query
= query
+ "&cids=" + cids_to_request
.toString();
422 var crow
= $("RROW-" + id
);
423 var article_is_unread
= crow
.className
.match("Unread");
426 showArticleInHeadlines(id
);
428 if (!cached_article
) {
430 var upic
= $('FUPDPIC-' + id
);
433 upic
.src
= getInitParam("sign_progress");
436 } else if (cached_article
&& article_is_unread
) {
438 query
= query
+ "&mode=prefetch";
440 render_article(cached_article
);
442 } else if (cached_article
) {
444 query
= query
+ "&mode=prefetch_old";
445 render_article(cached_article
);
451 last_requested_article
= id
;
453 new Ajax
.Request("backend.php", {
455 onComplete: function(transport
) {
456 article_callback2(transport
, id
);
462 exception_error("view", e
);
467 return toggleMark(id
);
471 return togglePub(id
);
474 function tMark_afh_off(effect
) {
476 var elem
= effect
.effects
[0].element
;
478 //console.log("tMark_afh_off : " + elem.id);
481 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
482 elem
.alt
= __("Star article");
487 exception_error("tMark_afh_off", e
);
491 function tPub_afh_off(effect
) {
493 var elem
= effect
.effects
[0].element
;
495 //console.log("tPub_afh_off : " + elem.id);
498 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
499 elem
.alt
= __("Publish article");
504 exception_error("tPub_afh_off", e
);
508 function toggleMark(id
, client_only
) {
510 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
512 var img
= $("FMPIC-" + id
);
516 if (img
.src
.match("mark_unset")) {
517 img
.src
= img
.src
.replace("mark_unset", "mark_set");
518 img
.alt
= __("Unstar article");
519 query
= query
+ "&mark=1";
522 db
.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id
]);
526 img
.src
= img
.src
.replace("mark_set", "mark_unset");
527 img
.alt
= __("Star article");
528 query
= query
+ "&mark=0";
531 db
.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id
]);
535 update_local_feedlist_counters();
538 new Ajax
.Request("backend.php", {
540 onComplete: function(transport
) {
541 handle_rpc_reply(transport
);
546 exception_error("toggleMark", e
);
550 function togglePub(id
, client_only
, no_effects
, note
) {
552 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
554 if (note
!= undefined) {
555 query
= query
+ "¬e=" + param_escape(note
);
557 query
= query
+ "¬e=undefined";
560 var img
= $("FPPIC-" + id
);
564 if (img
.src
.match("pub_unset") || note
!= undefined) {
565 img
.src
= img
.src
.replace("pub_unset", "pub_set");
566 img
.alt
= __("Unpublish article");
567 query
= query
+ "&pub=1";
570 img
.src
= img
.src
.replace("pub_set", "pub_unset");
571 img
.alt
= __("Publish article");
573 query
= query
+ "&pub=0";
577 new Ajax
.Request("backend.php", {
579 onComplete: function(transport
) {
580 handle_rpc_reply(transport
);
582 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
585 var note_id
= note
.getAttribute("id");
586 var note_size
= note
.getAttribute("size");
587 var note_content
= note
.firstChild
.nodeValue
;
589 var container
= $('POSTNOTE-' + note_id
);
591 cache_invalidate(note_id
);
594 if (note_size
== "0") {
595 Element
.hide(container
);
597 container
.innerHTML
= note_content
;
598 Element
.show(container
);
607 exception_error("togglePub", e
);
611 function moveToPost(mode
) {
615 var rows
= getVisibleArticleIds();
620 if (!$('RROW-' + active_post_id
)) {
621 active_post_id
= false;
624 if (active_post_id
== false) {
625 next_id
= getFirstVisibleHeadlineId();
626 prev_id
= getLastVisibleHeadlineId();
628 for (var i
= 0; i
< rows
.length
; i
++) {
629 if (rows
[i
] == active_post_id
) {
636 if (mode
== "next") {
640 cdmExpandArticle(next_id
);
641 cdmScrollToArticleId(next_id
);
644 correctHeadlinesOffset(next_id
);
645 view(next_id
, getActiveFeedId());
650 if (mode
== "prev") {
653 cdmExpandArticle(prev_id
);
654 cdmScrollToArticleId(prev_id
);
656 correctHeadlinesOffset(prev_id
);
657 view(prev_id
, getActiveFeedId());
663 exception_error("moveToPost", e
);
667 function toggleSelected(id
) {
670 var cb
= $("RCHK-" + id
);
672 var row
= $("RROW-" + id
);
674 var nc
= row
.className
;
676 if (!nc
.match("Selected")) {
677 nc
= nc
+ "Selected";
682 // In CDM basically last selected article == active article
683 if (isCdmMode()) active_post_id
= id
;
685 nc
= nc
.replace("Selected", "");
695 exception_error("toggleSelected", e
);
699 function toggleUnread_afh(effect
) {
702 var elem
= effect
.element
;
703 elem
.style
.backgroundColor
= "";
706 exception_error("toggleUnread_afh", e
);
710 function toggleUnread(id
, cmode
, effect
) {
713 var row
= $("RROW-" + id
);
715 var nc
= row
.className
;
716 var is_selected
= row
.className
.match("Selected");
717 nc
= nc
.replace("Unread", "");
718 nc
= nc
.replace("Selected", "");
720 // since we are removing selection from the object, uncheck
721 // corresponding checkbox
723 var cb
= $("RCHK-" + id
);
728 // NOTE: I'm not sure that resetting selection here is a feature -fox
730 if (cmode
== undefined || cmode
== 2) {
731 if (row
.className
.match("Unread")) {
735 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
736 afterFinish
: toggleUnread_afh
,
737 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
741 row
.className
= nc
+ "Unread";
745 db
.execute("UPDATE articles SET unread = not unread "+
746 "WHERE id = ?", [id
]);
749 } else if (cmode
== 0) {
753 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
754 afterFinish
: toggleUnread_afh
,
755 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
759 db
.execute("UPDATE articles SET unread = 0 "+
760 "WHERE id = ?", [id
]);
763 } else if (cmode
== 1) {
764 row
.className
= nc
+ "Unread";
767 db
.execute("UPDATE articles SET unread = 1 "+
768 "WHERE id = ?", [id
]);
773 update_local_feedlist_counters();
775 // Disable unmarking as selected for the time being (16.05.08) -fox
776 if (is_selected
) row
.className
= row
.className
+ "Selected";
778 if (cmode
== undefined) cmode
= 2;
780 var query
= "?op=rpc&subop=catchupSelected" +
781 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
783 // notify_progress("Loading, please wait...");
785 new Ajax
.Request("backend.php", {
787 onComplete: function(transport
) {
788 handle_rpc_reply(transport
);
794 exception_error("toggleUnread", e
);
798 function selectionRemoveLabel(id
) {
801 var ids
= getSelectedArticleIds2();
803 if (ids
.length
== 0) {
804 alert(__("No articles are selected."));
808 // var ok = confirm(__("Remove selected articles from label?"));
812 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
813 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
817 // notify_progress("Loading, please wait...");
819 cache_invalidate("F:" + (-11 - id
));
821 new Ajax
.Request("backend.php", {
823 onComplete: function(transport
) {
824 show_labels_in_headlines(transport
);
825 handle_rpc_reply(transport
);
831 exception_error("selectionAssignLabel", e
);
836 function selectionAssignLabel(id
) {
839 var ids
= getSelectedArticleIds2();
841 if (ids
.length
== 0) {
842 alert(__("No articles are selected."));
846 // var ok = confirm(__("Assign selected articles to label?"));
850 cache_invalidate("F:" + (-11 - id
));
852 var query
= "?op=rpc&subop=assignToLabel&ids=" +
853 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
857 // notify_progress("Loading, please wait...");
859 new Ajax
.Request("backend.php", {
861 onComplete: function(transport
) {
862 show_labels_in_headlines(transport
);
863 handle_rpc_reply(transport
);
869 exception_error("selectionAssignLabel", e
);
874 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
876 var rows
= getSelectedArticleIds2();
878 if (rows
.length
== 0 && !no_error
) {
879 alert(__("No articles are selected."));
883 for (i
= 0; i
< rows
.length
; i
++) {
884 var row
= $("RROW-" + rows
[i
]);
886 var nc
= row
.className
;
887 nc
= nc
.replace("Unread", "");
888 nc
= nc
.replace("Selected", "");
890 if (set_state
== undefined) {
891 if (row
.className
.match("Unread")) {
892 row
.className
= nc
+ "Selected";
894 row
.className
= nc
+ "UnreadSelected";
897 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
902 if (set_state
== false) {
903 row
.className
= nc
+ "Selected";
905 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
910 if (set_state
== true) {
911 row
.className
= nc
+ "UnreadSelected";
913 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
920 if (rows
.length
> 0) {
922 update_local_feedlist_counters();
926 if (set_state
== undefined) {
928 } else if (set_state
== true) {
930 } else if (set_state
== false) {
934 var query
= "?op=rpc&subop=catchupSelected" +
935 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
937 notify_progress("Loading, please wait...");
939 new Ajax
.Request("backend.php", {
941 onComplete: function(transport
) {
942 catchup_callback2(transport
, callback_func
);
948 exception_error("selectionToggleUnread", e
);
952 function selectionToggleMarked() {
955 var rows
= getSelectedArticleIds2();
957 if (rows
.length
== 0) {
958 alert(__("No articles are selected."));
962 for (i
= 0; i
< rows
.length
; i
++) {
963 toggleMark(rows
[i
], true, true);
966 update_local_feedlist_counters();
968 if (rows
.length
> 0) {
970 var query
= "?op=rpc&subop=markSelected&ids=" +
971 param_escape(rows
.toString()) + "&cmode=2";
973 new Ajax
.Request("backend.php", {
975 onComplete: function(transport
) {
976 handle_rpc_reply(transport
);
982 exception_error("selectionToggleMarked", e
);
986 function selectionTogglePublished() {
989 var rows
= getSelectedArticleIds2();
991 if (rows
.length
== 0) {
992 alert(__("No articles are selected."));
996 for (i
= 0; i
< rows
.length
; i
++) {
997 togglePub(rows
[i
], true, true);
1000 if (rows
.length
> 0) {
1002 var query
= "?op=rpc&subop=publishSelected&ids=" +
1003 param_escape(rows
.toString()) + "&cmode=2";
1005 new Ajax
.Request("backend.php", {
1007 onComplete: function(transport
) {
1008 handle_rpc_reply(transport
);
1014 exception_error("selectionToggleMarked", e
);
1018 function getSelectedArticleIds2() {
1019 var sel_articles
= new Array();
1023 var children
= $("headlinesInnerContainer").childNodes
;
1025 for (i
= 0; i
< children
.length
; i
++) {
1026 var child
= children
[i
];
1028 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1029 var c_id
= child
.id
.replace("RROW-", "");
1030 sel_articles
.push(c_id
);
1034 return sel_articles
;
1037 function getLoadedArticleIds() {
1038 var sel_articles
= new Array();
1040 var children
= $("headlinesInnerContainer").childNodes
;
1042 if (!children
) return sel_articles
;
1044 for (i
= 0; i
< children
.length
; i
++) {
1045 var child
= children
[i
];
1047 if (child
.id
&& child
.id
.match("RROW-")) {
1048 var c_id
= child
.id
.replace("RROW-", "");
1049 sel_articles
.push(c_id
);
1053 return sel_articles
;
1056 // mode = all,none,unread,invert
1057 function selectArticles(mode
) {
1062 var children
= $("headlinesInnerContainer").childNodes
;
1064 for (i
= 0; i
< children
.length
; i
++) {
1065 var child
= children
[i
];
1067 if (child
.id
&& child
.id
.match("RROW-")) {
1068 var aid
= child
.id
.replace("RROW-", "");
1070 var cb
= $("RCHK-" + aid
);
1072 if (mode
== "all") {
1073 if (!child
.className
.match("Selected")) {
1074 child
.className
= child
.className
+ "Selected";
1077 } else if (mode
== "unread") {
1078 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1079 child
.className
= child
.className
+ "Selected";
1082 } else if (mode
== "invert") {
1083 if (child
.className
.match("Selected")) {
1084 child
.className
= child
.className
.replace("Selected", "");
1087 child
.className
= child
.className
+ "Selected";
1092 child
.className
= child
.className
.replace("Selected", "");
1099 exception_error("selectArticles", e
);
1103 function catchupPage() {
1105 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1107 var str
= __("Mark all visible articles in %s as read?");
1109 str
= str
.replace("%s", fn
);
1111 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1115 selectArticles('all');
1116 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1117 selectArticles('none');
1120 function deleteSelection() {
1124 var rows
= getSelectedArticleIds2();
1126 if (rows
.length
== 0) {
1127 alert(__("No articles are selected."));
1131 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1135 if (getActiveFeedId() != 0) {
1136 str
= __("Delete %d selected articles in %s?");
1138 str
= __("Delete %d selected articles?");
1141 str
= str
.replace("%d", rows
.length
);
1142 str
= str
.replace("%s", fn
);
1144 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1148 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1152 new Ajax
.Request("backend.php", {
1154 onComplete: function(transport
) {
1159 exception_error("deleteSelection", e
);
1163 function archiveSelection() {
1167 var rows
= getSelectedArticleIds2();
1169 if (rows
.length
== 0) {
1170 alert(__("No articles are selected."));
1174 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1178 if (getActiveFeedId() != 0) {
1179 str
= __("Archive %d selected articles in %s?");
1182 str
= __("Move %d archived articles back?");
1186 str
= str
.replace("%d", rows
.length
);
1187 str
= str
.replace("%s", fn
);
1189 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1193 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1197 for (var i
= 0; i
< rows
.length
; i
++) {
1198 cache_invalidate(rows
[i
]);
1201 new Ajax
.Request("backend.php", {
1203 onComplete: function(transport
) {
1208 exception_error("archiveSelection", e
);
1212 function catchupSelection() {
1216 var rows
= getSelectedArticleIds2();
1218 if (rows
.length
== 0) {
1219 alert(__("No articles are selected."));
1223 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1225 var str
= __("Mark %d selected articles in %s as read?");
1227 str
= str
.replace("%d", rows
.length
);
1228 str
= str
.replace("%s", fn
);
1230 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1234 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1237 exception_error("catchupSelection", e
);
1241 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1242 displayDlg('editArticleTags', id
,
1244 $("tags_str").focus();
1246 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1247 "backend.php?op=rpc&subop=completeTags",
1248 { tokens
: ',', paramName
: "search" });
1252 function editTagsSave() {
1254 notify_progress("Saving article tags...");
1256 var form
= document
.forms
["tag_edit_form"];
1258 var query
= Form
.serialize("tag_edit_form");
1260 query
= "?op=rpc&subop=setArticleTags&" + query
;
1262 //console.log(query);
1264 new Ajax
.Request("backend.php", {
1266 onComplete: function(transport
) {
1268 //console.log("tags saved...");
1273 if (tagsAreDisplayed()) {
1274 _reload_feedlist_after_view
= true;
1277 if (transport
.responseXML
) {
1278 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1281 var id
= tags_str
.getAttribute("id");
1284 var tags
= $("ATSTR-" + id
);
1286 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1289 cache_invalidate(id
);
1295 exception_error("editTagsSave", e
);
1300 function editTagsInsert() {
1303 var form
= document
.forms
["tag_edit_form"];
1305 var found_tags
= form
.found_tags
;
1306 var tags_str
= form
.tags_str
;
1308 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1310 if (tags_str
.value
.length
> 0 &&
1311 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1313 tags_str
.value
= tags_str
.value
+ ", ";
1316 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1318 found_tags
.selectedIndex
= 0;
1321 exception_error("editTagsInsert", e
);
1325 function cdmScrollToArticleId(id
) {
1327 var ctr
= $("headlinesInnerContainer");
1328 var e
= $("RROW-" + id
);
1330 if (!e
|| !ctr
) return;
1332 ctr
.scrollTop
= e
.offsetTop
;
1335 exception_error("cdmScrollToArticleId", e
);
1339 function cdmWatchdog() {
1343 var ctr
= $("headlinesInnerContainer");
1347 var ids
= new Array();
1349 var e
= ctr
.firstChild
;
1352 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1353 e
.id
.match("RROW-")) {
1355 // article fits in viewport OR article is longer than viewport and
1356 // its bottom is visible
1358 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1359 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1361 // console.log(e.id + " is visible " + e.offsetTop + "." +
1362 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1363 // (ctr.scrollTop + ctr.offsetHeight));
1365 ids
.push(e
.id
.replace("RROW-", ""));
1367 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1368 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1369 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1371 ids
.push(e
.id
.replace("RROW-", ""));
1375 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1377 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1378 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1380 ids.push(e.id.replace("RROW-", ""));
1389 console
.log("cdmWatchdog, ids= " + ids
.toString());
1391 if (ids
.length
> 0) {
1393 for (var i
= 0; i
< ids
.length
; i
++) {
1394 var e
= $("RROW-" + ids
[i
]);
1396 e
.className
= e
.className
.replace("Unread", "");
1400 var query
= "?op=rpc&subop=catchupSelected" +
1401 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1403 new Ajax
.Request("backend.php", {
1405 onComplete: function(transport
) {
1406 handle_rpc_reply(transport
);
1411 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1414 exception_error("cdmWatchdog", e
);
1420 function cache_inject(id
, article
, param
) {
1423 if (!cache_check_param(id
, param
)) {
1424 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1426 var date
= new Date();
1427 var ts
= Math
.round(date
.getTime() / 1000);
1431 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1432 [id
, article
, param
, ts
]);
1437 cache_obj
["id"] = id
;
1438 cache_obj
["data"] = article
;
1439 cache_obj
["param"] = param
;
1441 if (param
) id
= id
+ ":" + param
;
1443 cache_added
["TS:" + id
] = ts
;
1445 if (has_local_storage())
1446 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1448 article_cache
.push(cache_obj
);
1452 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1455 exception_error("cache_inject", e
);
1459 function cache_find(id
) {
1462 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1465 if (rs
.isValidRow()) {
1466 var a
= rs
.field(0);
1475 if (has_local_storage()) {
1476 var cache_obj
= localStorage
.getItem(id
);
1479 cache_obj
= JSON
.parse(cache_obj
);
1482 return cache_obj
['data'];
1486 for (var i
= 0; i
< article_cache
.length
; i
++) {
1487 if (article_cache
[i
]["id"] == id
) {
1488 return article_cache
[i
]["data"];
1496 function cache_find_param(id
, param
) {
1499 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1503 if (rs
.isValidRow()) {
1513 if (has_local_storage()) {
1515 if (param
) id
= id
+ ":" + param
;
1517 var cache_obj
= localStorage
.getItem(id
);
1520 cache_obj
= JSON
.parse(cache_obj
);
1523 return cache_obj
['data'];
1527 for (var i
= 0; i
< article_cache
.length
; i
++) {
1528 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1529 return article_cache
[i
]["data"];
1537 function cache_check(id
) {
1540 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1544 if (rs
.isValidRow()) {
1545 a
= rs
.field(0) != "0";
1553 if (has_local_storage()) {
1554 if (localStorage
.getItem(id
))
1557 for (var i
= 0; i
< article_cache
.length
; i
++) {
1558 if (article_cache
[i
]["id"] == id
) {
1567 function cache_check_param(id
, param
) {
1570 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1574 if (rs
.isValidRow()) {
1575 a
= rs
.field(0) != "0";
1584 if (has_local_storage()) {
1586 if (param
) id
= id
+ ":" + param
;
1588 if (localStorage
.getItem(id
))
1592 for (var i
= 0; i
< article_cache
.length
; i
++) {
1593 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1602 function cache_expire() {
1604 var date
= new Date();
1605 var ts
= Math
.round(date
.getTime() / 1000);
1607 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1608 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1609 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1613 if (has_local_storage()) {
1615 var date
= new Date();
1616 var timestamp
= Math
.round(date
.getTime() / 1000);
1618 for (var i
= 0; i
< localStorage
.length
; i
++) {
1620 var id
= localStorage
.key(i
);
1622 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1623 localStorage
.removeItem(id
);
1628 while (article_cache
.length
> 25) {
1629 article_cache
.shift();
1635 function cache_flush() {
1637 db
.execute("DELETE FROM cache");
1638 } else if (has_local_storage()) {
1639 localStorage
.clear();
1641 article_cache
= new Array();
1645 function cache_invalidate(id
) {
1649 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1650 return rs
.rowsAffected
!= 0;
1653 if (has_local_storage()) {
1657 for (var i
= 0; i
< localStorage
.length
; i
++) {
1658 var key
= localStorage
.key(i
);
1660 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1662 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1663 localStorage
.removeItem(key
);
1674 while (i
< article_cache
.length
) {
1675 if (article_cache
[i
]["id"] == id
) {
1676 //console.log("cache_invalidate: removed id " + id);
1677 article_cache
.splice(i
, 1);
1685 //console.log("cache_invalidate: id not found: " + id);
1688 exception_error("cache_invalidate", e
);
1692 function getActiveArticleId() {
1693 return active_post_id
;
1696 function preloadBatchedArticles() {
1699 var query
= "?op=rpc&subop=getArticles&ids=" +
1700 preload_id_batch
.toString();
1702 new Ajax
.Request("backend.php", {
1704 onComplete: function(transport
) {
1706 preload_id_batch
= [];
1708 var articles
= transport
.responseXML
.getElementsByTagName("article");
1710 for (var i
= 0; i
< articles
.length
; i
++) {
1711 var id
= articles
[i
].getAttribute("id");
1712 if (!cache_check(id
)) {
1713 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1714 console
.log("preloaded article: " + id
);
1720 exception_error("preloadBatchedArticles", e
);
1724 function preloadArticleUnderPointer(id
) {
1726 if (getInitParam("bw_limit") == "1") return;
1728 if (post_under_pointer
== id
&& !cache_check(id
)) {
1730 console
.log("trying to preload article " + id
);
1732 var neighbor_ids
= getRelativePostIds(id
, 1);
1734 /* only request uncached articles */
1736 if (preload_id_batch
.indexOf(id
) == -1) {
1737 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1738 if (!cache_check(neighbor_ids
[i
])) {
1739 preload_id_batch
.push(neighbor_ids
[i
]);
1744 if (preload_id_batch
.indexOf(id
) == -1)
1745 preload_id_batch
.push(id
);
1747 //console.log("preload ids batch: " + preload_id_batch.toString());
1749 window
.clearTimeout(preload_timeout_id
);
1750 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1754 exception_error("preloadArticleUnderPointer", e
);
1758 function postMouseIn(id
) {
1760 if (post_under_pointer
!= id
) {
1761 post_under_pointer
= id
;
1763 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1768 exception_error("postMouseIn", e
);
1772 function postMouseOut(id
) {
1774 post_under_pointer
= false;
1776 exception_error("postMouseOut", e
);
1780 function headlines_scroll_handler() {
1783 var e
= $("headlinesInnerContainer");
1785 var toolbar_form
= document
.forms
["main_toolbar_form"];
1787 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1788 // _infscroll_disable);
1790 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1791 if (!_infscroll_disable
) {
1797 exception_error("headlines_scroll_handler", e
);
1801 function catchupRelativeToArticle(below
) {
1806 if (!getActiveArticleId()) {
1807 alert(__("No article is selected."));
1811 var visible_ids
= getVisibleArticleIds();
1813 var ids_to_mark
= new Array();
1816 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1817 if (visible_ids
[i
] != getActiveArticleId()) {
1818 var e
= $("RROW-" + visible_ids
[i
]);
1820 if (e
&& e
.className
.match("Unread")) {
1821 ids_to_mark
.push(visible_ids
[i
]);
1828 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1829 if (visible_ids
[i
] != getActiveArticleId()) {
1830 var e
= $("RROW-" + visible_ids
[i
]);
1832 if (e
&& e
.className
.match("Unread")) {
1833 ids_to_mark
.push(visible_ids
[i
]);
1841 if (ids_to_mark
.length
== 0) {
1842 alert(__("No articles found to mark"));
1844 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1846 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1848 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1849 var e
= $("RROW-" + ids_to_mark
[i
]);
1850 e
.className
= e
.className
.replace("Unread", "");
1853 var query
= "?op=rpc&subop=catchupSelected" +
1854 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1856 new Ajax
.Request("backend.php", {
1858 onComplete: function(transport
) {
1859 catchup_callback2(transport
);
1866 exception_error("catchupRelativeToArticle", e
);
1870 function cdmExpandArticle(id
) {
1875 var elem
= $("CICD-" + active_post_id
);
1877 var upd_img_pic
= $("FUPDPIC-" + id
);
1879 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1880 upd_img_pic
.src
.match("fresh_sign.png"))) {
1882 upd_img_pic
.src
= "images/blank_icon.gif";
1885 if (id
== active_post_id
&& Element
.visible(elem
))
1888 selectArticles("none");
1890 var old_offset
= $("RROW-" + id
).offsetTop
;
1892 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1894 Element
.show("CEXC-" + active_post_id
);
1897 active_post_id
= id
;
1899 elem
= $("CICD-" + id
);
1901 if (!Element
.visible(elem
)) {
1903 Element
.hide("CEXC-" + id
);
1905 if ($("CWRAP-" + id
).innerHTML
== "") {
1907 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1909 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1910 __("Loading, please wait...") + "</div>";
1912 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1914 //console.log(query);
1916 new Ajax
.Request("backend.php", {
1918 onComplete: function(transport
) {
1919 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1921 if (transport
.responseXML
) {
1922 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1923 var recv_id
= article
.getAttribute("id");
1926 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1929 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1937 var new_offset
= $("RROW-" + id
).offsetTop
;
1939 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
1941 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1942 $("headlinesInnerContainer").scrollTop
= new_offset
;
1944 toggleUnread(id
, 0, true);
1948 exception_error("cdmExpandArticle", e
);
1954 function fixHeadlinesOrder(ids
) {
1956 for (var i
= 0; i
< ids
.length
; i
++) {
1957 var e
= $("RROW-" + ids
[i
]);
1961 e
.className
= e
.className
.replace("even", "odd");
1963 e
.className
= e
.className
.replace("odd", "even");
1968 exception_error("fixHeadlinesOrder", e
);
1972 function getArticleUnderPointer() {
1973 return post_under_pointer
;
1976 function zoomToArticle(id
) {
1978 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1980 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1983 exception_error("zoomToArticle", e
);
1987 function scrollArticle(offset
) {
1990 var ci
= $("content-insert");
1992 ci
.scrollTop
+= offset
;
1995 var hi
= $("headlinesInnerContainer");
1997 hi
.scrollTop
+= offset
;
2002 exception_error("scrollArticle", e
);
2006 function show_labels_in_headlines(transport
) {
2008 if (transport
.responseXML
) {
2009 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2011 var elems
= info
.getElementsByTagName("entry");
2013 for (var l
= 0; l
< elems
.length
; l
++) {
2014 var e_id
= elems
[l
].getAttribute("id");
2018 var ctr
= $("HLLCTR-" + e_id
);
2021 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2029 exception_error("show_labels_in_headlines", e
);
2034 function toggleHeadlineActions() {
2036 var e
= $("headlineActionsBody");
2037 var p
= $("headlineActionsDrop");
2039 if (!Element
.visible(e
)) {
2046 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2047 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2050 exception_error("toggleHeadlineActions", e
);
2054 function publishWithNote(id
, def_note
) {
2056 if (!def_note
) def_note
= '';
2058 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2060 if (note
!= undefined) {
2061 togglePub(id
, false, false, note
);
2065 exception_error("publishWithNote", e
);
2069 function emailArticle(id
) {
2072 var ids
= getSelectedArticleIds2();
2074 if (ids
.length
== 0) {
2075 alert(__("No articles are selected."));
2079 id
= ids
.toString();
2082 displayDlg('emailArticle', id
,
2084 document
.forms
['article_email_form'].destination
.focus();
2086 new Ajax
.Autocompleter('destination', 'destination_choices',
2087 "backend.php?op=rpc&subop=completeEmails",
2088 { tokens
: '', paramName
: "search" });
2093 exception_error("emailArticle", e
);
2097 function emailArticleDo() {
2099 var f
= document
.forms
['article_email_form'];
2101 if (f
.destination
.value
== "") {
2102 alert("Please fill in the destination email.");
2106 if (f
.subject
.value
== "") {
2107 alert("Please fill in the subject.");
2111 var query
= Form
.serialize("article_email_form");
2113 // console.log(query);
2115 new Ajax
.Request("backend.php", {
2117 onComplete: function(transport
) {
2120 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2123 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2125 notify_info('Your message has been sent.');
2130 exception_error("sendEmailDo", e
);
2136 exception_error("emailArticleDo", e
);
2140 function dismissArticle(id
) {
2142 var elem
= $("RROW-" + id
);
2144 toggleUnread(id
, 0, true);
2146 new Effect
.Fade(elem
, {duration
: 0.5});
2148 active_post_id
= false;
2151 exception_error("dismissArticle", e
);
2155 function dismissSelectedArticles() {
2158 var ids
= getVisibleArticleIds();
2162 for (var i
= 0; i
< ids
.length
; i
++) {
2163 var elem
= $("RROW-" + ids
[i
]);
2165 if (elem
.className
&& elem
.className
.match("Selected") &&
2166 ids
[i
] != active_post_id
) {
2167 new Effect
.Fade(elem
, {duration
: 0.5});
2175 selectionToggleUnread(false);
2177 fixHeadlinesOrder(tmp
);
2180 exception_error("dismissSelectedArticles", e
);
2184 function dismissReadArticles() {
2187 var ids
= getVisibleArticleIds();
2190 for (var i
= 0; i
< ids
.length
; i
++) {
2191 var elem
= $("RROW-" + ids
[i
]);
2193 if (elem
.className
&& !elem
.className
.match("Unread") &&
2194 !elem
.className
.match("Selected")) {
2196 new Effect
.Fade(elem
, {duration
: 0.5});
2202 fixHeadlinesOrder(tmp
);
2205 exception_error("dismissSelectedArticles", e
);
2209 function getVisibleArticleIds() {
2213 var tmp
= getLoadedArticleIds();
2215 for (var i
= 0; i
< tmp
.length
; i
++) {
2216 var elem
= $("RROW-" + tmp
[i
]);
2217 if (elem
&& Element
.visible(elem
))
2222 exception_error("getVisibleArticleIds", e
);
2228 function cdmClicked(event
, id
) {
2230 var shift_key
= event
.shiftKey
;
2234 if (!event
.ctrlKey
) {
2235 selectArticles("none");
2238 var elem
= $("RROW-" + id
);
2241 elem
.className
= elem
.className
.replace("Unread", "");
2243 var upd_img_pic
= $("FUPDPIC-" + id
);
2245 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2246 upd_img_pic
.src
.match("fresh_sign.png"))) {
2248 upd_img_pic
.src
= "images/blank_icon.gif";
2251 var query
= "?op=rpc&subop=catchupSelected" +
2252 "&cmode=0&ids=" + param_escape(id
);
2254 new Ajax
.Request("backend.php", {
2256 onComplete: function(transport
) {
2257 handle_rpc_reply(transport
);
2266 exception_error("cdmClicked");
2272 function hlClicked(event
, id
) {
2275 if (!event
.ctrlKey
) {
2284 exception_error("hlClicked");
2290 function getFirstVisibleHeadlineId() {
2291 var rows
= getVisibleArticleIds();
2296 function getLastVisibleHeadlineId() {
2297 var rows
= getVisibleArticleIds();
2298 return rows
[rows
.length
-1];
2301 function openArticleInNewWindow(id
) {
2303 console
.log("openArticleInNewWindow: " + id
);
2305 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2306 var wname
= "ttrss_article_" + id
;
2308 console
.log(query
+ " " + wname
);
2310 var w
= window
.open("", wname
);
2312 if (!w
) notify_error("Failed to open window for the article");
2314 new Ajax
.Request("backend.php", {
2316 onComplete: function(transport
) {
2318 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2319 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2321 console
.log("open_article received link: " + link
);
2325 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2327 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2329 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2331 if (!w
) { notify_error("Failed to load article in new window"); }
2334 id
= id
.firstChild
.nodeValue
;
2335 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2338 notify_error("Can't open article: received invalid article link");
2343 exception_error("openArticleInNewWindow", e
);
2347 function isCdmMode() {
2348 return getInitParam("combined_display_mode");
2351 function markHeadline(id
) {
2352 var row
= $("RROW-" + id
);
2354 var is_active
= false;
2356 if (row
.className
.match("Active")) {
2359 row
.className
= row
.className
.replace("Selected", "");
2360 row
.className
= row
.className
.replace("Active", "");
2361 row
.className
= row
.className
.replace("Insensitive", "");
2364 row
.className
= row
.className
= "Active";
2367 var check
= $("RCHK-" + id
);
2370 check
.checked
= true;
2373 row
.className
= row
.className
+ "Selected";
2378 function getRelativePostIds(id
, limit
) {
2384 if (!limit
) limit
= 3;
2386 var ids
= getVisibleArticleIds();
2388 for (var i
= 0; i
< ids
.length
; i
++) {
2390 for (var k
= 1; k
<= limit
; k
++) {
2391 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2392 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2399 exception_error("getRelativePostIds", e
);
2405 function correctHeadlinesOffset(id
) {
2409 var container
= $("headlinesInnerContainer");
2410 var row
= $("RROW-" + id
);
2412 var viewport
= container
.offsetHeight
;
2414 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2415 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2417 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2418 //console.log("Vport: " + viewport);
2420 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2421 container
.scrollTop
= row
.offsetTop
;
2422 } else if (rel_offset_bottom
> viewport
) {
2424 /* doesn't properly work with Opera in some cases because
2425 Opera fucks up element scrolling */
2427 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2431 exception_error("correctHeadlinesOffset", e
);