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);
363 var reply
= transport
.responseXML
.firstChild
.firstChild
;
366 console
.warn("article_callback: returned no XML object");
367 //var f = $("content-frame");
368 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
371 var date
= new Date();
372 last_article_view
= date
.getTime() / 1000;
374 if (_reload_feedlist_after_view
) {
375 setTimeout('updateFeedList(false, false)', 50);
376 _reload_feedlist_after_view
= false;
383 exception_error("article_callback2", e
, transport
);
389 console
.log("loading article: " + id
);
391 var cached_article
= cache_find(id
);
393 console
.log("cache check result: " + (cached_article
!= false));
398 var query
= "?op=view&id=" + param_escape(id
);
400 var neighbor_ids
= getRelativePostIds(active_post_id
);
402 /* only request uncached articles */
404 var cids_to_request
= Array();
406 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
407 if (!cache_check(neighbor_ids
[i
])) {
408 cids_to_request
.push(neighbor_ids
[i
]);
412 console
.log("additional ids: " + cids_to_request
.toString());
414 query
= query
+ "&cids=" + cids_to_request
.toString();
416 var crow
= $("RROW-" + id
);
417 var article_is_unread
= crow
.hasClassName("Unread");
420 showArticleInHeadlines(id
);
422 if (!cached_article
) {
424 var upic
= $('FUPDPIC-' + id
);
427 upic
.src
= getInitParam("sign_progress");
430 } else if (cached_article
&& article_is_unread
) {
432 query
= query
+ "&mode=prefetch";
434 render_article(cached_article
);
436 } else if (cached_article
) {
438 query
= query
+ "&mode=prefetch_old";
439 render_article(cached_article
);
445 last_requested_article
= id
;
447 new Ajax
.Request("backend.php", {
449 onComplete: function(transport
) {
450 article_callback2(transport
, id
);
456 exception_error("view", e
);
461 return toggleMark(id
);
465 return togglePub(id
);
468 function tMark_afh_off(effect
) {
470 var elem
= effect
.effects
[0].element
;
472 //console.log("tMark_afh_off : " + elem.id);
475 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
476 elem
.alt
= __("Star article");
481 exception_error("tMark_afh_off", e
);
485 function tPub_afh_off(effect
) {
487 var elem
= effect
.effects
[0].element
;
489 //console.log("tPub_afh_off : " + elem.id);
492 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
493 elem
.alt
= __("Publish article");
498 exception_error("tPub_afh_off", e
);
502 function toggleMark(id
, client_only
) {
504 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
506 var img
= $("FMPIC-" + id
);
510 if (img
.src
.match("mark_unset")) {
511 img
.src
= img
.src
.replace("mark_unset", "mark_set");
512 img
.alt
= __("Unstar article");
513 query
= query
+ "&mark=1";
516 img
.src
= img
.src
.replace("mark_set", "mark_unset");
517 img
.alt
= __("Star article");
518 query
= query
+ "&mark=0";
522 new Ajax
.Request("backend.php", {
524 onComplete: function(transport
) {
525 handle_rpc_reply(transport
);
530 exception_error("toggleMark", e
);
534 function togglePub(id
, client_only
, no_effects
, note
) {
536 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
538 if (note
!= undefined) {
539 query
= query
+ "¬e=" + param_escape(note
);
541 query
= query
+ "¬e=undefined";
544 var img
= $("FPPIC-" + id
);
548 if (img
.src
.match("pub_unset") || note
!= undefined) {
549 img
.src
= img
.src
.replace("pub_unset", "pub_set");
550 img
.alt
= __("Unpublish article");
551 query
= query
+ "&pub=1";
554 img
.src
= img
.src
.replace("pub_set", "pub_unset");
555 img
.alt
= __("Publish article");
557 query
= query
+ "&pub=0";
561 new Ajax
.Request("backend.php", {
563 onComplete: function(transport
) {
564 handle_rpc_reply(transport
);
566 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
569 var note_id
= note
.getAttribute("id");
570 var note_size
= note
.getAttribute("size");
571 var note_content
= note
.firstChild
.nodeValue
;
573 var container
= $('POSTNOTE-' + note_id
);
575 cache_invalidate(note_id
);
578 if (note_size
== "0") {
579 Element
.hide(container
);
581 container
.innerHTML
= note_content
;
582 Element
.show(container
);
591 exception_error("togglePub", e
);
595 function moveToPost(mode
) {
599 var rows
= getVisibleArticleIds();
604 if (!$('RROW-' + active_post_id
)) {
605 active_post_id
= false;
608 if (active_post_id
== false) {
609 next_id
= getFirstVisibleHeadlineId();
610 prev_id
= getLastVisibleHeadlineId();
612 for (var i
= 0; i
< rows
.length
; i
++) {
613 if (rows
[i
] == active_post_id
) {
620 if (mode
== "next") {
624 cdmExpandArticle(next_id
);
625 cdmScrollToArticleId(next_id
);
628 correctHeadlinesOffset(next_id
);
629 view(next_id
, getActiveFeedId());
634 if (mode
== "prev") {
637 cdmExpandArticle(prev_id
);
638 cdmScrollToArticleId(prev_id
);
640 correctHeadlinesOffset(prev_id
);
641 view(prev_id
, getActiveFeedId());
647 exception_error("moveToPost", e
);
651 function toggleSelected(id
) {
654 var cb
= $("RCHK-" + id
);
655 var row
= $("RROW-" + id
);
658 if (row
.hasClassName('Selected')) {
659 row
.removeClassName('Selected');
660 if (cb
) cb
.checked
= false;
662 row
.addClassName('Selected');
663 if (cb
) cb
.checked
= true;
667 exception_error("toggleSelected", e
);
671 function toggleUnread_afh(effect
) {
674 var elem
= effect
.element
;
675 elem
.style
.backgroundColor
= "";
678 exception_error("toggleUnread_afh", e
);
682 function toggleUnread(id
, cmode
, effect
) {
685 var row
= $("RROW-" + id
);
687 if (cmode
== undefined || cmode
== 2) {
688 if (row
.hasClassName("Unread")) {
689 row
.removeClassName("Unread");
692 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
693 afterFinish
: toggleUnread_afh
,
694 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
698 row
.addClassName("Unread");
701 } else if (cmode
== 0) {
703 row
.removeClassName("Unread");
706 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
707 afterFinish
: toggleUnread_afh
,
708 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
711 } else if (cmode
== 1) {
712 row
.addClassName("Unread");
715 if (cmode
== undefined) cmode
= 2;
717 var query
= "?op=rpc&subop=catchupSelected" +
718 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
720 // notify_progress("Loading, please wait...");
722 new Ajax
.Request("backend.php", {
724 onComplete: function(transport
) {
725 handle_rpc_reply(transport
);
731 exception_error("toggleUnread", e
);
735 function selectionRemoveLabel(id
) {
738 var ids
= getSelectedArticleIds2();
740 if (ids
.length
== 0) {
741 alert(__("No articles are selected."));
745 // var ok = confirm(__("Remove selected articles from label?"));
749 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
750 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
754 // notify_progress("Loading, please wait...");
756 cache_invalidate("F:" + (-11 - id
));
758 new Ajax
.Request("backend.php", {
760 onComplete: function(transport
) {
761 show_labels_in_headlines(transport
);
762 handle_rpc_reply(transport
);
768 exception_error("selectionAssignLabel", e
);
773 function selectionAssignLabel(id
) {
776 var ids
= getSelectedArticleIds2();
778 if (ids
.length
== 0) {
779 alert(__("No articles are selected."));
783 // var ok = confirm(__("Assign selected articles to label?"));
787 cache_invalidate("F:" + (-11 - id
));
789 var query
= "?op=rpc&subop=assignToLabel&ids=" +
790 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
794 // notify_progress("Loading, please wait...");
796 new Ajax
.Request("backend.php", {
798 onComplete: function(transport
) {
799 show_labels_in_headlines(transport
);
800 handle_rpc_reply(transport
);
806 exception_error("selectionAssignLabel", e
);
811 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
813 var rows
= getSelectedArticleIds2();
815 if (rows
.length
== 0 && !no_error
) {
816 alert(__("No articles are selected."));
820 for (i
= 0; i
< rows
.length
; i
++) {
821 var row
= $("RROW-" + rows
[i
]);
823 if (set_state
== undefined) {
824 if (row
.hasClassName("Unread")) {
825 row
.removeClassName("Unread");
827 row
.addClassName("Unread");
831 if (set_state
== false) {
832 row
.removeClassName("Unread");
835 if (set_state
== true) {
836 row
.addClassName("Unread");
841 if (rows
.length
> 0) {
845 if (set_state
== undefined) {
847 } else if (set_state
== true) {
849 } else if (set_state
== false) {
853 var query
= "?op=rpc&subop=catchupSelected" +
854 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
856 notify_progress("Loading, please wait...");
858 new Ajax
.Request("backend.php", {
860 onComplete: function(transport
) {
861 catchup_callback2(transport
, callback_func
);
867 exception_error("selectionToggleUnread", e
);
871 function selectionToggleMarked() {
874 var rows
= getSelectedArticleIds2();
876 if (rows
.length
== 0) {
877 alert(__("No articles are selected."));
881 for (i
= 0; i
< rows
.length
; i
++) {
882 toggleMark(rows
[i
], true, true);
885 if (rows
.length
> 0) {
887 var query
= "?op=rpc&subop=markSelected&ids=" +
888 param_escape(rows
.toString()) + "&cmode=2";
890 new Ajax
.Request("backend.php", {
892 onComplete: function(transport
) {
893 handle_rpc_reply(transport
);
899 exception_error("selectionToggleMarked", e
);
903 function selectionTogglePublished() {
906 var rows
= getSelectedArticleIds2();
908 if (rows
.length
== 0) {
909 alert(__("No articles are selected."));
913 for (i
= 0; i
< rows
.length
; i
++) {
914 togglePub(rows
[i
], true, true);
917 if (rows
.length
> 0) {
919 var query
= "?op=rpc&subop=publishSelected&ids=" +
920 param_escape(rows
.toString()) + "&cmode=2";
922 new Ajax
.Request("backend.php", {
924 onComplete: function(transport
) {
925 handle_rpc_reply(transport
);
931 exception_error("selectionToggleMarked", e
);
935 function getSelectedArticleIds2() {
939 $$("#headlinesInnerContainer > div[id*=RROW][class*=Selected]").each(
941 rv
.push(child
.id
.replace("RROW-", ""));
947 function getLoadedArticleIds() {
950 var children
= $$("#headlinesInnerContainer > div[id*=RROW-]");
952 children
.each(function(child
) {
953 rv
.push(child
.id
.replace("RROW-", ""));
960 // mode = all,none,unread,invert
961 function selectArticles(mode
) {
964 var children
= $$("#headlinesInnerContainer > div[id*=RROW]");
966 children
.each(function(child
) {
967 var id
= child
.id
.replace("RROW-", "");
968 var cb
= $("RCHK-" + id
);
971 child
.addClassName("Selected");
973 } else if (mode
== "unread") {
974 if (child
.hasClassName("Unread")) {
975 child
.addClassName("Selected");
978 child
.removeClassName("Selected");
981 } else if (mode
== "invert") {
982 if (child
.hasClassName("Selected")) {
983 child
.removeClassName("Selected");
986 child
.addClassName("Selected");
991 child
.removeClassName("Selected");
997 exception_error("selectArticles", e
);
1001 function catchupPage() {
1003 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1005 var str
= __("Mark all visible articles in %s as read?");
1007 str
= str
.replace("%s", fn
);
1009 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1013 selectArticles('all');
1014 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1015 selectArticles('none');
1018 function deleteSelection() {
1022 var rows
= getSelectedArticleIds2();
1024 if (rows
.length
== 0) {
1025 alert(__("No articles are selected."));
1029 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1033 if (getActiveFeedId() != 0) {
1034 str
= __("Delete %d selected articles in %s?");
1036 str
= __("Delete %d selected articles?");
1039 str
= str
.replace("%d", rows
.length
);
1040 str
= str
.replace("%s", fn
);
1042 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1046 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
1050 new Ajax
.Request("backend.php", {
1052 onComplete: function(transport
) {
1057 exception_error("deleteSelection", e
);
1061 function archiveSelection() {
1065 var rows
= getSelectedArticleIds2();
1067 if (rows
.length
== 0) {
1068 alert(__("No articles are selected."));
1072 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1076 if (getActiveFeedId() != 0) {
1077 str
= __("Archive %d selected articles in %s?");
1080 str
= __("Move %d archived articles back?");
1084 str
= str
.replace("%d", rows
.length
);
1085 str
= str
.replace("%s", fn
);
1087 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1091 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1095 for (var i
= 0; i
< rows
.length
; i
++) {
1096 cache_invalidate(rows
[i
]);
1099 new Ajax
.Request("backend.php", {
1101 onComplete: function(transport
) {
1106 exception_error("archiveSelection", e
);
1110 function catchupSelection() {
1114 var rows
= getSelectedArticleIds2();
1116 if (rows
.length
== 0) {
1117 alert(__("No articles are selected."));
1121 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1123 var str
= __("Mark %d selected articles in %s as read?");
1125 str
= str
.replace("%d", rows
.length
);
1126 str
= str
.replace("%s", fn
);
1128 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1132 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1135 exception_error("catchupSelection", e
);
1139 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1140 displayDlg('editArticleTags', id
,
1142 $("tags_str").focus();
1144 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1145 "backend.php?op=rpc&subop=completeTags",
1146 { tokens
: ',', paramName
: "search" });
1150 function editTagsSave() {
1152 notify_progress("Saving article tags...");
1154 var form
= document
.forms
["tag_edit_form"];
1156 var query
= Form
.serialize("tag_edit_form");
1158 query
= "?op=rpc&subop=setArticleTags&" + query
;
1160 //console.log(query);
1162 new Ajax
.Request("backend.php", {
1164 onComplete: function(transport
) {
1166 //console.log("tags saved...");
1171 if (tagsAreDisplayed()) {
1172 _reload_feedlist_after_view
= true;
1175 if (transport
.responseXML
) {
1176 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1179 var id
= tags_str
.getAttribute("id");
1182 var tags
= $("ATSTR-" + id
);
1184 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1187 cache_invalidate(id
);
1193 exception_error("editTagsSave", e
);
1198 function editTagsInsert() {
1201 var form
= document
.forms
["tag_edit_form"];
1203 var found_tags
= form
.found_tags
;
1204 var tags_str
= form
.tags_str
;
1206 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1208 if (tags_str
.value
.length
> 0 &&
1209 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1211 tags_str
.value
= tags_str
.value
+ ", ";
1214 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1216 found_tags
.selectedIndex
= 0;
1219 exception_error("editTagsInsert", e
);
1223 function cdmScrollToArticleId(id
) {
1225 var ctr
= $("headlinesInnerContainer");
1226 var e
= $("RROW-" + id
);
1228 if (!e
|| !ctr
) return;
1230 ctr
.scrollTop
= e
.offsetTop
;
1233 exception_error("cdmScrollToArticleId", e
);
1237 function cdmWatchdog() {
1241 var ctr
= $("headlinesInnerContainer");
1245 var ids
= new Array();
1247 var e
= ctr
.firstChild
;
1250 if (e
.className
&& e
.hasClassName("Unread") && e
.id
&&
1251 e
.id
.match("RROW-")) {
1253 // article fits in viewport OR article is longer than viewport and
1254 // its bottom is visible
1256 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1257 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1259 // console.log(e.id + " is visible " + e.offsetTop + "." +
1260 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1261 // (ctr.scrollTop + ctr.offsetHeight));
1263 ids
.push(e
.id
.replace("RROW-", ""));
1265 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1266 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1267 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1269 ids
.push(e
.id
.replace("RROW-", ""));
1273 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1275 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1276 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1278 ids.push(e.id.replace("RROW-", ""));
1287 console
.log("cdmWatchdog, ids= " + ids
.toString());
1289 if (ids
.length
> 0) {
1291 for (var i
= 0; i
< ids
.length
; i
++) {
1292 var e
= $("RROW-" + ids
[i
]);
1294 e
.removeClassName("Unread");
1298 var query
= "?op=rpc&subop=catchupSelected" +
1299 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1301 new Ajax
.Request("backend.php", {
1303 onComplete: function(transport
) {
1304 handle_rpc_reply(transport
);
1309 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1312 exception_error("cdmWatchdog", e
);
1318 function cache_inject(id
, article
, param
) {
1321 if (!cache_check_param(id
, param
)) {
1322 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1324 var date
= new Date();
1325 var ts
= Math
.round(date
.getTime() / 1000);
1329 cache_obj
["id"] = id
;
1330 cache_obj
["data"] = article
;
1331 cache_obj
["param"] = param
;
1333 if (param
) id
= id
+ ":" + param
;
1335 cache_added
["TS:" + id
] = ts
;
1337 if (has_local_storage())
1338 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1340 article_cache
.push(cache_obj
);
1343 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1346 exception_error("cache_inject", e
);
1350 function cache_find(id
) {
1352 if (has_local_storage()) {
1353 var cache_obj
= localStorage
.getItem(id
);
1356 cache_obj
= JSON
.parse(cache_obj
);
1359 return cache_obj
['data'];
1363 for (var i
= 0; i
< article_cache
.length
; i
++) {
1364 if (article_cache
[i
]["id"] == id
) {
1365 return article_cache
[i
]["data"];
1372 function cache_find_param(id
, param
) {
1374 if (has_local_storage()) {
1376 if (param
) id
= id
+ ":" + param
;
1378 var cache_obj
= localStorage
.getItem(id
);
1381 cache_obj
= JSON
.parse(cache_obj
);
1384 return cache_obj
['data'];
1388 for (var i
= 0; i
< article_cache
.length
; i
++) {
1389 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1390 return article_cache
[i
]["data"];
1398 function cache_check(id
) {
1399 if (has_local_storage()) {
1400 if (localStorage
.getItem(id
))
1403 for (var i
= 0; i
< article_cache
.length
; i
++) {
1404 if (article_cache
[i
]["id"] == id
) {
1412 function cache_check_param(id
, param
) {
1413 if (has_local_storage()) {
1415 if (param
) id
= id
+ ":" + param
;
1417 if (localStorage
.getItem(id
))
1421 for (var i
= 0; i
< article_cache
.length
; i
++) {
1422 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1430 function cache_expire() {
1431 if (has_local_storage()) {
1433 var date
= new Date();
1434 var timestamp
= Math
.round(date
.getTime() / 1000);
1436 for (var i
= 0; i
< localStorage
.length
; i
++) {
1438 var id
= localStorage
.key(i
);
1440 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1441 localStorage
.removeItem(id
);
1446 while (article_cache
.length
> 25) {
1447 article_cache
.shift();
1452 function cache_flush() {
1453 if (has_local_storage()) {
1454 localStorage
.clear();
1456 article_cache
= new Array();
1460 function cache_invalidate(id
) {
1462 if (has_local_storage()) {
1466 for (var i
= 0; i
< localStorage
.length
; i
++) {
1467 var key
= localStorage
.key(i
);
1469 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1471 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1472 localStorage
.removeItem(key
);
1483 while (i
< article_cache
.length
) {
1484 if (article_cache
[i
]["id"] == id
) {
1485 //console.log("cache_invalidate: removed id " + id);
1486 article_cache
.splice(i
, 1);
1493 //console.log("cache_invalidate: id not found: " + id);
1496 exception_error("cache_invalidate", e
);
1500 function getActiveArticleId() {
1501 return active_post_id
;
1504 function preloadBatchedArticles() {
1507 var query
= "?op=rpc&subop=getArticles&ids=" +
1508 preload_id_batch
.toString();
1510 new Ajax
.Request("backend.php", {
1512 onComplete: function(transport
) {
1514 preload_id_batch
= [];
1516 var articles
= transport
.responseXML
.getElementsByTagName("article");
1518 for (var i
= 0; i
< articles
.length
; i
++) {
1519 var id
= articles
[i
].getAttribute("id");
1520 if (!cache_check(id
)) {
1521 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1522 console
.log("preloaded article: " + id
);
1528 exception_error("preloadBatchedArticles", e
);
1532 function preloadArticleUnderPointer(id
) {
1534 if (getInitParam("bw_limit") == "1") return;
1536 if (post_under_pointer
== id
&& !cache_check(id
)) {
1538 console
.log("trying to preload article " + id
);
1540 var neighbor_ids
= getRelativePostIds(id
, 1);
1542 /* only request uncached articles */
1544 if (preload_id_batch
.indexOf(id
) == -1) {
1545 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1546 if (!cache_check(neighbor_ids
[i
])) {
1547 preload_id_batch
.push(neighbor_ids
[i
]);
1552 if (preload_id_batch
.indexOf(id
) == -1)
1553 preload_id_batch
.push(id
);
1555 //console.log("preload ids batch: " + preload_id_batch.toString());
1557 window
.clearTimeout(preload_timeout_id
);
1558 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1562 exception_error("preloadArticleUnderPointer", e
);
1566 function postMouseIn(id
) {
1568 if (post_under_pointer
!= id
) {
1569 post_under_pointer
= id
;
1571 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1576 exception_error("postMouseIn", e
);
1580 function postMouseOut(id
) {
1582 post_under_pointer
= false;
1584 exception_error("postMouseOut", e
);
1588 function headlines_scroll_handler() {
1591 var e
= $("headlinesInnerContainer");
1593 var toolbar_form
= document
.forms
["main_toolbar_form"];
1595 // console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
1596 // _infscroll_disable);
1598 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1599 if (!_infscroll_disable
) {
1605 exception_error("headlines_scroll_handler", e
);
1609 function catchupRelativeToArticle(below
) {
1614 if (!getActiveArticleId()) {
1615 alert(__("No article is selected."));
1619 var visible_ids
= getVisibleArticleIds();
1621 var ids_to_mark
= new Array();
1624 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1625 if (visible_ids
[i
] != getActiveArticleId()) {
1626 var e
= $("RROW-" + visible_ids
[i
]);
1628 if (e
&& e
.hasClassName("Unread")) {
1629 ids_to_mark
.push(visible_ids
[i
]);
1636 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1637 if (visible_ids
[i
] != getActiveArticleId()) {
1638 var e
= $("RROW-" + visible_ids
[i
]);
1640 if (e
&& e
.hasClassName("Unread")) {
1641 ids_to_mark
.push(visible_ids
[i
]);
1649 if (ids_to_mark
.length
== 0) {
1650 alert(__("No articles found to mark"));
1652 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1654 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1656 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1657 var e
= $("RROW-" + ids_to_mark
[i
]);
1658 e
.removeClassName("Unread");
1661 var query
= "?op=rpc&subop=catchupSelected" +
1662 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1664 new Ajax
.Request("backend.php", {
1666 onComplete: function(transport
) {
1667 catchup_callback2(transport
);
1674 exception_error("catchupRelativeToArticle", e
);
1678 function cdmExpandArticle(id
) {
1683 var elem
= $("CICD-" + active_post_id
);
1685 var upd_img_pic
= $("FUPDPIC-" + id
);
1687 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1688 upd_img_pic
.src
.match("fresh_sign.png"))) {
1690 upd_img_pic
.src
= "images/blank_icon.gif";
1693 if (id
== active_post_id
&& Element
.visible(elem
))
1696 selectArticles("none");
1698 var old_offset
= $("RROW-" + id
).offsetTop
;
1700 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1702 Element
.show("CEXC-" + active_post_id
);
1705 active_post_id
= id
;
1707 elem
= $("CICD-" + id
);
1709 if (!Element
.visible(elem
)) {
1711 Element
.hide("CEXC-" + id
);
1713 if ($("CWRAP-" + id
).innerHTML
== "") {
1715 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1717 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1718 __("Loading, please wait...") + "</div>";
1720 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1722 //console.log(query);
1724 new Ajax
.Request("backend.php", {
1726 onComplete: function(transport
) {
1727 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1729 if (transport
.responseXML
) {
1730 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1731 var recv_id
= article
.getAttribute("id");
1734 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1737 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1745 var new_offset
= $("RROW-" + id
).offsetTop
;
1747 $("headlinesInnerContainer").scrollTop
+= (new_offset
-old_offset
);
1749 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1750 $("headlinesInnerContainer").scrollTop
= new_offset
;
1752 toggleUnread(id
, 0, true);
1756 exception_error("cdmExpandArticle", e
);
1762 function fixHeadlinesOrder(ids
) {
1764 for (var i
= 0; i
< ids
.length
; i
++) {
1765 var e
= $("RROW-" + ids
[i
]);
1769 e
.removeClassName("even");
1770 e
.addClassName("odd");
1772 e
.removeClassName("odd");
1773 e
.addClassName("even");
1778 exception_error("fixHeadlinesOrder", e
);
1782 function getArticleUnderPointer() {
1783 return post_under_pointer
;
1786 function zoomToArticle(id
) {
1788 var w
= window
.open("backend.php?op=view&mode=zoom&id=" + param_escape(id
),
1790 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
1793 exception_error("zoomToArticle", e
);
1797 function scrollArticle(offset
) {
1800 var ci
= $("content-insert");
1802 ci
.scrollTop
+= offset
;
1805 var hi
= $("headlinesInnerContainer");
1807 hi
.scrollTop
+= offset
;
1812 exception_error("scrollArticle", e
);
1816 function show_labels_in_headlines(transport
) {
1818 if (transport
.responseXML
) {
1819 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1821 var elems
= info
.getElementsByTagName("entry");
1823 for (var l
= 0; l
< elems
.length
; l
++) {
1824 var e_id
= elems
[l
].getAttribute("id");
1828 var ctr
= $("HLLCTR-" + e_id
);
1831 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1839 exception_error("show_labels_in_headlines", e
);
1844 function toggleHeadlineActions() {
1846 var e
= $("headlineActionsBody");
1847 var p
= $("headlineActionsDrop");
1849 if (!Element
.visible(e
)) {
1856 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1857 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1860 exception_error("toggleHeadlineActions", e
);
1864 function publishWithNote(id
, def_note
) {
1866 if (!def_note
) def_note
= '';
1868 var note
= prompt(__("Please enter a note for this article:"), def_note
);
1870 if (note
!= undefined) {
1871 togglePub(id
, false, false, note
);
1875 exception_error("publishWithNote", e
);
1879 function emailArticle(id
) {
1882 var ids
= getSelectedArticleIds2();
1884 if (ids
.length
== 0) {
1885 alert(__("No articles are selected."));
1889 id
= ids
.toString();
1892 displayDlg('emailArticle', id
,
1894 document
.forms
['article_email_form'].destination
.focus();
1896 new Ajax
.Autocompleter('destination', 'destination_choices',
1897 "backend.php?op=rpc&subop=completeEmails",
1898 { tokens
: '', paramName
: "search" });
1903 exception_error("emailArticle", e
);
1907 function emailArticleDo() {
1909 var f
= document
.forms
['article_email_form'];
1911 if (f
.destination
.value
== "") {
1912 alert("Please fill in the destination email.");
1916 if (f
.subject
.value
== "") {
1917 alert("Please fill in the subject.");
1921 var query
= Form
.serialize("article_email_form");
1923 // console.log(query);
1925 new Ajax
.Request("backend.php", {
1927 onComplete: function(transport
) {
1930 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
1933 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
1935 notify_info('Your message has been sent.');
1940 exception_error("sendEmailDo", e
);
1946 exception_error("emailArticleDo", e
);
1950 function dismissArticle(id
) {
1952 var elem
= $("RROW-" + id
);
1954 toggleUnread(id
, 0, true);
1956 new Effect
.Fade(elem
, {duration
: 0.5});
1958 active_post_id
= false;
1961 exception_error("dismissArticle", e
);
1965 function dismissSelectedArticles() {
1968 var ids
= getVisibleArticleIds();
1972 for (var i
= 0; i
< ids
.length
; i
++) {
1973 var elem
= $("RROW-" + ids
[i
]);
1975 if (elem
.className
&& elem
.hasClassName("Selected") &&
1976 ids
[i
] != active_post_id
) {
1977 new Effect
.Fade(elem
, {duration
: 0.5});
1985 selectionToggleUnread(false);
1987 fixHeadlinesOrder(tmp
);
1990 exception_error("dismissSelectedArticles", e
);
1994 function dismissReadArticles() {
1997 var ids
= getVisibleArticleIds();
2000 for (var i
= 0; i
< ids
.length
; i
++) {
2001 var elem
= $("RROW-" + ids
[i
]);
2003 if (elem
.className
&& !elem
.hasClassName("Unread") &&
2004 !elem
.hasClassName("Selected")) {
2006 new Effect
.Fade(elem
, {duration
: 0.5});
2012 fixHeadlinesOrder(tmp
);
2015 exception_error("dismissSelectedArticles", e
);
2019 function getVisibleArticleIds() {
2024 getLoadedArticleIds().each(function(id
) {
2025 var elem
= $("RROW-" + id
);
2026 if (elem
&& Element
.visible(elem
))
2031 exception_error("getVisibleArticleIds", e
);
2037 function cdmClicked(event
, id
) {
2039 var shift_key
= event
.shiftKey
;
2043 if (!event
.ctrlKey
) {
2044 selectArticles("none");
2047 var elem
= $("RROW-" + id
);
2050 elem
.removeClassName("Unread");
2052 var upd_img_pic
= $("FUPDPIC-" + id
);
2054 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2055 upd_img_pic
.src
.match("fresh_sign.png"))) {
2057 upd_img_pic
.src
= "images/blank_icon.gif";
2060 active_post_id
= id
;
2062 var query
= "?op=rpc&subop=catchupSelected" +
2063 "&cmode=0&ids=" + param_escape(id
);
2065 new Ajax
.Request("backend.php", {
2067 onComplete: function(transport
) {
2068 handle_rpc_reply(transport
);
2077 exception_error("cdmClicked");
2083 function hlClicked(event
, id
) {
2086 if (!event
.ctrlKey
) {
2095 exception_error("hlClicked");
2101 function getFirstVisibleHeadlineId() {
2102 var rows
= getVisibleArticleIds();
2107 function getLastVisibleHeadlineId() {
2108 var rows
= getVisibleArticleIds();
2109 return rows
[rows
.length
-1];
2112 function openArticleInNewWindow(id
) {
2114 console
.log("openArticleInNewWindow: " + id
);
2116 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2117 var wname
= "ttrss_article_" + id
;
2119 console
.log(query
+ " " + wname
);
2121 var w
= window
.open("", wname
);
2123 if (!w
) notify_error("Failed to open window for the article");
2125 new Ajax
.Request("backend.php", {
2127 onComplete: function(transport
) {
2129 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2130 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2132 console
.log("open_article received link: " + link
);
2136 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2138 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2140 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2142 if (!w
) { notify_error("Failed to load article in new window"); }
2145 id
= id
.firstChild
.nodeValue
;
2146 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2149 notify_error("Can't open article: received invalid article link");
2154 exception_error("openArticleInNewWindow", e
);
2158 function isCdmMode() {
2159 return getInitParam("combined_display_mode");
2162 function markHeadline(id
) {
2163 var row
= $("RROW-" + id
);
2165 var check
= $("RCHK-" + id
);
2168 check
.checked
= true;
2171 row
.addClassName("Selected");
2175 function getRelativePostIds(id
, limit
) {
2181 if (!limit
) limit
= 3;
2183 var ids
= getVisibleArticleIds();
2185 for (var i
= 0; i
< ids
.length
; i
++) {
2187 for (var k
= 1; k
<= limit
; k
++) {
2188 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2189 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2196 exception_error("getRelativePostIds", e
);
2202 function correctHeadlinesOffset(id
) {
2206 var container
= $("headlinesInnerContainer");
2207 var row
= $("RROW-" + id
);
2209 var viewport
= container
.offsetHeight
;
2211 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2212 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2214 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2215 //console.log("Vport: " + viewport);
2217 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2218 container
.scrollTop
= row
.offsetTop
;
2219 } else if (rel_offset_bottom
> viewport
) {
2221 /* doesn't properly work with Opera in some cases because
2222 Opera fucks up element scrolling */
2224 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2228 exception_error("correctHeadlinesOffset", e
);