]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
3914c757d9bee13fc60fd26b57a2b5b1d1dd9e6e
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(25);
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 dijit
.byId("headlines-frame").attr('content',
102 headlines_content
.firstChild
.nodeValue
);
104 dijit
.byId("headlines-toolbar").attr('content',
105 headlines_toolbar
.firstChild
.nodeValue
);
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 dijit
.byId("headlines-frame").attr('content',
125 "<div class='whiteBox'>" +
126 __('Could not update headlines (missing XML data)') + "</div>");
131 if (headlines_count
> 0) {
132 console
.log("adding some more headlines...");
134 var c
= dijit
.byId("headlines-frame");
135 var ids
= getSelectedArticleIds2();
137 c
.attr('content', c
.attr('content') +
138 headlines_content
.firstChild
.nodeValue
);
140 console
.log("restore selected ids: " + ids
);
142 for (var i
= 0; i
< ids
.length
; i
++) {
143 markHeadline(ids
[i
]);
147 console
.log("no new headlines received");
150 console
.warn("headlines_callback: returned no data");
151 notify_error("Error while trying to load more headlines");
157 for (var i
= 0; i
< articles
.length
; i
++) {
158 var a_id
= articles
[i
].getAttribute("id");
159 //console.log("found id: " + a_id);
160 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
163 console
.log("no cached articles received");
167 parse_counters(counters
);
172 parse_runtime_info(runtime_info
[0]);
176 console
.warn("headlines_callback: returned no XML object");
177 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
178 __('Could not update headlines (missing XML object)') + "</div>");
182 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
185 getActiveFeedId() != -3 &&
186 getInitParam("cdm_auto_catchup") == 1) {
187 console
.log("starting CDM watchdog");
188 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
189 _cdm_wd_vishist
= new Array();
191 console
.log("not in CDM mode or watchdog disabled");
194 _feed_cur_page
= feed_cur_page
;
195 _infscroll_request_sent
= 0;
200 exception_error("headlines_callback2", e
, transport
);
204 function render_article(article
) {
206 dijit
.byId("headlines-wrap-inner").addChild(
207 dijit
.byId("content-insert"));
209 var c
= $("content-insert");
215 c
.innerHTML
= article
;
217 correctHeadlinesOffset(getActiveArticleId());
220 exception_error("render_article", e
);
224 function showArticleInHeadlines(id
) {
228 selectArticles("none");
230 var crow
= $("RROW-" + id
);
234 var article_is_unread
= crow
.hasClassName("Unread");
236 crow
.removeClassName("Unread");
238 selectArticles('none');
240 var upd_img_pic
= $("FUPDPIC-" + id
);
242 var cache_prefix
= "";
244 if (activeFeedIsCat()) {
250 var view_mode
= false;
253 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
254 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
259 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
260 upd_img_pic
.src
.match("fresh_sign.png"))) {
262 upd_img_pic
.src
= "images/blank_icon.gif";
264 cache_invalidate(cache_prefix
+ getActiveFeedId());
266 cache_inject(cache_prefix
+ getActiveFeedId(),
267 $("headlines-frame").innerHTML
,
268 getFeedUnread(getActiveFeedId()));
270 } else if (article_is_unread
&& view_mode
== "all_articles") {
272 cache_invalidate(cache_prefix
+ getActiveFeedId());
274 cache_inject(cache_prefix
+ getActiveFeedId(),
275 $("headlines-frame").innerHTML
,
276 getFeedUnread(getActiveFeedId())-1);
278 } else if (article_is_unread
) {
279 cache_invalidate(cache_prefix
+ getActiveFeedId());
284 if (article_is_unread
)
285 _force_scheduled_update
= true;
288 exception_error("showArticleInHeadlines", e
);
292 function article_callback2(transport
, id
) {
294 console
.log("article_callback2 " + id
);
296 if (!handle_rpc_reply(transport
)) return;
298 if (transport
.responseXML
) {
300 if (!transport_error_check(transport
)) return;
302 var upic
= $('FUPDPIC-' + id
);
305 upic
.src
= 'images/blank_icon.gif';
308 if (id
!= last_requested_article
) {
309 console
.log("requested article id is out of sequence, aborting");
313 // active_post_id = id;
315 //console.log("looking for articles to cache...");
317 var articles
= transport
.responseXML
.getElementsByTagName("article");
319 for (var i
= 0; i
< articles
.length
; i
++) {
320 var a_id
= articles
[i
].getAttribute("id");
322 //console.log("found id: " + a_id);
324 if (a_id
== active_post_id
) {
325 //console.log("active article, rendering...");
326 render_article(articles
[i
].firstChild
.nodeValue
);
329 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
333 // showArticleInHeadlines(id);
335 var reply
= transport
.responseXML
.firstChild
.firstChild
;
338 console
.warn("article_callback: returned no XML object");
339 //var f = $("content-frame");
340 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
343 var date
= new Date();
344 last_article_view
= date
.getTime() / 1000;
350 exception_error("article_callback2", e
, transport
);
356 console
.log("loading article: " + id
);
358 var cached_article
= cache_find(id
);
360 console
.log("cache check result: " + (cached_article
!= false));
365 var query
= "?op=view&id=" + param_escape(id
);
367 var neighbor_ids
= getRelativePostIds(active_post_id
);
369 /* only request uncached articles */
371 var cids_to_request
= Array();
373 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
374 if (!cache_check(neighbor_ids
[i
])) {
375 cids_to_request
.push(neighbor_ids
[i
]);
379 console
.log("additional ids: " + cids_to_request
.toString());
381 query
= query
+ "&cids=" + cids_to_request
.toString();
383 var crow
= $("RROW-" + id
);
384 var article_is_unread
= crow
.hasClassName("Unread");
387 showArticleInHeadlines(id
);
389 if (!cached_article
) {
391 var upic
= $('FUPDPIC-' + id
);
394 upic
.src
= getInitParam("sign_progress");
397 } else if (cached_article
&& article_is_unread
) {
399 query
= query
+ "&mode=prefetch";
401 render_article(cached_article
);
403 } else if (cached_article
) {
405 query
= query
+ "&mode=prefetch_old";
406 render_article(cached_article
);
412 last_requested_article
= id
;
414 new Ajax
.Request("backend.php", {
416 onComplete: function(transport
) {
417 article_callback2(transport
, id
);
423 exception_error("view", e
);
428 return toggleMark(id
);
432 return togglePub(id
);
435 function toggleMark(id
, client_only
) {
437 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
439 var img
= $("FMPIC-" + id
);
443 if (img
.src
.match("mark_unset")) {
444 img
.src
= img
.src
.replace("mark_unset", "mark_set");
445 img
.alt
= __("Unstar article");
446 query
= query
+ "&mark=1";
449 img
.src
= img
.src
.replace("mark_set", "mark_unset");
450 img
.alt
= __("Star article");
451 query
= query
+ "&mark=0";
455 new Ajax
.Request("backend.php", {
457 onComplete: function(transport
) {
458 handle_rpc_reply(transport
);
463 exception_error("toggleMark", e
);
467 function togglePub(id
, client_only
, no_effects
, note
) {
469 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
471 if (note
!= undefined) {
472 query
= query
+ "¬e=" + param_escape(note
);
474 query
= query
+ "¬e=undefined";
477 var img
= $("FPPIC-" + id
);
481 if (img
.src
.match("pub_unset") || note
!= undefined) {
482 img
.src
= img
.src
.replace("pub_unset", "pub_set");
483 img
.alt
= __("Unpublish article");
484 query
= query
+ "&pub=1";
487 img
.src
= img
.src
.replace("pub_set", "pub_unset");
488 img
.alt
= __("Publish article");
490 query
= query
+ "&pub=0";
494 new Ajax
.Request("backend.php", {
496 onComplete: function(transport
) {
497 handle_rpc_reply(transport
);
499 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
502 var note_id
= note
.getAttribute("id");
503 var note_size
= note
.getAttribute("size");
504 var note_content
= note
.firstChild
.nodeValue
;
506 var container
= $('POSTNOTE-' + note_id
);
508 cache_invalidate(note_id
);
511 if (note_size
== "0") {
512 Element
.hide(container
);
514 container
.innerHTML
= note_content
;
515 Element
.show(container
);
524 exception_error("togglePub", e
);
528 function moveToPost(mode
) {
532 var rows
= getVisibleArticleIds();
537 if (!$('RROW-' + active_post_id
)) {
538 active_post_id
= false;
541 if (active_post_id
== false) {
542 next_id
= getFirstVisibleHeadlineId();
543 prev_id
= getLastVisibleHeadlineId();
545 for (var i
= 0; i
< rows
.length
; i
++) {
546 if (rows
[i
] == active_post_id
) {
553 if (mode
== "next") {
557 cdmExpandArticle(next_id
);
558 cdmScrollToArticleId(next_id
);
561 correctHeadlinesOffset(next_id
);
562 view(next_id
, getActiveFeedId());
567 if (mode
== "prev") {
570 cdmExpandArticle(prev_id
);
571 cdmScrollToArticleId(prev_id
);
573 correctHeadlinesOffset(prev_id
);
574 view(prev_id
, getActiveFeedId());
580 exception_error("moveToPost", e
);
584 function toggleSelected(id
, force_on
) {
587 var cb
= $("RCHK-" + id
);
588 var row
= $("RROW-" + id
);
591 if (row
.hasClassName('Selected') && !force_on
) {
592 row
.removeClassName('Selected');
593 if (cb
) cb
.checked
= false;
595 row
.addClassName('Selected');
596 if (cb
) cb
.checked
= true;
600 exception_error("toggleSelected", e
);
604 function toggleUnread_afh(effect
) {
607 var elem
= effect
.element
;
608 elem
.style
.backgroundColor
= "";
611 exception_error("toggleUnread_afh", e
);
615 function toggleUnread(id
, cmode
, effect
) {
618 var row
= $("RROW-" + id
);
620 if (cmode
== undefined || cmode
== 2) {
621 if (row
.hasClassName("Unread")) {
622 row
.removeClassName("Unread");
625 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
626 afterFinish
: toggleUnread_afh
,
627 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
631 row
.addClassName("Unread");
634 } else if (cmode
== 0) {
636 row
.removeClassName("Unread");
639 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
640 afterFinish
: toggleUnread_afh
,
641 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
644 } else if (cmode
== 1) {
645 row
.addClassName("Unread");
648 if (cmode
== undefined) cmode
= 2;
650 var query
= "?op=rpc&subop=catchupSelected" +
651 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
653 // notify_progress("Loading, please wait...");
655 new Ajax
.Request("backend.php", {
657 onComplete: function(transport
) {
658 handle_rpc_reply(transport
);
664 exception_error("toggleUnread", e
);
668 function selectionRemoveLabel(id
) {
671 var ids
= getSelectedArticleIds2();
673 if (ids
.length
== 0) {
674 alert(__("No articles are selected."));
678 // var ok = confirm(__("Remove selected articles from label?"));
682 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
683 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
687 // notify_progress("Loading, please wait...");
689 cache_invalidate("F:" + (-11 - id
));
691 new Ajax
.Request("backend.php", {
693 onComplete: function(transport
) {
694 show_labels_in_headlines(transport
);
695 handle_rpc_reply(transport
);
701 exception_error("selectionAssignLabel", e
);
706 function selectionAssignLabel(id
) {
709 var ids
= getSelectedArticleIds2();
711 if (ids
.length
== 0) {
712 alert(__("No articles are selected."));
716 // var ok = confirm(__("Assign selected articles to label?"));
720 cache_invalidate("F:" + (-11 - id
));
722 var query
= "?op=rpc&subop=assignToLabel&ids=" +
723 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
727 // notify_progress("Loading, please wait...");
729 new Ajax
.Request("backend.php", {
731 onComplete: function(transport
) {
732 show_labels_in_headlines(transport
);
733 handle_rpc_reply(transport
);
739 exception_error("selectionAssignLabel", e
);
744 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
746 var rows
= getSelectedArticleIds2();
748 if (rows
.length
== 0 && !no_error
) {
749 alert(__("No articles are selected."));
753 for (i
= 0; i
< rows
.length
; i
++) {
754 var row
= $("RROW-" + rows
[i
]);
756 if (set_state
== undefined) {
757 if (row
.hasClassName("Unread")) {
758 row
.removeClassName("Unread");
760 row
.addClassName("Unread");
764 if (set_state
== false) {
765 row
.removeClassName("Unread");
768 if (set_state
== true) {
769 row
.addClassName("Unread");
774 if (rows
.length
> 0) {
778 if (set_state
== undefined) {
780 } else if (set_state
== true) {
782 } else if (set_state
== false) {
786 var query
= "?op=rpc&subop=catchupSelected" +
787 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
789 notify_progress("Loading, please wait...");
791 new Ajax
.Request("backend.php", {
793 onComplete: function(transport
) {
794 catchup_callback2(transport
, callback_func
);
800 exception_error("selectionToggleUnread", e
);
804 function selectionToggleMarked() {
807 var rows
= getSelectedArticleIds2();
809 if (rows
.length
== 0) {
810 alert(__("No articles are selected."));
814 for (i
= 0; i
< rows
.length
; i
++) {
815 toggleMark(rows
[i
], true, true);
818 if (rows
.length
> 0) {
820 var query
= "?op=rpc&subop=markSelected&ids=" +
821 param_escape(rows
.toString()) + "&cmode=2";
823 new Ajax
.Request("backend.php", {
825 onComplete: function(transport
) {
826 handle_rpc_reply(transport
);
832 exception_error("selectionToggleMarked", e
);
836 function selectionTogglePublished() {
839 var rows
= getSelectedArticleIds2();
841 if (rows
.length
== 0) {
842 alert(__("No articles are selected."));
846 for (i
= 0; i
< rows
.length
; i
++) {
847 togglePub(rows
[i
], true, true);
850 if (rows
.length
> 0) {
852 var query
= "?op=rpc&subop=publishSelected&ids=" +
853 param_escape(rows
.toString()) + "&cmode=2";
855 new Ajax
.Request("backend.php", {
857 onComplete: function(transport
) {
858 handle_rpc_reply(transport
);
864 exception_error("selectionToggleMarked", e
);
868 function getSelectedArticleIds2() {
872 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
874 rv
.push(child
.id
.replace("RROW-", ""));
880 function getLoadedArticleIds() {
883 var children
= $$("#headlines-frame > div[id*=RROW-]");
885 children
.each(function(child
) {
886 rv
.push(child
.id
.replace("RROW-", ""));
893 // mode = all,none,unread,invert
894 function selectArticles(mode
) {
897 var children
= $$("#headlines-frame > div[id*=RROW]");
899 children
.each(function(child
) {
900 var id
= child
.id
.replace("RROW-", "");
901 var cb
= $("RCHK-" + id
);
904 child
.addClassName("Selected");
906 } else if (mode
== "unread") {
907 if (child
.hasClassName("Unread")) {
908 child
.addClassName("Selected");
911 child
.removeClassName("Selected");
914 } else if (mode
== "invert") {
915 if (child
.hasClassName("Selected")) {
916 child
.removeClassName("Selected");
919 child
.addClassName("Selected");
924 child
.removeClassName("Selected");
930 exception_error("selectArticles", e
);
934 function catchupPage() {
936 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
938 var str
= __("Mark all visible articles in %s as read?");
940 str
= str
.replace("%s", fn
);
942 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
946 selectArticles('all');
947 selectionToggleUnread(false, 'viewCurrentFeed()', true)
948 selectArticles('none');
951 function deleteSelection() {
955 var rows
= getSelectedArticleIds2();
957 if (rows
.length
== 0) {
958 alert(__("No articles are selected."));
962 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
966 if (getActiveFeedId() != 0) {
967 str
= __("Delete %d selected articles in %s?");
969 str
= __("Delete %d selected articles?");
972 str
= str
.replace("%d", rows
.length
);
973 str
= str
.replace("%s", fn
);
975 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
979 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
983 new Ajax
.Request("backend.php", {
985 onComplete: function(transport
) {
990 exception_error("deleteSelection", e
);
994 function archiveSelection() {
998 var rows
= getSelectedArticleIds2();
1000 if (rows
.length
== 0) {
1001 alert(__("No articles are selected."));
1005 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1009 if (getActiveFeedId() != 0) {
1010 str
= __("Archive %d selected articles in %s?");
1013 str
= __("Move %d archived articles back?");
1017 str
= str
.replace("%d", rows
.length
);
1018 str
= str
.replace("%s", fn
);
1020 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1024 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1028 for (var i
= 0; i
< rows
.length
; i
++) {
1029 cache_invalidate(rows
[i
]);
1032 new Ajax
.Request("backend.php", {
1034 onComplete: function(transport
) {
1039 exception_error("archiveSelection", e
);
1043 function catchupSelection() {
1047 var rows
= getSelectedArticleIds2();
1049 if (rows
.length
== 0) {
1050 alert(__("No articles are selected."));
1054 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1056 var str
= __("Mark %d selected articles in %s as read?");
1058 str
= str
.replace("%d", rows
.length
);
1059 str
= str
.replace("%s", fn
);
1061 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1065 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1068 exception_error("catchupSelection", e
);
1072 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1073 displayDlg('editArticleTags', id
,
1075 $("tags_str").focus();
1077 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1078 "backend.php?op=rpc&subop=completeTags",
1079 { tokens
: ',', paramName
: "search" });
1083 function editTagsSave() {
1085 notify_progress("Saving article tags...");
1087 var form
= document
.forms
["tag_edit_form"];
1089 var query
= Form
.serialize("tag_edit_form");
1091 query
= "?op=rpc&subop=setArticleTags&" + query
;
1095 new Ajax
.Request("backend.php", {
1097 onComplete: function(transport
) {
1099 //console.log("tags saved...");
1104 if (transport
.responseXML
) {
1105 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1108 var id
= tags_str
.getAttribute("id");
1111 var tags
= $("ATSTR-" + id
);
1113 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1116 cache_invalidate(id
);
1122 exception_error("editTagsSave", e
);
1127 function editTagsInsert() {
1130 var form
= document
.forms
["tag_edit_form"];
1132 var found_tags
= form
.found_tags
;
1133 var tags_str
= form
.tags_str
;
1135 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1137 if (tags_str
.value
.length
> 0 &&
1138 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1140 tags_str
.value
= tags_str
.value
+ ", ";
1143 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1145 found_tags
.selectedIndex
= 0;
1148 exception_error("editTagsInsert", e
);
1152 function cdmScrollToArticleId(id
) {
1154 var ctr
= $("headlines-frame");
1155 var e
= $("RROW-" + id
);
1157 if (!e
|| !ctr
) return;
1159 ctr
.scrollTop
= e
.offsetTop
;
1162 exception_error("cdmScrollToArticleId", e
);
1166 function cdmWatchdog() {
1170 var ctr
= $("headlines-frame");
1174 var ids
= new Array();
1176 var e
= ctr
.firstChild
;
1179 if (e
.className
&& e
.hasClassName("Unread") && e
.id
&&
1180 e
.id
.match("RROW-")) {
1182 // article fits in viewport OR article is longer than viewport and
1183 // its bottom is visible
1185 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1186 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1188 // console.log(e.id + " is visible " + e.offsetTop + "." +
1189 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1190 // (ctr.scrollTop + ctr.offsetHeight));
1192 ids
.push(e
.id
.replace("RROW-", ""));
1194 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1195 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1196 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1198 ids
.push(e
.id
.replace("RROW-", ""));
1202 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1204 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1205 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1207 ids.push(e.id.replace("RROW-", ""));
1216 console
.log("cdmWatchdog, ids= " + ids
.toString());
1218 if (ids
.length
> 0) {
1220 for (var i
= 0; i
< ids
.length
; i
++) {
1221 var e
= $("RROW-" + ids
[i
]);
1223 e
.removeClassName("Unread");
1227 var query
= "?op=rpc&subop=catchupSelected" +
1228 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1230 new Ajax
.Request("backend.php", {
1232 onComplete: function(transport
) {
1233 handle_rpc_reply(transport
);
1238 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1241 exception_error("cdmWatchdog", e
);
1247 function cache_inject(id
, article
, param
) {
1250 if (!cache_check_param(id
, param
)) {
1251 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1253 var date
= new Date();
1254 var ts
= Math
.round(date
.getTime() / 1000);
1258 cache_obj
["id"] = id
;
1259 cache_obj
["data"] = article
;
1260 cache_obj
["param"] = param
;
1262 if (param
) id
= id
+ ":" + param
;
1264 cache_added
["TS:" + id
] = ts
;
1266 if (has_local_storage())
1267 localStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1269 article_cache
.push(cache_obj
);
1272 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1275 exception_error("cache_inject", e
);
1279 function cache_find(id
) {
1281 if (has_local_storage()) {
1282 var cache_obj
= localStorage
.getItem(id
);
1285 cache_obj
= JSON
.parse(cache_obj
);
1288 return cache_obj
['data'];
1292 for (var i
= 0; i
< article_cache
.length
; i
++) {
1293 if (article_cache
[i
]["id"] == id
) {
1294 return article_cache
[i
]["data"];
1301 function cache_find_param(id
, param
) {
1303 if (has_local_storage()) {
1305 if (param
) id
= id
+ ":" + param
;
1307 var cache_obj
= localStorage
.getItem(id
);
1310 cache_obj
= JSON
.parse(cache_obj
);
1313 return cache_obj
['data'];
1317 for (var i
= 0; i
< article_cache
.length
; i
++) {
1318 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1319 return article_cache
[i
]["data"];
1327 function cache_check(id
) {
1328 if (has_local_storage()) {
1329 if (localStorage
.getItem(id
))
1332 for (var i
= 0; i
< article_cache
.length
; i
++) {
1333 if (article_cache
[i
]["id"] == id
) {
1341 function cache_check_param(id
, param
) {
1342 if (has_local_storage()) {
1344 if (param
) id
= id
+ ":" + param
;
1346 if (localStorage
.getItem(id
))
1350 for (var i
= 0; i
< article_cache
.length
; i
++) {
1351 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1359 function cache_expire() {
1360 if (has_local_storage()) {
1362 var date
= new Date();
1363 var timestamp
= Math
.round(date
.getTime() / 1000);
1365 for (var i
= 0; i
< localStorage
.length
; i
++) {
1367 var id
= localStorage
.key(i
);
1369 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1370 localStorage
.removeItem(id
);
1375 while (article_cache
.length
> 25) {
1376 article_cache
.shift();
1381 function cache_flush() {
1382 if (has_local_storage()) {
1383 localStorage
.clear();
1385 article_cache
= new Array();
1389 function cache_invalidate(id
) {
1391 if (has_local_storage()) {
1395 for (var i
= 0; i
< localStorage
.length
; i
++) {
1396 var key
= localStorage
.key(i
);
1398 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1400 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1401 localStorage
.removeItem(key
);
1412 while (i
< article_cache
.length
) {
1413 if (article_cache
[i
]["id"] == id
) {
1414 //console.log("cache_invalidate: removed id " + id);
1415 article_cache
.splice(i
, 1);
1422 //console.log("cache_invalidate: id not found: " + id);
1425 exception_error("cache_invalidate", e
);
1429 function getActiveArticleId() {
1430 return active_post_id
;
1433 function preloadBatchedArticles() {
1436 var query
= "?op=rpc&subop=getArticles&ids=" +
1437 preload_id_batch
.toString();
1439 new Ajax
.Request("backend.php", {
1441 onComplete: function(transport
) {
1443 preload_id_batch
= [];
1445 var articles
= transport
.responseXML
.getElementsByTagName("article");
1447 for (var i
= 0; i
< articles
.length
; i
++) {
1448 var id
= articles
[i
].getAttribute("id");
1449 if (!cache_check(id
)) {
1450 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1451 console
.log("preloaded article: " + id
);
1457 exception_error("preloadBatchedArticles", e
);
1461 function preloadArticleUnderPointer(id
) {
1463 if (getInitParam("bw_limit") == "1") return;
1465 if (post_under_pointer
== id
&& !cache_check(id
)) {
1467 console
.log("trying to preload article " + id
);
1469 var neighbor_ids
= getRelativePostIds(id
, 1);
1471 /* only request uncached articles */
1473 if (preload_id_batch
.indexOf(id
) == -1) {
1474 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1475 if (!cache_check(neighbor_ids
[i
])) {
1476 preload_id_batch
.push(neighbor_ids
[i
]);
1481 if (preload_id_batch
.indexOf(id
) == -1)
1482 preload_id_batch
.push(id
);
1484 //console.log("preload ids batch: " + preload_id_batch.toString());
1486 window
.clearTimeout(preload_timeout_id
);
1487 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1491 exception_error("preloadArticleUnderPointer", e
);
1495 function postMouseIn(id
) {
1497 if (post_under_pointer
!= id
) {
1498 post_under_pointer
= id
;
1500 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1505 exception_error("postMouseIn", e
);
1509 function postMouseOut(id
) {
1511 post_under_pointer
= false;
1513 exception_error("postMouseOut", e
);
1517 function headlines_scroll_handler(e
) {
1520 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1521 if (!_infscroll_disable
) {
1527 exception_error("headlines_scroll_handler", e
);
1531 function catchupRelativeToArticle(below
) {
1536 if (!getActiveArticleId()) {
1537 alert(__("No article is selected."));
1541 var visible_ids
= getVisibleArticleIds();
1543 var ids_to_mark
= new Array();
1546 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1547 if (visible_ids
[i
] != getActiveArticleId()) {
1548 var e
= $("RROW-" + visible_ids
[i
]);
1550 if (e
&& e
.hasClassName("Unread")) {
1551 ids_to_mark
.push(visible_ids
[i
]);
1558 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1559 if (visible_ids
[i
] != getActiveArticleId()) {
1560 var e
= $("RROW-" + visible_ids
[i
]);
1562 if (e
&& e
.hasClassName("Unread")) {
1563 ids_to_mark
.push(visible_ids
[i
]);
1571 if (ids_to_mark
.length
== 0) {
1572 alert(__("No articles found to mark"));
1574 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1576 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1578 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1579 var e
= $("RROW-" + ids_to_mark
[i
]);
1580 e
.removeClassName("Unread");
1583 var query
= "?op=rpc&subop=catchupSelected" +
1584 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1586 new Ajax
.Request("backend.php", {
1588 onComplete: function(transport
) {
1589 catchup_callback2(transport
);
1596 exception_error("catchupRelativeToArticle", e
);
1600 function cdmExpandArticle(id
) {
1605 var elem
= $("CICD-" + active_post_id
);
1607 var upd_img_pic
= $("FUPDPIC-" + id
);
1609 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1610 upd_img_pic
.src
.match("fresh_sign.png"))) {
1612 upd_img_pic
.src
= "images/blank_icon.gif";
1615 if (id
== active_post_id
&& Element
.visible(elem
))
1618 selectArticles("none");
1620 var old_offset
= $("RROW-" + id
).offsetTop
;
1622 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1624 Element
.show("CEXC-" + active_post_id
);
1627 active_post_id
= id
;
1629 elem
= $("CICD-" + id
);
1631 if (!Element
.visible(elem
)) {
1633 Element
.hide("CEXC-" + id
);
1635 if ($("CWRAP-" + id
).innerHTML
== "") {
1637 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1639 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1640 __("Loading, please wait...") + "</div>";
1642 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1644 //console.log(query);
1646 new Ajax
.Request("backend.php", {
1648 onComplete: function(transport
) {
1649 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1651 if (transport
.responseXML
) {
1652 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1653 var recv_id
= article
.getAttribute("id");
1656 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1659 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1667 var new_offset
= $("RROW-" + id
).offsetTop
;
1669 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1671 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1672 $("headlines-frame").scrollTop
= new_offset
;
1674 toggleUnread(id
, 0, true);
1678 exception_error("cdmExpandArticle", e
);
1684 function fixHeadlinesOrder(ids
) {
1686 for (var i
= 0; i
< ids
.length
; i
++) {
1687 var e
= $("RROW-" + ids
[i
]);
1691 e
.removeClassName("even");
1692 e
.addClassName("odd");
1694 e
.removeClassName("odd");
1695 e
.addClassName("even");
1700 exception_error("fixHeadlinesOrder", e
);
1704 function getArticleUnderPointer() {
1705 return post_under_pointer
;
1708 function zoomToArticle(event
, id
) {
1710 var cached_article
= cache_find(id
);
1712 if (dijit
.byId("ATAB-" + id
))
1713 if (!event
|| !event
.shiftKey
)
1714 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1716 if (cached_article
) {
1717 //closeArticlePanel();
1719 var article_pane
= new dijit
.layout
.ContentPane({
1720 title
: __("Loading...") , content
: cached_article
,
1721 style
: 'padding : 0px;',
1725 dijit
.byId("content-tabs").addChild(article_pane
);
1727 if (!event
|| !event
.shiftKey
)
1728 dijit
.byId("content-tabs").selectChild(article_pane
);
1730 if ($("PTITLE-" + id
))
1731 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1735 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1737 notify_progress("Loading, please wait...", true);
1739 new Ajax
.Request("backend.php", {
1741 onComplete: function(transport
) {
1744 if (transport
.responseXML
) {
1745 //closeArticlePanel();
1747 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1748 var content
= article
.firstChild
.nodeValue
;
1750 var article_pane
= new dijit
.layout
.ContentPane({
1751 title
: "article-" + id
, content
: content
,
1752 style
: 'padding : 0px;',
1756 dijit
.byId("content-tabs").addChild(article_pane
);
1758 if (!event
|| !event
.shiftKey
)
1759 dijit
.byId("content-tabs").selectChild(article_pane
);
1761 if ($("PTITLE-" + id
))
1762 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1769 exception_error("zoomToArticle", e
);
1773 function scrollArticle(offset
) {
1776 var ci
= $("content-insert");
1778 ci
.scrollTop
+= offset
;
1781 var hi
= $("headlines-frame");
1783 hi
.scrollTop
+= offset
;
1788 exception_error("scrollArticle", e
);
1792 function show_labels_in_headlines(transport
) {
1794 if (transport
.responseXML
) {
1795 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1797 var elems
= info
.getElementsByTagName("entry");
1799 for (var l
= 0; l
< elems
.length
; l
++) {
1800 var e_id
= elems
[l
].getAttribute("id");
1804 var ctr
= $("HLLCTR-" + e_id
);
1807 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1815 exception_error("show_labels_in_headlines", e
);
1820 function toggleHeadlineActions() {
1822 var e
= $("headlineActionsBody");
1823 var p
= $("headlineActionsDrop");
1825 if (!Element
.visible(e
)) {
1832 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1833 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1836 exception_error("toggleHeadlineActions", e
);
1840 function publishWithNote(id
, def_note
) {
1842 if (!def_note
) def_note
= '';
1844 var note
= prompt(__("Please enter a note for this article:"), def_note
);
1846 if (note
!= undefined) {
1847 togglePub(id
, false, false, note
);
1851 exception_error("publishWithNote", e
);
1855 function emailArticle(id
) {
1858 var ids
= getSelectedArticleIds2();
1860 if (ids
.length
== 0) {
1861 alert(__("No articles are selected."));
1865 id
= ids
.toString();
1868 displayDlg('emailArticle', id
,
1870 document
.forms
['article_email_form'].destination
.focus();
1872 new Ajax
.Autocompleter('destination', 'destination_choices',
1873 "backend.php?op=rpc&subop=completeEmails",
1874 { tokens
: '', paramName
: "search" });
1879 exception_error("emailArticle", e
);
1883 function emailArticleDo() {
1885 var f
= document
.forms
['article_email_form'];
1887 if (f
.destination
.value
== "") {
1888 alert("Please fill in the destination email.");
1892 if (f
.subject
.value
== "") {
1893 alert("Please fill in the subject.");
1897 var query
= Form
.serialize("article_email_form");
1899 // console.log(query);
1901 new Ajax
.Request("backend.php", {
1903 onComplete: function(transport
) {
1906 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
1909 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
1911 notify_info('Your message has been sent.');
1916 exception_error("sendEmailDo", e
);
1922 exception_error("emailArticleDo", e
);
1926 function dismissArticle(id
) {
1928 var elem
= $("RROW-" + id
);
1930 toggleUnread(id
, 0, true);
1932 new Effect
.Fade(elem
, {duration
: 0.5});
1934 active_post_id
= false;
1937 exception_error("dismissArticle", e
);
1941 function dismissSelectedArticles() {
1944 var ids
= getVisibleArticleIds();
1948 for (var i
= 0; i
< ids
.length
; i
++) {
1949 var elem
= $("RROW-" + ids
[i
]);
1951 if (elem
.className
&& elem
.hasClassName("Selected") &&
1952 ids
[i
] != active_post_id
) {
1953 new Effect
.Fade(elem
, {duration
: 0.5});
1961 selectionToggleUnread(false);
1963 fixHeadlinesOrder(tmp
);
1966 exception_error("dismissSelectedArticles", e
);
1970 function dismissReadArticles() {
1973 var ids
= getVisibleArticleIds();
1976 for (var i
= 0; i
< ids
.length
; i
++) {
1977 var elem
= $("RROW-" + ids
[i
]);
1979 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1980 !elem
.hasClassName("Selected")) {
1982 new Effect
.Fade(elem
, {duration
: 0.5});
1988 fixHeadlinesOrder(tmp
);
1991 exception_error("dismissSelectedArticles", e
);
1995 function getVisibleArticleIds() {
2000 getLoadedArticleIds().each(function(id
) {
2001 var elem
= $("RROW-" + id
);
2002 if (elem
&& Element
.visible(elem
))
2007 exception_error("getVisibleArticleIds", e
);
2013 function cdmClicked(event
, id
) {
2015 var shift_key
= event
.shiftKey
;
2019 if (!event
.ctrlKey
) {
2021 if (!getInitParam("cdm_expanded")) {
2022 return cdmExpandArticle(id
);
2025 selectArticles("none");
2028 var elem
= $("RROW-" + id
);
2031 elem
.removeClassName("Unread");
2033 var upd_img_pic
= $("FUPDPIC-" + id
);
2035 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2036 upd_img_pic
.src
.match("fresh_sign.png"))) {
2038 upd_img_pic
.src
= "images/blank_icon.gif";
2041 active_post_id
= id
;
2043 var query
= "?op=rpc&subop=catchupSelected" +
2044 "&cmode=0&ids=" + param_escape(id
);
2046 new Ajax
.Request("backend.php", {
2048 onComplete: function(transport
) {
2049 handle_rpc_reply(transport
);
2054 toggleSelected(id
, true);
2055 toggleUnread(id
, 0, false);
2056 zoomToArticle(event
, id
);
2060 exception_error("cdmClicked");
2066 function postClicked(event
, id
) {
2069 if (!event
.ctrlKey
) {
2072 zoomToArticle(event
, id
);
2077 exception_error("postClicked");
2081 function hlOpenInNewTab(event
, id
) {
2082 toggleUnread(id
, 0, false);
2083 zoomToArticle(event
, id
);
2086 function hlClicked(event
, id
) {
2089 if (!event
.ctrlKey
) {
2094 toggleUnread(id
, 0, false);
2095 zoomToArticle(event
, id
);
2100 exception_error("hlClicked");
2104 function getFirstVisibleHeadlineId() {
2105 var rows
= getVisibleArticleIds();
2110 function getLastVisibleHeadlineId() {
2111 var rows
= getVisibleArticleIds();
2112 return rows
[rows
.length
-1];
2115 function openArticleInNewWindow(id
) {
2117 console
.log("openArticleInNewWindow: " + id
);
2119 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
2120 var wname
= "ttrss_article_" + id
;
2122 console
.log(query
+ " " + wname
);
2124 var w
= window
.open("", wname
);
2126 if (!w
) notify_error("Failed to open window for the article");
2128 new Ajax
.Request("backend.php", {
2130 onComplete: function(transport
) {
2132 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
2133 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
2135 console
.log("open_article received link: " + link
);
2139 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
2141 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
2143 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
2145 if (!w
) { notify_error("Failed to load article in new window"); }
2148 id
= id
.firstChild
.nodeValue
;
2149 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
2152 notify_error("Can't open article: received invalid article link");
2157 exception_error("openArticleInNewWindow", e
);
2161 function isCdmMode() {
2162 return getInitParam("combined_display_mode");
2165 function markHeadline(id
) {
2166 var row
= $("RROW-" + id
);
2168 var check
= $("RCHK-" + id
);
2171 check
.checked
= true;
2174 row
.addClassName("Selected");
2178 function getRelativePostIds(id
, limit
) {
2184 if (!limit
) limit
= 3;
2186 var ids
= getVisibleArticleIds();
2188 for (var i
= 0; i
< ids
.length
; i
++) {
2190 for (var k
= 1; k
<= limit
; k
++) {
2191 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2192 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2199 exception_error("getRelativePostIds", e
);
2205 function correctHeadlinesOffset(id
) {
2209 var container
= $("headlines-frame");
2210 var row
= $("RROW-" + id
);
2212 var viewport
= container
.offsetHeight
;
2214 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2215 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2217 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2218 //console.log("Vport: " + viewport);
2220 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2221 container
.scrollTop
= row
.offsetTop
;
2222 } else if (rel_offset_bottom
> viewport
) {
2224 /* doesn't properly work with Opera in some cases because
2225 Opera fucks up element scrolling */
2227 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2231 exception_error("correctHeadlinesOffset", e
);
2236 function headlineActionsChange(elem
) {
2239 elem
.selectedIndex
= 0;
2241 exception_error("headlineActionsChange", e
);
2245 function closeArticlePanel() {
2247 var tabs
= dijit
.byId("content-tabs");
2248 var child
= tabs
.selectedChildWidget
;
2250 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
2251 tabs
.removeChild(child
);
2254 if (dijit
.byId("content-insert"))
2255 dijit
.byId("headlines-wrap-inner").removeChild(
2256 dijit
.byId("content-insert"));