]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
1 var active_post_id
= false;
3 var article_cache
= new Array();
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
12 var feed_precache_timeout_id
= false;
13 var precache_idle_timeout_id
= false;
15 var cids_requested
= [];
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
21 handle_rpc_json(transport
);
23 loading_set_progress(25);
25 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
33 reply
= JSON
.parse(transport
.responseText
);
40 is_cat
= reply
['headlines']['is_cat'];
41 feed_id
= reply
['headlines']['id'];
44 var content
= reply
['headlines']['content'];
46 if (getInitParam("cdm_auto_catchup") == 1) {
47 content
= content
+ "<div id='headlines-spacer'></div>";
50 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], content
);
54 setActiveFeedId(feed_id
, is_cat
);
57 if (offset
== 0 && infscroll_req
== false) {
58 $("headlines-frame").scrollTop
= 0;
62 var headlines_count
= reply
['headlines-info']['count'];
64 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
66 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
67 _infscroll_disable
= 1;
69 _infscroll_disable
= 0;
72 var counters
= reply
['counters'];
73 var articles
= reply
['articles'];
74 //var runtime_info = reply['runtime-info'];
76 if (offset
== 0 && infscroll_req
== false) {
77 dijit
.byId("headlines-frame").attr('content',
78 reply
['headlines']['content']);
80 dijit
.byId("headlines-toolbar").attr('content',
81 reply
['headlines']['toolbar']);
83 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
84 cp
= row
.getElementsByClassName("contentPreview")[0];
86 clamp_element(cp
, 50);
88 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
> 1) {
89 row
.parentNode
.removeChild(row
);
93 if (getInitParam("cdm_auto_catchup") == 1) {
94 var hsp
= $("headlines-spacer");
95 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
96 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
103 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
104 console
.log("adding some more headlines...");
106 var c
= dijit
.byId("headlines-frame");
107 var ids
= getSelectedArticleIds2();
109 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
111 var hsp
= $("headlines-spacer");
114 c
.domNode
.removeChild(hsp
);
116 $$("#headlines-tmp > div").each(function(row
) {
117 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
118 row
.style
.display
= 'none';
120 c
.domNode
.appendChild(row
);
122 row
.parentNode
.removeChild(row
);
126 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
128 fixHeadlinesOrder(getLoadedArticleIds());
130 if (getInitParam("cdm_auto_catchup") == 1) {
131 c
.domNode
.appendChild(hsp
);
134 console
.log("restore selected ids: " + ids
);
136 for (var i
= 0; i
< ids
.length
; i
++) {
137 markHeadline(ids
[i
]);
142 $$("#headlines-frame > div[id*=RROW]").each(
144 if (!Element
.visible(child
)) {
145 //new Effect.Appear(child, { duration : 0.5 });
148 cp
= child
.getElementsByClassName("contentPreview")[0];
149 clamp_element(cp
, 50);
154 console
.log("no new headlines received");
156 var hsp
= $("headlines-spacer");
158 if (hsp
) hsp
.innerHTML
= "";
162 if (headlines_count
> 0)
163 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
166 for (var i
= 0; i
< articles
.length
; i
++) {
167 var a_id
= articles
[i
]['id'];
168 cache_set("article:" + a_id
, articles
[i
]['content']);
171 console
.log("no cached articles received");
174 // do not precache stuff after fresh feed
176 precache_headlines();
179 parse_counters(counters
);
184 console
.error("Invalid object received: " + transport
.responseText
);
185 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
186 __('Could not update headlines (invalid object received - see error console for details)') +
190 _infscroll_request_sent
= 0;
195 exception_error("headlines_callback2", e
, transport
);
199 function render_article(article
) {
201 dijit
.byId("headlines-wrap-inner").addChild(
202 dijit
.byId("content-insert"));
204 var c
= dijit
.byId("content-insert");
207 c
.domNode
.scrollTop
= 0;
210 c
.attr('content', article
);
212 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 view_mode
= false;
244 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
245 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
250 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
251 upd_img_pic
.src
.match("fresh_sign.png"))) {
253 upd_img_pic
.src
= "images/blank_icon.gif";
255 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
257 } else if (article_is_unread
&& view_mode
== "all_articles") {
258 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
263 if (article_is_unread
)
264 _force_scheduled_update
= true;
267 exception_error("showArticleInHeadlines", e
);
271 function article_callback2(transport
, id
) {
273 console
.log("article_callback2 " + id
);
275 handle_rpc_json(transport
);
280 reply
= JSON
.parse(transport
.responseText
);
287 var upic
= $('FUPDPIC-' + id
);
289 if (upic
) upic
.src
= 'images/blank_icon.gif';
291 reply
.each(function(article
) {
292 if (active_post_id
== article
['id']) {
293 render_article(article
['content']);
295 cids_requested
.remove(article
['id']);
297 cache_set("article:" + article
['id'], article
['content']);
300 // if (id != last_requested_article) {
301 // console.log("requested article id is out of sequence, aborting");
306 console
.error("Invalid object received: " + transport
.responseText
);
308 render_article("<div class='whiteBox'>" +
309 __('Could not display article (invalid object received - see error console for details)') + "</div>");
315 if (!_infscroll_disable
&&
316 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
326 exception_error("article_callback2", e
, transport
);
332 console
.log("loading article: " + id
);
334 var cached_article
= cache_get("article:" + id
);
336 console
.log("cache check result: " + (cached_article
!= false));
340 var query
= "?op=article&method=view&id=" + param_escape(id
);
342 var neighbor_ids
= getRelativePostIds(id
);
344 /* only request uncached articles */
346 var cids_to_request
= [];
348 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
349 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
350 if (!cache_get("article:" + neighbor_ids
[i
])) {
351 cids_to_request
.push(neighbor_ids
[i
]);
352 cids_requested
.push(neighbor_ids
[i
]);
356 console
.log("additional ids: " + cids_to_request
.toString());
358 query
= query
+ "&cids=" + cids_to_request
.toString();
360 var crow
= $("RROW-" + id
);
361 var article_is_unread
= crow
.hasClassName("Unread");
364 showArticleInHeadlines(id
);
366 precache_headlines();
368 if (!cached_article
) {
370 var upic
= $('FUPDPIC-' + id
);
373 upic
.src
= getInitParam("sign_progress");
376 } else if (cached_article
&& article_is_unread
) {
378 query
= query
+ "&mode=prefetch";
380 render_article(cached_article
);
382 } else if (cached_article
) {
384 query
= query
+ "&mode=prefetch_old";
385 render_article(cached_article
);
387 // if we don't need to request any relative ids, we might as well skip
388 // the server roundtrip altogether
389 if (cids_to_request
.length
== 0) {
392 if (!_infscroll_disable
&&
393 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
405 last_requested_article
= id
;
409 if (article_is_unread
) {
410 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
413 new Ajax
.Request("backend.php", {
415 onComplete: function(transport
) {
416 article_callback2(transport
, id
);
422 exception_error("view", e
);
426 function toggleMark(id
, client_only
) {
428 var query
= "?op=rpc&id=" + id
+ "&method=mark";
430 var img
= $("FMPIC-" + id
);
434 if (img
.src
.match("mark_unset")) {
435 img
.src
= img
.src
.replace("mark_unset", "mark_set");
436 img
.alt
= __("Unstar article");
437 query
= query
+ "&mark=1";
440 img
.src
= img
.src
.replace("mark_set", "mark_unset");
441 img
.alt
= __("Star article");
442 query
= query
+ "&mark=0";
445 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
448 new Ajax
.Request("backend.php", {
450 onComplete: function(transport
) {
451 handle_rpc_json(transport
);
456 exception_error("toggleMark", e
);
460 function togglePub(id
, client_only
, no_effects
, note
) {
462 var query
= "?op=rpc&id=" + id
+ "&method=publ";
464 if (note
!= undefined) {
465 query
= query
+ "¬e=" + param_escape(note
);
467 query
= query
+ "¬e=undefined";
470 var img
= $("FPPIC-" + id
);
474 if (img
.src
.match("pub_unset") || note
!= undefined) {
475 img
.src
= img
.src
.replace("pub_unset", "pub_set");
476 img
.alt
= __("Unpublish article");
477 query
= query
+ "&pub=1";
480 img
.src
= img
.src
.replace("pub_set", "pub_unset");
481 img
.alt
= __("Publish article");
483 query
= query
+ "&pub=0";
486 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
489 new Ajax
.Request("backend.php", {
491 onComplete: function(transport
) {
492 handle_rpc_json(transport
);
497 exception_error("togglePub", e
);
501 function moveToPost(mode
) {
505 var rows
= getVisibleArticleIds();
510 if (!$('RROW-' + active_post_id
)) {
511 active_post_id
= false;
514 if (active_post_id
== false) {
516 prev_id
= rows
[rows
.length
-1]
518 for (var i
= 0; i
< rows
.length
; i
++) {
519 if (rows
[i
] == active_post_id
) {
521 // Account for adjacent identical article ids.
522 if (i
> 0) prev_id
= rows
[i
-1];
524 for (var j
= i
+1; j
< rows
.length
; j
++) {
525 if (rows
[j
] != active_post_id
) {
535 if (mode
== "next") {
539 cdmExpandArticle(next_id
);
540 cdmScrollToArticleId(next_id
);
543 correctHeadlinesOffset(next_id
);
544 view(next_id
, getActiveFeedId());
549 if (mode
== "prev") {
552 cdmExpandArticle(prev_id
);
553 cdmScrollToArticleId(prev_id
);
555 correctHeadlinesOffset(prev_id
);
556 view(prev_id
, getActiveFeedId());
562 exception_error("moveToPost", e
);
566 function toggleSelected(id
, force_on
) {
569 var cb
= $("RCHK-" + id
);
570 var row
= $("RROW-" + id
);
573 if (row
.hasClassName('Selected') && !force_on
) {
574 row
.removeClassName('Selected');
575 if (cb
) cb
.checked
= false;
577 row
.addClassName('Selected');
578 if (cb
) cb
.checked
= true;
582 exception_error("toggleSelected", e
);
586 function toggleUnread_afh(effect
) {
589 var elem
= effect
.element
;
590 elem
.style
.backgroundColor
= "";
593 exception_error("toggleUnread_afh", e
);
597 function toggleUnread(id
, cmode
, effect
) {
600 var row
= $("RROW-" + id
);
602 if (cmode
== undefined || cmode
== 2) {
603 if (row
.hasClassName("Unread")) {
604 row
.removeClassName("Unread");
607 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
608 afterFinish
: toggleUnread_afh
,
609 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
613 row
.addClassName("Unread");
616 } else if (cmode
== 0) {
618 row
.removeClassName("Unread");
621 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
622 afterFinish
: toggleUnread_afh
,
623 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
626 } else if (cmode
== 1) {
627 row
.addClassName("Unread");
630 if (cmode
== undefined) cmode
= 2;
632 var query
= "?op=rpc&method=catchupSelected" +
633 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
635 // notify_progress("Loading, please wait...");
637 new Ajax
.Request("backend.php", {
639 onComplete: function(transport
) {
640 handle_rpc_json(transport
);
646 exception_error("toggleUnread", e
);
650 function selectionRemoveLabel(id
, ids
) {
653 if (!ids
) ids
= getSelectedArticleIds2();
655 if (ids
.length
== 0) {
656 alert(__("No articles are selected."));
660 var query
= "?op=rpc&method=removeFromLabel&ids=" +
661 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
665 new Ajax
.Request("backend.php", {
667 onComplete: function(transport
) {
668 handle_rpc_json(transport
);
669 show_labels_in_headlines(transport
);
673 exception_error("selectionAssignLabel", e
);
678 function selectionAssignLabel(id
, ids
) {
681 if (!ids
) ids
= getSelectedArticleIds2();
683 if (ids
.length
== 0) {
684 alert(__("No articles are selected."));
688 var query
= "?op=rpc&method=assignToLabel&ids=" +
689 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
693 new Ajax
.Request("backend.php", {
695 onComplete: function(transport
) {
696 handle_rpc_json(transport
);
697 show_labels_in_headlines(transport
);
701 exception_error("selectionAssignLabel", e
);
706 function selectionToggleUnread(set_state
, callback
, no_error
) {
708 var rows
= getSelectedArticleIds2();
710 if (rows
.length
== 0 && !no_error
) {
711 alert(__("No articles are selected."));
715 for (var i
= 0; i
< rows
.length
; i
++) {
716 var row
= $("RROW-" + rows
[i
]);
718 if (set_state
== undefined) {
719 if (row
.hasClassName("Unread")) {
720 row
.removeClassName("Unread");
722 row
.addClassName("Unread");
726 if (set_state
== false) {
727 row
.removeClassName("Unread");
730 if (set_state
== true) {
731 row
.addClassName("Unread");
736 if (rows
.length
> 0) {
740 if (set_state
== undefined) {
742 } else if (set_state
== true) {
744 } else if (set_state
== false) {
748 var query
= "?op=rpc&method=catchupSelected" +
749 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
751 notify_progress("Loading, please wait...");
753 new Ajax
.Request("backend.php", {
755 onComplete: function(transport
) {
756 handle_rpc_json(transport
);
757 if (callback
) callback(transport
);
763 exception_error("selectionToggleUnread", e
);
767 function selectionToggleMarked() {
770 var rows
= getSelectedArticleIds2();
772 if (rows
.length
== 0) {
773 alert(__("No articles are selected."));
777 for (var i
= 0; i
< rows
.length
; i
++) {
778 toggleMark(rows
[i
], true, true);
781 if (rows
.length
> 0) {
783 var query
= "?op=rpc&method=markSelected&ids=" +
784 param_escape(rows
.toString()) + "&cmode=2";
786 new Ajax
.Request("backend.php", {
788 onComplete: function(transport
) {
789 handle_rpc_json(transport
);
795 exception_error("selectionToggleMarked", e
);
799 function selectionTogglePublished() {
802 var rows
= getSelectedArticleIds2();
804 if (rows
.length
== 0) {
805 alert(__("No articles are selected."));
809 for (var i
= 0; i
< rows
.length
; i
++) {
810 togglePub(rows
[i
], true, true);
813 if (rows
.length
> 0) {
815 var query
= "?op=rpc&method=publishSelected&ids=" +
816 param_escape(rows
.toString()) + "&cmode=2";
818 new Ajax
.Request("backend.php", {
820 onComplete: function(transport
) {
821 handle_rpc_json(transport
);
827 exception_error("selectionToggleMarked", e
);
831 function getSelectedArticleIds2() {
835 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
837 rv
.push(child
.id
.replace("RROW-", ""));
843 function getLoadedArticleIds() {
846 var children
= $$("#headlines-frame > div[id*=RROW-]");
848 children
.each(function(child
) {
849 rv
.push(child
.id
.replace("RROW-", ""));
856 // mode = all,none,unread,invert
857 function selectArticles(mode
) {
860 var children
= $$("#headlines-frame > div[id*=RROW]");
862 children
.each(function(child
) {
863 var id
= child
.id
.replace("RROW-", "");
864 var cb
= $("RCHK-" + id
);
867 child
.addClassName("Selected");
869 } else if (mode
== "unread") {
870 if (child
.hasClassName("Unread")) {
871 child
.addClassName("Selected");
874 child
.removeClassName("Selected");
877 } else if (mode
== "invert") {
878 if (child
.hasClassName("Selected")) {
879 child
.removeClassName("Selected");
882 child
.addClassName("Selected");
887 child
.removeClassName("Selected");
893 exception_error("selectArticles", e
);
897 function catchupPage() {
899 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
901 var str
= __("Mark all visible articles in %s as read?");
903 str
= str
.replace("%s", fn
);
905 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
909 selectArticles('all');
910 selectionToggleUnread(false, 'viewCurrentFeed()', true);
911 selectArticles('none');
914 function deleteSelection() {
918 var rows
= getSelectedArticleIds2();
920 if (rows
.length
== 0) {
921 alert(__("No articles are selected."));
925 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
928 if (getActiveFeedId() != 0) {
929 str
= __("Delete %d selected articles in %s?");
931 str
= __("Delete %d selected articles?");
934 str
= str
.replace("%d", rows
.length
);
935 str
= str
.replace("%s", fn
);
937 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
941 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
945 new Ajax
.Request("backend.php", {
947 onComplete: function(transport
) {
948 handle_rpc_json(transport
);
953 exception_error("deleteSelection", e
);
957 function archiveSelection() {
961 var rows
= getSelectedArticleIds2();
963 if (rows
.length
== 0) {
964 alert(__("No articles are selected."));
968 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
972 if (getActiveFeedId() != 0) {
973 str
= __("Archive %d selected articles in %s?");
976 str
= __("Move %d archived articles back?");
980 str
= str
.replace("%d", rows
.length
);
981 str
= str
.replace("%s", fn
);
983 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
987 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
991 for (var i
= 0; i
< rows
.length
; i
++) {
992 cache_delete("article:" + rows
[i
]);
995 new Ajax
.Request("backend.php", {
997 onComplete: function(transport
) {
998 handle_rpc_json(transport
);
1003 exception_error("archiveSelection", e
);
1007 function catchupSelection() {
1011 var rows
= getSelectedArticleIds2();
1013 if (rows
.length
== 0) {
1014 alert(__("No articles are selected."));
1018 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1020 var str
= __("Mark %d selected articles in %s as read?");
1022 str
= str
.replace("%d", rows
.length
);
1023 str
= str
.replace("%s", fn
);
1025 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1029 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1032 exception_error("catchupSelection", e
);
1036 function editArticleTags(id
) {
1037 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1039 if (dijit
.byId("editTagsDlg"))
1040 dijit
.byId("editTagsDlg").destroyRecursive();
1042 dialog
= new dijit
.Dialog({
1044 title
: __("Edit article Tags"),
1045 style
: "width: 600px",
1046 execute: function() {
1047 if (this.validate()) {
1048 var query
= dojo
.objectToQuery(this.attr('value'));
1050 notify_progress("Saving article tags...", true);
1052 new Ajax
.Request("backend.php", {
1054 onComplete: function(transport
) {
1058 var data
= JSON
.parse(transport
.responseText
);
1061 var tags_str
= article
.tags
;
1062 var id
= tags_str
.id
;
1064 var tags
= $("ATSTR-" + id
);
1065 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1067 if (tags
) tags
.innerHTML
= tags_str
.content
;
1068 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1070 cache_delete("article:" + id
);
1079 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1080 dojo
.disconnect(tmph
);
1082 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1083 "backend.php?op=rpc&method=completeTags",
1084 { tokens
: ',', paramName
: "search" });
1091 function cdmScrollToArticleId(id
) {
1093 var ctr
= $("headlines-frame");
1094 var e
= $("RROW-" + id
);
1096 if (!e
|| !ctr
) return;
1098 ctr
.scrollTop
= e
.offsetTop
;
1101 exception_error("cdmScrollToArticleId", e
);
1105 function getActiveArticleId() {
1106 return active_post_id
;
1109 function postMouseIn(id
) {
1110 post_under_pointer
= id
;
1113 function postMouseOut(id
) {
1114 post_under_pointer
= false;
1117 function headlines_scroll_handler(e
) {
1119 var hsp
= $("headlines-spacer");
1121 if (!_infscroll_disable
) {
1122 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1123 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1126 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1127 __("Loading, please wait...");
1129 loadMoreHeadlines();
1134 if (hsp
) hsp
.innerHTML
= "";
1137 if (getInitParam("cdm_auto_catchup") == 1) {
1139 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1141 if ($("headlines-frame").scrollTop
>
1142 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1144 var id
= child
.id
.replace("RROW-", "");
1146 if (catchup_id_batch
.indexOf(id
) == -1)
1147 catchup_id_batch
.push(id
);
1149 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1153 if (catchup_id_batch
.length
> 0) {
1154 window
.clearTimeout(catchup_timeout_id
);
1156 if (!_infscroll_request_sent
) {
1157 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1164 console
.warn("headlines_scroll_handler: " + e
);
1168 function catchupBatchedArticles() {
1170 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1172 var query
= "?op=rpc&method=catchupSelected" +
1173 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1175 new Ajax
.Request("backend.php", {
1177 onComplete: function(transport
) {
1178 handle_rpc_json(transport
);
1180 catchup_id_batch
.each(function(id
) {
1181 var elem
= $("RROW-" + id
);
1182 if (elem
) elem
.removeClassName("Unread");
1185 catchup_id_batch
= [];
1190 exception_error("catchupBatchedArticles", e
);
1194 function catchupRelativeToArticle(below
, id
) {
1198 if (!id
) id
= getActiveArticleId();
1201 alert(__("No article is selected."));
1205 var visible_ids
= getVisibleArticleIds();
1207 var ids_to_mark
= new Array();
1210 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1211 if (visible_ids
[i
] != id
) {
1212 var e
= $("RROW-" + visible_ids
[i
]);
1214 if (e
&& e
.hasClassName("Unread")) {
1215 ids_to_mark
.push(visible_ids
[i
]);
1222 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1223 if (visible_ids
[i
] != id
) {
1224 var e
= $("RROW-" + visible_ids
[i
]);
1226 if (e
&& e
.hasClassName("Unread")) {
1227 ids_to_mark
.push(visible_ids
[i
]);
1235 if (ids_to_mark
.length
== 0) {
1236 alert(__("No articles found to mark"));
1238 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1240 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1242 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1243 var e
= $("RROW-" + ids_to_mark
[i
]);
1244 e
.removeClassName("Unread");
1247 var query
= "?op=rpc&method=catchupSelected" +
1248 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1250 new Ajax
.Request("backend.php", {
1252 onComplete: function(transport
) {
1253 handle_rpc_json(transport
);
1260 exception_error("catchupRelativeToArticle", e
);
1264 function cdmExpandArticle(id
) {
1269 var elem
= $("CICD-" + active_post_id
);
1271 var upd_img_pic
= $("FUPDPIC-" + id
);
1273 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1274 upd_img_pic
.src
.match("fresh_sign.png"))) {
1276 upd_img_pic
.src
= "images/blank_icon.gif";
1279 if (id
== active_post_id
&& Element
.visible(elem
))
1282 selectArticles("none");
1284 var old_offset
= $("RROW-" + id
).offsetTop
;
1286 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1288 Element
.show("CEXC-" + active_post_id
);
1291 active_post_id
= id
;
1293 elem
= $("CICD-" + id
);
1295 if (!Element
.visible(elem
)) {
1297 Element
.hide("CEXC-" + id
);
1299 if ($("CWRAP-" + id
).innerHTML
== "") {
1301 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1303 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1304 __("Loading, please wait...") + "</div>";
1306 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1308 var neighbor_ids
= getRelativePostIds(id
);
1310 /* only request uncached articles */
1311 var cids_to_request
= [];
1313 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1314 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1315 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1316 cids_to_request
.push(neighbor_ids
[i
]);
1317 cids_requested
.push(neighbor_ids
[i
]);
1321 console
.log("additional ids: " + cids_to_request
.toString());
1323 query
= query
+ "&cids=" + cids_to_request
.toString();
1327 new Ajax
.Request("backend.php", {
1329 onComplete: function(transport
) {
1331 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1333 handle_rpc_json(transport
);
1335 var reply
= JSON
.parse(transport
.responseText
);
1337 reply
.each(function(article
) {
1338 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1339 cids_requested
.remove(article
['id']);
1346 var new_offset
= $("RROW-" + id
).offsetTop
;
1348 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1350 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1351 $("headlines-frame").scrollTop
= new_offset
;
1353 toggleUnread(id
, 0, true);
1357 exception_error("cdmExpandArticle", e
);
1363 function fixHeadlinesOrder(ids
) {
1365 for (var i
= 0; i
< ids
.length
; i
++) {
1366 var e
= $("RROW-" + ids
[i
]);
1370 e
.removeClassName("even");
1371 e
.addClassName("odd");
1373 e
.removeClassName("odd");
1374 e
.addClassName("even");
1379 exception_error("fixHeadlinesOrder", e
);
1383 function getArticleUnderPointer() {
1384 return post_under_pointer
;
1387 function zoomToArticle(event
, id
) {
1389 var cached_article
= cache_get("article: " + id
);
1391 if (dijit
.byId("ATAB-" + id
))
1392 if (!event
|| !event
.shiftKey
)
1393 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1395 if (dijit
.byId("ATSTRTIP-" + id
))
1396 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1398 if (cached_article
) {
1399 //closeArticlePanel();
1401 var article_pane
= new dijit
.layout
.ContentPane({
1402 title
: __("Loading...") , content
: cached_article
,
1403 style
: 'padding : 0px;',
1407 dijit
.byId("content-tabs").addChild(article_pane
);
1409 if (!event
|| !event
.shiftKey
)
1410 dijit
.byId("content-tabs").selectChild(article_pane
);
1412 if ($("PTITLE-" + id
))
1413 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1417 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1419 notify_progress("Loading, please wait...", true);
1421 new Ajax
.Request("backend.php", {
1423 onComplete: function(transport
) {
1426 var reply
= JSON
.parse(transport
.responseText
);
1429 //closeArticlePanel();
1431 var content
= reply
[0]['content'];
1433 var article_pane
= new dijit
.layout
.ContentPane({
1434 title
: "article-" + id
, content
: content
,
1435 style
: 'padding : 0px;',
1439 dijit
.byId("content-tabs").addChild(article_pane
);
1441 if (!event
|| !event
.shiftKey
)
1442 dijit
.byId("content-tabs").selectChild(article_pane
);
1444 if ($("PTITLE-" + id
))
1445 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1452 exception_error("zoomToArticle", e
);
1456 function scrollArticle(offset
) {
1459 var ci
= $("content-insert");
1461 ci
.scrollTop
+= offset
;
1464 var hi
= $("headlines-frame");
1466 hi
.scrollTop
+= offset
;
1471 exception_error("scrollArticle", e
);
1475 function show_labels_in_headlines(transport
) {
1477 var data
= JSON
.parse(transport
.responseText
);
1480 data
['info-for-headlines'].each(function(elem
) {
1481 var ctr
= $("HLLCTR-" + elem
.id
);
1483 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1486 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1490 exception_error("show_labels_in_headlines", e
);
1494 /* function toggleHeadlineActions() {
1496 var e = $("headlineActionsBody");
1497 var p = $("headlineActionsDrop");
1499 if (!Element.visible(e)) {
1506 e.style.left = (p.offsetLeft + 1) + "px";
1507 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1510 exception_error("toggleHeadlineActions", e);
1514 /* function publishWithNote(id, def_note) {
1516 if (!def_note) def_note = '';
1518 var note = prompt(__("Please enter a note for this article:"), def_note);
1520 if (note != undefined) {
1521 togglePub(id, false, false, note);
1525 exception_error("publishWithNote", e);
1529 function dismissArticle(id
) {
1531 var elem
= $("RROW-" + id
);
1533 toggleUnread(id
, 0, true);
1535 new Effect
.Fade(elem
, {duration
: 0.5});
1537 active_post_id
= false;
1540 exception_error("dismissArticle", e
);
1544 function dismissSelectedArticles() {
1547 var ids
= getVisibleArticleIds();
1551 for (var i
= 0; i
< ids
.length
; i
++) {
1552 var elem
= $("RROW-" + ids
[i
]);
1554 if (elem
.className
&& elem
.hasClassName("Selected") &&
1555 ids
[i
] != active_post_id
) {
1556 new Effect
.Fade(elem
, {duration
: 0.5});
1564 selectionToggleUnread(false);
1566 fixHeadlinesOrder(tmp
);
1569 exception_error("dismissSelectedArticles", e
);
1573 function dismissReadArticles() {
1576 var ids
= getVisibleArticleIds();
1579 for (var i
= 0; i
< ids
.length
; i
++) {
1580 var elem
= $("RROW-" + ids
[i
]);
1582 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1583 !elem
.hasClassName("Selected")) {
1585 new Effect
.Fade(elem
, {duration
: 0.5});
1591 fixHeadlinesOrder(tmp
);
1594 exception_error("dismissSelectedArticles", e
);
1598 function getVisibleArticleIds() {
1603 getLoadedArticleIds().each(function(id
) {
1604 var elem
= $("RROW-" + id
);
1605 if (elem
&& Element
.visible(elem
))
1610 exception_error("getVisibleArticleIds", e
);
1616 function cdmClicked(event
, id
) {
1618 //var shift_key = event.shiftKey;
1622 if (!event
.ctrlKey
) {
1624 if (!getInitParam("cdm_expanded")) {
1625 return cdmExpandArticle(id
);
1628 selectArticles("none");
1631 var elem
= $("RROW-" + id
);
1632 var article_is_unread
= elem
.hasClassName("Unread");
1635 elem
.removeClassName("Unread");
1637 var upd_img_pic
= $("FUPDPIC-" + id
);
1639 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1640 upd_img_pic
.src
.match("fresh_sign.png"))) {
1642 upd_img_pic
.src
= "images/blank_icon.gif";
1645 active_post_id
= id
;
1647 if (article_is_unread
) {
1648 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1651 var query
= "?op=rpc&method=catchupSelected" +
1652 "&cmode=0&ids=" + param_escape(id
);
1654 new Ajax
.Request("backend.php", {
1656 onComplete: function(transport
) {
1657 handle_rpc_json(transport
);
1664 toggleSelected(id
, true);
1666 var elem
= $("RROW-" + id
);
1667 var article_is_unread
= elem
.hasClassName("Unread");
1669 if (article_is_unread
) {
1670 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1673 toggleUnread(id
, 0, false);
1674 zoomToArticle(event
, id
);
1678 exception_error("cdmClicked");
1684 function postClicked(event
, id
) {
1687 if (!event
.ctrlKey
) {
1690 postOpenInNewTab(event
, id
);
1695 exception_error("postClicked");
1699 function hlOpenInNewTab(event
, id
) {
1700 toggleUnread(id
, 0, false);
1701 zoomToArticle(event
, id
);
1704 function postOpenInNewTab(event
, id
) {
1705 closeArticlePanel(id
);
1706 zoomToArticle(event
, id
);
1709 function hlClicked(event
, id
) {
1711 if (event
.which
== 2) {
1714 } else if (event
.altKey
) {
1715 openArticleInNewWindow(id
);
1716 } else if (!event
.ctrlKey
) {
1721 toggleUnread(id
, 0, false);
1722 zoomToArticle(event
, id
);
1727 exception_error("hlClicked");
1731 function getFirstVisibleHeadlineId() {
1732 var rows
= getVisibleArticleIds();
1737 function getLastVisibleHeadlineId() {
1738 var rows
= getVisibleArticleIds();
1739 return rows
[rows
.length
-1];
1742 function openArticleInNewWindow(id
) {
1743 toggleUnread(id
, 0, false);
1744 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1747 function isCdmMode() {
1748 return getInitParam("combined_display_mode");
1751 function markHeadline(id
) {
1752 var row
= $("RROW-" + id
);
1754 var check
= $("RCHK-" + id
);
1757 check
.checked
= true;
1760 row
.addClassName("Selected");
1764 function getRelativePostIds(id
, limit
) {
1770 if (!limit
) limit
= 6; //3
1772 var ids
= getVisibleArticleIds();
1774 for (var i
= 0; i
< ids
.length
; i
++) {
1776 for (var k
= 1; k
<= limit
; k
++) {
1777 //if (i > k-1) tmp.push(ids[i-k]);
1778 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1785 exception_error("getRelativePostIds", e
);
1791 function correctHeadlinesOffset(id
) {
1795 var container
= $("headlines-frame");
1796 var row
= $("RROW-" + id
);
1798 var viewport
= container
.offsetHeight
;
1800 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1801 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1803 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1804 //console.log("Vport: " + viewport);
1806 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1807 container
.scrollTop
= row
.offsetTop
;
1808 } else if (rel_offset_bottom
> viewport
) {
1810 /* doesn't properly work with Opera in some cases because
1811 Opera fucks up element scrolling */
1813 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1817 exception_error("correctHeadlinesOffset", e
);
1822 function headlineActionsChange(elem
) {
1825 elem
.attr('value', 'false');
1827 exception_error("headlineActionsChange", e
);
1831 function closeArticlePanel() {
1833 var tabs
= dijit
.byId("content-tabs");
1834 var child
= tabs
.selectedChildWidget
;
1836 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1837 tabs
.removeChild(child
);
1840 if (dijit
.byId("content-insert"))
1841 dijit
.byId("headlines-wrap-inner").removeChild(
1842 dijit
.byId("content-insert"));
1846 function initHeadlinesMenu() {
1848 if (dijit
.byId("headlinesMenu"))
1849 dijit
.byId("headlinesMenu").destroyRecursive();
1854 nodes
= $$("#headlines-frame > div[id*=RROW]");
1856 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1859 nodes
.each(function(node
) {
1863 var menu
= new dijit
.Menu({
1864 id
: "headlinesMenu",
1868 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1869 var callerNode
= event
.target
, match
= null, tries
= 0;
1871 while (match
== null && callerNode
&& tries
<= 3) {
1872 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1873 callerNode
= callerNode
.parentNode
;
1877 if (match
) this.callerRowId
= parseInt(match
[1]);
1881 /* if (!isCdmMode())
1882 menu.addChild(new dijit.MenuItem({
1883 label: __("View article"),
1884 onClick: function(event) {
1885 view(this.getParent().callerRowId);
1888 menu
.addChild(new dijit
.MenuItem({
1889 label
: __("Open original article"),
1890 onClick: function(event
) {
1891 openArticleInNewWindow(this.getParent().callerRowId
);
1894 menu
.addChild(new dijit
.MenuItem({
1895 label
: __("View in a tt-rss tab"),
1896 onClick: function(event
) {
1897 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1900 menu
.addChild(new dijit
.MenuSeparator());
1902 menu
.addChild(new dijit
.MenuItem({
1903 label
: __("Mark above as read"),
1904 onClick: function(event
) {
1905 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1908 menu
.addChild(new dijit
.MenuItem({
1909 label
: __("Mark below as read"),
1910 onClick: function(event
) {
1911 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1915 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1919 menu
.addChild(new dijit
.MenuSeparator());
1921 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1922 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1924 labels
.each(function(label
) {
1925 var id
= label
.id
[0];
1926 var bare_id
= id
.substr(id
.indexOf(":")+1);
1927 var name
= label
.name
[0];
1929 bare_id
= -11-bare_id
;
1931 labelAddMenu
.addChild(new dijit
.MenuItem({
1934 onClick: function(event
) {
1935 selectionAssignLabel(this.labelId
,
1936 [this.getParent().ownerMenu
.callerRowId
]);
1939 labelDelMenu
.addChild(new dijit
.MenuItem({
1942 onClick: function(event
) {
1943 selectionRemoveLabel(this.labelId
,
1944 [this.getParent().ownerMenu
.callerRowId
]);
1949 menu
.addChild(new dijit
.PopupMenuItem({
1950 label
: __("Assign label"),
1951 popup
: labelAddMenu
,
1954 menu
.addChild(new dijit
.PopupMenuItem({
1955 label
: __("Remove label"),
1956 popup
: labelDelMenu
,
1964 exception_error("initHeadlinesMenu", e
);
1969 function player(elem
) {
1970 var aid
= elem
.getAttribute("audio-id");
1971 var status
= elem
.getAttribute("status");
1979 elem
.innerHTML
= __("Playing...");
1980 elem
.title
= __("Click to pause");
1981 elem
.addClassName("playing");
1985 elem
.innerHTML
= __("Play");
1986 elem
.title
= __("Click to play");
1987 elem
.removeClassName("playing");
1990 elem
.setAttribute("status", status
);
1992 alert("Your browser doesn't seem to support HTML5 audio.");
1996 function cache_set(id
, obj
) {
1997 //console.log("cache_set: " + id);
2000 sessionStorage
[id
] = obj
;
2002 sessionStorage
.clear();
2006 function cache_get(id
) {
2008 return sessionStorage
[id
];
2011 function cache_clear() {
2013 sessionStorage
.clear();
2016 function cache_delete(id
) {
2018 sessionStorage
.removeItem(id
);
2021 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2022 if (toolbar_obj
&& content_obj
) {
2023 cache_set("feed:" + feed
+ ":" + is_cat
,
2024 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2027 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2030 obj
= JSON
.parse(obj
);
2032 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2033 if (content_obj
) obj
.content
= content_obj
;
2035 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2039 console
.warn("cache_headlines failed: " + e
);
2044 function render_local_headlines(feed
, is_cat
, obj
) {
2047 dijit
.byId("headlines-toolbar").attr('content',
2050 dijit
.byId("headlines-frame").attr('content',
2053 dojo
.parser
.parse('headlines-toolbar');
2055 $("headlines-frame").scrollTop
= 0;
2056 selectArticles('none');
2057 setActiveFeedId(feed
, is_cat
);
2058 initHeadlinesMenu();
2061 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
2062 cp
= row
.getElementsByClassName("contentPreview")[0];
2063 clamp_element(cp
, 50);
2066 precache_headlines();
2069 exception_error("render_local_headlines", e
);
2073 function precache_headlines_idle() {
2075 if (!feed_precache_timeout_id
) {
2076 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2079 feeds
.each(function(item
) {
2080 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2081 uncached
.push(item
);
2084 if (uncached
.length
> 0) {
2085 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2086 viewfeed(rf
[0], '', rf
[1], 0, true);
2089 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2092 exception_error("precache_headlines_idle", e
);
2096 function precache_headlines() {
2099 if (!feed_precache_timeout_id
) {
2100 feed_precache_timeout_id
= window
.setTimeout(function() {
2101 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2102 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2104 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2105 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2107 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2108 viewfeed(nf
[0], '', nf
[1], 0, true);
2110 window
.setTimeout(function() {
2111 feed_precache_timeout_id
= false;
2117 exception_error("precache_headlines", e
);