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
);
73 feedr
.addClassName("Selected");
76 var feedr
= $("FCAT-" + feed_id
);
78 feedr
.addClassName("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 (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
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
.hasClassName("Unread");
259 crow
.removeClassName("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
.hasClassName("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
);
671 var row
= $("RROW-" + id
);
674 if (row
.hasClassName('Selected')) {
675 row
.removeClassName('Selected');
676 if (cb
) cb
.checked
= false;
678 row
.addClassName('Selected');
679 if (cb
) cb
.checked
= true;
683 exception_error("toggleSelected", e
);
687 function toggleUnread_afh(effect
) {
690 var elem
= effect
.element
;
691 elem
.style
.backgroundColor
= "";
694 exception_error("toggleUnread_afh", e
);
698 function toggleUnread(id
, cmode
, effect
) {
701 var row
= $("RROW-" + id
);
703 if (cmode
== undefined || cmode
== 2) {
704 if (row
.hasClassName("Unread")) {
705 row
.removeClassName("Unread");
708 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
709 afterFinish
: toggleUnread_afh
,
710 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
714 row
.addClassName("Unread");
718 db
.execute("UPDATE articles SET unread = not unread "+
719 "WHERE id = ?", [id
]);
722 } else if (cmode
== 0) {
724 row
.removeClassName("Unread");
727 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
728 afterFinish
: toggleUnread_afh
,
729 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
733 db
.execute("UPDATE articles SET unread = 0 "+
734 "WHERE id = ?", [id
]);
737 } else if (cmode
== 1) {
738 row
.addClassName("Unread");
741 db
.execute("UPDATE articles SET unread = 1 "+
742 "WHERE id = ?", [id
]);
747 update_local_feedlist_counters();
749 if (cmode
== undefined) cmode
= 2;
751 var query
= "?op=rpc&subop=catchupSelected" +
752 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
754 // notify_progress("Loading, please wait...");
756 new Ajax
.Request("backend.php", {
758 onComplete: function(transport
) {
759 handle_rpc_reply(transport
);
765 exception_error("toggleUnread", e
);
769 function selectionRemoveLabel(id
) {
772 var ids
= getSelectedArticleIds2();
774 if (ids
.length
== 0) {
775 alert(__("No articles are selected."));
779 // var ok = confirm(__("Remove selected articles from label?"));
783 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
784 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
788 // notify_progress("Loading, please wait...");
790 cache_invalidate("F:" + (-11 - id
));
792 new Ajax
.Request("backend.php", {
794 onComplete: function(transport
) {
795 show_labels_in_headlines(transport
);
796 handle_rpc_reply(transport
);
802 exception_error("selectionAssignLabel", e
);
807 function selectionAssignLabel(id
) {
810 var ids
= getSelectedArticleIds2();
812 if (ids
.length
== 0) {
813 alert(__("No articles are selected."));
817 // var ok = confirm(__("Assign selected articles to label?"));
821 cache_invalidate("F:" + (-11 - id
));
823 var query
= "?op=rpc&subop=assignToLabel&ids=" +
824 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
828 // notify_progress("Loading, please wait...");
830 new Ajax
.Request("backend.php", {
832 onComplete: function(transport
) {
833 show_labels_in_headlines(transport
);
834 handle_rpc_reply(transport
);
840 exception_error("selectionAssignLabel", e
);
845 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
847 var rows
= getSelectedArticleIds2();
849 if (rows
.length
== 0 && !no_error
) {
850 alert(__("No articles are selected."));
854 for (i
= 0; i
< rows
.length
; i
++) {
855 var row
= $("RROW-" + rows
[i
]);
857 if (set_state
== undefined) {
858 if (row
.hasClassName("Unread")) {
859 row
.removeClassName("Unread");
861 row
.addClassName("Unread");
864 db
.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
869 if (set_state
== false) {
870 row
.removeClassName("Unread");
873 db
.execute("UPDATE articles SET unread = 0 WHERE id = ?",
878 if (set_state
== true) {
879 row
.addClassName("Unread");
882 db
.execute("UPDATE articles SET unread = 1 WHERE id = ?",
889 if (rows
.length
> 0) {
891 update_local_feedlist_counters();
895 if (set_state
== undefined) {
897 } else if (set_state
== true) {
899 } else if (set_state
== false) {
903 var query
= "?op=rpc&subop=catchupSelected" +
904 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
906 notify_progress("Loading, please wait...");
908 new Ajax
.Request("backend.php", {
910 onComplete: function(transport
) {
911 catchup_callback2(transport
, callback_func
);
917 exception_error("selectionToggleUnread", e
);
921 function selectionToggleMarked() {
924 var rows
= getSelectedArticleIds2();
926 if (rows
.length
== 0) {
927 alert(__("No articles are selected."));
931 for (i
= 0; i
< rows
.length
; i
++) {
932 toggleMark(rows
[i
], true, true);
935 update_local_feedlist_counters();
937 if (rows
.length
> 0) {
939 var query
= "?op=rpc&subop=markSelected&ids=" +
940 param_escape(rows
.toString()) + "&cmode=2";
942 new Ajax
.Request("backend.php", {
944 onComplete: function(transport
) {
945 handle_rpc_reply(transport
);
951 exception_error("selectionToggleMarked", e
);
955 function selectionTogglePublished() {
958 var rows
= getSelectedArticleIds2();
960 if (rows
.length
== 0) {
961 alert(__("No articles are selected."));
965 for (i
= 0; i
< rows
.length
; i
++) {
966 togglePub(rows
[i
], true, true);
969 if (rows
.length
> 0) {
971 var query
= "?op=rpc&subop=publishSelected&ids=" +
972 param_escape(rows
.toString()) + "&cmode=2";
974 new Ajax
.Request("backend.php", {
976 onComplete: function(transport
) {
977 handle_rpc_reply(transport
);
983 exception_error("selectionToggleMarked", e
);
987 function getSelectedArticleIds2() {
991 $$("#headlinesInnerContainer > div[id*=RROW][class*=Selected]").each(
993 rv
.push(child
.id
.replace("RROW-", ""));
999 function getLoadedArticleIds() {
1002 var children
= $$("#headlinesInnerContainer > div[id*=RROW-]");
1004 children
.each(function(child
) {
1005 rv
.push(child
.id
.replace("RROW-", ""));
1012 // mode = all,none,unread,invert
1013 function selectArticles(mode
) {
1016 var children
= $$("#headlinesInnerContainer > div[id*=RROW]");
1018 children
.each(function(child
) {
1019 var id
= child
.id
.replace("RROW-", "");
1020 var cb
= $("RCHK-" + id
);
1022 if (mode
== "all") {
1023 child
.addClassName("Selected");
1025 } else if (mode
== "unread") {
1026 if (child
.hasClassName("Unread")) {
1027 child
.addClassName("Selected");
1030 child
.removeClassName("Selected");
1033 } else if (mode
== "invert") {
1034 if (child
.hasClassName("Selected")) {
1035 child
.removeClassName("Selected");
1038 child
.addClassName("Selected");
1043 child
.removeClassName("Selected");
1049 exception_error("selectArticles", e
);
1053 function catchupPage() {
1055 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1057 var str
= __("Mark all visible articles in %s as read?");
1059 str
= str
.replace("%s", fn
);
1061 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1065 selectArticles('all');
1066 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1067 selectArticles('none');
1070 function deleteSelection() {
1074 var rows
= getSelectedArticleIds2();
1076 if (rows
.length
== 0) {
1077 alert(__("No articles are selected."));
1081 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1085 if (getActiveFeedId() != 0) {
1086 str
= __("Delete %d selected articles in %s?");
1088 str
= __("Delete %d selected articles?");
1091 str
= str
.replace("%d", rows
.length
);
1092 str
= str
.replace("%s", fn
);
1094 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1098 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1102 new Ajax
.Request("backend.php", {
1104 onComplete: function(transport
) {
1109 exception_error("deleteSelection", e
);
1113 function archiveSelection() {
1117 var rows
= getSelectedArticleIds2();
1119 if (rows
.length
== 0) {
1120 alert(__("No articles are selected."));
1124 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1128 if (getActiveFeedId() != 0) {
1129 str
= __("Archive %d selected articles in %s?");
1132 str
= __("Move %d archived articles back?");
1136 str
= str
.replace("%d", rows
.length
);
1137 str
= str
.replace("%s", fn
);
1139 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1143 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1147 for (var i
= 0; i
< rows
.length
; i
++) {
1148 cache_invalidate(rows
[i
]);
1151 new Ajax
.Request("backend.php", {
1153 onComplete: function(transport
) {
1158 exception_error("archiveSelection", e
);
1162 function catchupSelection() {
1166 var rows
= getSelectedArticleIds2();
1168 if (rows
.length
== 0) {
1169 alert(__("No articles are selected."));
1173 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1175 var str
= __("Mark %d selected articles in %s as read?");
1177 str
= str
.replace("%d", rows
.length
);
1178 str
= str
.replace("%s", fn
);
1180 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1184 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1187 exception_error("catchupSelection", e
);
1191 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1192 displayDlg('editArticleTags', id
,
1194 $("tags_str").focus();
1196 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1197 "backend.php?op=rpc&subop=completeTags",
1198 { tokens
: ',', paramName
: "search" });
1202 function editTagsSave() {
1204 notify_progress("Saving article tags...");
1206 var form
= document
.forms
["tag_edit_form"];
1208 var query
= Form
.serialize("tag_edit_form");
1210 query
= "?op=rpc&subop=setArticleTags&" + query
;
1212 //console.log(query);
1214 new Ajax
.Request("backend.php", {
1216 onComplete: function(transport
) {
1218 //console.log("tags saved...");
1223 if (tagsAreDisplayed()) {
1224 _reload_feedlist_after_view
= true;
1227 if (transport
.responseXML
) {
1228 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1231 var id
= tags_str
.getAttribute("id");
1234 var tags
= $("ATSTR-" + id
);
1236 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1239 cache_invalidate(id
);
1245 exception_error("editTagsSave", e
);
1250 function editTagsInsert() {
1253 var form
= document
.forms
["tag_edit_form"];
1255 var found_tags
= form
.found_tags
;
1256 var tags_str
= form
.tags_str
;
1258 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1260 if (tags_str
.value
.length
> 0 &&
1261 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1263 tags_str
.value
= tags_str
.value
+ ", ";
1266 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1268 found_tags
.selectedIndex
= 0;
1271 exception_error("editTagsInsert", e
);
1275 function cdmScrollToArticleId(id
) {
1277 var ctr
= $("headlinesInnerContainer");
1278 var e
= $("RROW-" + id
);
1280 if (!e
|| !ctr
) return;
1282 ctr
.scrollTop
= e
.offsetTop
;
1285 exception_error("cdmScrollToArticleId", e
);
1289 function cdmWatchdog() {
1293 var ctr
= $("headlinesInnerContainer");
1297 var ids
= new Array();
1299 var e
= ctr
.firstChild
;
1302 if (e
.className
&& e
.hasClassName("Unread") && e
.id
&&
1303 e
.id
.match("RROW-")) {
1305 // article fits in viewport OR article is longer than viewport and
1306 // its bottom is visible
1308 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1309 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1311 // console.log(e.id + " is visible " + e.offsetTop + "." +
1312 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1313 // (ctr.scrollTop + ctr.offsetHeight));
1315 ids
.push(e
.id
.replace("RROW-", ""));
1317 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1318 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1319 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1321 ids
.push(e
.id
.replace("RROW-", ""));
1325 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1327 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1328 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1330 ids.push(e.id.replace("RROW-", ""));
1339 console
.log("cdmWatchdog, ids= " + ids
.toString());
1341 if (ids
.length
> 0) {
1343 for (var i
= 0; i
< ids
.length
; i
++) {
1344 var e
= $("RROW-" + ids
[i
]);
1346 e
.removeClassName("Unread");
1350 var query
= "?op=rpc&subop=catchupSelected" +
1351 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1353 new Ajax
.Request("backend.php", {
1355 onComplete: function(transport
) {
1356 handle_rpc_reply(transport
);
1361 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1364 exception_error("cdmWatchdog", e
);
1370 function cache_inject(id
, article
, param
) {
1373 if (!cache_check_param(id
, param
)) {
1374 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1376 var date
= new Date();
1377 var ts
= Math
.round(date
.getTime() / 1000);
1381 db
.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1382 [id
, article
, param
, ts
]);
1387 cache_obj
["id"] = id
;
1388 cache_obj
["data"] = article
;
1389 cache_obj
["param"] = param
;
1391 if (param
) id
= id
+ ":" + param
;
1393 cache_added
["TS:" + id
] = ts
;
1395 if (has_local_storage())
1396 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1398 article_cache
.push(cache_obj
);
1402 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1405 exception_error("cache_inject", e
);
1409 function cache_find(id
) {
1412 var rs
= db
.execute("SELECT article FROM cache WHERE id = ?", [id
]);
1415 if (rs
.isValidRow()) {
1416 var a
= rs
.field(0);
1425 if (has_local_storage()) {
1426 var cache_obj
= localStorage
.getItem(id
);
1429 cache_obj
= JSON
.parse(cache_obj
);
1432 return cache_obj
['data'];
1436 for (var i
= 0; i
< article_cache
.length
; i
++) {
1437 if (article_cache
[i
]["id"] == id
) {
1438 return article_cache
[i
]["data"];
1446 function cache_find_param(id
, param
) {
1449 var rs
= db
.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1453 if (rs
.isValidRow()) {
1463 if (has_local_storage()) {
1465 if (param
) id
= id
+ ":" + param
;
1467 var cache_obj
= localStorage
.getItem(id
);
1470 cache_obj
= JSON
.parse(cache_obj
);
1473 return cache_obj
['data'];
1477 for (var i
= 0; i
< article_cache
.length
; i
++) {
1478 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1479 return article_cache
[i
]["data"];
1487 function cache_check(id
) {
1490 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1494 if (rs
.isValidRow()) {
1495 a
= rs
.field(0) != "0";
1503 if (has_local_storage()) {
1504 if (localStorage
.getItem(id
))
1507 for (var i
= 0; i
< article_cache
.length
; i
++) {
1508 if (article_cache
[i
]["id"] == id
) {
1517 function cache_check_param(id
, param
) {
1520 var rs
= db
.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1524 if (rs
.isValidRow()) {
1525 a
= rs
.field(0) != "0";
1534 if (has_local_storage()) {
1536 if (param
) id
= id
+ ":" + param
;
1538 if (localStorage
.getItem(id
))
1542 for (var i
= 0; i
< article_cache
.length
; i
++) {
1543 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1552 function cache_expire() {
1554 var date
= new Date();
1555 var ts
= Math
.round(date
.getTime() / 1000);
1557 db
.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts
]);
1558 db
.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts
]);
1559 db
.execute("DELETE FROM cache WHERE added < ? - 86400", [ts
]);
1563 if (has_local_storage()) {
1565 var date
= new Date();
1566 var timestamp
= Math
.round(date
.getTime() / 1000);
1568 for (var i
= 0; i
< localStorage
.length
; i
++) {
1570 var id
= localStorage
.key(i
);
1572 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1573 localStorage
.removeItem(id
);
1578 while (article_cache
.length
> 25) {
1579 article_cache
.shift();
1585 function cache_flush() {
1587 db
.execute("DELETE FROM cache");
1588 } else if (has_local_storage()) {
1589 localStorage
.clear();
1591 article_cache
= new Array();
1595 function cache_invalidate(id
) {
1599 rs
= db
.execute("DELETE FROM cache WHERE id = ?", [id
]);
1600 return rs
.rowsAffected
!= 0;
1603 if (has_local_storage()) {
1607 for (var i
= 0; i
< localStorage
.length
; i
++) {
1608 var key
= localStorage
.key(i
);
1610 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1612 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1613 localStorage
.removeItem(key
);
1624 while (i
< article_cache
.length
) {
1625 if (article_cache
[i
]["id"] == id
) {
1626 //console.log("cache_invalidate: removed id " + id);
1627 article_cache
.splice(i
, 1);
1635 //console.log("cache_invalidate: id not found: " + id);
1638 exception_error("cache_invalidate", e
);
1642 function getActiveArticleId() {
1643 return active_post_id
;
1646 function preloadBatchedArticles() {
1649 var query
= "?op=rpc&subop=getArticles&ids=" +
1650 preload_id_batch
.toString();
1652 new Ajax
.Request("backend.php", {
1654 onComplete: function(transport
) {
1656 preload_id_batch
= [];
1658 var articles
= transport
.responseXML
.getElementsByTagName("article");
1660 for (var i
= 0; i
< articles
.length
; i
++) {
1661 var id
= articles
[i
].getAttribute("id");
1662 if (!cache_check(id
)) {
1663 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1664 console
.log("preloaded article: " + id
);
1670 exception_error("preloadBatchedArticles", e
);
1674 function preloadArticleUnderPointer(id
) {
1676 if (getInitParam("bw_limit") == "1") return;
1678 if (post_under_pointer
== id
&& !cache_check(id
)) {
1680 console
.log("trying to preload article " + id
);
1682 var neighbor_ids
= getRelativePostIds(id
, 1);
1684 /* only request uncached articles */
1686 if (preload_id_batch
.indexOf(id
) == -1) {
1687 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1688 if (!cache_check(neighbor_ids
[i
])) {
1689 preload_id_batch
.push(neighbor_ids
[i
]);
1694 if (preload_id_batch
.indexOf(id
) == -1)
1695 preload_id_batch
.push(id
);
1697 //console.log("preload ids batch: " + preload_id_batch.toString());
1699 window
.clearTimeout(preload_timeout_id
);
1700 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1704 exception_error("preloadArticleUnderPointer", e
);
1708 function postMouseIn(id
) {
1710 if (post_under_pointer
!= id
) {
1711 post_under_pointer
= id
;
1713 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1718 exception_error("postMouseIn", e
);
1722 function postMouseOut(id
) {
1724 post_under_pointer
= false;
1726 exception_error("postMouseOut", e
);
1730 function headlines_scroll_handler() {
1733 var e
= $("headlinesInnerContainer");
1735 var toolbar_form
= document
.forms
["main_toolbar_form"];
1737 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1738 // _infscroll_disable);
1740 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1741 if (!_infscroll_disable
) {
1747 exception_error("headlines_scroll_handler", e
);
1751 function catchupRelativeToArticle(below
) {
1756 if (!getActiveArticleId()) {
1757 alert(__("No article is selected."));
1761 var visible_ids
= getVisibleArticleIds();
1763 var ids_to_mark
= new Array();
1766 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1767 if (visible_ids
[i
] != getActiveArticleId()) {
1768 var e
= $("RROW-" + visible_ids
[i
]);
1770 if (e
&& e
.hasClassName("Unread")) {
1771 ids_to_mark
.push(visible_ids
[i
]);
1778 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1779 if (visible_ids
[i
] != getActiveArticleId()) {
1780 var e
= $("RROW-" + visible_ids
[i
]);
1782 if (e
&& e
.hasClassName("Unread")) {
1783 ids_to_mark
.push(visible_ids
[i
]);
1791 if (ids_to_mark
.length
== 0) {
1792 alert(__("No articles found to mark"));
1794 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1796 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1798 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1799 var e
= $("RROW-" + ids_to_mark
[i
]);
1800 e
.removeClassName("Unread");
1803 var query
= "?op=rpc&subop=catchupSelected" +
1804 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1806 new Ajax
.Request("backend.php", {
1808 onComplete: function(transport
) {
1809 catchup_callback2(transport
);
1816 exception_error("catchupRelativeToArticle", e
);
1820 function cdmExpandArticle(id
) {
1825 var elem
= $("CICD-" + active_post_id
);
1827 var upd_img_pic
= $("FUPDPIC-" + id
);
1829 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1830 upd_img_pic
.src
.match("fresh_sign.png"))) {
1832 upd_img_pic
.src
= "images/blank_icon.gif";
1835 if (id
== active_post_id
&& Element
.visible(elem
))
1838 selectArticles("none");
1840 var old_offset
= $("RROW-" + id
).offsetTop
;
1842 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1844 Element
.show("CEXC-" + active_post_id
);
1847 active_post_id
= id
;
1849 elem
= $("CICD-" + id
);
1851 if (!Element
.visible(elem
)) {
1853 Element
.hide("CEXC-" + id
);
1855 if ($("CWRAP-" + id
).innerHTML
== "") {
1857 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1859 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1860 __("Loading, please wait...") + "</div>";
1862 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1864 //console.log(query);
1866 new Ajax
.Request("backend.php", {
1868 onComplete: function(transport
) {
1869 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1871 if (transport
.responseXML
) {
1872 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1873 var recv_id
= article
.getAttribute("id");
1876 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1879 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1887 var new_offset
= $("RROW-" + id
).offsetTop
;
1889 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
1891 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1892 $("headlinesInnerContainer").scrollTop
= new_offset
;
1894 toggleUnread(id
, 0, true);
1898 exception_error("cdmExpandArticle", e
);
1904 function fixHeadlinesOrder(ids
) {
1906 for (var i
= 0; i
< ids
.length
; i
++) {
1907 var e
= $("RROW-" + ids
[i
]);
1911 e
.removeClassName("even");
1912 e
.addClassName("odd");
1914 e
.removeClassName("odd");
1915 e
.addClassName("even");
1920 exception_error("fixHeadlinesOrder", e
);
1924 function getArticleUnderPointer() {
1925 return post_under_pointer
;
1928 function zoomToArticle(id
) {
1930 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1932 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1935 exception_error("zoomToArticle", e
);
1939 function scrollArticle(offset
) {
1942 var ci
= $("content-insert");
1944 ci
.scrollTop
+= offset
;
1947 var hi
= $("headlinesInnerContainer");
1949 hi
.scrollTop
+= offset
;
1954 exception_error("scrollArticle", e
);
1958 function show_labels_in_headlines(transport
) {
1960 if (transport
.responseXML
) {
1961 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1963 var elems
= info
.getElementsByTagName("entry");
1965 for (var l
= 0; l
< elems
.length
; l
++) {
1966 var e_id
= elems
[l
].getAttribute("id");
1970 var ctr
= $("HLLCTR-" + e_id
);
1973 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1981 exception_error("show_labels_in_headlines", e
);
1986 function toggleHeadlineActions() {
1988 var e
= $("headlineActionsBody");
1989 var p
= $("headlineActionsDrop");
1991 if (!Element
.visible(e
)) {
1998 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1999 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
2002 exception_error("toggleHeadlineActions", e
);
2006 function publishWithNote(id
, def_note
) {
2008 if (!def_note
) def_note
= '';
2010 var note
= prompt(__("Please enter a note for this article:"), def_note
);
2012 if (note
!= undefined) {
2013 togglePub(id
, false, false, note
);
2017 exception_error("publishWithNote", e
);
2021 function emailArticle(id
) {
2024 var ids
= getSelectedArticleIds2();
2026 if (ids
.length
== 0) {
2027 alert(__("No articles are selected."));
2031 id
= ids
.toString();
2034 displayDlg('emailArticle', id
,
2036 document
.forms
['article_email_form'].destination
.focus();
2038 new Ajax
.Autocompleter('destination', 'destination_choices',
2039 "backend.php?op=rpc&subop=completeEmails",
2040 { tokens
: '', paramName
: "search" });
2045 exception_error("emailArticle", e
);
2049 function emailArticleDo() {
2051 var f
= document
.forms
['article_email_form'];
2053 if (f
.destination
.value
== "") {
2054 alert("Please fill in the destination email.");
2058 if (f
.subject
.value
== "") {
2059 alert("Please fill in the subject.");
2063 var query
= Form
.serialize("article_email_form");
2065 // console.log(query);
2067 new Ajax
.Request("backend.php", {
2069 onComplete: function(transport
) {
2072 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
2075 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
2077 notify_info('Your message has been sent.');
2082 exception_error("sendEmailDo", e
);
2088 exception_error("emailArticleDo", e
);
2092 function dismissArticle(id
) {
2094 var elem
= $("RROW-" + id
);
2096 toggleUnread(id
, 0, true);
2098 new Effect
.Fade(elem
, {duration
: 0.5});
2100 active_post_id
= false;
2103 exception_error("dismissArticle", e
);
2107 function dismissSelectedArticles() {
2110 var ids
= getVisibleArticleIds();
2114 for (var i
= 0; i
< ids
.length
; i
++) {
2115 var elem
= $("RROW-" + ids
[i
]);
2117 if (elem
.className
&& elem
.hasClassName("Selected") &&
2118 ids
[i
] != active_post_id
) {
2119 new Effect
.Fade(elem
, {duration
: 0.5});
2127 selectionToggleUnread(false);
2129 fixHeadlinesOrder(tmp
);
2132 exception_error("dismissSelectedArticles", e
);
2136 function dismissReadArticles() {
2139 var ids
= getVisibleArticleIds();
2142 for (var i
= 0; i
< ids
.length
; i
++) {
2143 var elem
= $("RROW-" + ids
[i
]);
2145 if (elem
.className
&& !elem
.hasClassName("Unread") &&
2146 !elem
.hasClassName("Selected")) {
2148 new Effect
.Fade(elem
, {duration
: 0.5});
2154 fixHeadlinesOrder(tmp
);
2157 exception_error("dismissSelectedArticles", e
);
2161 function getVisibleArticleIds() {
2166 getLoadedArticleIds().each(function(id
) {
2167 var elem
= $("RROW-" + id
);
2168 if (elem
&& Element
.visible(elem
))
2173 exception_error("getVisibleArticleIds", e
);
2179 function cdmClicked(event
, id
) {
2181 var shift_key
= event
.shiftKey
;
2185 if (!event
.ctrlKey
) {
2186 selectArticles("none");
2189 var elem
= $("RROW-" + id
);
2192 elem
.removeClassName("Unread");
2194 var upd_img_pic
= $("FUPDPIC-" + id
);
2196 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2197 upd_img_pic
.src
.match("fresh_sign.png"))) {
2199 upd_img_pic
.src
= "images/blank_icon.gif";
2202 active_post_id
= id
;
2204 var query
= "?op=rpc&subop=catchupSelected" +
2205 "&cmode=0&ids=" + param_escape(id
);
2207 new Ajax
.Request("backend.php", {
2209 onComplete: function(transport
) {
2210 handle_rpc_reply(transport
);
2219 exception_error("cdmClicked");
2225 function hlClicked(event
, id
) {
2228 if (!event
.ctrlKey
) {
2237 exception_error("hlClicked");
2243 function getFirstVisibleHeadlineId() {
2244 var rows
= getVisibleArticleIds();
2249 function getLastVisibleHeadlineId() {
2250 var rows
= getVisibleArticleIds();
2251 return rows
[rows
.length
-1];
2254 function openArticleInNewWindow(id
) {
2256 console
.log("openArticleInNewWindow: " + id
);
2258 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2259 var wname
= "ttrss_article_" + id
;
2261 console
.log(query
+ " " + wname
);
2263 var w
= window
.open("", wname
);
2265 if (!w
) notify_error("Failed to open window for the article");
2267 new Ajax
.Request("backend.php", {
2269 onComplete: function(transport
) {
2271 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2272 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2274 console
.log("open_article received link: " + link
);
2278 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2280 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2282 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2284 if (!w
) { notify_error("Failed to load article in new window"); }
2287 id
= id
.firstChild
.nodeValue
;
2288 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2291 notify_error("Can't open article: received invalid article link");
2296 exception_error("openArticleInNewWindow", e
);
2300 function isCdmMode() {
2301 return getInitParam("combined_display_mode");
2304 function markHeadline(id
) {
2305 var row
= $("RROW-" + id
);
2307 var check
= $("RCHK-" + id
);
2310 check
.checked
= true;
2313 row
.addClassName("Selected");
2317 function getRelativePostIds(id
, limit
) {
2323 if (!limit
) limit
= 3;
2325 var ids
= getVisibleArticleIds();
2327 for (var i
= 0; i
< ids
.length
; i
++) {
2329 for (var k
= 1; k
<= limit
; k
++) {
2330 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2331 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2338 exception_error("getRelativePostIds", e
);
2344 function correctHeadlinesOffset(id
) {
2348 var container
= $("headlinesInnerContainer");
2349 var row
= $("RROW-" + id
);
2351 var viewport
= container
.offsetHeight
;
2353 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2354 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2356 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2357 //console.log("Vport: " + viewport);
2359 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2360 container
.scrollTop
= row
.offsetTop
;
2361 } else if (rel_offset_bottom
> viewport
) {
2363 /* doesn't properly work with Opera in some cases because
2364 Opera fucks up element scrolling */
2366 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2370 exception_error("correctHeadlinesOffset", e
);