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 /* 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 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
551 mark_img
.alt
= __("Star article");
554 db
.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id
]);
559 if (!no_effects
) update_local_feedlist_counters();
562 //console.log(query);
564 new Ajax
.Request("backend.php", {
566 onComplete: function(transport
) {
567 handle_rpc_reply(transport
);
573 exception_error("toggleMark", e
);
577 function togglePub(id
, client_only
, no_effects
, note
) {
581 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
583 query
= query
+ "&afid=" + getActiveFeedId();
585 if (note
!= undefined) {
586 query
= query
+ "¬e=" + param_escape(note
);
588 query
= query
+ "¬e=undefined";
591 if (tagsAreDisplayed()) {
592 query
= query
+ "&omode=tl";
594 query
= query
+ "&omode=flc";
597 var mark_img
= $("FPPIC-" + id
);
599 if (!mark_img
) return;
601 var vfeedu
= $("FEEDU--2");
602 var crow
= $("RROW-" + id
);
604 if (mark_img
.src
.match("pub_unset") || note
!= undefined) {
605 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
606 mark_img
.alt
= __("Unpublish article");
607 query
= query
+ "&pub=1";
610 mark_img
.alt
= __("Please wait...");
611 query
= query
+ "&pub=0";
613 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
614 mark_img
.alt
= __("Publish article");
619 new Ajax
.Request("backend.php", {
621 onComplete: function(transport
) {
622 handle_rpc_reply(transport
);
624 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
627 var note_id
= note
.getAttribute("id");
628 var note_size
= note
.getAttribute("size");
629 var note_content
= note
.firstChild
.nodeValue
;
631 var container
= $('POSTNOTE-' + note_id
);
633 cache_invalidate(note_id
);
636 if (note_size
== "0") {
637 Element
.hide(container
);
639 container
.innerHTML
= note_content
;
640 Element
.show(container
);
649 exception_error("togglePub", e
);
653 function moveToPost(mode
) {
657 var rows
= getVisibleArticleIds();
662 if (!$('RROW-' + active_post_id
)) {
663 active_post_id
= false;
666 if (active_post_id
== false) {
667 next_id
= getFirstVisibleHeadlineId();
668 prev_id
= getLastVisibleHeadlineId();
670 for (var i
= 0; i
< rows
.length
; i
++) {
671 if (rows
[i
] == active_post_id
) {
678 if (mode
== "next") {
682 cdmExpandArticle(next_id
);
683 cdmScrollToArticleId(next_id
);
686 correctHeadlinesOffset(next_id
);
687 view(next_id
, getActiveFeedId());
692 if (mode
== "prev") {
695 cdmExpandArticle(prev_id
);
696 cdmScrollToArticleId(prev_id
);
698 correctHeadlinesOffset(prev_id
);
699 view(prev_id
, getActiveFeedId());
705 exception_error("moveToPost", e
);
709 function toggleSelected(id
) {
712 var cb
= $("RCHK-" + id
);
714 var row
= $("RROW-" + id
);
716 var nc
= row
.className
;
718 if (!nc
.match("Selected")) {
719 nc
= nc
+ "Selected";
724 // In CDM basically last selected article == active article
725 if (isCdmMode()) active_post_id
= id
;
727 nc
= nc
.replace("Selected", "");
737 exception_error("toggleSelected", e
);
741 function toggleUnread_afh(effect
) {
744 var elem
= effect
.element
;
745 elem
.style
.backgroundColor
= "";
748 exception_error("toggleUnread_afh", e
);
752 function toggleUnread(id
, cmode
, effect
) {
755 var row
= $("RROW-" + id
);
757 var nc
= row
.className
;
758 var is_selected
= row
.className
.match("Selected");
759 nc
= nc
.replace("Unread", "");
760 nc
= nc
.replace("Selected", "");
762 // since we are removing selection from the object, uncheck
763 // corresponding checkbox
765 var cb
= $("RCHK-" + id
);
770 // NOTE: I'm not sure that resetting selection here is a feature -fox
772 if (cmode
== undefined || cmode
== 2) {
773 if (row
.className
.match("Unread")) {
777 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
778 afterFinish
: toggleUnread_afh
,
779 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
783 row
.className
= nc
+ "Unread";
787 db
.execute("UPDATE articles SET unread = not unread "+
788 "WHERE id = ?", [id
]);
791 } else if (cmode
== 0) {
795 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
796 afterFinish
: toggleUnread_afh
,
797 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
801 db
.execute("UPDATE articles SET unread = 0 "+
802 "WHERE id = ?", [id
]);
805 } else if (cmode
== 1) {
806 row
.className
= nc
+ "Unread";
809 db
.execute("UPDATE articles SET unread = 1 "+
810 "WHERE id = ?", [id
]);
815 update_local_feedlist_counters();
817 // Disable unmarking as selected for the time being (16.05.08) -fox
818 if (is_selected
) row
.className
= row
.className
+ "Selected";
820 if (cmode
== undefined) cmode
= 2;
822 var query
= "?op=rpc&subop=catchupSelected" +
823 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
825 // notify_progress("Loading, please wait...");
827 new Ajax
.Request("backend.php", {
829 onComplete: function(transport
) {
830 handle_rpc_reply(transport
);
836 exception_error("toggleUnread", e
);
840 function selectionRemoveLabel(id
) {
843 var ids
= getSelectedArticleIds2();
845 if (ids
.length
== 0) {
846 alert(__("No articles are selected."));
850 // var ok = confirm(__("Remove selected articles from label?"));
854 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
855 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
859 // notify_progress("Loading, please wait...");
861 cache_invalidate("F:" + (-11 - id
));
863 new Ajax
.Request("backend.php", {
865 onComplete: function(transport
) {
866 show_labels_in_headlines(transport
);
867 handle_rpc_reply(transport
);
873 exception_error("selectionAssignLabel", e
);
878 function selectionAssignLabel(id
) {
881 var ids
= getSelectedArticleIds2();
883 if (ids
.length
== 0) {
884 alert(__("No articles are selected."));
888 // var ok = confirm(__("Assign selected articles to label?"));
892 cache_invalidate("F:" + (-11 - id
));
894 var query
= "?op=rpc&subop=assignToLabel&ids=" +
895 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
899 // notify_progress("Loading, please wait...");
901 new Ajax
.Request("backend.php", {
903 onComplete: function(transport
) {
904 show_labels_in_headlines(transport
);
905 handle_rpc_reply(transport
);
911 exception_error("selectionAssignLabel", e
);
916 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
918 var rows
= getSelectedArticleIds2();
920 if (rows
.length
== 0 && !no_error
) {
921 alert(__("No articles are selected."));
925 for (i
= 0; i
< rows
.length
; i
++) {
926 var row
= $("RROW-" + rows
[i
]);
928 var nc
= row
.className
;
929 nc
= nc
.replace("Unread", "");
930 nc
= nc
.replace("Selected", "");
932 if (set_state
== undefined) {
933 if (row
.className
.match("Unread")) {
934 row
.className
= nc
+ "Selected";
936 row
.className
= nc
+ "UnreadSelected";
939 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
944 if (set_state
== false) {
945 row
.className
= nc
+ "Selected";
947 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
952 if (set_state
== true) {
953 row
.className
= nc
+ "UnreadSelected";
955 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
962 if (rows
.length
> 0) {
964 update_local_feedlist_counters();
968 if (set_state
== undefined) {
970 } else if (set_state
== true) {
972 } else if (set_state
== false) {
976 var query
= "?op=rpc&subop=catchupSelected" +
977 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
979 notify_progress("Loading, please wait...");
981 new Ajax
.Request("backend.php", {
983 onComplete: function(transport
) {
984 catchup_callback2(transport
, callback_func
);
990 exception_error("selectionToggleUnread", e
);
994 function selectionToggleMarked() {
997 var rows
= getSelectedArticleIds2();
999 if (rows
.length
== 0) {
1000 alert(__("No articles are selected."));
1004 for (i
= 0; i
< rows
.length
; i
++) {
1005 toggleMark(rows
[i
], true, true);
1008 update_local_feedlist_counters();
1010 if (rows
.length
> 0) {
1012 var query
= "?op=rpc&subop=markSelected&ids=" +
1013 param_escape(rows
.toString()) + "&cmode=2";
1015 query
= query
+ "&afid=" + getActiveFeedId();
1017 query
= query
+ "&omode=lc";
1019 new Ajax
.Request("backend.php", {
1021 onComplete: function(transport
) {
1022 handle_rpc_reply(transport
);
1028 exception_error("selectionToggleMarked", e
);
1032 function selectionTogglePublished() {
1035 var rows
= getSelectedArticleIds2();
1037 if (rows
.length
== 0) {
1038 alert(__("No articles are selected."));
1042 for (i
= 0; i
< rows
.length
; i
++) {
1043 togglePub(rows
[i
], true, true);
1046 if (rows
.length
> 0) {
1048 var query
= "?op=rpc&subop=publishSelected&ids=" +
1049 param_escape(rows
.toString()) + "&cmode=2";
1051 query
= query
+ "&afid=" + getActiveFeedId();
1053 query
= query
+ "&omode=lc";
1055 new Ajax
.Request("backend.php", {
1057 onComplete: function(transport
) {
1058 handle_rpc_reply(transport
);
1064 exception_error("selectionToggleMarked", e
);
1068 function getSelectedArticleIds2() {
1069 var sel_articles
= new Array();
1073 var children
= $("headlinesInnerContainer").childNodes
;
1075 for (i
= 0; i
< children
.length
; i
++) {
1076 var child
= children
[i
];
1078 if (child
.id
&& child
.id
.match("RROW-") && child
.className
.match("Selected")) {
1079 var c_id
= child
.id
.replace("RROW-", "");
1080 sel_articles
.push(c_id
);
1084 return sel_articles
;
1087 function getLoadedArticleIds() {
1088 var sel_articles
= new Array();
1090 var children
= $("headlinesInnerContainer").childNodes
;
1092 if (!children
) return sel_articles
;
1094 for (i
= 0; i
< children
.length
; i
++) {
1095 var child
= children
[i
];
1097 if (child
.id
&& child
.id
.match("RROW-")) {
1098 var c_id
= child
.id
.replace("RROW-", "");
1099 sel_articles
.push(c_id
);
1103 return sel_articles
;
1106 // mode = all,none,unread,invert
1107 function selectArticles(mode
) {
1112 var children
= $("headlinesInnerContainer").childNodes
;
1114 for (i
= 0; i
< children
.length
; i
++) {
1115 var child
= children
[i
];
1117 if (child
.id
&& child
.id
.match("RROW-")) {
1118 var aid
= child
.id
.replace("RROW-", "");
1120 var cb
= $("RCHK-" + aid
);
1122 if (mode
== "all") {
1123 if (!child
.className
.match("Selected")) {
1124 child
.className
= child
.className
+ "Selected";
1127 } else if (mode
== "unread") {
1128 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
1129 child
.className
= child
.className
+ "Selected";
1132 } else if (mode
== "invert") {
1133 if (child
.className
.match("Selected")) {
1134 child
.className
= child
.className
.replace("Selected", "");
1137 child
.className
= child
.className
+ "Selected";
1142 child
.className
= child
.className
.replace("Selected", "");
1149 exception_error("selectArticles", e
);
1153 function catchupPage() {
1155 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1157 var str
= __("Mark all visible articles in %s as read?");
1159 str
= str
.replace("%s", fn
);
1161 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1165 selectArticles('all');
1166 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1167 selectArticles('none');
1170 function deleteSelection() {
1174 var rows
= getSelectedArticleIds2();
1176 if (rows
.length
== 0) {
1177 alert(__("No articles are selected."));
1181 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1185 if (getActiveFeedId() != 0) {
1186 str
= __("Delete %d selected articles in %s?");
1188 str
= __("Delete %d selected articles?");
1191 str
= str
.replace("%d", rows
.length
);
1192 str
= str
.replace("%s", fn
);
1194 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1198 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1202 new Ajax
.Request("backend.php", {
1204 onComplete: function(transport
) {
1209 exception_error("deleteSelection", e
);
1213 function archiveSelection() {
1217 var rows
= getSelectedArticleIds2();
1219 if (rows
.length
== 0) {
1220 alert(__("No articles are selected."));
1224 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1228 if (getActiveFeedId() != 0) {
1229 str
= __("Archive %d selected articles in %s?");
1232 str
= __("Move %d archived articles back?");
1236 str
= str
.replace("%d", rows
.length
);
1237 str
= str
.replace("%s", fn
);
1239 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1243 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1247 for (var i
= 0; i
< rows
.length
; i
++) {
1248 cache_invalidate(rows
[i
]);
1251 new Ajax
.Request("backend.php", {
1253 onComplete: function(transport
) {
1258 exception_error("archiveSelection", e
);
1262 function catchupSelection() {
1266 var rows
= getSelectedArticleIds2();
1268 if (rows
.length
== 0) {
1269 alert(__("No articles are selected."));
1273 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1275 var str
= __("Mark %d selected articles in %s as read?");
1277 str
= str
.replace("%d", rows
.length
);
1278 str
= str
.replace("%s", fn
);
1280 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1284 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1287 exception_error("catchupSelection", e
);
1291 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1292 displayDlg('editArticleTags', id
,
1294 $("tags_str").focus();
1296 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1297 "backend.php?op=rpc&subop=completeTags",
1298 { tokens
: ',', paramName
: "search" });
1302 function editTagsSave() {
1304 notify_progress("Saving article tags...");
1306 var form
= document
.forms
["tag_edit_form"];
1308 var query
= Form
.serialize("tag_edit_form");
1310 query
= "?op=rpc&subop=setArticleTags&" + query
;
1312 //console.log(query);
1314 new Ajax
.Request("backend.php", {
1316 onComplete: function(transport
) {
1318 //console.log("tags saved...");
1323 if (tagsAreDisplayed()) {
1324 _reload_feedlist_after_view
= true;
1327 if (transport
.responseXML
) {
1328 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1331 var id
= tags_str
.getAttribute("id");
1334 var tags
= $("ATSTR-" + id
);
1336 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1339 cache_invalidate(id
);
1345 exception_error("editTagsSave", e
);
1350 function editTagsInsert() {
1353 var form
= document
.forms
["tag_edit_form"];
1355 var found_tags
= form
.found_tags
;
1356 var tags_str
= form
.tags_str
;
1358 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1360 if (tags_str
.value
.length
> 0 &&
1361 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1363 tags_str
.value
= tags_str
.value
+ ", ";
1366 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1368 found_tags
.selectedIndex
= 0;
1371 exception_error("editTagsInsert", e
);
1375 function cdmScrollToArticleId(id
) {
1377 var ctr
= $("headlinesInnerContainer");
1378 var e
= $("RROW-" + id
);
1380 if (!e
|| !ctr
) return;
1382 ctr
.scrollTop
= e
.offsetTop
;
1385 exception_error("cdmScrollToArticleId", e
);
1389 function cdmWatchdog() {
1393 var ctr
= $("headlinesInnerContainer");
1397 var ids
= new Array();
1399 var e
= ctr
.firstChild
;
1402 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1403 e
.id
.match("RROW-")) {
1405 // article fits in viewport OR article is longer than viewport and
1406 // its bottom is visible
1408 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1409 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1411 // console.log(e.id + " is visible " + e.offsetTop + "." +
1412 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1413 // (ctr.scrollTop + ctr.offsetHeight));
1415 ids
.push(e
.id
.replace("RROW-", ""));
1417 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1418 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1419 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1421 ids
.push(e
.id
.replace("RROW-", ""));
1425 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1427 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1428 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1430 ids.push(e.id.replace("RROW-", ""));
1439 console
.log("cdmWatchdog, ids= " + ids
.toString());
1441 if (ids
.length
> 0) {
1443 for (var i
= 0; i
< ids
.length
; i
++) {
1444 var e
= $("RROW-" + ids
[i
]);
1446 e
.className
= e
.className
.replace("Unread", "");
1450 var query
= "?op=rpc&subop=catchupSelected" +
1451 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1453 new Ajax
.Request("backend.php", {
1455 onComplete: function(transport
) {
1456 handle_rpc_reply(transport
);
1461 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1464 exception_error("cdmWatchdog", e
);
1470 function cache_inject(id
, article
, param
) {
1473 if (!cache_check_param(id
, param
)) {
1474 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1476 var date
= new Date();
1477 var ts
= Math
.round(date
.getTime() / 1000);
1481 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1482 [id
, article
, param
, ts
]);
1487 cache_obj
["id"] = id
;
1488 cache_obj
["data"] = article
;
1489 cache_obj
["param"] = param
;
1491 if (param
) id
= id
+ ":" + param
;
1493 cache_added
["TS:" + id
] = ts
;
1495 if (has_local_storage())
1496 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1498 article_cache
.push(cache_obj
);
1502 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1505 exception_error("cache_inject", e
);
1509 function cache_find(id
) {
1512 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1515 if (rs
.isValidRow()) {
1516 var a
= rs
.field(0);
1525 if (has_local_storage()) {
1526 var cache_obj
= localStorage
.getItem(id
);
1529 cache_obj
= JSON
.parse(cache_obj
);
1532 return cache_obj
['data'];
1536 for (var i
= 0; i
< article_cache
.length
; i
++) {
1537 if (article_cache
[i
]["id"] == id
) {
1538 return article_cache
[i
]["data"];
1546 function cache_find_param(id
, param
) {
1549 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1553 if (rs
.isValidRow()) {
1563 if (has_local_storage()) {
1565 if (param
) id
= id
+ ":" + param
;
1567 var cache_obj
= localStorage
.getItem(id
);
1570 cache_obj
= JSON
.parse(cache_obj
);
1573 return cache_obj
['data'];
1577 for (var i
= 0; i
< article_cache
.length
; i
++) {
1578 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1579 return article_cache
[i
]["data"];
1587 function cache_check(id
) {
1590 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1594 if (rs
.isValidRow()) {
1595 a
= rs
.field(0) != "0";
1603 if (has_local_storage()) {
1604 if (localStorage
.getItem(id
))
1607 for (var i
= 0; i
< article_cache
.length
; i
++) {
1608 if (article_cache
[i
]["id"] == id
) {
1617 function cache_check_param(id
, param
) {
1620 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1624 if (rs
.isValidRow()) {
1625 a
= rs
.field(0) != "0";
1634 if (has_local_storage()) {
1636 if (param
) id
= id
+ ":" + param
;
1638 if (localStorage
.getItem(id
))
1642 for (var i
= 0; i
< article_cache
.length
; i
++) {
1643 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1652 function cache_expire() {
1654 var date
= new Date();
1655 var ts
= Math
.round(date
.getTime() / 1000);
1657 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1658 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1659 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1663 if (has_local_storage()) {
1665 var date
= new Date();
1666 var timestamp
= Math
.round(date
.getTime() / 1000);
1668 for (var i
= 0; i
< localStorage
.length
; i
++) {
1670 var id
= localStorage
.key(i
);
1672 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1673 localStorage
.removeItem(id
);
1678 while (article_cache
.length
> 25) {
1679 article_cache
.shift();
1685 function cache_flush() {
1687 db
.execute("DELETE FROM cache");
1688 } else if (has_local_storage()) {
1689 localStorage
.clear();
1691 article_cache
= new Array();
1695 function cache_invalidate(id
) {
1699 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1700 return rs
.rowsAffected
!= 0;
1703 if (has_local_storage()) {
1707 for (var i
= 0; i
< localStorage
.length
; i
++) {
1708 var key
= localStorage
.key(i
);
1710 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1712 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1713 localStorage
.removeItem(key
);
1724 while (i
< article_cache
.length
) {
1725 if (article_cache
[i
]["id"] == id
) {
1726 //console.log("cache_invalidate: removed id " + id);
1727 article_cache
.splice(i
, 1);
1735 //console.log("cache_invalidate: id not found: " + id);
1738 exception_error("cache_invalidate", e
);
1742 function getActiveArticleId() {
1743 return active_post_id
;
1746 function preloadBatchedArticles() {
1749 var query
= "?op=rpc&subop=getArticles&ids=" +
1750 preload_id_batch
.toString();
1752 new Ajax
.Request("backend.php", {
1754 onComplete: function(transport
) {
1756 preload_id_batch
= [];
1758 var articles
= transport
.responseXML
.getElementsByTagName("article");
1760 for (var i
= 0; i
< articles
.length
; i
++) {
1761 var id
= articles
[i
].getAttribute("id");
1762 if (!cache_check(id
)) {
1763 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1764 console
.log("preloaded article: " + id
);
1770 exception_error("preloadBatchedArticles", e
);
1774 function preloadArticleUnderPointer(id
) {
1776 if (getInitParam("bw_limit") == "1") return;
1778 if (post_under_pointer
== id
&& !cache_check(id
)) {
1780 console
.log("trying to preload article " + id
);
1782 var neighbor_ids
= getRelativePostIds(id
, 1);
1784 /* only request uncached articles */
1786 if (preload_id_batch
.indexOf(id
) == -1) {
1787 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1788 if (!cache_check(neighbor_ids
[i
])) {
1789 preload_id_batch
.push(neighbor_ids
[i
]);
1794 if (preload_id_batch
.indexOf(id
) == -1)
1795 preload_id_batch
.push(id
);
1797 //console.log("preload ids batch: " + preload_id_batch.toString());
1799 window
.clearTimeout(preload_timeout_id
);
1800 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1804 exception_error("preloadArticleUnderPointer", e
);
1808 function postMouseIn(id
) {
1810 if (post_under_pointer
!= id
) {
1811 post_under_pointer
= id
;
1813 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1818 exception_error("postMouseIn", e
);
1822 function postMouseOut(id
) {
1824 post_under_pointer
= false;
1826 exception_error("postMouseOut", e
);
1830 function headlines_scroll_handler() {
1833 var e
= $("headlinesInnerContainer");
1835 var toolbar_form
= document
.forms
["main_toolbar_form"];
1837 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1838 // _infscroll_disable);
1840 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1841 if (!_infscroll_disable
) {
1847 exception_error("headlines_scroll_handler", e
);
1851 function catchupRelativeToArticle(below
) {
1856 if (!getActiveArticleId()) {
1857 alert(__("No article is selected."));
1861 var visible_ids
= getVisibleArticleIds();
1863 var ids_to_mark
= new Array();
1866 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1867 if (visible_ids
[i
] != getActiveArticleId()) {
1868 var e
= $("RROW-" + visible_ids
[i
]);
1870 if (e
&& e
.className
.match("Unread")) {
1871 ids_to_mark
.push(visible_ids
[i
]);
1878 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1879 if (visible_ids
[i
] != getActiveArticleId()) {
1880 var e
= $("RROW-" + visible_ids
[i
]);
1882 if (e
&& e
.className
.match("Unread")) {
1883 ids_to_mark
.push(visible_ids
[i
]);
1891 if (ids_to_mark
.length
== 0) {
1892 alert(__("No articles found to mark"));
1894 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1896 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1898 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1899 var e
= $("RROW-" + ids_to_mark
[i
]);
1900 e
.className
= e
.className
.replace("Unread", "");
1903 var query
= "?op=rpc&subop=catchupSelected" +
1904 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1906 new Ajax
.Request("backend.php", {
1908 onComplete: function(transport
) {
1909 catchup_callback2(transport
);
1916 exception_error("catchupRelativeToArticle", e
);
1920 function cdmExpandArticle(id
) {
1925 var elem
= $("CICD-" + active_post_id
);
1927 var upd_img_pic
= $("FUPDPIC-" + id
);
1929 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1930 upd_img_pic
.src
.match("fresh_sign.png"))) {
1932 upd_img_pic
.src
= "images/blank_icon.gif";
1935 if (id
== active_post_id
&& Element
.visible(elem
))
1938 selectArticles("none");
1940 var old_offset
= $("RROW-" + id
).offsetTop
;
1942 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1944 Element
.show("CEXC-" + active_post_id
);
1947 active_post_id
= id
;
1949 elem
= $("CICD-" + id
);
1951 if (!Element
.visible(elem
)) {
1953 Element
.hide("CEXC-" + id
);
1955 if ($("CWRAP-" + id
).innerHTML
== "") {
1957 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1959 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1960 __("Loading, please wait...") + "</div>";
1962 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1964 //console.log(query);
1966 new Ajax
.Request("backend.php", {
1968 onComplete: function(transport
) {
1969 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1971 if (transport
.responseXML
) {
1972 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1973 var recv_id
= article
.getAttribute("id");
1976 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1979 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1987 var new_offset
= $("RROW-" + id
).offsetTop
;
1989 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
1991 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1992 $("headlinesInnerContainer").scrollTop
= new_offset
;
1994 toggleUnread(id
, 0, true);
1998 exception_error("cdmExpandArticle", e
);
2004 function fixHeadlinesOrder(ids
) {
2006 for (var i
= 0; i
< ids
.length
; i
++) {
2007 var e
= $("RROW-" + ids
[i
]);
2011 e
.className
= e
.className
.replace("even", "odd");
2013 e
.className
= e
.className
.replace("odd", "even");
2018 exception_error("fixHeadlinesOrder", e
);
2022 function getArticleUnderPointer() {
2023 return post_under_pointer
;
2026 function zoomToArticle(id
) {
2028 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
2030 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2033 exception_error("zoomToArticle", e
);
2037 function scrollArticle(offset
) {
2040 var ci
= $("content-insert");
2042 ci
.scrollTop
+= offset
;
2045 var hi
= $("headlinesInnerContainer");
2047 hi
.scrollTop
+= offset
;
2052 exception_error("scrollArticle", e
);
2056 function show_labels_in_headlines(transport
) {
2058 if (transport
.responseXML
) {
2059 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
2061 var elems
= info
.getElementsByTagName("entry");
2063 for (var l
= 0; l
< elems
.length
; l
++) {
2064 var e_id
= elems
[l
].getAttribute("id");
2068 var ctr
= $("HLLCTR-" + e_id
);
2071 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
2079 exception_error("show_labels_in_headlines", e
);
2084 function toggleHeadlineActions() {
2086 var e
= $("headlineActionsBody");
2087 var p
= $("headlineActionsDrop");
2089 if (!Element
.visible(e
)) {
2096 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
2097 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2100 exception_error("toggleHeadlineActions", e
);
2104 function publishWithNote(id
, def_note
) {
2106 if (!def_note
) def_note
= '';
2108 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2110 if (note
!= undefined) {
2111 togglePub(id
, false, false, note
);
2115 exception_error("publishWithNote", e
);
2119 function emailArticle(id
) {
2122 var ids
= getSelectedArticleIds2();
2124 if (ids
.length
== 0) {
2125 alert(__("No articles are selected."));
2129 id
= ids
.toString();
2132 displayDlg('emailArticle', id
,
2134 document
.forms
['article_email_form'].destination
.focus();
2136 new Ajax
.Autocompleter('destination', 'destination_choices',
2137 "backend.php?op=rpc&subop=completeEmails",
2138 { tokens
: '', paramName
: "search" });
2143 exception_error("emailArticle", e
);
2147 function emailArticleDo() {
2149 var f
= document
.forms
['article_email_form'];
2151 if (f
.destination
.value
== "") {
2152 alert("Please fill in the destination email.");
2156 if (f
.subject
.value
== "") {
2157 alert("Please fill in the subject.");
2161 var query
= Form
.serialize("article_email_form");
2163 // console.log(query);
2165 new Ajax
.Request("backend.php", {
2167 onComplete: function(transport
) {
2170 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2173 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2175 notify_info('Your message has been sent.');
2180 exception_error("sendEmailDo", e
);
2186 exception_error("emailArticleDo", e
);
2190 function dismissArticle(id
) {
2192 var elem
= $("RROW-" + id
);
2194 toggleUnread(id
, 0, true);
2196 new Effect
.Fade(elem
, {duration
: 0.5});
2198 active_post_id
= false;
2201 exception_error("dismissArticle", e
);
2205 function dismissSelectedArticles() {
2208 var ids
= getVisibleArticleIds();
2212 for (var i
= 0; i
< ids
.length
; i
++) {
2213 var elem
= $("RROW-" + ids
[i
]);
2215 if (elem
.className
&& elem
.className
.match("Selected") &&
2216 ids
[i
] != active_post_id
) {
2217 new Effect
.Fade(elem
, {duration
: 0.5});
2225 selectionToggleUnread(false);
2227 fixHeadlinesOrder(tmp
);
2230 exception_error("dismissSelectedArticles", e
);
2234 function dismissReadArticles() {
2237 var ids
= getVisibleArticleIds();
2240 for (var i
= 0; i
< ids
.length
; i
++) {
2241 var elem
= $("RROW-" + ids
[i
]);
2243 if (elem
.className
&& !elem
.className
.match("Unread") &&
2244 !elem
.className
.match("Selected")) {
2246 new Effect
.Fade(elem
, {duration
: 0.5});
2252 fixHeadlinesOrder(tmp
);
2255 exception_error("dismissSelectedArticles", e
);
2259 function getVisibleArticleIds() {
2263 var tmp
= getLoadedArticleIds();
2265 for (var i
= 0; i
< tmp
.length
; i
++) {
2266 var elem
= $("RROW-" + tmp
[i
]);
2267 if (elem
&& Element
.visible(elem
))
2272 exception_error("getVisibleArticleIds", e
);
2278 function cdmClicked(event
, id
) {
2280 var shift_key
= event
.shiftKey
;
2284 if (!event
.ctrlKey
) {
2285 selectArticles("none");
2288 var elem
= $("RROW-" + id
);
2291 elem
.className
= elem
.className
.replace("Unread", "");
2293 var upd_img_pic
= $("FUPDPIC-" + id
);
2295 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2296 upd_img_pic
.src
.match("fresh_sign.png"))) {
2298 upd_img_pic
.src
= "images/blank_icon.gif";
2301 var query
= "?op=rpc&subop=catchupSelected" +
2302 "&cmode=0&ids=" + param_escape(id
);
2304 new Ajax
.Request("backend.php", {
2306 onComplete: function(transport
) {
2307 handle_rpc_reply(transport
);
2316 exception_error("cdmClicked");
2322 function hlClicked(event
, id
) {
2325 if (!event
.ctrlKey
) {
2334 exception_error("hlClicked");
2340 function getFirstVisibleHeadlineId() {
2341 var rows
= getVisibleArticleIds();
2346 function getLastVisibleHeadlineId() {
2347 var rows
= getVisibleArticleIds();
2348 return rows
[rows
.length
-1];
2351 function openArticleInNewWindow(id
) {
2353 console
.log("openArticleInNewWindow: " + id
);
2355 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2356 var wname
= "ttrss_article_" + id
;
2358 console
.log(query
+ " " + wname
);
2360 var w
= window
.open("", wname
);
2362 if (!w
) notify_error("Failed to open window for the article");
2364 new Ajax
.Request("backend.php", {
2366 onComplete: function(transport
) {
2368 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2369 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2371 console
.log("open_article received link: " + link
);
2375 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2377 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2379 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2381 if (!w
) { notify_error("Failed to load article in new window"); }
2384 id
= id
.firstChild
.nodeValue
;
2385 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2388 notify_error("Can't open article: received invalid article link");
2393 exception_error("openArticleInNewWindow", e
);
2397 function isCdmMode() {
2398 return getInitParam("combined_display_mode");
2401 function markHeadline(id
) {
2402 var row
= $("RROW-" + id
);
2404 var is_active
= false;
2406 if (row
.className
.match("Active")) {
2409 row
.className
= row
.className
.replace("Selected", "");
2410 row
.className
= row
.className
.replace("Active", "");
2411 row
.className
= row
.className
.replace("Insensitive", "");
2414 row
.className
= row
.className
= "Active";
2417 var check
= $("RCHK-" + id
);
2420 check
.checked
= true;
2423 row
.className
= row
.className
+ "Selected";
2428 function getRelativePostIds(id
, limit
) {
2434 if (!limit
) limit
= 3;
2436 var ids
= getVisibleArticleIds();
2438 for (var i
= 0; i
< ids
.length
; i
++) {
2440 for (var k
= 1; k
<= limit
; k
++) {
2441 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2442 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2449 exception_error("getRelativePostIds", e
);
2455 function correctHeadlinesOffset(id
) {
2459 var container
= $("headlinesInnerContainer");
2460 var row
= $("RROW-" + id
);
2462 var viewport
= container
.offsetHeight
;
2464 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2465 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2467 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2468 //console.log("Vport: " + viewport);
2470 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2471 container
.scrollTop
= row
.offsetTop
;
2472 } else if (rel_offset_bottom
> viewport
) {
2474 /* doesn't properly work with Opera in some cases because
2475 Opera fucks up element scrolling */
2477 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2481 exception_error("correctHeadlinesOffset", e
);