]>
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']);
84 if (getInitParam("cdm_auto_catchup") == 1) {
85 var hsp
= $("headlines-spacer");
86 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
87 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
94 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
95 console
.log("adding some more headlines...");
97 var c
= dijit
.byId("headlines-frame");
98 var ids
= getSelectedArticleIds2();
100 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
102 var hsp
= $("headlines-spacer");
105 c
.domNode
.removeChild(hsp
);
107 $$("#headlines-tmp > div").each(function(row
) {
108 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
109 row
.style
.display
= 'none';
110 c
.domNode
.appendChild(row
);
112 row
.parentNode
.removeChild(row
);
116 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
118 fixHeadlinesOrder(getLoadedArticleIds());
120 if (getInitParam("cdm_auto_catchup") == 1) {
121 c
.domNode
.appendChild(hsp
);
124 console
.log("restore selected ids: " + ids
);
126 for (var i
= 0; i
< ids
.length
; i
++) {
127 markHeadline(ids
[i
]);
132 $$("#headlines-frame > div[id*=RROW]").each(
134 if (!Element
.visible(child
))
135 new Effect
.Appear(child
, { duration
: 0.5 });
139 console
.log("no new headlines received");
141 var hsp
= $("headlines-spacer");
143 if (hsp
) hsp
.innerHTML
= "";
147 if (headlines_count
> 0)
148 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
151 for (var i
= 0; i
< articles
.length
; i
++) {
152 var a_id
= articles
[i
]['id'];
153 cache_set("article:" + a_id
, articles
[i
]['content']);
156 console
.log("no cached articles received");
159 // do not precache stuff after fresh feed
161 precache_headlines();
164 parse_counters(counters
);
169 console
.error("Invalid object received: " + transport
.responseText
);
170 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
171 __('Could not update headlines (invalid object received - see error console for details)') +
175 _infscroll_request_sent
= 0;
180 exception_error("headlines_callback2", e
, transport
);
184 function render_article(article
) {
186 dijit
.byId("headlines-wrap-inner").addChild(
187 dijit
.byId("content-insert"));
189 var c
= dijit
.byId("content-insert");
192 c
.domNode
.scrollTop
= 0;
195 c
.attr('content', article
);
197 correctHeadlinesOffset(getActiveArticleId());
204 exception_error("render_article", e
);
208 function showArticleInHeadlines(id
) {
212 selectArticles("none");
214 var crow
= $("RROW-" + id
);
218 var article_is_unread
= crow
.hasClassName("Unread");
220 crow
.removeClassName("Unread");
222 selectArticles('none');
224 var upd_img_pic
= $("FUPDPIC-" + id
);
226 var view_mode
= false;
229 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
230 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
235 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
236 upd_img_pic
.src
.match("fresh_sign.png"))) {
238 upd_img_pic
.src
= "images/blank_icon.gif";
240 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
242 } else if (article_is_unread
&& view_mode
== "all_articles") {
243 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
248 if (article_is_unread
)
249 _force_scheduled_update
= true;
252 exception_error("showArticleInHeadlines", e
);
256 function article_callback2(transport
, id
) {
258 console
.log("article_callback2 " + id
);
260 handle_rpc_json(transport
);
265 reply
= JSON
.parse(transport
.responseText
);
272 var upic
= $('FUPDPIC-' + id
);
274 if (upic
) upic
.src
= 'images/blank_icon.gif';
276 reply
.each(function(article
) {
277 if (active_post_id
== article
['id']) {
278 render_article(article
['content']);
280 cids_requested
.remove(article
['id']);
282 cache_set("article:" + article
['id'], article
['content']);
285 // if (id != last_requested_article) {
286 // console.log("requested article id is out of sequence, aborting");
291 console
.error("Invalid object received: " + transport
.responseText
);
293 render_article("<div class='whiteBox'>" +
294 __('Could not display article (invalid object received - see error console for details)') + "</div>");
300 if (!_infscroll_disable
&&
301 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
311 exception_error("article_callback2", e
, transport
);
317 console
.log("loading article: " + id
);
319 var cached_article
= cache_get("article:" + id
);
321 console
.log("cache check result: " + (cached_article
!= false));
325 var query
= "?op=article&method=view&id=" + param_escape(id
);
327 var neighbor_ids
= getRelativePostIds(id
);
329 /* only request uncached articles */
331 var cids_to_request
= [];
333 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
334 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
335 if (!cache_get("article:" + neighbor_ids
[i
])) {
336 cids_to_request
.push(neighbor_ids
[i
]);
337 cids_requested
.push(neighbor_ids
[i
]);
341 console
.log("additional ids: " + cids_to_request
.toString());
343 query
= query
+ "&cids=" + cids_to_request
.toString();
345 var crow
= $("RROW-" + id
);
346 var article_is_unread
= crow
.hasClassName("Unread");
349 showArticleInHeadlines(id
);
351 precache_headlines();
353 if (!cached_article
) {
355 var upic
= $('FUPDPIC-' + id
);
358 upic
.src
= getInitParam("sign_progress");
361 } else if (cached_article
&& article_is_unread
) {
363 query
= query
+ "&mode=prefetch";
365 render_article(cached_article
);
367 } else if (cached_article
) {
369 query
= query
+ "&mode=prefetch_old";
370 render_article(cached_article
);
372 // if we don't need to request any relative ids, we might as well skip
373 // the server roundtrip altogether
374 if (cids_to_request
.length
== 0) {
377 if (!_infscroll_disable
&&
378 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
390 last_requested_article
= id
;
394 if (article_is_unread
) {
395 var ctr
= getFeedUnread(getActiveFeedId(), activeFeedIsCat());
398 setFeedUnread(getActiveFeedId(), activeFeedIsCat(), ctr
- 1);
400 var cat
= parseInt(getFeedCategory(getActiveFeedId()));
403 ctr
= getFeedUnread(cat
, true);
406 setFeedUnread(cat
, true, ctr
- 1);
412 new Ajax
.Request("backend.php", {
414 onComplete: function(transport
) {
415 article_callback2(transport
, id
);
421 exception_error("view", e
);
425 function toggleMark(id
, client_only
) {
427 var query
= "?op=rpc&id=" + id
+ "&method=mark";
429 var img
= $("FMPIC-" + id
);
433 if (img
.src
.match("mark_unset")) {
434 img
.src
= img
.src
.replace("mark_unset", "mark_set");
435 img
.alt
= __("Unstar article");
436 query
= query
+ "&mark=1";
439 img
.src
= img
.src
.replace("mark_set", "mark_unset");
440 img
.alt
= __("Star article");
441 query
= query
+ "&mark=0";
444 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
447 new Ajax
.Request("backend.php", {
449 onComplete: function(transport
) {
450 handle_rpc_json(transport
);
455 exception_error("toggleMark", e
);
459 function togglePub(id
, client_only
, no_effects
, note
) {
461 var query
= "?op=rpc&id=" + id
+ "&method=publ";
463 if (note
!= undefined) {
464 query
= query
+ "¬e=" + param_escape(note
);
466 query
= query
+ "¬e=undefined";
469 var img
= $("FPPIC-" + id
);
473 if (img
.src
.match("pub_unset") || note
!= undefined) {
474 img
.src
= img
.src
.replace("pub_unset", "pub_set");
475 img
.alt
= __("Unpublish article");
476 query
= query
+ "&pub=1";
479 img
.src
= img
.src
.replace("pub_set", "pub_unset");
480 img
.alt
= __("Publish article");
482 query
= query
+ "&pub=0";
485 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
488 new Ajax
.Request("backend.php", {
490 onComplete: function(transport
) {
491 handle_rpc_json(transport
);
496 exception_error("togglePub", e
);
500 function moveToPost(mode
) {
504 var rows
= getVisibleArticleIds();
509 if (!$('RROW-' + active_post_id
)) {
510 active_post_id
= false;
513 if (active_post_id
== false) {
515 prev_id
= rows
[rows
.length
-1]
517 for (var i
= 0; i
< rows
.length
; i
++) {
518 if (rows
[i
] == active_post_id
) {
520 // Account for adjacent identical article ids.
521 if (i
> 0) prev_id
= rows
[i
-1];
523 for (var j
= i
+1; j
< rows
.length
; j
++) {
524 if (rows
[j
] != active_post_id
) {
534 if (mode
== "next") {
538 cdmExpandArticle(next_id
);
539 cdmScrollToArticleId(next_id
);
542 correctHeadlinesOffset(next_id
);
543 view(next_id
, getActiveFeedId());
548 if (mode
== "prev") {
551 cdmExpandArticle(prev_id
);
552 cdmScrollToArticleId(prev_id
);
554 correctHeadlinesOffset(prev_id
);
555 view(prev_id
, getActiveFeedId());
561 exception_error("moveToPost", e
);
565 function toggleSelected(id
, force_on
) {
568 var cb
= $("RCHK-" + id
);
569 var row
= $("RROW-" + id
);
572 if (row
.hasClassName('Selected') && !force_on
) {
573 row
.removeClassName('Selected');
574 if (cb
) cb
.checked
= false;
576 row
.addClassName('Selected');
577 if (cb
) cb
.checked
= true;
581 exception_error("toggleSelected", e
);
585 function toggleUnread_afh(effect
) {
588 var elem
= effect
.element
;
589 elem
.style
.backgroundColor
= "";
592 exception_error("toggleUnread_afh", e
);
596 function toggleUnread(id
, cmode
, effect
) {
599 var row
= $("RROW-" + id
);
601 if (cmode
== undefined || cmode
== 2) {
602 if (row
.hasClassName("Unread")) {
603 row
.removeClassName("Unread");
606 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
607 afterFinish
: toggleUnread_afh
,
608 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
612 row
.addClassName("Unread");
615 } else if (cmode
== 0) {
617 row
.removeClassName("Unread");
620 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
621 afterFinish
: toggleUnread_afh
,
622 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
625 } else if (cmode
== 1) {
626 row
.addClassName("Unread");
629 if (cmode
== undefined) cmode
= 2;
631 var query
= "?op=rpc&method=catchupSelected" +
632 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
634 // notify_progress("Loading, please wait...");
636 new Ajax
.Request("backend.php", {
638 onComplete: function(transport
) {
639 handle_rpc_json(transport
);
645 exception_error("toggleUnread", e
);
649 function selectionRemoveLabel(id
, ids
) {
652 if (!ids
) ids
= getSelectedArticleIds2();
654 if (ids
.length
== 0) {
655 alert(__("No articles are selected."));
659 var query
= "?op=rpc&method=removeFromLabel&ids=" +
660 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
664 new Ajax
.Request("backend.php", {
666 onComplete: function(transport
) {
667 handle_rpc_json(transport
);
668 show_labels_in_headlines(transport
);
672 exception_error("selectionAssignLabel", e
);
677 function selectionAssignLabel(id
, ids
) {
680 if (!ids
) ids
= getSelectedArticleIds2();
682 if (ids
.length
== 0) {
683 alert(__("No articles are selected."));
687 var query
= "?op=rpc&method=assignToLabel&ids=" +
688 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
692 new Ajax
.Request("backend.php", {
694 onComplete: function(transport
) {
695 handle_rpc_json(transport
);
696 show_labels_in_headlines(transport
);
700 exception_error("selectionAssignLabel", e
);
705 function selectionToggleUnread(set_state
, callback
, no_error
) {
707 var rows
= getSelectedArticleIds2();
709 if (rows
.length
== 0 && !no_error
) {
710 alert(__("No articles are selected."));
714 for (var i
= 0; i
< rows
.length
; i
++) {
715 var row
= $("RROW-" + rows
[i
]);
717 if (set_state
== undefined) {
718 if (row
.hasClassName("Unread")) {
719 row
.removeClassName("Unread");
721 row
.addClassName("Unread");
725 if (set_state
== false) {
726 row
.removeClassName("Unread");
729 if (set_state
== true) {
730 row
.addClassName("Unread");
735 if (rows
.length
> 0) {
739 if (set_state
== undefined) {
741 } else if (set_state
== true) {
743 } else if (set_state
== false) {
747 var query
= "?op=rpc&method=catchupSelected" +
748 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
750 notify_progress("Loading, please wait...");
752 new Ajax
.Request("backend.php", {
754 onComplete: function(transport
) {
755 handle_rpc_json(transport
);
756 if (callback
) callback(transport
);
762 exception_error("selectionToggleUnread", e
);
766 function selectionToggleMarked() {
769 var rows
= getSelectedArticleIds2();
771 if (rows
.length
== 0) {
772 alert(__("No articles are selected."));
776 for (var i
= 0; i
< rows
.length
; i
++) {
777 toggleMark(rows
[i
], true, true);
780 if (rows
.length
> 0) {
782 var query
= "?op=rpc&method=markSelected&ids=" +
783 param_escape(rows
.toString()) + "&cmode=2";
785 new Ajax
.Request("backend.php", {
787 onComplete: function(transport
) {
788 handle_rpc_json(transport
);
794 exception_error("selectionToggleMarked", e
);
798 function selectionTogglePublished() {
801 var rows
= getSelectedArticleIds2();
803 if (rows
.length
== 0) {
804 alert(__("No articles are selected."));
808 for (var i
= 0; i
< rows
.length
; i
++) {
809 togglePub(rows
[i
], true, true);
812 if (rows
.length
> 0) {
814 var query
= "?op=rpc&method=publishSelected&ids=" +
815 param_escape(rows
.toString()) + "&cmode=2";
817 new Ajax
.Request("backend.php", {
819 onComplete: function(transport
) {
820 handle_rpc_json(transport
);
826 exception_error("selectionToggleMarked", e
);
830 function getSelectedArticleIds2() {
834 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
836 rv
.push(child
.id
.replace("RROW-", ""));
842 function getLoadedArticleIds() {
845 var children
= $$("#headlines-frame > div[id*=RROW-]");
847 children
.each(function(child
) {
848 rv
.push(child
.id
.replace("RROW-", ""));
855 // mode = all,none,unread,invert
856 function selectArticles(mode
) {
859 var children
= $$("#headlines-frame > div[id*=RROW]");
861 children
.each(function(child
) {
862 var id
= child
.id
.replace("RROW-", "");
863 var cb
= $("RCHK-" + id
);
866 child
.addClassName("Selected");
868 } else if (mode
== "unread") {
869 if (child
.hasClassName("Unread")) {
870 child
.addClassName("Selected");
873 child
.removeClassName("Selected");
876 } else if (mode
== "invert") {
877 if (child
.hasClassName("Selected")) {
878 child
.removeClassName("Selected");
881 child
.addClassName("Selected");
886 child
.removeClassName("Selected");
892 exception_error("selectArticles", e
);
896 function catchupPage() {
898 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
900 var str
= __("Mark all visible articles in %s as read?");
902 str
= str
.replace("%s", fn
);
904 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
908 selectArticles('all');
909 selectionToggleUnread(false, 'viewCurrentFeed()', true);
910 selectArticles('none');
913 function deleteSelection() {
917 var rows
= getSelectedArticleIds2();
919 if (rows
.length
== 0) {
920 alert(__("No articles are selected."));
924 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
927 if (getActiveFeedId() != 0) {
928 str
= __("Delete %d selected articles in %s?");
930 str
= __("Delete %d selected articles?");
933 str
= str
.replace("%d", rows
.length
);
934 str
= str
.replace("%s", fn
);
936 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
940 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
944 new Ajax
.Request("backend.php", {
946 onComplete: function(transport
) {
947 handle_rpc_json(transport
);
952 exception_error("deleteSelection", e
);
956 function archiveSelection() {
960 var rows
= getSelectedArticleIds2();
962 if (rows
.length
== 0) {
963 alert(__("No articles are selected."));
967 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
971 if (getActiveFeedId() != 0) {
972 str
= __("Archive %d selected articles in %s?");
975 str
= __("Move %d archived articles back?");
979 str
= str
.replace("%d", rows
.length
);
980 str
= str
.replace("%s", fn
);
982 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
986 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
990 for (var i
= 0; i
< rows
.length
; i
++) {
991 cache_delete("article:" + rows
[i
]);
994 new Ajax
.Request("backend.php", {
996 onComplete: function(transport
) {
997 handle_rpc_json(transport
);
1002 exception_error("archiveSelection", e
);
1006 function catchupSelection() {
1010 var rows
= getSelectedArticleIds2();
1012 if (rows
.length
== 0) {
1013 alert(__("No articles are selected."));
1017 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1019 var str
= __("Mark %d selected articles in %s as read?");
1021 str
= str
.replace("%d", rows
.length
);
1022 str
= str
.replace("%s", fn
);
1024 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1028 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1031 exception_error("catchupSelection", e
);
1035 function editArticleTags(id
) {
1036 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1038 if (dijit
.byId("editTagsDlg"))
1039 dijit
.byId("editTagsDlg").destroyRecursive();
1041 dialog
= new dijit
.Dialog({
1043 title
: __("Edit article Tags"),
1044 style
: "width: 600px",
1045 execute: function() {
1046 if (this.validate()) {
1047 var query
= dojo
.objectToQuery(this.attr('value'));
1049 notify_progress("Saving article tags...", true);
1051 new Ajax
.Request("backend.php", {
1053 onComplete: function(transport
) {
1057 var data
= JSON
.parse(transport
.responseText
);
1060 var tags_str
= article
.tags
;
1061 var id
= tags_str
.id
;
1063 var tags
= $("ATSTR-" + id
);
1064 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1066 if (tags
) tags
.innerHTML
= tags_str
.content
;
1067 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1069 cache_delete("article:" + id
);
1078 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1079 dojo
.disconnect(tmph
);
1081 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1082 "backend.php?op=rpc&method=completeTags",
1083 { tokens
: ',', paramName
: "search" });
1090 function cdmScrollToArticleId(id
) {
1092 var ctr
= $("headlines-frame");
1093 var e
= $("RROW-" + id
);
1095 if (!e
|| !ctr
) return;
1097 ctr
.scrollTop
= e
.offsetTop
;
1100 exception_error("cdmScrollToArticleId", e
);
1104 function getActiveArticleId() {
1105 return active_post_id
;
1108 function postMouseIn(id
) {
1109 post_under_pointer
= id
;
1112 function postMouseOut(id
) {
1113 post_under_pointer
= false;
1116 function headlines_scroll_handler(e
) {
1118 var hsp
= $("headlines-spacer");
1120 if (!_infscroll_disable
) {
1121 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1122 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1125 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1126 __("Loading, please wait...");
1128 loadMoreHeadlines();
1133 if (hsp
) hsp
.innerHTML
= "";
1136 if (getInitParam("cdm_auto_catchup") == 1) {
1138 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1140 if ($("headlines-frame").scrollTop
>
1141 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1143 var id
= child
.id
.replace("RROW-", "");
1145 if (catchup_id_batch
.indexOf(id
) == -1)
1146 catchup_id_batch
.push(id
);
1148 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1152 if (catchup_id_batch
.length
> 0) {
1153 window
.clearTimeout(catchup_timeout_id
);
1155 if (!_infscroll_request_sent
) {
1156 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1163 console
.warn("headlines_scroll_handler: " + e
);
1167 function catchupBatchedArticles() {
1169 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1171 var query
= "?op=rpc&method=catchupSelected" +
1172 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1174 new Ajax
.Request("backend.php", {
1176 onComplete: function(transport
) {
1177 handle_rpc_json(transport
);
1179 catchup_id_batch
.each(function(id
) {
1180 var elem
= $("RROW-" + id
);
1181 if (elem
) elem
.removeClassName("Unread");
1184 catchup_id_batch
= [];
1189 exception_error("catchupBatchedArticles", e
);
1193 function catchupRelativeToArticle(below
, id
) {
1197 if (!id
) id
= getActiveArticleId();
1200 alert(__("No article is selected."));
1204 var visible_ids
= getVisibleArticleIds();
1206 var ids_to_mark
= new Array();
1209 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1210 if (visible_ids
[i
] != id
) {
1211 var e
= $("RROW-" + visible_ids
[i
]);
1213 if (e
&& e
.hasClassName("Unread")) {
1214 ids_to_mark
.push(visible_ids
[i
]);
1221 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1222 if (visible_ids
[i
] != id
) {
1223 var e
= $("RROW-" + visible_ids
[i
]);
1225 if (e
&& e
.hasClassName("Unread")) {
1226 ids_to_mark
.push(visible_ids
[i
]);
1234 if (ids_to_mark
.length
== 0) {
1235 alert(__("No articles found to mark"));
1237 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1239 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1241 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1242 var e
= $("RROW-" + ids_to_mark
[i
]);
1243 e
.removeClassName("Unread");
1246 var query
= "?op=rpc&method=catchupSelected" +
1247 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1249 new Ajax
.Request("backend.php", {
1251 onComplete: function(transport
) {
1252 handle_rpc_json(transport
);
1259 exception_error("catchupRelativeToArticle", e
);
1263 function cdmExpandArticle(id
) {
1268 var elem
= $("CICD-" + active_post_id
);
1270 var upd_img_pic
= $("FUPDPIC-" + id
);
1272 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1273 upd_img_pic
.src
.match("fresh_sign.png"))) {
1275 upd_img_pic
.src
= "images/blank_icon.gif";
1278 if (id
== active_post_id
&& Element
.visible(elem
))
1281 selectArticles("none");
1283 var old_offset
= $("RROW-" + id
).offsetTop
;
1285 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1287 Element
.show("CEXC-" + active_post_id
);
1290 active_post_id
= id
;
1292 elem
= $("CICD-" + id
);
1294 if (!Element
.visible(elem
)) {
1296 Element
.hide("CEXC-" + id
);
1298 if ($("CWRAP-" + id
).innerHTML
== "") {
1300 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1302 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1303 __("Loading, please wait...") + "</div>";
1305 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1307 var neighbor_ids
= getRelativePostIds(id
);
1309 /* only request uncached articles */
1310 var cids_to_request
= [];
1312 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1313 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1314 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1315 cids_to_request
.push(neighbor_ids
[i
]);
1316 cids_requested
.push(neighbor_ids
[i
]);
1320 console
.log("additional ids: " + cids_to_request
.toString());
1322 query
= query
+ "&cids=" + cids_to_request
.toString();
1326 new Ajax
.Request("backend.php", {
1328 onComplete: function(transport
) {
1330 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1332 handle_rpc_json(transport
);
1334 var reply
= JSON
.parse(transport
.responseText
);
1336 reply
.each(function(article
) {
1337 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1338 cids_requested
.remove(article
['id']);
1345 var new_offset
= $("RROW-" + id
).offsetTop
;
1347 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1349 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1350 $("headlines-frame").scrollTop
= new_offset
;
1352 toggleUnread(id
, 0, true);
1356 exception_error("cdmExpandArticle", e
);
1362 function fixHeadlinesOrder(ids
) {
1364 for (var i
= 0; i
< ids
.length
; i
++) {
1365 var e
= $("RROW-" + ids
[i
]);
1369 e
.removeClassName("even");
1370 e
.addClassName("odd");
1372 e
.removeClassName("odd");
1373 e
.addClassName("even");
1378 exception_error("fixHeadlinesOrder", e
);
1382 function getArticleUnderPointer() {
1383 return post_under_pointer
;
1386 function zoomToArticle(event
, id
) {
1388 var cached_article
= cache_get("article: " + id
);
1390 if (dijit
.byId("ATAB-" + id
))
1391 if (!event
|| !event
.shiftKey
)
1392 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1394 if (dijit
.byId("ATSTRTIP-" + id
))
1395 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1397 if (cached_article
) {
1398 //closeArticlePanel();
1400 var article_pane
= new dijit
.layout
.ContentPane({
1401 title
: __("Loading...") , content
: cached_article
,
1402 style
: 'padding : 0px;',
1406 dijit
.byId("content-tabs").addChild(article_pane
);
1408 if (!event
|| !event
.shiftKey
)
1409 dijit
.byId("content-tabs").selectChild(article_pane
);
1411 if ($("PTITLE-" + id
))
1412 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1416 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1418 notify_progress("Loading, please wait...", true);
1420 new Ajax
.Request("backend.php", {
1422 onComplete: function(transport
) {
1425 var reply
= JSON
.parse(transport
.responseText
);
1428 //closeArticlePanel();
1430 var content
= reply
[0]['content'];
1432 var article_pane
= new dijit
.layout
.ContentPane({
1433 title
: "article-" + id
, content
: content
,
1434 style
: 'padding : 0px;',
1438 dijit
.byId("content-tabs").addChild(article_pane
);
1440 if (!event
|| !event
.shiftKey
)
1441 dijit
.byId("content-tabs").selectChild(article_pane
);
1443 if ($("PTITLE-" + id
))
1444 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1451 exception_error("zoomToArticle", e
);
1455 function scrollArticle(offset
) {
1458 var ci
= $("content-insert");
1460 ci
.scrollTop
+= offset
;
1463 var hi
= $("headlines-frame");
1465 hi
.scrollTop
+= offset
;
1470 exception_error("scrollArticle", e
);
1474 function show_labels_in_headlines(transport
) {
1476 var data
= JSON
.parse(transport
.responseText
);
1479 data
['info-for-headlines'].each(function(elem
) {
1480 var ctr
= $("HLLCTR-" + elem
.id
);
1482 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1485 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1489 exception_error("show_labels_in_headlines", e
);
1493 /* function toggleHeadlineActions() {
1495 var e = $("headlineActionsBody");
1496 var p = $("headlineActionsDrop");
1498 if (!Element.visible(e)) {
1505 e.style.left = (p.offsetLeft + 1) + "px";
1506 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1509 exception_error("toggleHeadlineActions", e);
1513 /* function publishWithNote(id, def_note) {
1515 if (!def_note) def_note = '';
1517 var note = prompt(__("Please enter a note for this article:"), def_note);
1519 if (note != undefined) {
1520 togglePub(id, false, false, note);
1524 exception_error("publishWithNote", e);
1528 function dismissArticle(id
) {
1530 var elem
= $("RROW-" + id
);
1532 toggleUnread(id
, 0, true);
1534 new Effect
.Fade(elem
, {duration
: 0.5});
1536 active_post_id
= false;
1539 exception_error("dismissArticle", e
);
1543 function dismissSelectedArticles() {
1546 var ids
= getVisibleArticleIds();
1550 for (var i
= 0; i
< ids
.length
; i
++) {
1551 var elem
= $("RROW-" + ids
[i
]);
1553 if (elem
.className
&& elem
.hasClassName("Selected") &&
1554 ids
[i
] != active_post_id
) {
1555 new Effect
.Fade(elem
, {duration
: 0.5});
1563 selectionToggleUnread(false);
1565 fixHeadlinesOrder(tmp
);
1568 exception_error("dismissSelectedArticles", e
);
1572 function dismissReadArticles() {
1575 var ids
= getVisibleArticleIds();
1578 for (var i
= 0; i
< ids
.length
; i
++) {
1579 var elem
= $("RROW-" + ids
[i
]);
1581 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1582 !elem
.hasClassName("Selected")) {
1584 new Effect
.Fade(elem
, {duration
: 0.5});
1590 fixHeadlinesOrder(tmp
);
1593 exception_error("dismissSelectedArticles", e
);
1597 function getVisibleArticleIds() {
1602 getLoadedArticleIds().each(function(id
) {
1603 var elem
= $("RROW-" + id
);
1604 if (elem
&& Element
.visible(elem
))
1609 exception_error("getVisibleArticleIds", e
);
1615 function cdmClicked(event
, id
) {
1617 //var shift_key = event.shiftKey;
1621 if (!event
.ctrlKey
) {
1623 if (!getInitParam("cdm_expanded")) {
1624 return cdmExpandArticle(id
);
1627 selectArticles("none");
1630 var elem
= $("RROW-" + id
);
1633 elem
.removeClassName("Unread");
1635 var upd_img_pic
= $("FUPDPIC-" + id
);
1637 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1638 upd_img_pic
.src
.match("fresh_sign.png"))) {
1640 upd_img_pic
.src
= "images/blank_icon.gif";
1643 active_post_id
= id
;
1645 var query
= "?op=rpc&method=catchupSelected" +
1646 "&cmode=0&ids=" + param_escape(id
);
1648 new Ajax
.Request("backend.php", {
1650 onComplete: function(transport
) {
1651 handle_rpc_json(transport
);
1658 toggleSelected(id
, true);
1659 toggleUnread(id
, 0, false);
1660 zoomToArticle(event
, id
);
1664 exception_error("cdmClicked");
1670 function postClicked(event
, id
) {
1673 if (!event
.ctrlKey
) {
1676 postOpenInNewTab(event
, id
);
1681 exception_error("postClicked");
1685 function hlOpenInNewTab(event
, id
) {
1686 toggleUnread(id
, 0, false);
1687 zoomToArticle(event
, id
);
1690 function postOpenInNewTab(event
, id
) {
1691 closeArticlePanel(id
);
1692 zoomToArticle(event
, id
);
1695 function hlClicked(event
, id
) {
1697 if (event
.which
== 2) {
1700 } else if (event
.altKey
) {
1701 openArticleInNewWindow(id
);
1702 } else if (!event
.ctrlKey
) {
1707 toggleUnread(id
, 0, false);
1708 zoomToArticle(event
, id
);
1713 exception_error("hlClicked");
1717 function getFirstVisibleHeadlineId() {
1718 var rows
= getVisibleArticleIds();
1723 function getLastVisibleHeadlineId() {
1724 var rows
= getVisibleArticleIds();
1725 return rows
[rows
.length
-1];
1728 function openArticleInNewWindow(id
) {
1729 toggleUnread(id
, 0, false);
1730 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1733 function isCdmMode() {
1734 return getInitParam("combined_display_mode");
1737 function markHeadline(id
) {
1738 var row
= $("RROW-" + id
);
1740 var check
= $("RCHK-" + id
);
1743 check
.checked
= true;
1746 row
.addClassName("Selected");
1750 function getRelativePostIds(id
, limit
) {
1756 if (!limit
) limit
= 6; //3
1758 var ids
= getVisibleArticleIds();
1760 for (var i
= 0; i
< ids
.length
; i
++) {
1762 for (var k
= 1; k
<= limit
; k
++) {
1763 //if (i > k-1) tmp.push(ids[i-k]);
1764 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1771 exception_error("getRelativePostIds", e
);
1777 function correctHeadlinesOffset(id
) {
1781 var container
= $("headlines-frame");
1782 var row
= $("RROW-" + id
);
1784 var viewport
= container
.offsetHeight
;
1786 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1787 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1789 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1790 //console.log("Vport: " + viewport);
1792 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1793 container
.scrollTop
= row
.offsetTop
;
1794 } else if (rel_offset_bottom
> viewport
) {
1796 /* doesn't properly work with Opera in some cases because
1797 Opera fucks up element scrolling */
1799 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1803 exception_error("correctHeadlinesOffset", e
);
1808 function headlineActionsChange(elem
) {
1811 elem
.attr('value', 'false');
1813 exception_error("headlineActionsChange", e
);
1817 function closeArticlePanel() {
1819 var tabs
= dijit
.byId("content-tabs");
1820 var child
= tabs
.selectedChildWidget
;
1822 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1823 tabs
.removeChild(child
);
1826 if (dijit
.byId("content-insert"))
1827 dijit
.byId("headlines-wrap-inner").removeChild(
1828 dijit
.byId("content-insert"));
1832 function initHeadlinesMenu() {
1834 if (dijit
.byId("headlinesMenu"))
1835 dijit
.byId("headlinesMenu").destroyRecursive();
1840 nodes
= $$("#headlines-frame > div[id*=RROW]");
1842 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1845 nodes
.each(function(node
) {
1849 var menu
= new dijit
.Menu({
1850 id
: "headlinesMenu",
1854 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1855 var callerNode
= event
.target
, match
= null, tries
= 0;
1857 while (match
== null && callerNode
&& tries
<= 3) {
1858 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1859 callerNode
= callerNode
.parentNode
;
1863 if (match
) this.callerRowId
= parseInt(match
[1]);
1867 /* if (!isCdmMode())
1868 menu.addChild(new dijit.MenuItem({
1869 label: __("View article"),
1870 onClick: function(event) {
1871 view(this.getParent().callerRowId);
1874 menu
.addChild(new dijit
.MenuItem({
1875 label
: __("Open original article"),
1876 onClick: function(event
) {
1877 openArticleInNewWindow(this.getParent().callerRowId
);
1880 menu
.addChild(new dijit
.MenuItem({
1881 label
: __("View in a tt-rss tab"),
1882 onClick: function(event
) {
1883 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1886 menu
.addChild(new dijit
.MenuSeparator());
1888 menu
.addChild(new dijit
.MenuItem({
1889 label
: __("Mark above as read"),
1890 onClick: function(event
) {
1891 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1894 menu
.addChild(new dijit
.MenuItem({
1895 label
: __("Mark below as read"),
1896 onClick: function(event
) {
1897 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1901 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1905 menu
.addChild(new dijit
.MenuSeparator());
1907 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1908 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1910 labels
.each(function(label
) {
1911 var id
= label
.id
[0];
1912 var bare_id
= id
.substr(id
.indexOf(":")+1);
1913 var name
= label
.name
[0];
1915 bare_id
= -11-bare_id
;
1917 labelAddMenu
.addChild(new dijit
.MenuItem({
1920 onClick: function(event
) {
1921 selectionAssignLabel(this.labelId
,
1922 [this.getParent().ownerMenu
.callerRowId
]);
1925 labelDelMenu
.addChild(new dijit
.MenuItem({
1928 onClick: function(event
) {
1929 selectionRemoveLabel(this.labelId
,
1930 [this.getParent().ownerMenu
.callerRowId
]);
1935 menu
.addChild(new dijit
.PopupMenuItem({
1936 label
: __("Assign label"),
1937 popup
: labelAddMenu
,
1940 menu
.addChild(new dijit
.PopupMenuItem({
1941 label
: __("Remove label"),
1942 popup
: labelDelMenu
,
1950 exception_error("initHeadlinesMenu", e
);
1955 function player(elem
) {
1956 var aid
= elem
.getAttribute("audio-id");
1957 var status
= elem
.getAttribute("status");
1965 elem
.innerHTML
= __("Playing...");
1966 elem
.title
= __("Click to pause");
1967 elem
.addClassName("playing");
1971 elem
.innerHTML
= __("Play");
1972 elem
.title
= __("Click to play");
1973 elem
.removeClassName("playing");
1976 elem
.setAttribute("status", status
);
1978 alert("Your browser doesn't seem to support HTML5 audio.");
1982 function cache_set(id
, obj
) {
1983 //console.log("cache_set: " + id);
1986 sessionStorage
[id
] = obj
;
1988 sessionStorage
.clear();
1992 function cache_get(id
) {
1994 return sessionStorage
[id
];
1997 function cache_clear() {
1999 sessionStorage
.clear();
2002 function cache_delete(id
) {
2004 sessionStorage
.removeItem(id
);
2007 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2008 if (toolbar_obj
&& content_obj
) {
2009 cache_set("feed:" + feed
+ ":" + is_cat
,
2010 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2013 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2016 obj
= JSON
.parse(obj
);
2018 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2019 if (content_obj
) obj
.content
= content_obj
;
2021 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2025 console
.warn("cache_headlines failed: " + e
);
2030 function render_local_headlines(feed
, is_cat
, obj
) {
2033 dijit
.byId("headlines-toolbar").attr('content',
2036 dijit
.byId("headlines-frame").attr('content',
2039 dojo
.parser
.parse('headlines-toolbar');
2041 $("headlines-frame").scrollTop
= 0;
2042 selectArticles('none');
2043 setActiveFeedId(feed
, is_cat
);
2044 initHeadlinesMenu();
2046 precache_headlines();
2049 exception_error("render_local_headlines", e
);
2053 function precache_headlines_idle() {
2055 if (!feed_precache_timeout_id
) {
2056 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2059 feeds
.each(function(item
) {
2060 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2061 uncached
.push(item
);
2064 if (uncached
.length
> 0) {
2065 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2066 viewfeed(rf
[0], '', rf
[1], 0, true);
2069 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2072 exception_error("precache_headlines_idle", e
);
2076 function precache_headlines() {
2079 if (!feed_precache_timeout_id
) {
2080 feed_precache_timeout_id
= window
.setTimeout(function() {
2081 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2082 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2084 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2085 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2087 if (nf
!= nuf
&& nf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2088 viewfeed(nf
[0], '', nf
[1], 0, true);
2090 window
.setTimeout(function() {
2091 feed_precache_timeout_id
= false;
2097 exception_error("precache_headlines", e
);