]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
d8448afc70407601d8a7d88ff8b2e63f4b6b2b2b
1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _cdm_wd_timeout
= false;
6 var _cdm_wd_vishist
= new Array();
8 var article_cache
= new Array();
10 var vgroup_last_feed
= false;
11 var post_under_pointer
= false;
13 var last_requested_article
= false;
15 var preload_id_batch
= [];
16 var preload_timeout_id
= false;
20 function catchup_callback2(transport
, callback
) {
22 console
.log("catchup_callback2 " + transport
+ ", " + callback
);
24 handle_rpc_reply(transport
);
26 setTimeout(callback
, 10);
29 exception_error("catchup_callback2", e
, transport
);
33 function headlines_callback2(transport
, feed_cur_page
) {
36 if (!handle_rpc_reply(transport
)) return;
38 loading_set_progress(100);
40 console
.log("headlines_callback2 [page=" + feed_cur_page
+ "]");
42 if (!transport_error_check(transport
)) return;
47 if (transport
.responseXML
) {
48 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
50 is_cat
= headlines
.getAttribute("is_cat");
51 feed_id
= headlines
.getAttribute("id");
52 setActiveFeedId(feed_id
, is_cat
);
56 var update_btn
= document
.forms
["main_toolbar_form"].update
;
58 update_btn
.disabled
= !(feed_id
>= 0 && !is_cat
);
61 if (feed_cur_page
== 0) {
62 $("headlines-frame").scrollTop
= 0;
66 if (transport
.responseXML
) {
67 var response
= transport
.responseXML
;
69 var headlines
= response
.getElementsByTagName("headlines")[0];
71 var headlines_content
= headlines
.getElementsByTagName("content")[0];
72 var headlines_toolbar
= headlines
.getElementsByTagName("toolbar")[0];
74 var headlines_info
= response
.getElementsByTagName("headlines-info")[0];
77 headlines_info
= JSON
.parse(headlines_info
.firstChild
.nodeValue
);
79 console
.error("didn't find headlines-info object in response");
83 var headlines_count
= headlines_info
.count
;
84 var headlines_unread
= headlines_info
.unread
;
85 var disable_cache
= headlines_info
.disable_cache
;
87 vgroup_last_feed
= headlines_info
.vgroup_last_feed
;
89 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
90 _infscroll_disable
= 1;
92 _infscroll_disable
= 0;
95 var counters
= response
.getElementsByTagName("counters")[0];
96 var articles
= response
.getElementsByTagName("article");
97 var runtime_info
= response
.getElementsByTagName("runtime-info");
99 if (feed_cur_page
== 0) {
101 $("headlinesInnerContainer").innerHTML
= headlines_content
.firstChild
.nodeValue
;
102 $("headlines-toolbar").innerHTML
= headlines_toolbar
.firstChild
.nodeValue
;
104 dojo
.parser
.parse("headlines-toolbar");
105 //dijit.byId("main").resize();
107 var cache_prefix
= "";
115 cache_invalidate(cache_prefix
+ feed_id
);
117 if (!disable_cache
) {
118 cache_inject(cache_prefix
+ feed_id
,
119 $("headlines-frame").innerHTML
, headlines_unread
);
123 console
.warn("headlines_callback: returned no data");
124 $('headlinesInnerContainer').innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
129 if (headlines_count
> 0) {
130 console
.log("adding some more headlines...");
132 c
= $("headlinesInnerContainer");
134 var ids
= getSelectedArticleIds2();
136 c
.innerHTML
= c
.innerHTML
+ headlines_content
.firstChild
.nodeValue
;
138 console
.log("restore selected ids: " + ids
);
140 for (var i
= 0; i
< ids
.length
; i
++) {
141 markHeadline(ids
[i
]);
145 console
.log("no new headlines received");
148 console
.warn("headlines_callback: returned no data");
149 notify_error("Error while trying to load more headlines");
155 for (var i
= 0; i
< articles
.length
; i
++) {
156 var a_id
= articles
[i
].getAttribute("id");
157 //console.log("found id: " + a_id);
158 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
161 console
.log("no cached articles received");
165 parse_counters(counters
);
170 parse_runtime_info(runtime_info
[0]);
174 console
.warn("headlines_callback: returned no XML object");
175 $('headlinesInnerContainer').innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
179 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
182 getActiveFeedId() != -3 &&
183 getInitParam("cdm_auto_catchup") == 1) {
184 console
.log("starting CDM watchdog");
185 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
186 _cdm_wd_vishist
= new Array();
188 console
.log("not in CDM mode or watchdog disabled");
191 _feed_cur_page
= feed_cur_page
;
192 _infscroll_request_sent
= 0;
199 exception_error("headlines_callback2", e
, transport
);
203 function render_article(article
) {
205 dijit
.byId("headlines-wrap-inner").addChild(
206 dijit
.byId("content-insert"));
208 var c
= $("content-insert");
214 c
.innerHTML
= article
;
216 correctHeadlinesOffset(getActiveArticleId());
219 exception_error("render_article", e
);
223 function showArticleInHeadlines(id
) {
227 selectArticles("none");
229 var crow
= $("RROW-" + id
);
233 var article_is_unread
= crow
.hasClassName("Unread");
235 crow
.removeClassName("Unread");
237 selectArticles('none');
239 var upd_img_pic
= $("FUPDPIC-" + id
);
241 var cache_prefix
= "";
243 if (activeFeedIsCat()) {
249 var view_mode
= false;
252 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
253 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
258 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
259 upd_img_pic
.src
.match("fresh_sign.png"))) {
261 upd_img_pic
.src
= "images/blank_icon.gif";
263 cache_invalidate(cache_prefix
+ getActiveFeedId());
265 cache_inject(cache_prefix
+ getActiveFeedId(),
266 $("headlines-frame").innerHTML
,
267 getFeedUnread(getActiveFeedId()));
269 } else if (article_is_unread
&& view_mode
== "all_articles") {
271 cache_invalidate(cache_prefix
+ getActiveFeedId());
273 cache_inject(cache_prefix
+ getActiveFeedId(),
274 $("headlines-frame").innerHTML
,
275 getFeedUnread(getActiveFeedId())-1);
277 } else if (article_is_unread
) {
278 cache_invalidate(cache_prefix
+ getActiveFeedId());
283 if (article_is_unread
)
284 _force_scheduled_update
= true;
287 exception_error("showArticleInHeadlines", e
);
291 function article_callback2(transport
, id
) {
293 console
.log("article_callback2 " + id
);
295 if (!handle_rpc_reply(transport
)) return;
297 if (transport
.responseXML
) {
299 if (!transport_error_check(transport
)) return;
301 var upic
= $('FUPDPIC-' + id
);
304 upic
.src
= 'images/blank_icon.gif';
307 if (id
!= last_requested_article
) {
308 console
.log("requested article id is out of sequence, aborting");
312 // active_post_id = id;
314 //console.log("looking for articles to cache...");
316 var articles
= transport
.responseXML
.getElementsByTagName("article");
318 for (var i
= 0; i
< articles
.length
; i
++) {
319 var a_id
= articles
[i
].getAttribute("id");
321 //console.log("found id: " + a_id);
323 if (a_id
== active_post_id
) {
324 //console.log("active article, rendering...");
325 render_article(articles
[i
].firstChild
.nodeValue
);
328 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
332 // showArticleInHeadlines(id);
334 var reply
= transport
.responseXML
.firstChild
.firstChild
;
337 console
.warn("article_callback: returned no XML object");
338 //var f = $("content-frame");
339 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
342 var date
= new Date();
343 last_article_view
= date
.getTime() / 1000;
349 exception_error("article_callback2", e
, transport
);
355 console
.log("loading article: " + id
);
357 var cached_article
= cache_find(id
);
359 console
.log("cache check result: " + (cached_article
!= false));
364 var query
= "?op=view&id=" + param_escape(id
);
366 var neighbor_ids
= getRelativePostIds(active_post_id
);
368 /* only request uncached articles */
370 var cids_to_request
= Array();
372 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
373 if (!cache_check(neighbor_ids
[i
])) {
374 cids_to_request
.push(neighbor_ids
[i
]);
378 console
.log("additional ids: " + cids_to_request
.toString());
380 query
= query
+ "&cids=" + cids_to_request
.toString();
382 var crow
= $("RROW-" + id
);
383 var article_is_unread
= crow
.hasClassName("Unread");
386 showArticleInHeadlines(id
);
388 if (!cached_article
) {
390 var upic
= $('FUPDPIC-' + id
);
393 upic
.src
= getInitParam("sign_progress");
396 } else if (cached_article
&& article_is_unread
) {
398 query
= query
+ "&mode=prefetch";
400 render_article(cached_article
);
402 } else if (cached_article
) {
404 query
= query
+ "&mode=prefetch_old";
405 render_article(cached_article
);
411 last_requested_article
= id
;
413 new Ajax
.Request("backend.php", {
415 onComplete: function(transport
) {
416 article_callback2(transport
, id
);
422 exception_error("view", e
);
427 return toggleMark(id
);
431 return togglePub(id
);
434 function toggleMark(id
, client_only
) {
436 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
438 var img
= $("FMPIC-" + id
);
442 if (img
.src
.match("mark_unset")) {
443 img
.src
= img
.src
.replace("mark_unset", "mark_set");
444 img
.alt
= __("Unstar article");
445 query
= query
+ "&mark=1";
448 img
.src
= img
.src
.replace("mark_set", "mark_unset");
449 img
.alt
= __("Star article");
450 query
= query
+ "&mark=0";
454 new Ajax
.Request("backend.php", {
456 onComplete: function(transport
) {
457 handle_rpc_reply(transport
);
462 exception_error("toggleMark", e
);
466 function togglePub(id
, client_only
, no_effects
, note
) {
468 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
470 if (note
!= undefined) {
471 query
= query
+ "¬e=" + param_escape(note
);
473 query
= query
+ "¬e=undefined";
476 var img
= $("FPPIC-" + id
);
480 if (img
.src
.match("pub_unset") || note
!= undefined) {
481 img
.src
= img
.src
.replace("pub_unset", "pub_set");
482 img
.alt
= __("Unpublish article");
483 query
= query
+ "&pub=1";
486 img
.src
= img
.src
.replace("pub_set", "pub_unset");
487 img
.alt
= __("Publish article");
489 query
= query
+ "&pub=0";
493 new Ajax
.Request("backend.php", {
495 onComplete: function(transport
) {
496 handle_rpc_reply(transport
);
498 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
501 var note_id
= note
.getAttribute("id");
502 var note_size
= note
.getAttribute("size");
503 var note_content
= note
.firstChild
.nodeValue
;
505 var container
= $('POSTNOTE-' + note_id
);
507 cache_invalidate(note_id
);
510 if (note_size
== "0") {
511 Element
.hide(container
);
513 container
.innerHTML
= note_content
;
514 Element
.show(container
);
523 exception_error("togglePub", e
);
527 function moveToPost(mode
) {
531 var rows
= getVisibleArticleIds();
536 if (!$('RROW-' + active_post_id
)) {
537 active_post_id
= false;
540 if (active_post_id
== false) {
541 next_id
= getFirstVisibleHeadlineId();
542 prev_id
= getLastVisibleHeadlineId();
544 for (var i
= 0; i
< rows
.length
; i
++) {
545 if (rows
[i
] == active_post_id
) {
552 if (mode
== "next") {
556 cdmExpandArticle(next_id
);
557 cdmScrollToArticleId(next_id
);
560 correctHeadlinesOffset(next_id
);
561 view(next_id
, getActiveFeedId());
566 if (mode
== "prev") {
569 cdmExpandArticle(prev_id
);
570 cdmScrollToArticleId(prev_id
);
572 correctHeadlinesOffset(prev_id
);
573 view(prev_id
, getActiveFeedId());
579 exception_error("moveToPost", e
);
583 function toggleSelected(id
, force_on
) {
586 var cb
= $("RCHK-" + id
);
587 var row
= $("RROW-" + id
);
590 if (row
.hasClassName('Selected') && !force_on
) {
591 row
.removeClassName('Selected');
592 if (cb
) cb
.checked
= false;
594 row
.addClassName('Selected');
595 if (cb
) cb
.checked
= true;
599 exception_error("toggleSelected", e
);
603 function toggleUnread_afh(effect
) {
606 var elem
= effect
.element
;
607 elem
.style
.backgroundColor
= "";
610 exception_error("toggleUnread_afh", e
);
614 function toggleUnread(id
, cmode
, effect
) {
617 var row
= $("RROW-" + id
);
619 if (cmode
== undefined || cmode
== 2) {
620 if (row
.hasClassName("Unread")) {
621 row
.removeClassName("Unread");
624 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
625 afterFinish
: toggleUnread_afh
,
626 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
630 row
.addClassName("Unread");
633 } else if (cmode
== 0) {
635 row
.removeClassName("Unread");
638 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
639 afterFinish
: toggleUnread_afh
,
640 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
643 } else if (cmode
== 1) {
644 row
.addClassName("Unread");
647 if (cmode
== undefined) cmode
= 2;
649 var query
= "?op=rpc&subop=catchupSelected" +
650 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
652 // notify_progress("Loading, please wait...");
654 new Ajax
.Request("backend.php", {
656 onComplete: function(transport
) {
657 handle_rpc_reply(transport
);
663 exception_error("toggleUnread", e
);
667 function selectionRemoveLabel(id
) {
670 var ids
= getSelectedArticleIds2();
672 if (ids
.length
== 0) {
673 alert(__("No articles are selected."));
677 // var ok = confirm(__("Remove selected articles from label?"));
681 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
682 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
686 // notify_progress("Loading, please wait...");
688 cache_invalidate("F:" + (-11 - id
));
690 new Ajax
.Request("backend.php", {
692 onComplete: function(transport
) {
693 show_labels_in_headlines(transport
);
694 handle_rpc_reply(transport
);
700 exception_error("selectionAssignLabel", e
);
705 function selectionAssignLabel(id
) {
708 var ids
= getSelectedArticleIds2();
710 if (ids
.length
== 0) {
711 alert(__("No articles are selected."));
715 // var ok = confirm(__("Assign selected articles to label?"));
719 cache_invalidate("F:" + (-11 - id
));
721 var query
= "?op=rpc&subop=assignToLabel&ids=" +
722 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
726 // notify_progress("Loading, please wait...");
728 new Ajax
.Request("backend.php", {
730 onComplete: function(transport
) {
731 show_labels_in_headlines(transport
);
732 handle_rpc_reply(transport
);
738 exception_error("selectionAssignLabel", e
);
743 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
745 var rows
= getSelectedArticleIds2();
747 if (rows
.length
== 0 && !no_error
) {
748 alert(__("No articles are selected."));
752 for (i
= 0; i
< rows
.length
; i
++) {
753 var row
= $("RROW-" + rows
[i
]);
755 if (set_state
== undefined) {
756 if (row
.hasClassName("Unread")) {
757 row
.removeClassName("Unread");
759 row
.addClassName("Unread");
763 if (set_state
== false) {
764 row
.removeClassName("Unread");
767 if (set_state
== true) {
768 row
.addClassName("Unread");
773 if (rows
.length
> 0) {
777 if (set_state
== undefined) {
779 } else if (set_state
== true) {
781 } else if (set_state
== false) {
785 var query
= "?op=rpc&subop=catchupSelected" +
786 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
788 notify_progress("Loading, please wait...");
790 new Ajax
.Request("backend.php", {
792 onComplete: function(transport
) {
793 catchup_callback2(transport
, callback_func
);
799 exception_error("selectionToggleUnread", e
);
803 function selectionToggleMarked() {
806 var rows
= getSelectedArticleIds2();
808 if (rows
.length
== 0) {
809 alert(__("No articles are selected."));
813 for (i
= 0; i
< rows
.length
; i
++) {
814 toggleMark(rows
[i
], true, true);
817 if (rows
.length
> 0) {
819 var query
= "?op=rpc&subop=markSelected&ids=" +
820 param_escape(rows
.toString()) + "&cmode=2";
822 new Ajax
.Request("backend.php", {
824 onComplete: function(transport
) {
825 handle_rpc_reply(transport
);
831 exception_error("selectionToggleMarked", e
);
835 function selectionTogglePublished() {
838 var rows
= getSelectedArticleIds2();
840 if (rows
.length
== 0) {
841 alert(__("No articles are selected."));
845 for (i
= 0; i
< rows
.length
; i
++) {
846 togglePub(rows
[i
], true, true);
849 if (rows
.length
> 0) {
851 var query
= "?op=rpc&subop=publishSelected&ids=" +
852 param_escape(rows
.toString()) + "&cmode=2";
854 new Ajax
.Request("backend.php", {
856 onComplete: function(transport
) {
857 handle_rpc_reply(transport
);
863 exception_error("selectionToggleMarked", e
);
867 function getSelectedArticleIds2() {
871 $$("#headlinesInnerContainer > div[id*=RROW][class*=Selected]").each(
873 rv
.push(child
.id
.replace("RROW-", ""));
879 function getLoadedArticleIds() {
882 var children
= $$("#headlinesInnerContainer > div[id*=RROW-]");
884 children
.each(function(child
) {
885 rv
.push(child
.id
.replace("RROW-", ""));
892 // mode = all,none,unread,invert
893 function selectArticles(mode
) {
896 var children
= $$("#headlinesInnerContainer > div[id*=RROW]");
898 children
.each(function(child
) {
899 var id
= child
.id
.replace("RROW-", "");
900 var cb
= $("RCHK-" + id
);
903 child
.addClassName("Selected");
905 } else if (mode
== "unread") {
906 if (child
.hasClassName("Unread")) {
907 child
.addClassName("Selected");
910 child
.removeClassName("Selected");
913 } else if (mode
== "invert") {
914 if (child
.hasClassName("Selected")) {
915 child
.removeClassName("Selected");
918 child
.addClassName("Selected");
923 child
.removeClassName("Selected");
929 exception_error("selectArticles", e
);
933 function catchupPage() {
935 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
937 var str
= __("Mark all visible articles in %s as read?");
939 str
= str
.replace("%s", fn
);
941 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
945 selectArticles('all');
946 selectionToggleUnread(false, 'viewCurrentFeed()', true)
947 selectArticles('none');
950 function deleteSelection() {
954 var rows
= getSelectedArticleIds2();
956 if (rows
.length
== 0) {
957 alert(__("No articles are selected."));
961 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
965 if (getActiveFeedId() != 0) {
966 str
= __("Delete %d selected articles in %s?");
968 str
= __("Delete %d selected articles?");
971 str
= str
.replace("%d", rows
.length
);
972 str
= str
.replace("%s", fn
);
974 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
978 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
982 new Ajax
.Request("backend.php", {
984 onComplete: function(transport
) {
989 exception_error("deleteSelection", e
);
993 function archiveSelection() {
997 var rows
= getSelectedArticleIds2();
999 if (rows
.length
== 0) {
1000 alert(__("No articles are selected."));
1004 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1008 if (getActiveFeedId() != 0) {
1009 str
= __("Archive %d selected articles in %s?");
1012 str
= __("Move %d archived articles back?");
1016 str
= str
.replace("%d", rows
.length
);
1017 str
= str
.replace("%s", fn
);
1019 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1023 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1027 for (var i
= 0; i
< rows
.length
; i
++) {
1028 cache_invalidate(rows
[i
]);
1031 new Ajax
.Request("backend.php", {
1033 onComplete: function(transport
) {
1038 exception_error("archiveSelection", e
);
1042 function catchupSelection() {
1046 var rows
= getSelectedArticleIds2();
1048 if (rows
.length
== 0) {
1049 alert(__("No articles are selected."));
1053 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1055 var str
= __("Mark %d selected articles in %s as read?");
1057 str
= str
.replace("%d", rows
.length
);
1058 str
= str
.replace("%s", fn
);
1060 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1064 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1067 exception_error("catchupSelection", e
);
1071 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1072 displayDlg('editArticleTags', id
,
1074 $("tags_str").focus();
1076 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1077 "backend.php?op=rpc&subop=completeTags",
1078 { tokens
: ',', paramName
: "search" });
1082 function editTagsSave() {
1084 notify_progress("Saving article tags...");
1086 var form
= document
.forms
["tag_edit_form"];
1088 var query
= Form
.serialize("tag_edit_form");
1090 query
= "?op=rpc&subop=setArticleTags&" + query
;
1094 new Ajax
.Request("backend.php", {
1096 onComplete: function(transport
) {
1098 //console.log("tags saved...");
1103 if (transport
.responseXML
) {
1104 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1107 var id
= tags_str
.getAttribute("id");
1110 var tags
= $("ATSTR-" + id
);
1112 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1115 cache_invalidate(id
);
1121 exception_error("editTagsSave", e
);
1126 function editTagsInsert() {
1129 var form
= document
.forms
["tag_edit_form"];
1131 var found_tags
= form
.found_tags
;
1132 var tags_str
= form
.tags_str
;
1134 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1136 if (tags_str
.value
.length
> 0 &&
1137 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1139 tags_str
.value
= tags_str
.value
+ ", ";
1142 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1144 found_tags
.selectedIndex
= 0;
1147 exception_error("editTagsInsert", e
);
1151 function cdmScrollToArticleId(id
) {
1153 var ctr
= $("headlines-frame");
1154 var e
= $("RROW-" + id
);
1156 if (!e
|| !ctr
) return;
1158 ctr
.scrollTop
= e
.offsetTop
;
1161 exception_error("cdmScrollToArticleId", e
);
1165 function cdmWatchdog() {
1169 var ctr
= $("headlinesInnerContainer");
1173 var ids
= new Array();
1175 var e
= ctr
.firstChild
;
1178 if (e
.className
&& e
.hasClassName("Unread") && e
.id
&&
1179 e
.id
.match("RROW-")) {
1181 // article fits in viewport OR article is longer than viewport and
1182 // its bottom is visible
1184 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1185 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1187 // console.log(e.id + " is visible " + e.offsetTop + "." +
1188 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1189 // (ctr.scrollTop + ctr.offsetHeight));
1191 ids
.push(e
.id
.replace("RROW-", ""));
1193 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1194 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1195 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1197 ids
.push(e
.id
.replace("RROW-", ""));
1201 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1203 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1204 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1206 ids.push(e.id.replace("RROW-", ""));
1215 console
.log("cdmWatchdog, ids= " + ids
.toString());
1217 if (ids
.length
> 0) {
1219 for (var i
= 0; i
< ids
.length
; i
++) {
1220 var e
= $("RROW-" + ids
[i
]);
1222 e
.removeClassName("Unread");
1226 var query
= "?op=rpc&subop=catchupSelected" +
1227 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1229 new Ajax
.Request("backend.php", {
1231 onComplete: function(transport
) {
1232 handle_rpc_reply(transport
);
1237 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1240 exception_error("cdmWatchdog", e
);
1246 function cache_inject(id
, article
, param
) {
1249 if (!cache_check_param(id
, param
)) {
1250 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1252 var date
= new Date();
1253 var ts
= Math
.round(date
.getTime() / 1000);
1257 cache_obj
["id"] = id
;
1258 cache_obj
["data"] = article
;
1259 cache_obj
["param"] = param
;
1261 if (param
) id
= id
+ ":" + param
;
1263 cache_added
["TS:" + id
] = ts
;
1265 if (has_local_storage())
1266 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1268 article_cache
.push(cache_obj
);
1271 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1274 exception_error("cache_inject", e
);
1278 function cache_find(id
) {
1280 if (has_local_storage()) {
1281 var cache_obj
= localStorage
.getItem(id
);
1284 cache_obj
= JSON
.parse(cache_obj
);
1287 return cache_obj
['data'];
1291 for (var i
= 0; i
< article_cache
.length
; i
++) {
1292 if (article_cache
[i
]["id"] == id
) {
1293 return article_cache
[i
]["data"];
1300 function cache_find_param(id
, param
) {
1302 if (has_local_storage()) {
1304 if (param
) id
= id
+ ":" + param
;
1306 var cache_obj
= localStorage
.getItem(id
);
1309 cache_obj
= JSON
.parse(cache_obj
);
1312 return cache_obj
['data'];
1316 for (var i
= 0; i
< article_cache
.length
; i
++) {
1317 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1318 return article_cache
[i
]["data"];
1326 function cache_check(id
) {
1327 if (has_local_storage()) {
1328 if (localStorage
.getItem(id
))
1331 for (var i
= 0; i
< article_cache
.length
; i
++) {
1332 if (article_cache
[i
]["id"] == id
) {
1340 function cache_check_param(id
, param
) {
1341 if (has_local_storage()) {
1343 if (param
) id
= id
+ ":" + param
;
1345 if (localStorage
.getItem(id
))
1349 for (var i
= 0; i
< article_cache
.length
; i
++) {
1350 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1358 function cache_expire() {
1359 if (has_local_storage()) {
1361 var date
= new Date();
1362 var timestamp
= Math
.round(date
.getTime() / 1000);
1364 for (var i
= 0; i
< localStorage
.length
; i
++) {
1366 var id
= localStorage
.key(i
);
1368 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1369 localStorage
.removeItem(id
);
1374 while (article_cache
.length
> 25) {
1375 article_cache
.shift();
1380 function cache_flush() {
1381 if (has_local_storage()) {
1382 localStorage
.clear();
1384 article_cache
= new Array();
1388 function cache_invalidate(id
) {
1390 if (has_local_storage()) {
1394 for (var i
= 0; i
< localStorage
.length
; i
++) {
1395 var key
= localStorage
.key(i
);
1397 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1399 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1400 localStorage
.removeItem(key
);
1411 while (i
< article_cache
.length
) {
1412 if (article_cache
[i
]["id"] == id
) {
1413 //console.log("cache_invalidate: removed id " + id);
1414 article_cache
.splice(i
, 1);
1421 //console.log("cache_invalidate: id not found: " + id);
1424 exception_error("cache_invalidate", e
);
1428 function getActiveArticleId() {
1429 return active_post_id
;
1432 function preloadBatchedArticles() {
1435 var query
= "?op=rpc&subop=getArticles&ids=" +
1436 preload_id_batch
.toString();
1438 new Ajax
.Request("backend.php", {
1440 onComplete: function(transport
) {
1442 preload_id_batch
= [];
1444 var articles
= transport
.responseXML
.getElementsByTagName("article");
1446 for (var i
= 0; i
< articles
.length
; i
++) {
1447 var id
= articles
[i
].getAttribute("id");
1448 if (!cache_check(id
)) {
1449 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1450 console
.log("preloaded article: " + id
);
1456 exception_error("preloadBatchedArticles", e
);
1460 function preloadArticleUnderPointer(id
) {
1462 if (getInitParam("bw_limit") == "1") return;
1464 if (post_under_pointer
== id
&& !cache_check(id
)) {
1466 console
.log("trying to preload article " + id
);
1468 var neighbor_ids
= getRelativePostIds(id
, 1);
1470 /* only request uncached articles */
1472 if (preload_id_batch
.indexOf(id
) == -1) {
1473 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1474 if (!cache_check(neighbor_ids
[i
])) {
1475 preload_id_batch
.push(neighbor_ids
[i
]);
1480 if (preload_id_batch
.indexOf(id
) == -1)
1481 preload_id_batch
.push(id
);
1483 //console.log("preload ids batch: " + preload_id_batch.toString());
1485 window
.clearTimeout(preload_timeout_id
);
1486 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1490 exception_error("preloadArticleUnderPointer", e
);
1494 function postMouseIn(id
) {
1496 if (post_under_pointer
!= id
) {
1497 post_under_pointer
= id
;
1499 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1504 exception_error("postMouseIn", e
);
1508 function postMouseOut(id
) {
1510 post_under_pointer
= false;
1512 exception_error("postMouseOut", e
);
1516 function headlines_scroll_handler(e
) {
1519 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1520 if (!_infscroll_disable
) {
1526 exception_error("headlines_scroll_handler", e
);
1530 function catchupRelativeToArticle(below
) {
1535 if (!getActiveArticleId()) {
1536 alert(__("No article is selected."));
1540 var visible_ids
= getVisibleArticleIds();
1542 var ids_to_mark
= new Array();
1545 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1546 if (visible_ids
[i
] != getActiveArticleId()) {
1547 var e
= $("RROW-" + visible_ids
[i
]);
1549 if (e
&& e
.hasClassName("Unread")) {
1550 ids_to_mark
.push(visible_ids
[i
]);
1557 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1558 if (visible_ids
[i
] != getActiveArticleId()) {
1559 var e
= $("RROW-" + visible_ids
[i
]);
1561 if (e
&& e
.hasClassName("Unread")) {
1562 ids_to_mark
.push(visible_ids
[i
]);
1570 if (ids_to_mark
.length
== 0) {
1571 alert(__("No articles found to mark"));
1573 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1575 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1577 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1578 var e
= $("RROW-" + ids_to_mark
[i
]);
1579 e
.removeClassName("Unread");
1582 var query
= "?op=rpc&subop=catchupSelected" +
1583 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1585 new Ajax
.Request("backend.php", {
1587 onComplete: function(transport
) {
1588 catchup_callback2(transport
);
1595 exception_error("catchupRelativeToArticle", e
);
1599 function cdmExpandArticle(id
) {
1604 var elem
= $("CICD-" + active_post_id
);
1606 var upd_img_pic
= $("FUPDPIC-" + id
);
1608 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1609 upd_img_pic
.src
.match("fresh_sign.png"))) {
1611 upd_img_pic
.src
= "images/blank_icon.gif";
1614 if (id
== active_post_id
&& Element
.visible(elem
))
1617 selectArticles("none");
1619 var old_offset
= $("RROW-" + id
).offsetTop
;
1621 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1623 Element
.show("CEXC-" + active_post_id
);
1626 active_post_id
= id
;
1628 elem
= $("CICD-" + id
);
1630 if (!Element
.visible(elem
)) {
1632 Element
.hide("CEXC-" + id
);
1634 if ($("CWRAP-" + id
).innerHTML
== "") {
1636 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1638 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1639 __("Loading, please wait...") + "</div>";
1641 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1643 //console.log(query);
1645 new Ajax
.Request("backend.php", {
1647 onComplete: function(transport
) {
1648 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1650 if (transport
.responseXML
) {
1651 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1652 var recv_id
= article
.getAttribute("id");
1655 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1658 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1666 var new_offset
= $("RROW-" + id
).offsetTop
;
1668 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1670 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1671 $("headlines-frame").scrollTop
= new_offset
;
1673 toggleUnread(id
, 0, true);
1677 exception_error("cdmExpandArticle", e
);
1683 function fixHeadlinesOrder(ids
) {
1685 for (var i
= 0; i
< ids
.length
; i
++) {
1686 var e
= $("RROW-" + ids
[i
]);
1690 e
.removeClassName("even");
1691 e
.addClassName("odd");
1693 e
.removeClassName("odd");
1694 e
.addClassName("even");
1699 exception_error("fixHeadlinesOrder", e
);
1703 function getArticleUnderPointer() {
1704 return post_under_pointer
;
1707 function zoomToArticle(event
, id
) {
1709 var cached_article
= cache_find(id
);
1711 if (dijit
.byId("ATAB-" + id
))
1712 if (!event
|| !event
.shiftKey
)
1713 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1715 if (cached_article
) {
1716 closeArticlePanel();
1718 var article_pane
= new dijit
.layout
.ContentPane({
1719 title
: __("Loading...") , content
: cached_article
,
1720 style
: 'padding : 0px;',
1724 dijit
.byId("content-tabs").addChild(article_pane
);
1726 if (!event
|| !event
.shiftKey
)
1727 dijit
.byId("content-tabs").selectChild(article_pane
);
1729 if ($("PTITLE-" + id
))
1730 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1734 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1736 notify_progress("Loading, please wait...", true);
1738 new Ajax
.Request("backend.php", {
1740 onComplete: function(transport
) {
1743 if (transport
.responseXML
) {
1744 closeArticlePanel();
1746 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1747 var content
= article
.firstChild
.nodeValue
;
1749 var article_pane
= new dijit
.layout
.ContentPane({
1750 title
: "article-" + id
, content
: content
,
1751 style
: 'padding : 0px;',
1755 dijit
.byId("content-tabs").addChild(article_pane
);
1757 if (!event
|| !event
.shiftKey
)
1758 dijit
.byId("content-tabs").selectChild(article_pane
);
1760 if ($("PTITLE-" + id
))
1761 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1768 exception_error("zoomToArticle", e
);
1772 function scrollArticle(offset
) {
1775 var ci
= $("content-insert");
1777 ci
.scrollTop
+= offset
;
1780 var hi
= $("headlinesInnerContainer");
1782 hi
.scrollTop
+= offset
;
1787 exception_error("scrollArticle", e
);
1791 function show_labels_in_headlines(transport
) {
1793 if (transport
.responseXML
) {
1794 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1796 var elems
= info
.getElementsByTagName("entry");
1798 for (var l
= 0; l
< elems
.length
; l
++) {
1799 var e_id
= elems
[l
].getAttribute("id");
1803 var ctr
= $("HLLCTR-" + e_id
);
1806 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1814 exception_error("show_labels_in_headlines", e
);
1819 function toggleHeadlineActions() {
1821 var e
= $("headlineActionsBody");
1822 var p
= $("headlineActionsDrop");
1824 if (!Element
.visible(e
)) {
1831 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1832 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1835 exception_error("toggleHeadlineActions", e
);
1839 function publishWithNote(id
, def_note
) {
1841 if (!def_note
) def_note
= '';
1843 var note
= prompt(__("Please enter a note for this article:"), def_note
);
1845 if (note
!= undefined) {
1846 togglePub(id
, false, false, note
);
1850 exception_error("publishWithNote", e
);
1854 function emailArticle(id
) {
1857 var ids
= getSelectedArticleIds2();
1859 if (ids
.length
== 0) {
1860 alert(__("No articles are selected."));
1864 id
= ids
.toString();
1867 displayDlg('emailArticle', id
,
1869 document
.forms
['article_email_form'].destination
.focus();
1871 new Ajax
.Autocompleter('destination', 'destination_choices',
1872 "backend.php?op=rpc&subop=completeEmails",
1873 { tokens
: '', paramName
: "search" });
1878 exception_error("emailArticle", e
);
1882 function emailArticleDo() {
1884 var f
= document
.forms
['article_email_form'];
1886 if (f
.destination
.value
== "") {
1887 alert("Please fill in the destination email.");
1891 if (f
.subject
.value
== "") {
1892 alert("Please fill in the subject.");
1896 var query
= Form
.serialize("article_email_form");
1898 // console.log(query);
1900 new Ajax
.Request("backend.php", {
1902 onComplete: function(transport
) {
1905 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
1908 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
1910 notify_info('Your message has been sent.');
1915 exception_error("sendEmailDo", e
);
1921 exception_error("emailArticleDo", e
);
1925 function dismissArticle(id
) {
1927 var elem
= $("RROW-" + id
);
1929 toggleUnread(id
, 0, true);
1931 new Effect
.Fade(elem
, {duration
: 0.5});
1933 active_post_id
= false;
1936 exception_error("dismissArticle", e
);
1940 function dismissSelectedArticles() {
1943 var ids
= getVisibleArticleIds();
1947 for (var i
= 0; i
< ids
.length
; i
++) {
1948 var elem
= $("RROW-" + ids
[i
]);
1950 if (elem
.className
&& elem
.hasClassName("Selected") &&
1951 ids
[i
] != active_post_id
) {
1952 new Effect
.Fade(elem
, {duration
: 0.5});
1960 selectionToggleUnread(false);
1962 fixHeadlinesOrder(tmp
);
1965 exception_error("dismissSelectedArticles", e
);
1969 function dismissReadArticles() {
1972 var ids
= getVisibleArticleIds();
1975 for (var i
= 0; i
< ids
.length
; i
++) {
1976 var elem
= $("RROW-" + ids
[i
]);
1978 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1979 !elem
.hasClassName("Selected")) {
1981 new Effect
.Fade(elem
, {duration
: 0.5});
1987 fixHeadlinesOrder(tmp
);
1990 exception_error("dismissSelectedArticles", e
);
1994 function getVisibleArticleIds() {
1999 getLoadedArticleIds().each(function(id
) {
2000 var elem
= $("RROW-" + id
);
2001 if (elem
&& Element
.visible(elem
))
2006 exception_error("getVisibleArticleIds", e
);
2012 function cdmClicked(event
, id
) {
2014 var shift_key
= event
.shiftKey
;
2018 if (!event
.ctrlKey
) {
2020 if (!getInitParam("cdm_expanded")) {
2021 return cdmExpandArticle(id
);
2024 selectArticles("none");
2027 var elem
= $("RROW-" + id
);
2030 elem
.removeClassName("Unread");
2032 var upd_img_pic
= $("FUPDPIC-" + id
);
2034 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2035 upd_img_pic
.src
.match("fresh_sign.png"))) {
2037 upd_img_pic
.src
= "images/blank_icon.gif";
2040 active_post_id
= id
;
2042 var query
= "?op=rpc&subop=catchupSelected" +
2043 "&cmode=0&ids=" + param_escape(id
);
2045 new Ajax
.Request("backend.php", {
2047 onComplete: function(transport
) {
2048 handle_rpc_reply(transport
);
2053 toggleSelected(id
, true);
2054 toggleUnread(id
, 0, false);
2055 zoomToArticle(event
, id
);
2059 exception_error("cdmClicked");
2065 function postClicked(event
, id
) {
2068 if (!event
.ctrlKey
) {
2071 zoomToArticle(event
, id
);
2076 exception_error("postClicked");
2080 function hlClicked(event
, id
) {
2083 if (!event
.ctrlKey
) {
2087 selectArticles('none');
2089 toggleUnread(id
, 0, false);
2090 zoomToArticle(event
, id
);
2095 exception_error("hlClicked");
2099 function getFirstVisibleHeadlineId() {
2100 var rows
= getVisibleArticleIds();
2105 function getLastVisibleHeadlineId() {
2106 var rows
= getVisibleArticleIds();
2107 return rows
[rows
.length
-1];
2110 function openArticleInNewWindow(id
) {
2112 console
.log("openArticleInNewWindow: " + id
);
2114 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2115 var wname
= "ttrss_article_" + id
;
2117 console
.log(query
+ " " + wname
);
2119 var w
= window
.open("", wname
);
2121 if (!w
) notify_error("Failed to open window for the article");
2123 new Ajax
.Request("backend.php", {
2125 onComplete: function(transport
) {
2127 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2128 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2130 console
.log("open_article received link: " + link
);
2134 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2136 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2138 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2140 if (!w
) { notify_error("Failed to load article in new window"); }
2143 id
= id
.firstChild
.nodeValue
;
2144 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2147 notify_error("Can't open article: received invalid article link");
2152 exception_error("openArticleInNewWindow", e
);
2156 function isCdmMode() {
2157 return getInitParam("combined_display_mode");
2160 function markHeadline(id
) {
2161 var row
= $("RROW-" + id
);
2163 var check
= $("RCHK-" + id
);
2166 check
.checked
= true;
2169 row
.addClassName("Selected");
2173 function getRelativePostIds(id
, limit
) {
2179 if (!limit
) limit
= 3;
2181 var ids
= getVisibleArticleIds();
2183 for (var i
= 0; i
< ids
.length
; i
++) {
2185 for (var k
= 1; k
<= limit
; k
++) {
2186 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2187 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2194 exception_error("getRelativePostIds", e
);
2200 function correctHeadlinesOffset(id
) {
2204 var container
= $("headlines-frame");
2205 var row
= $("RROW-" + id
);
2207 var viewport
= container
.offsetHeight
;
2209 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2210 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2212 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2213 //console.log("Vport: " + viewport);
2215 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2216 container
.scrollTop
= row
.offsetTop
;
2217 } else if (rel_offset_bottom
> viewport
) {
2219 /* doesn't properly work with Opera in some cases because
2220 Opera fucks up element scrolling */
2222 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2226 exception_error("correctHeadlinesOffset", e
);
2231 function headlineActionsChange(elem
) {
2234 elem
.selectedIndex
= 0;
2236 exception_error("headlineActionsChange", e
);
2240 function closeArticlePanel() {
2242 var tabs
= dijit
.byId("content-tabs");
2243 var child
= tabs
.selectedChildWidget
;
2245 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
2246 tabs
.removeChild(child
);
2249 if (dijit
.byId("content-insert"))
2250 dijit
.byId("headlines-wrap-inner").removeChild(
2251 dijit
.byId("content-insert"));