]>
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 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
> 1) {
85 row
.parentNode
.removeChild(row
);
89 if (getInitParam("cdm_auto_catchup") == 1) {
90 var hsp
= $("headlines-spacer");
91 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
92 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
99 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
100 console
.log("adding some more headlines...");
102 var c
= dijit
.byId("headlines-frame");
103 var ids
= getSelectedArticleIds2();
105 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
107 var hsp
= $("headlines-spacer");
110 c
.domNode
.removeChild(hsp
);
112 $$("#headlines-tmp > div").each(function(row
) {
113 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
114 row
.style
.display
= 'none';
115 c
.domNode
.appendChild(row
);
117 row
.parentNode
.removeChild(row
);
121 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
123 fixHeadlinesOrder(getLoadedArticleIds());
125 if (getInitParam("cdm_auto_catchup") == 1) {
126 c
.domNode
.appendChild(hsp
);
129 console
.log("restore selected ids: " + ids
);
131 for (var i
= 0; i
< ids
.length
; i
++) {
132 markHeadline(ids
[i
]);
137 $$("#headlines-frame > div[id*=RROW]").each(
139 if (!Element
.visible(child
))
140 new Effect
.Appear(child
, { duration
: 0.5 });
144 console
.log("no new headlines received");
146 var hsp
= $("headlines-spacer");
148 if (hsp
) hsp
.innerHTML
= "";
152 if (headlines_count
> 0)
153 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
156 for (var i
= 0; i
< articles
.length
; i
++) {
157 var a_id
= articles
[i
]['id'];
158 cache_set("article:" + a_id
, articles
[i
]['content']);
161 console
.log("no cached articles received");
164 // do not precache stuff after fresh feed
166 precache_headlines();
169 parse_counters(counters
);
174 console
.error("Invalid object received: " + transport
.responseText
);
175 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
176 __('Could not update headlines (invalid object received - see error console for details)') +
180 _infscroll_request_sent
= 0;
185 exception_error("headlines_callback2", e
, transport
);
189 function render_article(article
) {
191 dijit
.byId("headlines-wrap-inner").addChild(
192 dijit
.byId("content-insert"));
194 var c
= dijit
.byId("content-insert");
197 c
.domNode
.scrollTop
= 0;
200 c
.attr('content', article
);
202 correctHeadlinesOffset(getActiveArticleId());
209 exception_error("render_article", e
);
213 function showArticleInHeadlines(id
) {
217 selectArticles("none");
219 var crow
= $("RROW-" + id
);
223 var article_is_unread
= crow
.hasClassName("Unread");
225 crow
.removeClassName("Unread");
227 selectArticles('none');
229 var upd_img_pic
= $("FUPDPIC-" + id
);
231 var view_mode
= false;
234 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
235 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
240 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
241 upd_img_pic
.src
.match("fresh_sign.png"))) {
243 upd_img_pic
.src
= "images/blank_icon.gif";
245 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
247 } else if (article_is_unread
&& view_mode
== "all_articles") {
248 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
253 if (article_is_unread
)
254 _force_scheduled_update
= true;
257 exception_error("showArticleInHeadlines", e
);
261 function article_callback2(transport
, id
) {
263 console
.log("article_callback2 " + id
);
265 handle_rpc_json(transport
);
270 reply
= JSON
.parse(transport
.responseText
);
277 var upic
= $('FUPDPIC-' + id
);
279 if (upic
) upic
.src
= 'images/blank_icon.gif';
281 reply
.each(function(article
) {
282 if (active_post_id
== article
['id']) {
283 render_article(article
['content']);
285 cids_requested
.remove(article
['id']);
287 cache_set("article:" + article
['id'], article
['content']);
290 // if (id != last_requested_article) {
291 // console.log("requested article id is out of sequence, aborting");
296 console
.error("Invalid object received: " + transport
.responseText
);
298 render_article("<div class='whiteBox'>" +
299 __('Could not display article (invalid object received - see error console for details)') + "</div>");
305 if (!_infscroll_disable
&&
306 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
316 exception_error("article_callback2", e
, transport
);
322 console
.log("loading article: " + id
);
324 var cached_article
= cache_get("article:" + id
);
326 console
.log("cache check result: " + (cached_article
!= false));
330 var query
= "?op=article&method=view&id=" + param_escape(id
);
332 var neighbor_ids
= getRelativePostIds(id
);
334 /* only request uncached articles */
336 var cids_to_request
= [];
338 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
339 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
340 if (!cache_get("article:" + neighbor_ids
[i
])) {
341 cids_to_request
.push(neighbor_ids
[i
]);
342 cids_requested
.push(neighbor_ids
[i
]);
346 console
.log("additional ids: " + cids_to_request
.toString());
348 query
= query
+ "&cids=" + cids_to_request
.toString();
350 var crow
= $("RROW-" + id
);
351 var article_is_unread
= crow
.hasClassName("Unread");
354 showArticleInHeadlines(id
);
356 precache_headlines();
358 if (!cached_article
) {
360 var upic
= $('FUPDPIC-' + id
);
363 upic
.src
= getInitParam("sign_progress");
366 } else if (cached_article
&& article_is_unread
) {
368 query
= query
+ "&mode=prefetch";
370 render_article(cached_article
);
372 } else if (cached_article
) {
374 query
= query
+ "&mode=prefetch_old";
375 render_article(cached_article
);
377 // if we don't need to request any relative ids, we might as well skip
378 // the server roundtrip altogether
379 if (cids_to_request
.length
== 0) {
382 if (!_infscroll_disable
&&
383 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
395 last_requested_article
= id
;
399 if (article_is_unread
) {
400 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
403 new Ajax
.Request("backend.php", {
405 onComplete: function(transport
) {
406 article_callback2(transport
, id
);
412 exception_error("view", e
);
416 function toggleMark(id
, client_only
) {
418 var query
= "?op=rpc&id=" + id
+ "&method=mark";
420 var img
= $("FMPIC-" + id
);
424 if (img
.src
.match("mark_unset")) {
425 img
.src
= img
.src
.replace("mark_unset", "mark_set");
426 img
.alt
= __("Unstar article");
427 query
= query
+ "&mark=1";
430 img
.src
= img
.src
.replace("mark_set", "mark_unset");
431 img
.alt
= __("Star article");
432 query
= query
+ "&mark=0";
435 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
438 new Ajax
.Request("backend.php", {
440 onComplete: function(transport
) {
441 handle_rpc_json(transport
);
446 exception_error("toggleMark", e
);
450 function togglePub(id
, client_only
, no_effects
, note
) {
452 var query
= "?op=rpc&id=" + id
+ "&method=publ";
454 if (note
!= undefined) {
455 query
= query
+ "¬e=" + param_escape(note
);
457 query
= query
+ "¬e=undefined";
460 var img
= $("FPPIC-" + id
);
464 if (img
.src
.match("pub_unset") || note
!= undefined) {
465 img
.src
= img
.src
.replace("pub_unset", "pub_set");
466 img
.alt
= __("Unpublish article");
467 query
= query
+ "&pub=1";
470 img
.src
= img
.src
.replace("pub_set", "pub_unset");
471 img
.alt
= __("Publish article");
473 query
= query
+ "&pub=0";
476 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
479 new Ajax
.Request("backend.php", {
481 onComplete: function(transport
) {
482 handle_rpc_json(transport
);
487 exception_error("togglePub", e
);
491 function moveToPost(mode
) {
495 var rows
= getVisibleArticleIds();
500 if (!$('RROW-' + active_post_id
)) {
501 active_post_id
= false;
504 if (active_post_id
== false) {
506 prev_id
= rows
[rows
.length
-1]
508 for (var i
= 0; i
< rows
.length
; i
++) {
509 if (rows
[i
] == active_post_id
) {
511 // Account for adjacent identical article ids.
512 if (i
> 0) prev_id
= rows
[i
-1];
514 for (var j
= i
+1; j
< rows
.length
; j
++) {
515 if (rows
[j
] != active_post_id
) {
525 if (mode
== "next") {
529 cdmExpandArticle(next_id
);
530 cdmScrollToArticleId(next_id
);
533 correctHeadlinesOffset(next_id
);
534 view(next_id
, getActiveFeedId());
539 if (mode
== "prev") {
542 cdmExpandArticle(prev_id
);
543 cdmScrollToArticleId(prev_id
);
545 correctHeadlinesOffset(prev_id
);
546 view(prev_id
, getActiveFeedId());
552 exception_error("moveToPost", e
);
556 function toggleSelected(id
, force_on
) {
559 var cb
= $("RCHK-" + id
);
560 var row
= $("RROW-" + id
);
563 if (row
.hasClassName('Selected') && !force_on
) {
564 row
.removeClassName('Selected');
565 if (cb
) cb
.checked
= false;
567 row
.addClassName('Selected');
568 if (cb
) cb
.checked
= true;
572 exception_error("toggleSelected", e
);
576 function toggleUnread_afh(effect
) {
579 var elem
= effect
.element
;
580 elem
.style
.backgroundColor
= "";
583 exception_error("toggleUnread_afh", e
);
587 function toggleUnread(id
, cmode
, effect
) {
590 var row
= $("RROW-" + id
);
592 if (cmode
== undefined || cmode
== 2) {
593 if (row
.hasClassName("Unread")) {
594 row
.removeClassName("Unread");
597 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
598 afterFinish
: toggleUnread_afh
,
599 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
603 row
.addClassName("Unread");
606 } else if (cmode
== 0) {
608 row
.removeClassName("Unread");
611 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
612 afterFinish
: toggleUnread_afh
,
613 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
616 } else if (cmode
== 1) {
617 row
.addClassName("Unread");
620 if (cmode
== undefined) cmode
= 2;
622 var query
= "?op=rpc&method=catchupSelected" +
623 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
625 // notify_progress("Loading, please wait...");
627 new Ajax
.Request("backend.php", {
629 onComplete: function(transport
) {
630 handle_rpc_json(transport
);
636 exception_error("toggleUnread", e
);
640 function selectionRemoveLabel(id
, ids
) {
643 if (!ids
) ids
= getSelectedArticleIds2();
645 if (ids
.length
== 0) {
646 alert(__("No articles are selected."));
650 var query
= "?op=rpc&method=removeFromLabel&ids=" +
651 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
655 new Ajax
.Request("backend.php", {
657 onComplete: function(transport
) {
658 handle_rpc_json(transport
);
659 show_labels_in_headlines(transport
);
663 exception_error("selectionAssignLabel", e
);
668 function selectionAssignLabel(id
, ids
) {
671 if (!ids
) ids
= getSelectedArticleIds2();
673 if (ids
.length
== 0) {
674 alert(__("No articles are selected."));
678 var query
= "?op=rpc&method=assignToLabel&ids=" +
679 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
683 new Ajax
.Request("backend.php", {
685 onComplete: function(transport
) {
686 handle_rpc_json(transport
);
687 show_labels_in_headlines(transport
);
691 exception_error("selectionAssignLabel", e
);
696 function selectionToggleUnread(set_state
, callback
, no_error
) {
698 var rows
= getSelectedArticleIds2();
700 if (rows
.length
== 0 && !no_error
) {
701 alert(__("No articles are selected."));
705 for (var i
= 0; i
< rows
.length
; i
++) {
706 var row
= $("RROW-" + rows
[i
]);
708 if (set_state
== undefined) {
709 if (row
.hasClassName("Unread")) {
710 row
.removeClassName("Unread");
712 row
.addClassName("Unread");
716 if (set_state
== false) {
717 row
.removeClassName("Unread");
720 if (set_state
== true) {
721 row
.addClassName("Unread");
726 if (rows
.length
> 0) {
730 if (set_state
== undefined) {
732 } else if (set_state
== true) {
734 } else if (set_state
== false) {
738 var query
= "?op=rpc&method=catchupSelected" +
739 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
741 notify_progress("Loading, please wait...");
743 new Ajax
.Request("backend.php", {
745 onComplete: function(transport
) {
746 handle_rpc_json(transport
);
747 if (callback
) callback(transport
);
753 exception_error("selectionToggleUnread", e
);
757 function selectionToggleMarked() {
760 var rows
= getSelectedArticleIds2();
762 if (rows
.length
== 0) {
763 alert(__("No articles are selected."));
767 for (var i
= 0; i
< rows
.length
; i
++) {
768 toggleMark(rows
[i
], true, true);
771 if (rows
.length
> 0) {
773 var query
= "?op=rpc&method=markSelected&ids=" +
774 param_escape(rows
.toString()) + "&cmode=2";
776 new Ajax
.Request("backend.php", {
778 onComplete: function(transport
) {
779 handle_rpc_json(transport
);
785 exception_error("selectionToggleMarked", e
);
789 function selectionTogglePublished() {
792 var rows
= getSelectedArticleIds2();
794 if (rows
.length
== 0) {
795 alert(__("No articles are selected."));
799 for (var i
= 0; i
< rows
.length
; i
++) {
800 togglePub(rows
[i
], true, true);
803 if (rows
.length
> 0) {
805 var query
= "?op=rpc&method=publishSelected&ids=" +
806 param_escape(rows
.toString()) + "&cmode=2";
808 new Ajax
.Request("backend.php", {
810 onComplete: function(transport
) {
811 handle_rpc_json(transport
);
817 exception_error("selectionToggleMarked", e
);
821 function getSelectedArticleIds2() {
825 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
827 rv
.push(child
.id
.replace("RROW-", ""));
833 function getLoadedArticleIds() {
836 var children
= $$("#headlines-frame > div[id*=RROW-]");
838 children
.each(function(child
) {
839 rv
.push(child
.id
.replace("RROW-", ""));
846 // mode = all,none,unread,invert
847 function selectArticles(mode
) {
850 var children
= $$("#headlines-frame > div[id*=RROW]");
852 children
.each(function(child
) {
853 var id
= child
.id
.replace("RROW-", "");
854 var cb
= $("RCHK-" + id
);
857 child
.addClassName("Selected");
859 } else if (mode
== "unread") {
860 if (child
.hasClassName("Unread")) {
861 child
.addClassName("Selected");
864 child
.removeClassName("Selected");
867 } else if (mode
== "invert") {
868 if (child
.hasClassName("Selected")) {
869 child
.removeClassName("Selected");
872 child
.addClassName("Selected");
877 child
.removeClassName("Selected");
883 exception_error("selectArticles", e
);
887 function catchupPage() {
889 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
891 var str
= __("Mark all visible articles in %s as read?");
893 str
= str
.replace("%s", fn
);
895 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
899 selectArticles('all');
900 selectionToggleUnread(false, 'viewCurrentFeed()', true);
901 selectArticles('none');
904 function deleteSelection() {
908 var rows
= getSelectedArticleIds2();
910 if (rows
.length
== 0) {
911 alert(__("No articles are selected."));
915 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
918 if (getActiveFeedId() != 0) {
919 str
= __("Delete %d selected articles in %s?");
921 str
= __("Delete %d selected articles?");
924 str
= str
.replace("%d", rows
.length
);
925 str
= str
.replace("%s", fn
);
927 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
931 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
935 new Ajax
.Request("backend.php", {
937 onComplete: function(transport
) {
938 handle_rpc_json(transport
);
943 exception_error("deleteSelection", e
);
947 function archiveSelection() {
951 var rows
= getSelectedArticleIds2();
953 if (rows
.length
== 0) {
954 alert(__("No articles are selected."));
958 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
962 if (getActiveFeedId() != 0) {
963 str
= __("Archive %d selected articles in %s?");
966 str
= __("Move %d archived articles back?");
970 str
= str
.replace("%d", rows
.length
);
971 str
= str
.replace("%s", fn
);
973 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
977 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
981 for (var i
= 0; i
< rows
.length
; i
++) {
982 cache_delete("article:" + rows
[i
]);
985 new Ajax
.Request("backend.php", {
987 onComplete: function(transport
) {
988 handle_rpc_json(transport
);
993 exception_error("archiveSelection", e
);
997 function catchupSelection() {
1001 var rows
= getSelectedArticleIds2();
1003 if (rows
.length
== 0) {
1004 alert(__("No articles are selected."));
1008 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1010 var str
= __("Mark %d selected articles in %s as read?");
1012 str
= str
.replace("%d", rows
.length
);
1013 str
= str
.replace("%s", fn
);
1015 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1019 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1022 exception_error("catchupSelection", e
);
1026 function editArticleTags(id
) {
1027 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1029 if (dijit
.byId("editTagsDlg"))
1030 dijit
.byId("editTagsDlg").destroyRecursive();
1032 dialog
= new dijit
.Dialog({
1034 title
: __("Edit article Tags"),
1035 style
: "width: 600px",
1036 execute: function() {
1037 if (this.validate()) {
1038 var query
= dojo
.objectToQuery(this.attr('value'));
1040 notify_progress("Saving article tags...", true);
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1048 var data
= JSON
.parse(transport
.responseText
);
1051 var tags_str
= article
.tags
;
1052 var id
= tags_str
.id
;
1054 var tags
= $("ATSTR-" + id
);
1055 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1057 if (tags
) tags
.innerHTML
= tags_str
.content
;
1058 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1060 cache_delete("article:" + id
);
1069 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1070 dojo
.disconnect(tmph
);
1072 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1073 "backend.php?op=rpc&method=completeTags",
1074 { tokens
: ',', paramName
: "search" });
1081 function cdmScrollToArticleId(id
) {
1083 var ctr
= $("headlines-frame");
1084 var e
= $("RROW-" + id
);
1086 if (!e
|| !ctr
) return;
1088 ctr
.scrollTop
= e
.offsetTop
;
1091 exception_error("cdmScrollToArticleId", e
);
1095 function getActiveArticleId() {
1096 return active_post_id
;
1099 function postMouseIn(id
) {
1100 post_under_pointer
= id
;
1103 function postMouseOut(id
) {
1104 post_under_pointer
= false;
1107 function headlines_scroll_handler(e
) {
1109 var hsp
= $("headlines-spacer");
1111 if (!_infscroll_disable
) {
1112 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1113 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1116 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1117 __("Loading, please wait...");
1119 loadMoreHeadlines();
1124 if (hsp
) hsp
.innerHTML
= "";
1127 if (getInitParam("cdm_auto_catchup") == 1) {
1129 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1131 if ($("headlines-frame").scrollTop
>
1132 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1134 var id
= child
.id
.replace("RROW-", "");
1136 if (catchup_id_batch
.indexOf(id
) == -1)
1137 catchup_id_batch
.push(id
);
1139 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1143 if (catchup_id_batch
.length
> 0) {
1144 window
.clearTimeout(catchup_timeout_id
);
1146 if (!_infscroll_request_sent
) {
1147 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1154 console
.warn("headlines_scroll_handler: " + e
);
1158 function catchupBatchedArticles() {
1160 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1162 var query
= "?op=rpc&method=catchupSelected" +
1163 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1165 new Ajax
.Request("backend.php", {
1167 onComplete: function(transport
) {
1168 handle_rpc_json(transport
);
1170 catchup_id_batch
.each(function(id
) {
1171 var elem
= $("RROW-" + id
);
1172 if (elem
) elem
.removeClassName("Unread");
1175 catchup_id_batch
= [];
1180 exception_error("catchupBatchedArticles", e
);
1184 function catchupRelativeToArticle(below
, id
) {
1188 if (!id
) id
= getActiveArticleId();
1191 alert(__("No article is selected."));
1195 var visible_ids
= getVisibleArticleIds();
1197 var ids_to_mark
= new Array();
1200 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1201 if (visible_ids
[i
] != id
) {
1202 var e
= $("RROW-" + visible_ids
[i
]);
1204 if (e
&& e
.hasClassName("Unread")) {
1205 ids_to_mark
.push(visible_ids
[i
]);
1212 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1213 if (visible_ids
[i
] != id
) {
1214 var e
= $("RROW-" + visible_ids
[i
]);
1216 if (e
&& e
.hasClassName("Unread")) {
1217 ids_to_mark
.push(visible_ids
[i
]);
1225 if (ids_to_mark
.length
== 0) {
1226 alert(__("No articles found to mark"));
1228 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1230 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1232 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1233 var e
= $("RROW-" + ids_to_mark
[i
]);
1234 e
.removeClassName("Unread");
1237 var query
= "?op=rpc&method=catchupSelected" +
1238 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1240 new Ajax
.Request("backend.php", {
1242 onComplete: function(transport
) {
1243 handle_rpc_json(transport
);
1250 exception_error("catchupRelativeToArticle", e
);
1254 function cdmExpandArticle(id
) {
1259 var elem
= $("CICD-" + active_post_id
);
1261 var upd_img_pic
= $("FUPDPIC-" + id
);
1263 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1264 upd_img_pic
.src
.match("fresh_sign.png"))) {
1266 upd_img_pic
.src
= "images/blank_icon.gif";
1269 if (id
== active_post_id
&& Element
.visible(elem
))
1272 selectArticles("none");
1274 var old_offset
= $("RROW-" + id
).offsetTop
;
1276 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1278 Element
.show("CEXC-" + active_post_id
);
1281 active_post_id
= id
;
1283 elem
= $("CICD-" + id
);
1285 if (!Element
.visible(elem
)) {
1287 Element
.hide("CEXC-" + id
);
1289 if ($("CWRAP-" + id
).innerHTML
== "") {
1291 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1293 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1294 __("Loading, please wait...") + "</div>";
1296 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1298 var neighbor_ids
= getRelativePostIds(id
);
1300 /* only request uncached articles */
1301 var cids_to_request
= [];
1303 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1304 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1305 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1306 cids_to_request
.push(neighbor_ids
[i
]);
1307 cids_requested
.push(neighbor_ids
[i
]);
1311 console
.log("additional ids: " + cids_to_request
.toString());
1313 query
= query
+ "&cids=" + cids_to_request
.toString();
1317 new Ajax
.Request("backend.php", {
1319 onComplete: function(transport
) {
1321 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1323 handle_rpc_json(transport
);
1325 var reply
= JSON
.parse(transport
.responseText
);
1327 reply
.each(function(article
) {
1328 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1329 cids_requested
.remove(article
['id']);
1336 var new_offset
= $("RROW-" + id
).offsetTop
;
1338 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1340 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1341 $("headlines-frame").scrollTop
= new_offset
;
1343 toggleUnread(id
, 0, true);
1347 exception_error("cdmExpandArticle", e
);
1353 function fixHeadlinesOrder(ids
) {
1355 for (var i
= 0; i
< ids
.length
; i
++) {
1356 var e
= $("RROW-" + ids
[i
]);
1360 e
.removeClassName("even");
1361 e
.addClassName("odd");
1363 e
.removeClassName("odd");
1364 e
.addClassName("even");
1369 exception_error("fixHeadlinesOrder", e
);
1373 function getArticleUnderPointer() {
1374 return post_under_pointer
;
1377 function zoomToArticle(event
, id
) {
1379 var cached_article
= cache_get("article: " + id
);
1381 if (dijit
.byId("ATAB-" + id
))
1382 if (!event
|| !event
.shiftKey
)
1383 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1385 if (dijit
.byId("ATSTRTIP-" + id
))
1386 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1388 if (cached_article
) {
1389 //closeArticlePanel();
1391 var article_pane
= new dijit
.layout
.ContentPane({
1392 title
: __("Loading...") , content
: cached_article
,
1393 style
: 'padding : 0px;',
1397 dijit
.byId("content-tabs").addChild(article_pane
);
1399 if (!event
|| !event
.shiftKey
)
1400 dijit
.byId("content-tabs").selectChild(article_pane
);
1402 if ($("PTITLE-" + id
))
1403 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1407 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1409 notify_progress("Loading, please wait...", true);
1411 new Ajax
.Request("backend.php", {
1413 onComplete: function(transport
) {
1416 var reply
= JSON
.parse(transport
.responseText
);
1419 //closeArticlePanel();
1421 var content
= reply
[0]['content'];
1423 var article_pane
= new dijit
.layout
.ContentPane({
1424 title
: "article-" + id
, content
: content
,
1425 style
: 'padding : 0px;',
1429 dijit
.byId("content-tabs").addChild(article_pane
);
1431 if (!event
|| !event
.shiftKey
)
1432 dijit
.byId("content-tabs").selectChild(article_pane
);
1434 if ($("PTITLE-" + id
))
1435 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1442 exception_error("zoomToArticle", e
);
1446 function scrollArticle(offset
) {
1449 var ci
= $("content-insert");
1451 ci
.scrollTop
+= offset
;
1454 var hi
= $("headlines-frame");
1456 hi
.scrollTop
+= offset
;
1461 exception_error("scrollArticle", e
);
1465 function show_labels_in_headlines(transport
) {
1467 var data
= JSON
.parse(transport
.responseText
);
1470 data
['info-for-headlines'].each(function(elem
) {
1471 var ctr
= $("HLLCTR-" + elem
.id
);
1473 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1476 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1480 exception_error("show_labels_in_headlines", e
);
1484 /* function toggleHeadlineActions() {
1486 var e = $("headlineActionsBody");
1487 var p = $("headlineActionsDrop");
1489 if (!Element.visible(e)) {
1496 e.style.left = (p.offsetLeft + 1) + "px";
1497 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1500 exception_error("toggleHeadlineActions", e);
1504 /* function publishWithNote(id, def_note) {
1506 if (!def_note) def_note = '';
1508 var note = prompt(__("Please enter a note for this article:"), def_note);
1510 if (note != undefined) {
1511 togglePub(id, false, false, note);
1515 exception_error("publishWithNote", e);
1519 function dismissArticle(id
) {
1521 var elem
= $("RROW-" + id
);
1523 toggleUnread(id
, 0, true);
1525 new Effect
.Fade(elem
, {duration
: 0.5});
1527 active_post_id
= false;
1530 exception_error("dismissArticle", e
);
1534 function dismissSelectedArticles() {
1537 var ids
= getVisibleArticleIds();
1541 for (var i
= 0; i
< ids
.length
; i
++) {
1542 var elem
= $("RROW-" + ids
[i
]);
1544 if (elem
.className
&& elem
.hasClassName("Selected") &&
1545 ids
[i
] != active_post_id
) {
1546 new Effect
.Fade(elem
, {duration
: 0.5});
1554 selectionToggleUnread(false);
1556 fixHeadlinesOrder(tmp
);
1559 exception_error("dismissSelectedArticles", e
);
1563 function dismissReadArticles() {
1566 var ids
= getVisibleArticleIds();
1569 for (var i
= 0; i
< ids
.length
; i
++) {
1570 var elem
= $("RROW-" + ids
[i
]);
1572 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1573 !elem
.hasClassName("Selected")) {
1575 new Effect
.Fade(elem
, {duration
: 0.5});
1581 fixHeadlinesOrder(tmp
);
1584 exception_error("dismissSelectedArticles", e
);
1588 function getVisibleArticleIds() {
1593 getLoadedArticleIds().each(function(id
) {
1594 var elem
= $("RROW-" + id
);
1595 if (elem
&& Element
.visible(elem
))
1600 exception_error("getVisibleArticleIds", e
);
1606 function cdmClicked(event
, id
) {
1608 //var shift_key = event.shiftKey;
1612 if (!event
.ctrlKey
) {
1614 if (!getInitParam("cdm_expanded")) {
1615 return cdmExpandArticle(id
);
1618 selectArticles("none");
1621 var elem
= $("RROW-" + id
);
1622 var article_is_unread
= elem
.hasClassName("Unread");
1625 elem
.removeClassName("Unread");
1627 var upd_img_pic
= $("FUPDPIC-" + id
);
1629 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1630 upd_img_pic
.src
.match("fresh_sign.png"))) {
1632 upd_img_pic
.src
= "images/blank_icon.gif";
1635 active_post_id
= id
;
1637 if (article_is_unread
) {
1638 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1641 var query
= "?op=rpc&method=catchupSelected" +
1642 "&cmode=0&ids=" + param_escape(id
);
1644 new Ajax
.Request("backend.php", {
1646 onComplete: function(transport
) {
1647 handle_rpc_json(transport
);
1654 toggleSelected(id
, true);
1656 var elem
= $("RROW-" + id
);
1657 var article_is_unread
= elem
.hasClassName("Unread");
1659 if (article_is_unread
) {
1660 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1663 toggleUnread(id
, 0, false);
1664 zoomToArticle(event
, id
);
1668 exception_error("cdmClicked");
1674 function postClicked(event
, id
) {
1677 if (!event
.ctrlKey
) {
1680 postOpenInNewTab(event
, id
);
1685 exception_error("postClicked");
1689 function hlOpenInNewTab(event
, id
) {
1690 toggleUnread(id
, 0, false);
1691 zoomToArticle(event
, id
);
1694 function postOpenInNewTab(event
, id
) {
1695 closeArticlePanel(id
);
1696 zoomToArticle(event
, id
);
1699 function hlClicked(event
, id
) {
1701 if (event
.which
== 2) {
1704 } else if (event
.altKey
) {
1705 openArticleInNewWindow(id
);
1706 } else if (!event
.ctrlKey
) {
1711 toggleUnread(id
, 0, false);
1712 zoomToArticle(event
, id
);
1717 exception_error("hlClicked");
1721 function getFirstVisibleHeadlineId() {
1722 var rows
= getVisibleArticleIds();
1727 function getLastVisibleHeadlineId() {
1728 var rows
= getVisibleArticleIds();
1729 return rows
[rows
.length
-1];
1732 function openArticleInNewWindow(id
) {
1733 toggleUnread(id
, 0, false);
1734 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1737 function isCdmMode() {
1738 return getInitParam("combined_display_mode");
1741 function markHeadline(id
) {
1742 var row
= $("RROW-" + id
);
1744 var check
= $("RCHK-" + id
);
1747 check
.checked
= true;
1750 row
.addClassName("Selected");
1754 function getRelativePostIds(id
, limit
) {
1760 if (!limit
) limit
= 6; //3
1762 var ids
= getVisibleArticleIds();
1764 for (var i
= 0; i
< ids
.length
; i
++) {
1766 for (var k
= 1; k
<= limit
; k
++) {
1767 //if (i > k-1) tmp.push(ids[i-k]);
1768 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1775 exception_error("getRelativePostIds", e
);
1781 function correctHeadlinesOffset(id
) {
1785 var container
= $("headlines-frame");
1786 var row
= $("RROW-" + id
);
1788 var viewport
= container
.offsetHeight
;
1790 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1791 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1793 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1794 //console.log("Vport: " + viewport);
1796 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1797 container
.scrollTop
= row
.offsetTop
;
1798 } else if (rel_offset_bottom
> viewport
) {
1800 /* doesn't properly work with Opera in some cases because
1801 Opera fucks up element scrolling */
1803 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1807 exception_error("correctHeadlinesOffset", e
);
1812 function headlineActionsChange(elem
) {
1815 elem
.attr('value', 'false');
1817 exception_error("headlineActionsChange", e
);
1821 function closeArticlePanel() {
1823 var tabs
= dijit
.byId("content-tabs");
1824 var child
= tabs
.selectedChildWidget
;
1826 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1827 tabs
.removeChild(child
);
1830 if (dijit
.byId("content-insert"))
1831 dijit
.byId("headlines-wrap-inner").removeChild(
1832 dijit
.byId("content-insert"));
1836 function initHeadlinesMenu() {
1838 if (dijit
.byId("headlinesMenu"))
1839 dijit
.byId("headlinesMenu").destroyRecursive();
1844 nodes
= $$("#headlines-frame > div[id*=RROW]");
1846 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1849 nodes
.each(function(node
) {
1853 var menu
= new dijit
.Menu({
1854 id
: "headlinesMenu",
1858 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1859 var callerNode
= event
.target
, match
= null, tries
= 0;
1861 while (match
== null && callerNode
&& tries
<= 3) {
1862 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1863 callerNode
= callerNode
.parentNode
;
1867 if (match
) this.callerRowId
= parseInt(match
[1]);
1871 /* if (!isCdmMode())
1872 menu.addChild(new dijit.MenuItem({
1873 label: __("View article"),
1874 onClick: function(event) {
1875 view(this.getParent().callerRowId);
1878 menu
.addChild(new dijit
.MenuItem({
1879 label
: __("Open original article"),
1880 onClick: function(event
) {
1881 openArticleInNewWindow(this.getParent().callerRowId
);
1884 menu
.addChild(new dijit
.MenuItem({
1885 label
: __("View in a tt-rss tab"),
1886 onClick: function(event
) {
1887 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1890 menu
.addChild(new dijit
.MenuSeparator());
1892 menu
.addChild(new dijit
.MenuItem({
1893 label
: __("Mark above as read"),
1894 onClick: function(event
) {
1895 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1898 menu
.addChild(new dijit
.MenuItem({
1899 label
: __("Mark below as read"),
1900 onClick: function(event
) {
1901 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1905 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1909 menu
.addChild(new dijit
.MenuSeparator());
1911 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1912 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1914 labels
.each(function(label
) {
1915 var id
= label
.id
[0];
1916 var bare_id
= id
.substr(id
.indexOf(":")+1);
1917 var name
= label
.name
[0];
1919 bare_id
= -11-bare_id
;
1921 labelAddMenu
.addChild(new dijit
.MenuItem({
1924 onClick: function(event
) {
1925 selectionAssignLabel(this.labelId
,
1926 [this.getParent().ownerMenu
.callerRowId
]);
1929 labelDelMenu
.addChild(new dijit
.MenuItem({
1932 onClick: function(event
) {
1933 selectionRemoveLabel(this.labelId
,
1934 [this.getParent().ownerMenu
.callerRowId
]);
1939 menu
.addChild(new dijit
.PopupMenuItem({
1940 label
: __("Assign label"),
1941 popup
: labelAddMenu
,
1944 menu
.addChild(new dijit
.PopupMenuItem({
1945 label
: __("Remove label"),
1946 popup
: labelDelMenu
,
1954 exception_error("initHeadlinesMenu", e
);
1959 function player(elem
) {
1960 var aid
= elem
.getAttribute("audio-id");
1961 var status
= elem
.getAttribute("status");
1969 elem
.innerHTML
= __("Playing...");
1970 elem
.title
= __("Click to pause");
1971 elem
.addClassName("playing");
1975 elem
.innerHTML
= __("Play");
1976 elem
.title
= __("Click to play");
1977 elem
.removeClassName("playing");
1980 elem
.setAttribute("status", status
);
1982 alert("Your browser doesn't seem to support HTML5 audio.");
1986 function cache_set(id
, obj
) {
1987 //console.log("cache_set: " + id);
1990 sessionStorage
[id
] = obj
;
1992 sessionStorage
.clear();
1996 function cache_get(id
) {
1998 return sessionStorage
[id
];
2001 function cache_clear() {
2003 sessionStorage
.clear();
2006 function cache_delete(id
) {
2008 sessionStorage
.removeItem(id
);
2011 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2012 if (toolbar_obj
&& content_obj
) {
2013 cache_set("feed:" + feed
+ ":" + is_cat
,
2014 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2017 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2020 obj
= JSON
.parse(obj
);
2022 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2023 if (content_obj
) obj
.content
= content_obj
;
2025 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2029 console
.warn("cache_headlines failed: " + e
);
2034 function render_local_headlines(feed
, is_cat
, obj
) {
2037 dijit
.byId("headlines-toolbar").attr('content',
2040 dijit
.byId("headlines-frame").attr('content',
2043 dojo
.parser
.parse('headlines-toolbar');
2045 $("headlines-frame").scrollTop
= 0;
2046 selectArticles('none');
2047 setActiveFeedId(feed
, is_cat
);
2048 initHeadlinesMenu();
2050 precache_headlines();
2053 exception_error("render_local_headlines", e
);
2057 function precache_headlines_idle() {
2059 if (!feed_precache_timeout_id
) {
2060 if (get_timestamp() - _viewfeed_last
> 120) {
2062 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2065 feeds
.each(function(item
) {
2066 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2067 uncached
.push(item
);
2070 if (uncached
.length
> 0) {
2071 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2072 viewfeed(rf
[0], '', rf
[1], 0, true);
2076 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2079 exception_error("precache_headlines_idle", e
);
2083 function precache_headlines() {
2086 if (!feed_precache_timeout_id
) {
2087 feed_precache_timeout_id
= window
.setTimeout(function() {
2088 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2089 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2091 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2092 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2094 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2095 viewfeed(nf
[0], '', nf
[1], 0, true);
2097 window
.setTimeout(function() {
2098 feed_precache_timeout_id
= false;
2104 exception_error("precache_headlines", e
);